Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion TODOS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

### P1: review-depth receipt follow-ups (filed 2026-10-28, from the #3567 /ship plan audit)

- **Derive `carry.covers` from depth.** A carried receipt's `covers` is the fixed `CARRY_COVERS` list (lib/ship-receipt.ts); derive it from the recorded `review_depth` so a light review's carry does not claim the checks a full review ran (plan item 5, deferred at /ship). **Effort:** S. **Priority:** P1.
- **Bound the queue's recompute time.** `gstack-ship-queue` recomputes each receipt's needed depth at READY and at train build; add a test that a five-PR train recomputes within a fixed budget, so a large diff cannot stall the train. **Effort:** S. **Priority:** P1.

### P3: `/codex --effort` follow-ups (filed 2026-10-11, from the #3146 autoplan review)
Expand Down
6 changes: 3 additions & 3 deletions bin/gstack-ship-receipt
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ function cmdCarry(rest: string[], json: boolean): number {
// Rewritten history: the receipt follows only onto a tree it already covers, with the product diff it recorded.
const recorded = receipt.product_patch_id !== undefined ? (receipt.product_patch_id === 'none' ? '' : receipt.product_patch_id) : fromKnown ? productPatchAgainstBase(repoRoot, rules, baseRef, from) : { error: 'the receipt records no product patch-id and its head is not in this clone' };
if (typeof recorded !== 'string') return refused('RECEIPT_CARRY_REFUSED', `the reviewed product patch-id is unavailable: ${recorded.error}; run /ship on ${head.slice(0, 12)}`);
plan = planTreeCarry({ from, head, headTree, coveredTrees: covered, productPatchId: { recorded, head: headPatch } });
plan = planTreeCarry({ from, head, headTree, coveredTrees: covered, productPatchId: { recorded, head: headPatch }, depth: receipt.review_depth });
} else {
const fromBase = git(['merge-base', baseRef, from], repoRoot);
if (!fromBase) return refused('RECEIPT_CARRY_REFUSED', `cannot resolve the merge base of ${baseRef} (fetch it first)`);
Expand Down Expand Up @@ -599,7 +599,7 @@ function cmdCarry(rest: string[], json: boolean): number {
// Evidence for the record, never the decision: a slow range-diff is reported unavailable rather than waited for.
const rangeRaw = spawnSync('git', ['range-diff', '--no-color', `${fromBase}..${from}`, `${headBase}..${head}`], { cwd: repoRoot, encoding: 'utf8', timeout: 15_000, maxBuffer: 64 * 1024 * 1024 });
const rangeDiff = rangeRaw.status === 0 ? (rangeRaw.stdout.trim().split('\n').slice(0, 20).join('\n') || '(empty: identical ranges)') : `unavailable: ${(rangeRaw.stderr ?? '').trim().split('\n')[0] || (rangeRaw.signal ? `range-diff killed by ${rangeRaw.signal} after 15 s` : 'range-diff failed')}`;
plan = planCarry({ from, head, changed, productPatchId: { from: reviewed as string, head: current as string }, testPatchId: { from: testFrom, head: testHead }, changedProduct, mergeCommits: Number(mergeCommits) || 0, rangeDiff, ...(retarget ? { retargetedFrom: reviewedBase } : {}) });
plan = planCarry({ from, head, changed, productPatchId: { from: reviewed as string, head: current as string }, testPatchId: { from: testFrom, head: testHead }, changedProduct, mergeCommits: Number(mergeCommits) || 0, rangeDiff, ...(retarget ? { retargetedFrom: reviewedBase } : {}), depth: receipt.review_depth });
}
if (!plan.ok) return refused(plan.code, plan.message);
// Eligibility is not publication: a receipt that recorded a pregate is rebound only with a pregate current for HEAD,
Expand Down Expand Up @@ -636,7 +636,7 @@ function cmdCarry(rest: string[], json: boolean): number {
const line = receiptSummaryLine(carried);
if (rest.includes('--dry-run')) {
process.stderr.write(line + '\n');
process.stdout.write(json ? JSON.stringify({ skill: 'ship', status: 'dry-run', head, carry: plan.carry }) + '\n' : `CARRY: would carry from ${from.slice(0, 12)} to ${head.slice(0, 12)} (${plan.carry.reason}); nothing written\n`);
process.stdout.write(json ? JSON.stringify({ skill: 'ship', status: 'dry-run', head, carry: { ...plan.carry, covers: carried.carry!.covers } }) + '\n' : `CARRY: would carry from ${from.slice(0, 12)} to ${head.slice(0, 12)} (${plan.carry.reason}); nothing written\n`);
return EXIT.ok;
}
if (bodyFile) fs.writeFileSync(bodyFile, newBody);
Expand Down
10 changes: 9 additions & 1 deletion docs/ship-policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,15 @@ contributes no product change of its own. A receipt carried twice keeps the revi
`carry: { from, reason, product_patch_id, changed_paths, merge_commits,
range_diff, covers, reruns, ancestry, trees }` (`ancestry` is `linear`
along the receipt's own history, `rewritten` once any hop was a rebase;
`trees` lists the earlier covered trees) with the `git range-diff` evidence, prints
`trees` lists the earlier covered trees; `covers` names what the recorded
`review_depth` requires, from `carryCovers`: that depth is the one the head
needed at write, which the review is expected to have met, not a record of what
ran. The adversarial review is claimed only at full, at standard for the code or
gate class, and at light with runtime lines, so a light docs-only review's carry
does not claim it. A later carry keeps the first carry's `covers`, because a
carry rebinds `review_depth` to its new head; it reads the fixed list a carry
recorded before `covers` followed the depth as no depth recorded. A receipt
without a depth claims the review with no depth named) with the `git range-diff` evidence, prints
`CARRY: carried from <old> to <new> (<reason>)` and the `GSTACK_RESULT:
skill=ship status=complete` line, and its summary line ends with
`carried_from=<old12>`. `CARRY: current` means the receipt already names HEAD;
Expand Down
42 changes: 38 additions & 4 deletions lib/ship-receipt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,40 @@ export interface CarryPlanInput {
rangeDiff: string;
/** The base the receipt was reviewed against when it differs from the carry's (a stack parent that landed, #3570): productPatchId.from is then the recorded diff against it. */
retargetedFrom?: string;
/** The receipt's recorded review depth; `covers` claims only what that depth requires. */
depth?: RecordedDepth;
}
export interface CarryRecord { from: string; reason: string; product_patch_id: string; changed_paths: string[]; merge_commits: number; range_diff: string; covers: string[]; reruns: string[]; trees?: string[]; ancestry?: 'linear' | 'rewritten' }
export type CarryPlan = { ok: true; carry: CarryRecord } | { ok: false; code: 'RECEIPT_CARRY_PRODUCT_CHANGED' | 'RECEIPT_CARRY_REFUSED' | 'RECEIPT_CARRY_TREE_MISMATCH'; message: string };
const CARRY_COVERS = ['pre-landing review', 'adversarial review', 'gate integrity', 'documentation audit'];
/**
* The receipt's `review_depth`: the depth the head needed at write, which the
* review is expected to have met. It is not a record of what ran: a fail-closed
* `full` (dirty checkout, scan unavailable) names more than a light review ran.
*/
type RecordedDepth = ShipReceipt['review_depth'];

/**
* What a carried receipt's review covered, derived from its recorded depth
* (docs/review-policy.md#review-depth): light with no runtime lines needs the
* core checklist only, so its carry claims no adversarial review; standard
* needs the adversarial pass for the code class only. Gate integrity (core
* checklist) and the documentation audit run at every depth. A receipt without
* a depth (written before it was recorded) claims the review without the
* passes a depth would name.
*/
export function carryCovers(depth: RecordedDepth): string[] {
const always = ['gate integrity', 'documentation audit'];
if (!depth) return ['pre-landing review (depth not recorded)', ...always];
const light = depth.runtime_lines > 0 ? 'core checklist and one batched specialist' : 'core checklist only';
const review = depth.depth === 'light' ? `pre-landing review at light depth (${light})`
: depth.depth === 'standard' ? 'pre-landing review at standard depth (specialists and Red Team by runtime-line thresholds)'
: 'pre-landing review at full depth (every specialist and the Red Team)';
const adversarial = depth.depth === 'full' || (depth.depth === 'standard' ? depth.class === 'code' || depth.class === 'gate' : depth.runtime_lines > 0);
return [review, ...(adversarial ? ['adversarial review'] : []), ...always];
}
/** The fixed `covers` every carry recorded before it followed the depth; a later carry reads it, or a missing list, as no depth recorded. */
const UNDERIVED_COVERS = ['pre-landing review', 'adversarial review', 'gate integrity', 'documentation audit'];
const underived = (covers: string[]) => covers.length === UNDERIVED_COVERS.length && covers.every((c, i) => c === UNDERIVED_COVERS[i]);
const CARRY_RERUNS = ['CI at head (gstack-ship-queue ready requires it); test and helper code changed since the reviewed head runs there unreviewed'];

/**
Expand Down Expand Up @@ -245,7 +275,7 @@ export function planCarry(input: CarryPlanInput): CarryPlan {
carry: {
from: input.from, reason: reasons.join(' + '), product_patch_id: input.productPatchId.head || 'none',
changed_paths: input.changed.slice(0, 50).map(c => `${c.class}:${c.path}`), merge_commits: input.mergeCommits, range_diff: input.rangeDiff,
covers: CARRY_COVERS, reruns: CARRY_RERUNS, ancestry: 'linear',
covers: carryCovers(input.depth), reruns: CARRY_RERUNS, ancestry: 'linear',
},
};
}
Expand All @@ -256,6 +286,8 @@ export interface TreeCarryInput {
headTree: string; coveredTrees: readonly string[];
/** The product patch-id against the base the receipt recorded, and the one HEAD has against the current base. */
productPatchId: { recorded: string; head: string };
/** The receipt's recorded review depth; `covers` claims only what that depth requires. */
depth?: RecordedDepth;
}

