From 63900b308cd57a9fae29141b64c1dd9b00752579 Mon Sep 17 00:00:00 2001 From: Garry Tan Date: Sun, 22 Nov 2026 04:53:49 -0800 Subject: [PATCH] A fix closes its review finding only after a finished full review, and a security finding never closes this way (GST-3260) (#4700) A commit that says it fixes a review finding now closes that finding only after a full review that finished, made no fixes of its own, and read the fix. A security finding never closes this way, so its file and line can't reach the public PR body. Why: three gaps on main let a finding close too easily: a review that was still fixing things, a security finding's location, and a follow-up check whose record of what it read was missing. Nothing to do. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Review-Finding: p1/specialist-batched#1 reader=testing --- ...ings-close-only-after-a-finished-review.md | 1 + docs/review-policy.md | 10 +++-- lib/fix-check-clearing.ts | 11 +++-- test/fix-check-clearing.test.ts | 41 +++++++++++++++++++ 4 files changed, 56 insertions(+), 7 deletions(-) create mode 100644 changelog.d/findings-close-only-after-a-finished-review.md diff --git a/changelog.d/findings-close-only-after-a-finished-review.md b/changelog.d/findings-close-only-after-a-finished-review.md new file mode 100644 index 000000000..a85b8b5b2 --- /dev/null +++ b/changelog.d/findings-close-only-after-a-finished-review.md @@ -0,0 +1 @@ +**A fix commit's `Review-Finding:` trailer now closes its finding only after a full review that finished and converged with the fix in its range.** Before, a completed review pass that had made its own fixes (and so hadn't converged), or whose range began after the fix, could close the finding. A first pass, which reads the whole pull request, still closes it. A security finding known only by its file (with or without a line) never closes this way or by grant, so its location can't reach the public PR body, and a granted follow-up check whose dispatch ledger is missing no longer counts. (GST-3260) diff --git a/docs/review-policy.md b/docs/review-policy.md index 5e9bba8d9..9b6b0576d 100644 --- a/docs/review-policy.md +++ b/docs/review-policy.md @@ -267,9 +267,13 @@ shared by two blockers closes neither. Anything less closes nothing, and write says why on a `FIX_CHECK_CLEAR:` line. The receipt records `cleared_by_grant`, and the Agent notes section gets one `Closed by grant …` line. A finding whose fix commit carries its `Review-Finding:` trailer also closes once a later full -round, bound to its committed tree and holding that commit, left nothing open -at all, by its status, its findings file or an inline finding -(`cleared_by_trailer`, #4597). finish counts the same +round that finished and converged, bound to its committed tree and with that +commit inside its range (a pass 1's `range_base: null` is the whole PR), left +nothing open at all, by its status, its findings file or an inline finding +(`cleared_by_trailer`, #4597). A security finding's raw `path:line:category` +fingerprint, with or without its line, never closes by grant or trailer, so no +closure line puts its location in the PR body, and a fix-check row whose +dispatch ledger can't be read closes nothing. finish counts the same stamped row, anchored on the grant's stop rather than the newest reviewed tree (#4612). diff --git a/lib/fix-check-clearing.ts b/lib/fix-check-clearing.ts index e388eef48..8d8203f71 100644 --- a/lib/fix-check-clearing.ts +++ b/lib/fix-check-clearing.ts @@ -10,10 +10,12 @@ * lists which blockers are open. */ import { createHash } from 'node:crypto'; +import * as fs from 'node:fs'; import * as path from 'node:path'; import { grantedStop } from './pr-review-history'; import { ownLinesSame, type ReviewRoundGrant } from './review-round-grant'; import { ledgerPass, parseFixTrailers, reviewRowKey, rowTime } from './review-scope'; +import { isSecurityFinding } from './security-findings'; import { receiptRuns } from './ship-receipt'; import { spawnSync } from './spawn-sync'; @@ -68,7 +70,7 @@ export function bindFixCheckRow(cwd: string, row: Row, grants: readonly ReviewRo if (unread === null || unread.length) return no(`the hunks its reader was given leave out ${unread?.join(', ') ?? 'paths git could not list'}, which git diff ${s12(base)} ${s12(commit)} changes`); if (typeof h.ledger === 'string') { let ids: string[]; - try { ids = ledgerPass(h.ledger, id => `${path.basename(path.dirname(h.ledger))}/${id}`).ids ?? []; } catch { return no(`its dispatch ledger ${h.ledger} is unreadable`); } + try { fs.readFileSync(h.ledger); ids = ledgerPass(h.ledger, id => `${path.basename(path.dirname(h.ledger))}/${id}`).ids ?? []; } catch { return no(`its dispatch ledger ${h.ledger} is unreadable`); } const disposed = new Set(findings.filter(f => f.action !== 'open').map(f => f.ledger_id)); const left = ids.filter(id => !disposed.has(id)); if (left.length) return no(`its dispatch ledger holds ${left.join(', ')}, which the row does not dispose`); @@ -104,7 +106,7 @@ export function clearByGrant(cwd: string, o: { pr: number; run: string; head: st if (!(Date.parse(String(stop.at)) < Date.parse(String(claim.at)) && Date.parse(String(claim.at)) < Date.parse(String(started)))) return none(`the stop (${stop.at ?? 'no time'}), the claim (${claim.at ?? 'no time'}) and the fix-check's start (${started ?? 'no time'}) are not recorded in that order`); const gated = new Set(o.rows.flatMap(r => findingsOf(r).filter(f => f.gate !== undefined).flatMap(f => [f.ledger_id, f.fingerprint]))); const asked = new Set(Array.isArray(row!.hunks?.fix_list) ? row!.hunks.fix_list : []); - const ids = g.findings!.filter(name => asked.has(name) && o.open.filter(b => nameOf(b) === name).length === 1 && !o.open.some(b => typeof b !== 'string' && b.fingerprint === name) && !gated.has(name)); + const ids = g.findings!.filter(name => asked.has(name) && !isSecurityFinding(name) && o.open.filter(b => nameOf(b) === name).length === 1 && !o.open.some(b => typeof b !== 'string' && b.fingerprint === name) && !gated.has(name)); const unasked = g.findings!.filter(name => !asked.has(name)); const unnamed = g.findings!.filter(name => asked.has(name) && !ids.includes(name)); const why = [...(unasked.length ? [`the fix list its reader was given does not name ${unasked.join(', ')}`] : []), ...(unnamed.length ? [`grant ${g.approval} names ${unnamed.join(', ')}, which no open blocker carries alone`] : [])].join('; '); @@ -125,10 +127,11 @@ export function clearByTrailer(cwd: string, o: { head: string; baseRef: string; const raised = o.rows.flatMap(r => findingsOf(r).filter(f => f.action === 'open' && (f.ledger_id === id || (f.ledger_id === undefined && f.fingerprint === fp))).map(f => ({ r, f }))); const alone = o.open.filter(c => (typeof c === 'string' ? c : c.fingerprint) === fp).length === 1; const t = trailers.find(x => x.finding === id || (alone && x.finding === fp)); - if (!t || !raised.length || raised.some(x => x.f.gate !== undefined)) return []; + if (!t || !raised.length || raised.some(x => x.f.gate !== undefined) || isSecurityFinding(t.finding)) return []; const after = Math.max(...raised.map(x => rowTime(x.r))); + const inRange = (from: unknown, fix: string) => from == null || (typeof from === 'string' && (b => !!b && !ancestor(cwd, fix, b))(git(cwd, ['rev-parse', '--verify', '--quiet', `${from}^{commit}`])?.trim())); const review = o.rows.find(r => r?.skill === 'review' && r.via === 'ship' && r.completed === true && r.scope !== 'fix-range' && r.scope !== 'scoped' && rowTime(r) > after - && (r.review_binding?.state === 'verified' || r.review_binding?.state === 'incomplete') && typeof r.tree === 'string' && r.review_binding.start_wtree === r.tree && r.review_binding.end_wtree === r.tree + && r.converged === true && r.review_binding?.state === 'verified' && inRange(r.range_base, t.commit) && typeof r.tree === 'string' && r.review_binding.start_wtree === r.tree && r.review_binding.end_wtree === r.tree && SHA.test(String(r.commit_full)) && treeOf(cwd, r.commit_full) === r.tree && ancestor(cwd, t.commit, r.commit_full) && ancestor(cwd, r.commit_full, o.head) && r.status !== 'issues_found' && r.status !== 'issues_open' && Number(r.findings_open ?? 0) === 0 && !findingsOf(r).some(f => f.action === 'open')); return review ? [{ id, commit: t.commit, review: review.commit_full as string }] : []; diff --git a/test/fix-check-clearing.test.ts b/test/fix-check-clearing.test.ts index a3e2857c1..7cc3f64da 100644 --- a/test/fix-check-clearing.test.ts +++ b/test/fix-check-clearing.test.ts @@ -152,6 +152,34 @@ describe('a granted, clean fix-check closes exactly its grant\'s findings at wri expect(byTrailer(pass2)).toHaveLength(1); expect(byTrailer({ ...pass2, status: 'issues_found', findings_open: 1, findings_file: '/tmp/f.jsonl', status_source: 'derived' })).toEqual([]); expect(byTrailer({ ...pass2, findings: [{ fingerprint: 'src/x.ts:9:style', severity: 'INFORMATIONAL', action: 'open' }] })).toEqual([]); + // Value: protects=only a finished, converged full round that read the fix closes by trailer (#4664 trail read, flag 2); + // fails_when=a completed round that made its own fixes (converged false, bound incomplete), or whose range starts at or after + // the fix commit, closes the trailer's finding; seam=clearByTrailer + expect(byTrailer({ ...pass2, converged: false, review_binding: { ...pass2.review_binding, state: 'incomplete' } })).toEqual([]); + expect(byTrailer({ ...pass2, range_base: headOf(f) })).toEqual([]); + // Value: protects=a pass 1, which logs range_base null, reads the whole PR and still closes a committed fix by trailer (#4696 + // ship-4696c, p1/outside-voice#4); fails_when=null reads as a range that leaves the fix out; seam=clearByTrailer + expect(byTrailer({ ...pass2, range_base: null })).toHaveLength(1); + }); + // Value: protects=a security-class fingerprint never closes by trailer, so no closure line puts its location in the public body + // (#4664 trail read, flag 3); fails_when=a blocker with no ledger id closes by its raw path:line:security fingerprint; + // why_new=the #4597 replay uses a ledger id; seam=clearByTrailer; no_claim=closure by ledger id, which carries no location + test('a trailer naming a security fingerprint closes nothing, while the same trailer on a plain fingerprint closes', () => { + const byFingerprint = (fp: string) => { + const f = shipFixture({ 'src/x.ts': 'export const x = 1;\n' }, { 'src/x.ts': 'export const x = 2;\n' }); + fxs.push(f); + const run = (bin: string, args: string[]) => f.run(path.join(BIN, bin), args, { GSTACK_APPROVALS_MIRROR: '0' }); + const g = { run } as Granted; + logRow(g, 'review', { pass: 1, ...CLEAN }); + logRow(g, 'adversarial-review', { status: 'issues_found', source: 'outside-voice', phase: 'adversarial', gate: 'informational', completed: true, findings: [{ fingerprint: fp, severity: 'CRITICAL', action: 'open', blocking: true, raised_by: 'outside-voice' }] }); + f.write({ 'src/x.ts': 'export const x = 3;\n' }); + f.git('add', '-A'); f.git('commit', '-qm', 'fix the blocker', '--trailer', 'Review-Finding: ' + fp + ' reader=outside-voice'); + logRow(g, 'review', { pass: 2, ...CLEAN }); + return clearByTrailer(f.work, { head: headOf(f), baseRef: 'origin/main', rows: rowsOf(g as Granted), open: [fp] }); + }; + expect(byFingerprint('src/x.ts:1:style').map(t => t.id)).toEqual(['src/x.ts:1:style']); + expect(byFingerprint('src/x.ts:1:security')).toEqual([]); + expect(byFingerprint('src/x.ts::security')).toEqual([]); }); }); @@ -271,6 +299,19 @@ describe('clearing refuses every gap GSTA-665\'s trail reads found in #4546 (lib expect(clear({ body: late }).why).toContain('not recorded in that order'); expect(clear({ rows: [...base.rows, { skill: 'review', via: 'ship', findings: [{ ledger_id: ID, gate: 'RH1', action: 'open' }] }] }).ids).toEqual([]); }); + // Value: protects=a grant naming a security-class fingerprint closes nothing by grant either, line or no line (#4664 trail read, + // flag 3; #4696 ship-4696c p1/specialist-batched#1); fails_when=a raw security fingerprint the fix list names closes; seam=clearByGrant + test('a grant naming a security fingerprint closes nothing, while the same grant on a plain fingerprint closes', () => { + const named = (fp: string) => clear({ grants: base.grants.map(x => ({ ...x, findings: [fp] })), open: [fp], rows: withRow({ ...fixRow(), hunks: { ...fixRow().hunks, fix_list: [fp] } }) }).ids; + expect(named('src/x.ts:1:style')).toEqual(['src/x.ts:1:style']); + expect(named('src/x.ts:1:security')).toEqual([]); + expect(named('src/x.ts::security')).toEqual([]); + }); + // Value: protects=a fix-check row whose dispatch ledger can't be read closes nothing (#4664 trail read, flag 1); fails_when=a + // missing ledger reads as empty, so the check that the row disposes every id the reader raised passes; seam=bindFixCheckRow + test('a fix-check row naming a dispatch ledger that is missing closes nothing', () => { + expect(clear({ rows: withRow({ ...fixRow(), hunks: { ...fixRow().hunks, ledger: path.join(g.f.root, 'gone', 'fc', 'ledger.jsonl') } }) })).toMatchObject({ ids: [], why: expect.stringContaining('unreadable') }); + }); // Value: protects=a clean fix-check closes only the grant ids its fix list named; fails_when=a grant id the reader was never // asked about closes; seam=gstack-review-plan --fix-check-prompt, clearByGrant test('the fix list\'s names are recorded, and a grant id the fix list left out closes nothing', () => {