/ship keeps its review count and grant claims honest, and a symlinked harness pin needs a fresh review (GST-3463) (#4703)

/ship now keeps a PR's earlier runs when it rewrites the PR description,
so later runs count review rounds correctly, and it refuses to start
reviewers when it could not save a granted round's claim.

Why: both slips let a PR get more review rounds than the two-round limit
allows, without anyone seeing it.

Nothing to do: the fixes apply on the next /ship run.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Review-Finding: p1/red-team#1 reader=red-team
Review-Finding: p1/red-team#3 reader=red-team
This commit is contained in:
Garry Tanandcapy-ai[bot] authored and GitHub committed 2026-11-22 13:59:38 +00:00
1 parent f528f5bacc
commit 45e33b5e7b
15 files changed
+195 -23

No files matched your search

+12 -3
View File
@@ -53,7 +53,7 @@ import { approvalForReceipt } from '../lib/approval-citations';
import {
CARRY_NAMED_PATHS,
bindReceipt, carryReceipt, recheckCarried, classifyCarryPath, computeCensus, extractReceipt, landedStackParent, missingIssueLines, orderReceipt, parseReviewLoop, placeReceipt, planCarry, planTreeCarry,
receiptIssuesFrom, receiptRuns, receiptSummaryLine, renderCensus, renderReceiptBlock, unruledOpenBlockers, validateReceipt, type CensusPr,
RUNS_FENCE, receiptIssuesFrom, receiptRuns, receiptSummaryLine, renderCensus, renderReceiptBlock, unruledOpenBlockers, validateReceipt, type CensusPr,
} from '../lib/ship-receipt';
import { checkDocsCaps, docsCapLine, docsExceptionLine, parseReceiptDocs } from '../lib/ship-receipt-docs';
import { comparePath, contextPacket, PACKET_SECTION_CAP, readScopedReview, touchedPaths } from '../lib/ship-patch';
@@ -68,7 +68,7 @@ import { appliedGateDispositions, gateDispositionText, publicGateDisposition } f
import { securityFingerprints } from '../lib/security-findings';
import { laneExceptionBodyLines } from '../lib/test-lane-exception';
import { abandonMarker, grantedStop, grantMarker, historyLine, placeRunEntry, prReviewHistory, receiptedRun, reviewRoute, runStub, stopFrom, stopMarker } from '../lib/pr-review-history';
import { changeRunRecord } from '../lib/ship-run-record';
import { changeRunRecord, readRunRecord } from '../lib/ship-run-record';
import { splitAgentNotes, withAgentNotes } from '../lib/agent-notes';
import { grantFor, publicRoundGrant, readReviewRoundGrants, type ReviewRoundGrant } from '../lib/review-round-grant';
import { readMechanicalLines } from '../lib/ship-mechanical';
@@ -439,7 +439,15 @@ async function cmdWrite(rest: string[], json: boolean): Promise<number> {
const closed = [...(receipt.cleared_by_grant ? [`Closed by grant ${receipt.cleared_by_grant.approval}: ${receipt.cleared_by_grant.ids.join(', ')} (the granted fix-check of run ${receipt.cleared_by_grant.run} read the fix clean)`] : []),
...(receipt.cleared_by_trailer ?? []).map(t => `Closed by fix ${t.commit.slice(0, 12)}: ${t.id} (a later full review at ${t.review.slice(0, 12)} read it clean)`)];
if (body) {
const text = fs.existsSync(body) ? fs.readFileSync(body, 'utf8') : '';
let text = fs.existsSync(body) ? fs.readFileSync(body, 'utf8') : '';
const pr = flag(rest, '--pr');
if (pr && fs.existsSync(body) && !extractReceipt(text).found && !receiptRuns(text).length) {
const live = readBody(['--pr', pr, ...(flag(rest, '--repo') ? ['--repo', flag(rest, '--repo')!] : [])]);
const prior = live.ok ? extractReceipt(live.body).receipt : undefined;
const runs = live.ok ? receiptRuns(live.body) : [];
if (!live.ok) process.stderr.write(`RECEIPT_RUNS: PR #${pr}'s earlier runs were not read (${live.why}), so ${body} keeps only this run; fix: ${live.fix}\n`);
else if (prior || runs.length) text = withAgentNotes(text, [(splitAgentNotes(text).notes ?? '').trim(), prior ? renderReceiptBlock(prior) : '', runs.length ? '```' + RUNS_FENCE + '\n' + runs.map(r => JSON.stringify(r)).join('\n') + '\n```\n' : ''].filter(Boolean).join('\n\n'));
}
const notes = splitAgentNotes(text).notes ?? '';
const lines = closed.filter(l => !notes.includes(l));
fs.writeFileSync(body, placeReceipt(lines.length ? withAgentNotes(text, [notes.trim(), ...lines].filter(Boolean).join('\n\n')) : text, receipt));
@@ -1061,6 +1069,7 @@ function cmdClaim(rest: string[]): number {
const first = receiptRuns(again.body).find(r => r.mark === 'grant' && r.grant === id);
if (first?.run !== run) { process.stderr.write(`${resultLine('gstack-ship-receipt claim', 'GRANT_SPENT', `grant ${id} was claimed by run ${first?.run ?? 'another run'} while this run claimed it: a grant buys one round; the lane or its Captain records a new one`)}\n`); return EXIT.refused; }
const recorded = changeRunRecord(repoRoot, 'claim', run, { claim: { grant: id, ...(g.stop_run ? { stop_run: g.stop_run } : {}), stop_head: g.head, findings: g.findings ?? [], pr: g.pr } });
if (!recorded.ok && readRunRecord(repoRoot).kind !== 'none') { process.stderr.write(`gstack-ship-receipt claim: the run record did not take the claim (${recorded.why}); not claimed, so do not dispatch: the PR body already holds run ${run}'s claim, so rerun claim with this same --run once the record is writable (a new run id reads GRANT_SPENT)\n`); return EXIT.fail; }
process.stdout.write(`GRANT_CLAIMED: grant=${id} kind=${g.kind} run=${run} head=${g.head.slice(0, 12)}\n${recorded.ok ? '' : `RUN_RECORD: claim not recorded (${recorded.why})\n`}`);
return EXIT.ok;
}