/**
Expand All @@ -276,7 +308,7 @@ export function planTreeCarry(input: TreeCarryInput): CarryPlan {
ok: true,
carry: {
from: input.from, reason: 'rebase onto a reviewed tree', product_patch_id: input.productPatchId.head || 'none',
changed_paths: [], merge_commits: 0, range_diff: 'tree-equal', covers: CARRY_COVERS, reruns: CARRY_RERUNS, ancestry: 'rewritten',
changed_paths: [], merge_commits: 0, range_diff: 'tree-equal', covers: carryCovers(input.depth), reruns: CARRY_RERUNS, ancestry: 'rewritten',
},
};
}
Expand All @@ -285,11 +317,13 @@ export function planTreeCarry(input: TreeCarryInput): CarryPlan {
* The carried receipt: the same evidence, bound to the new head, with the carry
* recorded. A receipt carried before keeps the reviewed head as `from` and adds
* this hop's merges and paths, so the record always names the head a review saw.
* It also keeps the first carry's `covers`: a carry rebinds `review_depth` to
* the new head, so a later hop's depth no longer describes the review.
*/
export function carryReceipt(receipt: ShipReceipt, head: string, carry: CarryRecord, at: { tree: string; fromTree?: string; productPatchId: string }): ShipReceipt {
const prior = receipt.carry;
const merged: CarryRecord = !prior ? carry : {
...carry, from: prior.from, reason: prior.reason === carry.reason ? carry.reason : `${prior.reason} + ${carry.reason}`,
...carry, from: prior.from, covers: Array.isArray(prior.covers) && !underived(prior.covers) ? prior.covers : carryCovers(undefined), reason: prior.reason === carry.reason ? carry.reason : `${prior.reason} + ${carry.reason}`,
merge_commits: prior.merge_commits + carry.merge_commits,
changed_paths: [...prior.changed_paths, ...carry.changed_paths.filter(p => !prior.changed_paths.includes(p))].slice(0, 50),
ancestry: prior.ancestry === 'rewritten' ? 'rewritten' : carry.ancestry,
Expand Down
2 changes: 1 addition & 1 deletion test/gstack-ship-receipt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ describe('gstack-ship-receipt carry (harness lane E row 3: receipt follows a hea
const after = extractReceipt(fs.readFileSync(body, 'utf8'));
expect(after.errors).toEqual([]);
expect(after.receipt).toMatchObject({ pr: 5, head, base: 'main', review_loop: { passes: 2 } });
expect(after.receipt!.carry).toMatchObject({ from: reviewed, reason: 'base merge + test-only change', merge_commits: 1, covers: ['pre-landing review', 'adversarial review', 'gate integrity', 'documentation audit'] });
expect(after.receipt!.carry).toMatchObject({ from: reviewed, reason: 'base merge + test-only change', merge_commits: 1, covers: ['pre-landing review (depth not recorded)', 'gate integrity', 'documentation audit'] });
expect(after.receipt!.carry!.product_patch_id).toMatch(/^[0-9a-f]{40}$/);
expect(after.receipt!.carry!.changed_paths.sort()).toEqual(['product:src/other.ts', 'test:test/app.test.ts']);
expect(after.receipt!.carry!.range_diff).not.toMatch(/^unavailable/);
Expand Down
83 changes: 82 additions & 1 deletion test/ship-receipt-depth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { afterEach, describe, expect, test } from 'bun:test';
import * as fs from 'node:fs';
import * as path from 'node:path';
import { EXIT } from '../lib/headless-artifacts';
import { extractReceipt, renderReceiptBlock } from '../lib/ship-receipt';
import { carryCovers, extractReceipt, planCarry, planTreeCarry, renderReceiptBlock } from '../lib/ship-receipt';
import { bindShippedReceipt, receiptDepthVerdict, reviewLoopExceptionLine } from '../lib/ship-receipt-depth';
import { cleanup, commit, makeFixtureRepo, runBin, type FixtureRepo } from './helpers/pregate-fixture';

Expand Down Expand Up @@ -142,6 +142,87 @@ describe('carry and the review depth', () => {
expect(receiptIn(body).head).toBe(plain);
}, 90_000);

// Value: protects=a carried receipt claims only the checks its recorded review depth ran; fails_when=a light review with
// no runtime lines (no adversarial pass) carries a covers list that claims the adversarial review, or a light code
// review's carry stops naming its depth; seam=none
test('carry covers follow the recorded depth: light docs-only claims no adversarial review, light code claims it', () => {
const docs = makeFixtureRepo(); repos.push(docs);
commit(docs, { 'docs/guide.md': '# Guide\n' });
const docsBody = path.join(docs.root, 'body.md');
expect(writeReceipt(docs, docsBody).status).toBe(EXIT.ok);
expect(receiptIn(docsBody).review_depth).toMatchObject({ depth: 'light', runtime_lines: 0 });
commit(docs, { 'test/guide.test.js': "test('a', () => {});\n" });
expect(runBin(docs, 'gstack-ship-receipt', ['carry', '--body', docsBody, '--base', 'main']).status).toBe(EXIT.ok);
const docsCovers = receiptIn(docsBody).carry!.covers;
expect(docsCovers).not.toContain('adversarial review');
expect(docsCovers.join('\n')).toContain('light depth (core checklist only)');
expect(docsCovers).toEqual(expect.arrayContaining(['gate integrity', 'documentation audit']));

const code = makeFixtureRepo(); repos.push(code);
commit(code, { 'lib/util.js': lines(3), 'test/util.test.js': "test('a', () => {});\n" });
const codeBody = path.join(code.root, 'body.md');
expect(writeReceipt(code, codeBody).status).toBe(EXIT.ok);
commit(code, { 'test/util.test.js': "test('a', () => {});\ntest('b', () => {});\n" });
expect(runBin(code, 'gstack-ship-receipt', ['carry', '--body', codeBody, '--base', 'main']).status).toBe(EXIT.ok);
const codeCovers = receiptIn(codeBody).carry!.covers;
expect(codeCovers).toContain('adversarial review');
expect(codeCovers.join('\n')).toContain('light depth (core checklist and one batched specialist)');
}, 90_000);

// Value: protects=a receipt carried twice keeps the covers of the review that ran (in the written receipt and the
// --dry-run --json report), and a carry written before covers followed the depth is read as no depth recorded;
// fails_when=the second hop derives covers from the review_depth the first hop rebound to its head (an e2e file counts
// runtime lines, not product), so a docs-only review claims the adversarial review, or an inherited fixed list keeps
// claiming it; seam=none
test('a second carry keeps the first carry covers; an inherited fixed list reads as no depth recorded', () => {
const repo = makeFixtureRepo(); repos.push(repo);
commit(repo, { 'docs/guide.md': '# Guide\n' });
const body = path.join(repo.root, 'body.md');
expect(writeReceipt(repo, body).status).toBe(EXIT.ok);
commit(repo, { 'e2e/smoke.js': 'exports.smoke = () => 1;\n' });
expect(runBin(repo, 'gstack-ship-receipt', ['carry', '--body', body, '--base', 'main']).status).toBe(EXIT.ok);
const first = receiptIn(body);
expect(first.review_depth!.runtime_lines).toBeGreaterThan(0);
const firstCovers = first.carry!.covers;
expect(firstCovers).not.toContain('adversarial review');
commit(repo, { 'test/guide.test.js': "test('a', () => {});\n" });
const dry = runBin(repo, 'gstack-ship-receipt', ['carry', '--body', body, '--base', 'main', '--dry-run', '--json']);
expect(dry.status).toBe(EXIT.ok);
expect(JSON.parse(dry.out.trim().split('\n').pop()!).carry.covers).toEqual(firstCovers);
expect(runBin(repo, 'gstack-ship-receipt', ['carry', '--body', body, '--base', 'main']).status).toBe(EXIT.ok);
expect(receiptIn(body).carry!.covers).toEqual(firstCovers);

rewrite(body, r => { r.carry.covers = ['pre-landing review', 'adversarial review', 'gate integrity', 'documentation audit']; });
commit(repo, { 'test/guide.test.js': "test('a', () => {});\ntest('b', () => {});\n" });
expect(runBin(repo, 'gstack-ship-receipt', ['carry', '--body', body, '--base', 'main']).status).toBe(EXIT.ok);
expect(receiptIn(body).carry!.covers).toEqual(carryCovers(undefined));
}, 90_000);

// Value: protects=both carry planners claim the adversarial review only for a depth whose pass 1 runs it
// (docs/review-policy.md#review-depth), and a receipt without a depth claims no pass a depth would name;
// fails_when=covers ignores the depth, standard docs/tests or light runtime 0 claims the adversarial review, or a
// tree carry derives covers differently from a linear one; seam=none
test('covers per depth for a linear and a rewritten carry', () => {
const depth = (d: 'light' | 'standard' | 'full', cls: 'docs' | 'tests' | 'code' | 'gate', runtime: number) =>
({ depth: d, class: cls, runtime_lines: runtime, rules: 'r', base: 'b', registry: null, gate_scan: { tagged: 0, head: 'h' }, reasons: [] });
const linear = (d?: ReturnType<typeof depth>) => planCarry({ from: 'a'.repeat(40), head: 'b'.repeat(40), changed: [], productPatchId: { from: 'p', head: 'p' }, testPatchId: { from: '', head: '' }, changedProduct: [], mergeCommits: 0, rangeDiff: '', depth: d });
const tree = (d?: ReturnType<typeof depth>) => planTreeCarry({ from: 'a'.repeat(40), head: 'b'.repeat(40), headTree: 't', coveredTrees: ['t'], productPatchId: { recorded: 'p', head: 'p' }, depth: d });
const cases: Array<[ReturnType<typeof depth> | undefined, string, boolean]> = [
[depth('light', 'docs', 0), 'pre-landing review at light depth (core checklist only)', false],
[depth('light', 'code', 12), 'pre-landing review at light depth (core checklist and one batched specialist)', true],
[depth('standard', 'code', 80), 'pre-landing review at standard depth (specialists and Red Team by runtime-line thresholds)', true],
[depth('standard', 'tests', 0), 'pre-landing review at standard depth (specialists and Red Team by runtime-line thresholds)', false],
[depth('full', 'gate', 3), 'pre-landing review at full depth (every specialist and the Red Team)', true],
[undefined, 'pre-landing review (depth not recorded)', false],
];
for (const [d, review, adversarial] of cases) {
const want = [review, ...(adversarial ? ['adversarial review'] : []), 'gate integrity', 'documentation audit'];
expect(carryCovers(d)).toEqual(want);
expect(linear(d)).toMatchObject({ ok: true, carry: { covers: want } });
expect(tree(d)).toMatchObject({ ok: true, carry: { covers: want } });
}
});

// Value: protects=a carry never binds a scan of one checkout to another commit, and never rebinds a receipt the queue would
// refuse; fails_when=carry --head from another checkout carries a skipped test at light, or a current receipt without
// review_depth carries; seam=none
Expand Down