diff --git a/bin/gstack-review-read b/bin/gstack-review-read index 1c6dcb698..a83c355f3 100755 --- a/bin/gstack-review-read +++ b/bin/gstack-review-read @@ -11,7 +11,8 @@ # gate row closes reads `kept` with its `disposition`, and the row's `gate_dispositions` lists # those approval ids (lib/gate-dispositions.ts). review_freshness counts the owner's # gstack-approvals rule rows at a head in the row's range (ruledOn), and the row's `ruled_notes` -# lists their approval ids; values the row itself carried are discarded. +# lists their approval ids; values the row itself carried are discarded. When a stopped pass stays +# UNVERIFIED, its reason names the findings no ruling covers yet (rulingGap, GST-3267). set -euo pipefail GSTACK_BUN_CONFIG=/dev/null; case "${OSTYPE:-}" in msys*|cygwin*) if command -v cygpath >/dev/null 2>&1; then GSTACK_BUN_CONFIG=NUL; fi ;; esac SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" @@ -26,7 +27,7 @@ GSTACK_HOME="$_gstack_sr_root" WTREE=$("$SCRIPT_DIR/gstack-wtree" --review 2>/dev/null || echo "unknown") if [ -f "$GSTACK_HOME/projects/$SLUG/$BRANCH-reviews.jsonl" ]; then GSTACK_REVIEW_LIB="$SCRIPT_DIR/../lib/review-evidence.ts" GSTACK_GATE_LIB="$SCRIPT_DIR/../lib/gate-dispositions.ts" GSTACK_RULED_LIB="$SCRIPT_DIR/../lib/ruled-notes.ts" GSTACK_REVIEW_WTREE="$WTREE" bun --no-env-file --config="${GSTACK_BUN_CONFIG:-/dev/null}" -e ' - const { reviewFreshness } = await import(process.env.GSTACK_REVIEW_LIB); + const { reviewFreshness, rulingGap } = await import(process.env.GSTACK_REVIEW_LIB); const { dispositionedOn, gateKey, readGateDispositions, ruledOn, showDispositioned } = await import(process.env.GSTACK_GATE_LIB); const { readRuledNotes } = await import(process.env.GSTACK_RULED_LIB); let dispositions = []; @@ -44,8 +45,10 @@ if [ -f "$GSTACK_HOME/projects/$SLUG/$BRANCH-reviews.jsonl" ]; then for (const f of Array.isArray(rec.findings) ? rec.findings : []) if (f && typeof f === "object") delete f.disposition; const closed = dispositionedOn(process.cwd(), rec, dispositions); const ruled = ruledOn(process.cwd(), rec, rulings); - const freshness = reviewFreshness(rec, process.env.GSTACK_REVIEW_WTREE, new Set(ruled.map(n => n.finding)), new Set(closed.map(d => gateKey(d.finding, d.gate_id)))); - if (freshness) rec.review_freshness = freshness; + const ruledSet = new Set(ruled.map(n => n.finding)), gatedSet = new Set(closed.map(d => gateKey(d.finding, d.gate_id))); + const freshness = reviewFreshness(rec, process.env.GSTACK_REVIEW_WTREE, ruledSet, gatedSet); + const gap = freshness?.status === "UNVERIFIED" ? rulingGap(rec, ruledSet, gatedSet) : undefined; + if (freshness) rec.review_freshness = gap ? { ...freshness, reason: freshness.reason + ": " + gap } : freshness; if (ruled.length) rec.ruled_notes = ruled.map(n => n.approval); showDispositioned(rec, closed); console.log(JSON.stringify(rec)); diff --git a/changelog.d/review-read-names-unruled-findings.md b/changelog.d/review-read-names-unruled-findings.md new file mode 100644 index 000000000..ef0e18ba6 --- /dev/null +++ b/changelog.d/review-read-names-unruled-findings.md @@ -0,0 +1 @@ +- **When owner rulings don't clear a stopped review, `gstack-review-read` now says which findings are left.** The unverified reason used to read only `missing start capture or incomplete/nonconverged pass`. It now adds each finding that still has no ruling, as ` (, )`, up to ten, or says the row lists fewer findings than it claims. A finding logged `noted` at CRITICAL is on that list, because a note never closes a CRITICAL; rule it like the others and the review binds (harness-evals#498). A gate finding on that list also names the `gate_id` its gate disposition needs, since a ruling never closes one. diff --git a/docs/ship-policy.md b/docs/ship-policy.md index d3dc96ac2..c44322360 100644 --- a/docs/ship-policy.md +++ b/docs/ship-policy.md @@ -1793,7 +1793,13 @@ once every blocking finding on it is ruled it binds at that tree as a clean read (harness-evals#361, GST-2251). A CRITICAL with no ruling stays open, and while one does, finish prints `FIX_CHECK_OPEN: on the fix-check at ` naming the `gstack-approvals rule` command for each -([troubleshooting](troubleshooting.md#fix-check-open)). A review-loop exception is +([troubleshooting](troubleshooting.md#fix-check-open)). On any stopped review row, +the final review and the native reader included, `gstack-review-read` names them +too: its UNVERIFIED reason ends `N finding(s) still need an owner ruling at this +head: (, ); …`, ten names at most. A `noted` or +`deferred` CRITICAL is on that list, because neither action closes a CRITICAL, +and a gate finding is listed with the `gate_id` its gate disposition needs, since a +ruling never closes one (harness-evals#498, GST-3267). A review-loop exception is not a ruling: it accepts edits after a fix-check, never the fix-check's own findings. Nothing ruled is hidden: `gstack-approvals rulings` prints one `Ruled note: …` line per ruling for the diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md index beafe6159..4a692e5e9 100644 --- a/docs/troubleshooting.md +++ b/docs/troubleshooting.md @@ -7477,6 +7477,9 @@ note:` line ([ship-policy.md](ship-policy.md#ruled-notes)). A ruling at a head outside the range is listed as `not applied`, and a path edited after the fix-check still routes by the post-review rules. When the owner wants the findings fixed instead, fix them and ask for a grant for one more fix-check. +A stopped final review or native reader row works the same way: its +`gstack-review-read` reason lists each finding still waiting for a ruling, a +`noted` CRITICAL included, so rule each listed fingerprint at the head it names. ### `RECEIPT_BLOCKER_OPEN` diff --git a/lib/review-evidence.ts b/lib/review-evidence.ts index 60db6974c..7696cdb6c 100644 --- a/lib/review-evidence.ts +++ b/lib/review-evidence.ts @@ -352,8 +352,11 @@ export const holdsOpen = (f: unknown) => !record(f) || unresolvedFinding(f) || f * taken out the same way only when `gated` holds its ` ` key (the owner's gate_disposition rows whose * head lies in this row's range, lib/gate-dispositions.ts, GST-2491); a ruling never closes a gate finding. */ +const isRuledBy = (ruled: ReadonlySet, gated: ReadonlySet) => (f: unknown) => record(f) && typeof f.fingerprint === 'string' && + (f.gate ? (f.action === 'open' || f.action === 'kept') && gated.has(`${f.fingerprint} ${f.gate_id}`) : RULABLE.has(f.action) && ruled.has(f.fingerprint)); + function withoutRuledNotes(rec: Record, ruled: ReadonlySet, gated: ReadonlySet): Record { - const isRuled = (f: unknown) => record(f) && typeof f.fingerprint === 'string' && (f.gate ? (f.action === 'open' || f.action === 'kept') && gated.has(`${f.fingerprint} ${f.gate_id}`) : RULABLE.has(f.action) && ruled.has(f.fingerprint)); + const isRuled = isRuledBy(ruled, gated); if ((!ruled.size && !gated.size) || rec.status_source === 'derived' || rec.completed !== true || !Array.isArray(rec.findings) || !rec.findings.some(isRuled) || rec.findings.length < Number(rec.issues_found ?? 0) || rec.findings.filter(f => record(f) && isCriticalFinding(f)).length < Number(rec.critical ?? 0) || @@ -361,6 +364,29 @@ function withoutRuledNotes(rec: Record, ruled: ReadonlySet, return { ...rec, status: 'clean', issues_found: 0, critical: 0, informational: 0, findings: rec.findings.filter(f => !isRuled(f)) }; } +/** + * GST-3267 (harness-evals#498): why the rulings did not clear a completed pass that stopped (converged:false, bound + * `incomplete` on unchanged content). Names each finding that still holds the row open with no ruling, a `noted` or + * `deferred` CRITICAL included, and a gate finding with the gate_id its disposition needs, or says the findings list + * fewer issues than the row claims; undefined for any other row. + */ +export function rulingGap(rec: Record, ruled: ReadonlySet, gated: ReadonlySet): string | undefined { + const binding = rec.review_binding; + if (!DIFF_REVIEWS.has(rec.skill) || rec.skill === 'ship' || rec.scope === 'fix-range' || rec.status_source === 'derived' || + rec.completed !== true || rec.converged !== false || binding?.state !== 'incomplete' || !binding.start_wtree || + binding.start_wtree !== binding.end_wtree || !Array.isArray(rec.findings)) return; + const issues = Number(rec.issues_found ?? 0), critical = Number(rec.critical ?? 0); + const listedCritical = rec.findings.filter(f => record(f) && isCriticalFinding(f)).length; + if (rec.findings.length < issues || listedCritical < critical) { + return `its findings list ${rec.findings.length} issue(s) and ${listedCritical} CRITICAL, fewer than the ${issues} issue(s) and ${critical} CRITICAL it claims, so no ruling can cover the rest`; + } + const isRuled = isRuledBy(ruled, gated); + const left = rec.findings.filter(f => !isRuled(f) && holdsOpen(f)) + .map(f => !record(f) ? 'malformed finding' : `${f.fingerprint ?? 'unfingerprinted'} (${f.severity ?? 'unknown'}, ${f.action ?? 'no action'}${f.gate ? `; gate ${f.gate_id ?? 'with no gate_id'} needs a gate disposition, not a ruling` : ''})`); + if (!left.length) return; + return `${left.length} finding(s) still need an owner ruling at this head: ${left.slice(0, 10).join('; ')}${left.length > 10 ? `; +${left.length - 10} more` : ''} (a noted or deferred CRITICAL still counts as open)`; +} + export function reviewFreshness(rec: Record, currentWtree: string, ruled: ReadonlySet = new Set(), gated: ReadonlySet = new Set()): { status: string; reason: string } | undefined { if (!DIFF_REVIEWS.has(rec.skill)) return; if (rec.skill === 'ship') return { status: 'UNVERIFIED', reason: 'ship telemetry is not a review pass' }; diff --git a/test/ship-finish-ruled-notes.test.ts b/test/ship-finish-ruled-notes.test.ts index e3cf7fbba..31ed511ee 100644 --- a/test/ship-finish-ruled-notes.test.ts +++ b/test/ship-finish-ruled-notes.test.ts @@ -606,3 +606,78 @@ describe('Step 11.5 binds a stopped review the owner ruled at its head (harness- expect(run(f, 'gstack-approvals', ['rulings']).stdout).not.toContain('ruled by gstack'); }); }); + +// harness-evals#498 after a26529ac (GST-3267, 2026-11-20): all 22 rulings applied, yet both rows still read UNVERIFIED with the +// fallback reason. The review row also held 7 duplicates logged `noted` at severity CRITICAL with blocking:false (3 of them on +// the in-host native row too), and the review floor keeps a noted CRITICAL open, so each needs its own ruling. The reason +// said "missing start capture or incomplete/nonconverged pass" and named none of them. +const crit = (fp: string, action: string, raised_by: string) => ({ fingerprint: fp, severity: 'CRITICAL', action, blocking: action === 'open', gate: null, raised_by }); +const R22 = Array.from({ length: 22 }, (_, i) => `scripts/mcp/run.ts:${i + 1}:data-loss`); +const DUP_T = Array.from({ length: 4 }, (_, i) => `scripts/mcp/audit.ts:${i + 1}:dup`); +const DUP_N = Array.from({ length: 3 }, (_, i) => `analysis/interim.ts:${i + 1}:dup`); +const INFO = Array.from({ length: 4 }, (_, i) => ({ fingerprint: `scripts/mcp/pins.ts:${i + 1}:parity`, severity: 'INFORMATIONAL', action: 'noted', blocking: false, gate: null, raised_by: 'outside-voice' })); +const HE498_FINAL = { + pass: 2, range_base: null, completed: true, converged: false, status: 'issues_found', issues_found: 22, critical: 22, informational: 11, + findings: [...R22.map(x => crit(x, 'open', 'specialist')), ...DUP_T.map(x => crit(x, 'noted', 'targeted')), ...DUP_N.map(x => crit(x, 'noted', 'adversarial-native')), ...INFO], +}; +const HE498_IN_HOST = { source: 'in-host', completed: true, converged: false, status: 'issues_found', issues_found: null, critical: null, informational: null, + findings: [crit(R22[21]!, 'open', 'adversarial-native'), ...DUP_N.map(x => crit(x, 'noted', 'adversarial-native'))] }; +const HE498_SUBAGENT = { source: 'host-subagent', completed: true, converged: false, status: 'issues_found', issues_found: null, critical: null, informational: null, + findings: [...R22.slice(18, 21).map(x => crit(x, 'open', 'adversarial-native')), ...INFO] }; +const FALLBACK = 'missing start capture or incomplete/nonconverged pass'; +const named = (fps: string[]) => `${fps.length} finding(s) still need an owner ruling at this head: ${fps.slice(0, 10).map(x => `${x} (CRITICAL, ${R22.includes(x) ? 'open' : 'noted'})`).join('; ')}${fps.length > 10 ? `; +${fps.length - 10} more` : ''} (a noted or deferred CRITICAL still counts as open)`; +function finalRows() { + const f = shipFixture({ 'src/x.ts': 'export const x = 1;\n' }, { 'src/x.ts': 'export const x = 2;\n' }); + ships.push(f); + logRow(f, 'review', HE498_FINAL); + logRow(f, 'adversarial-review', HE498_IN_HOST); + logRow(f, 'adversarial-review', HE498_SUBAGENT); + return { f, head: f.git('rev-parse', 'HEAD').stdout.trim() }; +} +const rowsAt = (f: ShipFx) => run(f, 'gstack-review-read', []).stdout.split('\n---CONFIG---')[0]!.split('\n') + .flatMap(l => { try { const v = JSON.parse(l); return v?.review_freshness ? [v] : []; } catch { return []; } }); + +// Value: protects=harness-evals#498 after a26529ac: a stopped pass the owner's rulings leave open names every finding still +// unruled, noted CRITICALs included, and binds once those are ruled; fails_when=the reason stays the bare fallback, omits a +// noted CRITICAL, names a ruled finding, or a noted CRITICAL clears without its own ruling; seam=gstack-review-read over +// rows from gstack-review-log and rulings from gstack-approvals rule; no_claim=finish's FIX_CHECK lines, which keep their +// own FIX_CHECK_OPEN listing +describe('a stopped review names the findings its rulings leave open (harness-evals#498 after a26529ac, GST-3267)', () => { + test('#498 final shape: 22 rulings leave the 7 noted CRITICAL duplicates named, and ruling them binds every row', () => { + const { f, head } = finalRows(); + for (const x of R22) expect(rule(f, x, head, 'harness minder (HARN-1)').status).toBe(0); + const [review, inHost, subagent] = rowsAt(f); + expect([review.review_freshness, inHost.review_freshness, subagent.review_freshness.status]).toEqual([ + { status: 'UNVERIFIED', reason: `${FALLBACK}: ${named([...DUP_T, ...DUP_N])}` }, + { status: 'UNVERIFIED', reason: `${FALLBACK}: ${named(DUP_N)}` }, + 'CURRENT', + ]); + for (const x of [...DUP_T, ...DUP_N]) expect(rule(f, x, head, 'harness minder (HARN-1)').status).toBe(0); + expect(rowsAt(f).map(r => [r.review_freshness.status, r.review_freshness.reason])).toEqual(Array(3).fill(['CURRENT', 'completed clean pass on unchanged content'])); + }); + + test('with no rulings every holding finding counts, capped at ten names', () => { + const { f } = finalRows(); + expect(rowsAt(f)[0].review_freshness.reason).toBe(`${FALLBACK}: ${named([...R22, ...DUP_T, ...DUP_N])}`); + }); + + test('a pass that did not complete, or whose findings do not account for its claim, keeps or explains the plain reason', () => { + const f = shipFixture({ 'src/x.ts': 'export const x = 1;\n' }, { 'src/x.ts': 'export const x = 2;\n' }); + ships.push(f); + logRow(f, 'review', { ...HE498_FINAL, completed: false }); + expect(rowsAt(f)[0].review_freshness).toEqual({ status: 'UNVERIFIED', reason: FALLBACK }); + logRow(f, 'review', { ...HE498_FINAL, issues_found: 40 }); + expect(rowsAt(f).at(-1).review_freshness.reason).toBe(`${FALLBACK}: its findings list 33 issue(s) and 29 CRITICAL, fewer than the 40 issue(s) and 22 CRITICAL it claims, so no ruling can cover the rest`); + }); + + test('a deferred CRITICAL is named, and a ruled gate finding is named with the gate_id its disposition needs', () => { + const f = shipFixture({ 'src/x.ts': 'export const x = 1;\n' }, { 'src/x.ts': 'export const x = 2;\n' }); + ships.push(f); + const gate = { fingerprint: 'test/x.test.ts:3:gate-integrity', severity: 'CRITICAL', action: 'open', blocking: true, gate: 'RH-15', gate_id: 'g-x3', raised_by: 'core' }; + logRow(f, 'review', { completed: true, converged: false, status: 'issues_found', issues_found: 2, critical: 2, informational: 0, + findings: [crit('src/x.ts:1:dup', 'deferred', 'specialist'), gate] }); + const head = f.git('rev-parse', 'HEAD').stdout.trim(); + expect(rule(f, gate.fingerprint, head, 'harness minder (HARN-1)').status).toBe(0); + expect(rowsAt(f)[0].review_freshness.reason).toBe(`${FALLBACK}: 2 finding(s) still need an owner ruling at this head: src/x.ts:1:dup (CRITICAL, deferred); ${gate.fingerprint} (CRITICAL, open; gate g-x3 needs a gate disposition, not a ruling) (a noted or deferred CRITICAL still counts as open)`); + }); +});