/ship can finish when its docs audit fixes a reviewed doc after the last review round (GST-3532) (#4708)

/ship no longer gets stuck when its last-step docs audit corrects a line
in a doc the review read, after the PR's last allowed review round.

Why: gbrain#10059 had to skip its /ship record to land, because the only
fix /ship offered was a third review round, which the two-round limit
forbids.

Nothing to do: the next /ship run asks for one small read of the audit's
change on its own.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Review-Finding: p1/specialist-batched#1 reader=testing
Review-Finding: p1/red-team#1 reader=red-team
Review-Finding: p1/red-team#2 reader=red-team
Review-Finding: p2/outside-voice#1 reader=outside-voice
Review-Finding: p2/adversarial-native#1 reader=adversarial-native
Review-Finding: p2/adversarial-native#2 reader=adversarial-native
This commit is contained in:
Garry Tanandcapy-ai[bot] authored and GitHub committed 2026-11-22 15:25:28 +00:00
1 parent a88cc7c1be
commit 4ae9ec7b00
18 files changed
+274 -21

No files matched your search

+48
View File
@@ -0,0 +1,48 @@
/**
* The scoped read of a Step 14.5 docs-audit edit to a doc the reviewers read (GST-3532, gbrain#10059). Write's docs-audit
* exception (lib/ship-receipt-depth.ts writeExcludeBinds) binds docs the exclusion hides or keeps because code names them; a doc
* the review keeps for its own content (a gate path, gate tags, agent prose or a secret line) was read by the reviewers, so its
* edit after the review needs a reader too. Instead of another review round, which the round cap forbids, one scoped reader reads
* a packet of that audit change, the way carry's scoped review reads spliced hunks; it is not a review round under R51. Its clean
* record, bound to the head and the packet, binds into the receipt as `docs_audit_read`. A finding, another head or packet, or an
* edit over BOUNDED_LINES lines still refuses.
*/
import { spawnSync } from './spawn-sync';
import { createHash } from 'node:crypto';
import { BOUNDED_LINES, packetBrief, readScopedReview } from './ship-patch';
/** Kept reasons that mean the reviewers read the doc for its own content; any other kept reason keeps refusing. */
export const READ_REASONS: readonly string[] = ['gate-path', 'gate-tagged', 'agent-prose', 'secret-line'];
export interface DocsAuditRead { paths: string[]; reviewer: string; packet_sha256: string }
export type DocsAuditPacket = { ok: true; text: string; sha256: string } | { ok: false; why: string };
/** The packet for the audit's change to `files`, each from its content before the audit (a blob id, or null when the audit added it) to HEAD's. */
export function docsAuditPacket(root: string, head: string, files: ReadonlyArray<{ path: string; before: string | null }>): DocsAuditPacket {
const git = (args: string[], input?: string) => { const r = spawnSync('git', ['-c', 'core.quotePath=false', ...args], { cwd: root, input, encoding: 'utf8', timeout: 60_000, maxBuffer: 64 * 1024 * 1024 }); return r.status === 0 ? r.stdout : null; };
const sections: string[] = [];
for (const { path: p, before } of files) {
const after = git(['rev-parse', '--verify', '--quiet', `${head}:${p}`])?.trim();
const from = before ?? git(['hash-object', '-w', '--stdin'], '')?.trim();
const diff = after && from ? git(['diff', '--no-color', '--no-ext-diff', '-U3', from, after]) : null;
if (diff === null) return { ok: false, why: `git could not diff ${p} from before the audit to HEAD` };
const lines = diff.split('\n');
const at = lines.findIndex(l => l.startsWith('@@'));
if (at < 0 && diff.trim()) return { ok: false, why: `git shows the audit's change to ${p} with no text hunk (a binary or very large file), so one scoped reader cannot read it` };
const hunks = at < 0 ? [] : lines.slice(at);
const changed = hunks.filter(l => /^[+-]/.test(l)).length;
if (changed > BOUNDED_LINES) return { ok: false, why: `the audit changed ${changed} lines of ${p}, a doc the reviewers read: too large for one scoped reader (at most ${BOUNDED_LINES})` };
sections.push(`## ${p}\n\n\`\`\`diff\n${hunks.join('\n').trimEnd()}\n\`\`\`\n`);
}
const text = [`# Scoped review: the docs audit edited docs the reviewers read\n\nHEAD ${head.slice(0, 12)}. After the review, /ship's Step 14.5 docs audit changed these docs, which the review read for their own content (a gate path, gate tags, agent prose or a secret line). Read each change as gate text: does it still say what the code does, and does it change what a gate, cap, reviewer, approval, secret or money rule says? This one read replaces another review round (docs/review-policy.md#docs-audit-edits-to-reviewed-docs). Report clean, or findings at the blocking floor.\n`,
...sections, `## Targeted brief\n\n${packetBrief()}\n`].join('\n');
return { ok: true, text, sha256: createHash('sha256').update(text).digest('hex') };
}
/** The reader's record for this packet at `head`: clean, covering every file, bound to the packet; else why it does not stand. */
export function readDocsAuditRead(file: string, head: string, paths: readonly string[], sha256: string): { ok: true; read: DocsAuditRead } | { ok: false; why: string } {
const r = readScopedReview(file, { head }, paths);
if (!r.ok) return { ok: false, why: `--docs-audit-read: ${r.message}` };
if (r.review.packet_sha256 !== sha256) return { ok: false, why: `--docs-audit-read: the record's packet_sha256 is ${r.review.packet_sha256?.slice(0, 12) ?? 'missing'}, not ${sha256.slice(0, 12)}: rerun the reader on the packet write names` };
return { ok: true, read: { paths: [...paths], reviewer: r.review.reviewer, packet_sha256: sha256 } };
}
+3
View File
@@ -150,6 +150,8 @@ export interface ShipReceipt {
review_exclude?: { source: string; patterns: string[]; applied: string[]; excluded: number; excluded_bytes: number; kept: number; gate_tagged: string[]; patterns_sha256: string; list_sha256: string; digest: string };
/** The base policy failed only on its exclusion keys, so they were set aside and every file was reviewed (GST-3399): the policy's source and its errors. */
review_exclude_fallback?: { source: string; errors: string[] };
/** The scoped reader's clean read of Step 14.5 docs-audit edits to docs the review read (lib/docs-audit-read.ts, GST-3532). */
docs_audit_read?: { paths: string[]; reviewer: string; packet_sha256: string };
/** Routine stops the run recorded and went on past instead of waiting for a Captain (plan K1; GSTA-258 L5 writes them): one record per stop. */
no_stop?: Array<{ class: NoStopClass; reason: string; evidence: string }>;
}
@@ -289,6 +291,7 @@ export const ARTIFACT_SCHEMAS = {
review_targeted: { type: 'object', required: ['classes', 'rules', 'brief_sha', 'product_patch_id', 'status', 'findings', 'raised_by'], properties: { classes: { type: 'array', items: { enum: ['money', 'gate', 'auth', 'secret'] } }, rules: str, brief_sha: str, product_patch_id: str, status: { enum: ['done', 'failed', 'not-run'] }, findings: { type: 'integer', minimum: 0 }, raised_by: str } },
review_exclude: { type: 'object', required: ['source', 'patterns', 'applied', 'excluded', 'excluded_bytes', 'kept', 'gate_tagged', 'patterns_sha256', 'list_sha256', 'digest'], properties: { source: str, patterns: strList, applied: strList, excluded: { type: 'integer', minimum: 0 }, excluded_bytes: { type: 'integer', minimum: 0 }, kept: { type: 'integer', minimum: 0 }, gate_tagged: strList, patterns_sha256: str, list_sha256: str, digest: str } },
review_exclude_fallback: { type: 'object', required: ['source', 'errors'], properties: { source: str, errors: strList } },
docs_audit_read: { type: 'object', required: ['paths', 'reviewer', 'packet_sha256'], properties: { paths: strList, reviewer: str, packet_sha256: str } },
review_loop_exception: { type: 'object', required: ['accepted_by', 'date', 'via', 'reason'], properties: { accepted_by: str, date: str, via: str, reason: str, fix_check: { type: 'object', required: ['head', 'findings'], properties: { head: str, findings: { type: 'integer', minimum: 0 }, files: strList } }, second_pass: { type: 'object', required: ['head', 'deferred'], properties: { head: str, deferred: strList } } } },
review_round_grants: { type: 'array', items: { type: 'object', required: ['kind', 'head', 'pr', 'by', 'reason', 'at', 'approval'], properties: { kind: { enum: ['extra-round', 'fix-check'] }, head: str, pr: { type: 'integer', minimum: 1 }, by: str, reason: str, at: str, approval: str, stop_run: str, findings: { type: 'array', items: str } } } },
cleared_by_grant: { type: 'object', required: ['approval', 'run', 'ids'], properties: { approval: str, run: str, ids: strList } },
+5
View File
@@ -475,6 +475,11 @@ export const RELEASE_RESULT_CODES = {
summary: 'the branch\'s own +/- lines are the reviewed ones, but the base edited context next to them, so the merge may have spliced the two (GST-384); the receipt carries only after a scoped review of those hunks',
fix: 'dispatch one fix-check reviewer on the packet the refusal names, write its clean verdict as { head, paths, reviewer, verdict } and rerun carry with --scoped-review <record.json>; a blocking finding means /ship on the new head',
},
RECEIPT_DOCS_AUDIT_READ: {
anchor: 'receipt-docs-audit-read',
summary: 'the Step 14.5 docs audit edited a doc the review read for its own content (a gate path, gate tags, agent prose or a secret line) after the review, so the receipt binds only after one scoped reader reads that change (GST-3532); it is not a review round',
fix: 'dispatch one reader on the packet the refusal names, write its clean verdict as { head, paths, reviewer, verdict, packet_sha256 } and rerun write with --docs-audit-read <record.json>; a finding goes to the lane\'s Captain',
},
DOCS_AUDIT_BLOCKED: {
anchor: 'docs-audit-blocked',
summary: 'the documentation audit (/ship Step 14.5) is blocked: gstack-ship-receipt docs-caps found a declared doc cap over, or gstack-ship-receipt write was given a blocked audit with no owner exception and refused to record the ship as audited',
+25 -10
View File
@@ -38,6 +38,7 @@ import { branchSides } from './stamp-only';
import { classifyFiles } from './tree-receipt';
import { mergeChangelogs } from './changelog-check';
import { bindReceipt, type ReceiptBindingCode } from './ship-receipt';
import { READ_REASONS, docsAuditPacket, readDocsAuditRead, type DocsAuditRead } from './docs-audit-read';
import { carriedAudits, docsExceptionLine, parseReceiptDocs, sameRun, type CarriedAudit } from './ship-receipt-docs';
export type ReceiptDepth = NonNullable<ShipReceipt['review_depth']>;
@@ -345,13 +346,14 @@ const treatment = (x: ActiveExclusion, p: string) => (x.excluded.has(p) ? 'exclu
* them left. When the whole carried list does not rebuild the reviewed selection, write retries without the oldest carried audits,
* one at a time down to none (a review that ran between two audits already read the earlier one's edits); only that digest
* mismatch retries, so an integrity refusal (an edit after an audit, a file changed between audits, a foreign HEAD) ends it, and
* the refusal names the whole list's reason. A file the merged base changed since an audit's HEAD and the PR's own three-dot diff
* the refusal names the whole list's reason, unless a retry matched the reviewed selection: then that retry's own refusal or
* reader packet comes back. A file the merged base changed since an audit's HEAD and the PR's own three-dot diff
* leaves alone holds no PR edit, so it is not counted as changed; a latest audit that changed nothing still binds through the audits
* it carries; and the rebuilt selection binds the reviewed digest as carryExcludeBinds does, so a base policy change alone does not
* void it (GST-3260). Content compares as git stores it or as it checks out (autocrlf, filters). Anything else, an unreadable
* snapshot included, refuses with `why`.
*/
export function writeExcludeBinds(root: string, base: string, head: string, review: { exclude: Exclusion; tagged: ReadonlySet<string> | null }, flagged: string | undefined, docsPost: string | undefined, docsPre?: string): { ok: true; line?: string } | { ok: false; why?: string } {
export function writeExcludeBinds(root: string, base: string, head: string, review: { exclude: Exclusion; tagged: ReadonlySet<string> | null }, flagged: string | undefined, docsPost: string | undefined, docsPre?: string, docsRead?: string): { ok: true; line?: string; read?: DocsAuditRead } | { ok: false; why?: string; packet?: { text: string; sha256: string; paths: string[] } } {
const x = review.exclude;
const given = flagged ?? 'none';
const now = x.state === 'active' ? x.record.digest : 'none';
@@ -398,7 +400,7 @@ export function writeExcludeBinds(root: string, base: string, head: string, revi
if (!holds(head, p, post.hashes[p] ?? null)) return no(`${p} at HEAD is not the content the snapshot recorded (an edit after the audit)`);
}
const auditFiles = pre ? changed.filter(p => !(p in pre.hashes) || pre.hashes[p] !== post.hashes[p]) : changed;
const bindAudits = (carried: CarriedAudit[]): { ok: true; line: string } | { ok: false; why: string; retry?: true } => {
const bindAudits = (carried: CarriedAudit[]): { ok: true; line: string; read?: DocsAuditRead } | { ok: false; why: string; retry?: true; matched?: true; packet?: { text: string; sha256: string; paths: string[] } } => {
const resets = new Map<string, { rev: string; want: unknown; from: string }>(auditFiles.map(p => [p, { rev: at, want: pre ? pre.hashes[p] : undefined, from: `--docs-pre ${docsPre}` }]));
const left = new Map<string, { after: string | null; audit: string }>();
for (const e of carried) {
@@ -424,13 +426,14 @@ export function writeExcludeBinds(root: string, base: string, head: string, revi
const run = (args: string[], input?: string) => { const r = spawnSync('git', args, { cwd: root, encoding: 'utf8', env, input, timeout: 60_000 }); return { ok: r.status === 0, out: (r.stdout ?? '').trim() }; };
const treeEntry = (rev: string, p: string) => run(['ls-tree', '-z', '--full-tree', rev, '--', p]).out.split('\0').find(l => l.endsWith(`\t${p}`));
let reset: string;
const befores = new Map<string, string | null>();
try {
const entries: string[] = [];
for (const [p, { rev, want, from }] of resets) {
const atEntry = treeEntry(rev, p);
if (want === undefined || (atEntry && holds(rev, p, want))) entries.push(atEntry ? `${atEntry}\0` : `0 ${'0'.repeat(rev.length)}\t${p}\0`);
else if (want === null) entries.push(`0 ${'0'.repeat(rev.length)}\t${p}\0`);
else if (typeof want === 'string' && run(['cat-file', '-e', `${want}^{blob}`]).ok) entries.push(`${(treeEntry(head, p) ?? atEntry ?? '100644').split(' ')[0]} blob ${want}\t${p}\0`);
if (want === undefined || (atEntry && holds(rev, p, want))) { entries.push(atEntry ? `${atEntry}\0` : `0 ${'0'.repeat(rev.length)}\t${p}\0`); befores.set(p, atEntry ? blob(rev, p) : null); }
else if (want === null) { entries.push(`0 ${'0'.repeat(rev.length)}\t${p}\0`); befores.set(p, null); }
else if (typeof want === 'string' && run(['cat-file', '-e', `${want}^{blob}`]).ok) { entries.push(`${(treeEntry(head, p) ?? atEntry ?? '100644').split(' ')[0]} blob ${want}\t${p}\0`); befores.set(p, want); }
else return no(`${p}'s content before the audit (${short(String(want))} in ${from}) is not in git's object store, so the selection the reviewers read cannot be rebuilt`);
}
const tree = run(['read-tree', head]).ok && run(['update-index', '-z', '--index-info'], entries.join('')).ok ? run(['write-tree']) : { ok: false, out: '' };
@@ -441,20 +444,32 @@ export function writeExcludeBinds(root: string, base: string, head: string, revi
const before = exclusionAt(root, ref, sha, reset, collectCommit(root, sha ?? ref, reset), review.tagged, 'gstack-ship-receipt');
if (before.state !== 'active') return no(`the selection with ${files.join(',')} reset to before the audit cannot be read`);
if (!carryExcludeBinds(before, { review_exclude: reviewedRecord(root, base, before, given) })) return { retry: true, ...no(`the reviewed digest ${short(given)} is not the selection HEAD has with the files under review_exclude_paths that changed since the snapshot reset to ${pre ? 'their --docs-pre content' : short(at)}${left.size ? ` and the files audit ${carried.map(e => e.audit_id).join(',')} edited reset to before that audit` : ''} (${short(before.record.digest)}), so more than the docs audit changed what the reviewers read`) };
const late = (why: string) => ({ ...no(why), matched: true as const });
const read = new Set<string>();
for (const p of files) for (const [side, s] of [['the review', before], ['HEAD', x]] as const) {
const t = treatment(s, p);
if (!['absent', 'excluded', 'named-by-code'].includes(t)) return no(`${p} is ${t} at ${side}: the docs audit binds only docs the exclusion hides or keeps because code names them`);
if (['absent', 'excluded', 'named-by-code'].includes(t)) continue;
if (!READ_REASONS.includes(t)) return late(`${p} is ${t} at ${side}: the docs audit binds only docs the exclusion hides, keeps because code names them, or keeps for the reviewers to read (${READ_REASONS.join(', ')}), which one scoped reader reads`);
read.add(p);
}
const audit = new Set(files);
for (const p of new Set([...before.excluded, ...x.excluded, ...before.kept.map(k => k.path), ...x.kept.map(k => k.path)])) {
if (!audit.has(p) && treatment(before, p) !== treatment(x, p)) return no(`${p} is ${treatment(before, p)} at the review and ${treatment(x, p)} at HEAD`);
if (!audit.has(p) && treatment(before, p) !== treatment(x, p)) return late(`${p} is ${treatment(before, p)} at the review and ${treatment(x, p)} at HEAD`);
}
return { ok: true, line: `REVIEW_EXCLUDE_DOCS_AUDIT: reviewed=${short(given)} head=${short(x.record.digest)} snapshot=${short(at)} files=${files.join(',')}${carried.length ? ` audits=${[...carried.map(e => e.audit_id), post.audit_id].join(',')}` : ''} (the selection changed only by this /ship run's Step 14.5 docs audits' files under review_exclude_paths; the receipt records HEAD's)` };
const line = `REVIEW_EXCLUDE_DOCS_AUDIT: reviewed=${short(given)} head=${short(x.record.digest)} snapshot=${short(at)} files=${files.join(',')}${carried.length ? ` audits=${[...carried.map(e => e.audit_id), post.audit_id].join(',')}` : ''} (the selection changed only by this /ship run's Step 14.5 docs audits' files under review_exclude_paths; the receipt records HEAD's)`;
if (!read.size) return { ok: true, line };
const paths = [...read].sort();
const packet = docsAuditPacket(root, head, paths.map(p => ({ path: p, before: befores.get(p) ?? null })));
if (!packet.ok) return late(packet.why);
if (docsRead === undefined) return { ok: false, why: `${paths.join(',')} ${paths.length === 1 ? 'is a doc' : 'are docs'} the reviewers read, edited by the docs audit after the review`, matched: true, packet: { text: packet.text, sha256: packet.sha256, paths } };
const record = readDocsAuditRead(docsRead, head, paths, packet.sha256);
if (!record.ok) return late(record.why);
return { ok: true, line: `${line}; read=${paths.join(',')} by ${record.read.reviewer}`, read: record.read };
};
let first: { ok: false; why: string } | undefined;
for (let k = 0; k <= earlier.length; k++) {
const r = bindAudits(earlier.slice(k));
if (r.ok) return r;
if (r.ok || r.matched) return r;
first ??= r;
if (!r.retry) return first;
}
+1 -1
View File
@@ -25,7 +25,7 @@ const KEY_ORDER: Array<keyof ShipReceipt | 'docs'> = [
'schema_version', 'pr', 'head', 'version', 'base', 'gated_tree', 'predecessor', 'tree', 'gate_reuse', 'gate', 'ci', 'ci_carried', 'spend_usd', 'calls',
'session_kind', 'artifacts_consumed', 'run', 'thread', 'policy', 'queue_mode', 'preregistration', 'history',
'head_tree', 'product_patch_id', 'gstack_version', 'review_depth', 'pregate', 'requires_remote', 'issues', 'approval', 'docs', 'review_loop',
'review_loop_exception', 'review_round_grants', 'cleared_by_grant', 'cleared_by_trailer', 'ruled_notes', 'gate_dispositions', 'mechanical', 'review_targeted', 'design', 'review_exclude', 'review_exclude_fallback', 'carry', 'base_red', 'flaky_exception', 'no_stop',
'review_loop_exception', 'review_round_grants', 'cleared_by_grant', 'cleared_by_trailer', 'ruled_notes', 'gate_dispositions', 'mechanical', 'review_targeted', 'design', 'review_exclude', 'review_exclude_fallback', 'docs_audit_read', 'carry', 'base_red', 'flaky_exception', 'no_stop',
];
/** Keys in the fixed order so identifiers lead; undefined values are dropped. */