mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-21 23:51:35 +01:00
fix(ship): the receipt counts every blocker the readers found (GST-951)
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
dd9834d44d
commit
f4a1cf093b
22 files changed
+322
-36
No files matched your search
@@ -106,7 +106,7 @@ export interface ShipReceipt {
|
||||
// Related open PRs by other authors (Lane D): `supersedes` / `credit` only on the owner's confirmation.
|
||||
issues?: { fixes: number[]; refs: number[]; flakes: Array<{ issue: number; run: string }>; related?: Array<{ pr: number; repo?: string; author: string; closes: number[]; supersedes?: boolean; credit?: boolean }> };
|
||||
/** Harness lane E: the review loop's counters (gstack-review-scope summary) and the carry record when the receipt followed a head whose product diff was unchanged (gstack-ship-receipt carry). */
|
||||
review_loop?: { passes: number; blocking_found: number; deferred: number; noted?: number; fixed?: number; scope?: string; fix_checks?: number; rounds?: number; dispatches?: Record<string, number>; est_input_tokens?: number };
|
||||
review_loop?: { passes: number; blocking_found: number; deferred: number; noted?: number; fixed?: number; scope?: string; fix_checks?: number; rounds?: number; dispatches?: Record<string, number>; est_input_tokens?: number; unrecorded?: number; ledgers?: number };
|
||||
carry?: { 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' };
|
||||
/** The reviewed head's tree and its product patch-id against the base (gstack-ship-receipt write; carry rebinds both): what a carry across rewritten history compares. */
|
||||
head_tree?: string; product_patch_id?: string;
|
||||
|
||||
@@ -360,6 +360,11 @@ export const RELEASE_RESULT_CODES = {
|
||||
summary: 'gstack-review-scope could not read the diff it scopes findings against: the base or the range base does not resolve, or the range base is not an ancestor of HEAD',
|
||||
fix: 'fetch origin/<base>, check --range-base against the saved pass heads, and start a full pass (--pass 1) when history was rewritten',
|
||||
},
|
||||
REVIEW_SCOPE_LEDGER: {
|
||||
anchor: 'review-scope-ledger',
|
||||
summary: 'gstack-review-scope summary could not count the dispatch ledgers: none was named (no --run, --ledger or --no-ledger), --run holds no review-ledger.jsonl, or a ledger, its merged file or its judged set is unreadable or changed since judge',
|
||||
fix: 'pass --run <run dir> (the directory the review passes wrote) or each --ledger <f>; --no-ledger only when no reader ran through gstack-review-dispatch; restore or re-collect a ledger file that moved',
|
||||
},
|
||||
RECEIPT_CARRY_REFUSED: {
|
||||
anchor: 'receipt-carry-refused',
|
||||
summary: 'gstack-ship-receipt carry could not carry the /ship receipt to HEAD: the PR body has no receipt, the working tree has uncommitted changes, the receipt head is not an ancestor of HEAD and the receipt records no tree to compare, or the product diff could not be compared',
|
||||
|
||||
@@ -236,6 +236,40 @@ export function recordJudgment(ledger: string, merged: MergedLine[], judged: Jud
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* The blocking findings a run's ledger holds (GST-951): every collected line whose label ranks CRITICAL, raised to its judged
|
||||
* severity when the newest judge accepted a judged set that is unchanged since; lead judgment's additions count and a folded
|
||||
* duplicate does not. Every reader counts the same way, whatever it is and whether or not Step 9.4 classified its findings.
|
||||
* A ledger, merged file or judged set it cannot read, or a judged set changed since judge, throws: the count is never a guess.
|
||||
*/
|
||||
export function ledgerBlockers(ledger: string): string[] {
|
||||
const fail = (why: string): never => { throw new Error(`${ledger}: ${why}`); };
|
||||
const read = (file: unknown, what: string): string => {
|
||||
try { return fs.readFileSync(String(file), 'utf8'); } catch { return fail(`${what} ${String(file)} is unreadable`); }
|
||||
};
|
||||
const jsonLines = (text: string, what: string): any[] =>
|
||||
text.split('\n').filter(l => l.trim()).map(l => { try { return JSON.parse(l); } catch { return fail(`${what} has a line that is not JSON`); } });
|
||||
const events = jsonLines(read(ledger, 'ledger'), 'the ledger') as LedgerEvent[];
|
||||
const ranks = new Map<string, number>();
|
||||
for (const o of events.filter(e => e.event === 'output' && Array.isArray(e.ids) && e.ids.length)) {
|
||||
const lines = jsonLines(read(o.merged, `merged file of ${String(o.reader)}`), String(o.merged)) as MergedLine[];
|
||||
for (const id of o.ids as string[]) {
|
||||
const line = lines.find(l => l.id === id) ?? fail(`collected id ${id} is missing from ${String(o.merged)}`);
|
||||
ranks.set(id, rank(line.label) ?? 0);
|
||||
}
|
||||
}
|
||||
const verdict = [...events].reverse().find(e => e.event === 'judge');
|
||||
if (verdict?.ok === true) {
|
||||
const text = read(verdict.judged, 'judged set');
|
||||
if (promptHash(text) !== verdict.judged_sha256) fail(`judged set ${String(verdict.judged)} changed since judge`);
|
||||
for (const j of jsonLines(text, String(verdict.judged)) as JudgedLine[]) {
|
||||
if (j.duplicate_of) ranks.delete(j.id);
|
||||
else ranks.set(j.id, Math.max(ranks.get(j.id) ?? 0, rank(j.severity) ?? 0));
|
||||
}
|
||||
}
|
||||
return [...ranks].filter(([, r]) => r >= 4).map(([id]) => id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a recorded output was a review: it has findings, or its file (unchanged since collect) carries the reader's clean marker, so
|
||||
* a ledger written before collect recorded the field is judged by the same rule; with no readable file, collect's own review field.
|
||||
|
||||
+39
-4
@@ -14,6 +14,7 @@
|
||||
* Pure functions here; bin/gstack-review-scope runs git and gh.
|
||||
*/
|
||||
import { SPECIALISTS } from './review-depth';
|
||||
import { rank } from './review-ledger';
|
||||
import { parseSpecialistOutput } from './state-matrix';
|
||||
|
||||
export type Locus = 'diff' | 'fix-range' | 'outside';
|
||||
@@ -306,6 +307,10 @@ export interface ReviewLoopSummary {
|
||||
dispatches?: Record<string, number>;
|
||||
/** Prompt plus diff bytes the dispatches read, / 4: a relative estimate, never a bill. */
|
||||
est_input_tokens?: number;
|
||||
/** Blocking findings no row gives a disposition (fixed, deferred, noted, skipped or a gate answer): found, outcome unrecorded. */
|
||||
unrecorded?: number;
|
||||
/** Dispatch ledgers whose collected and judged findings were counted (gstack-review-dispatch). */
|
||||
ledgers?: number;
|
||||
}
|
||||
|
||||
/** Review-log rows of one /ship invocation (skill review, via ship, at or after `since`) → the loop summary. */
|
||||
@@ -348,12 +353,29 @@ function rowDispatches(row: Record<string, any>): Array<{ role: string; bytes: n
|
||||
.map(([name]) => ({ role: name === 'red-team' ? 'red-team' : 'specialist', bytes: null }));
|
||||
}
|
||||
|
||||
export function summarizeReviewLoop(rows: readonly Record<string, any>[], since: string): ReviewLoopSummary {
|
||||
/** Row actions that record what happened to a finding. */
|
||||
const DISPOSITIONS = ['fixed', 'auto-fixed', 'deferred', 'noted', 'skipped', 'kept', 'restored', 'open'];
|
||||
/** A row finding that blocks: classified blocking, or an unclassified CRITICAL defect (logged before Step 9.4's classify). */
|
||||
const rowBlocks = (f: Record<string, any>) => f.blocking === true || (f.blocking === undefined && f.advisory !== true && rank(f.severity) === 4);
|
||||
/** The reviewer a finding counts under: a row's raised_by or a ledger id's reader; every specialist is one group, as in the ledger. */
|
||||
function raiserGroup(raiser: unknown): string {
|
||||
const role = typeof raiser === 'string' ? raiser.split(/[/#]/)[0]!.trim() : '';
|
||||
if (!role || role === 'unknown') return 'unattributed';
|
||||
return ['core', 'qa', 'red-team', 'adversarial-native', 'outside-voice', 'fix-check', 'targeted'].includes(role) ? role : 'specialist';
|
||||
}
|
||||
|
||||
/**
|
||||
* The loop summary. blocking_found counts every blocker found (GST-951): per reviewer group, the larger of the rows'
|
||||
* blockers and the dispatch ledgers' CRITICAL findings (`ledgerBlockers`, one id list per ledger), so a blocker that only
|
||||
* a ledger holds (an adversarial or outside-voice finding, a finding logged before classification) still counts. Two
|
||||
* sources can each hold one the other lacks only when the rows name no reviewer; then the count may run high, never low.
|
||||
*/
|
||||
export function summarizeReviewLoop(rows: readonly Record<string, any>[], since: string, ledgers: readonly (readonly string[])[] = []): ReviewLoopSummary {
|
||||
const sinceMs = Date.parse(since);
|
||||
const inRun = (r: Record<string, any>) => r && r.via === 'ship' && Number.isFinite(rowTime(r)) && (!Number.isFinite(sinceMs) || rowTime(r) >= sinceMs);
|
||||
const loopRows = rows.filter(r => inRun(r) && (r.skill === 'review' || r.skill === LATE_DEFER_SKILL || r.skill === FIX_CHECK_SKILL));
|
||||
const passes = loopRows.filter(r => r.skill === 'review');
|
||||
const blocking = new Set<string>();
|
||||
const blocking = new Map<string, { group: string; disposed: boolean }>();
|
||||
const deferred = new Set<string>();
|
||||
const noted = new Set<string>();
|
||||
const fixed = new Set<string>();
|
||||
@@ -363,13 +385,25 @@ export function summarizeReviewLoop(rows: readonly Record<string, any>[], since:
|
||||
for (const f of Array.isArray(row.findings) ? row.findings : []) {
|
||||
if (!f || typeof f !== 'object') continue;
|
||||
const id = findingIdentity(f);
|
||||
if (f.blocking === true) blocking.add(id);
|
||||
if (rowBlocks(f)) {
|
||||
const b = blocking.get(id) ?? { group: raiserGroup(f.raised_by), disposed: false };
|
||||
if (DISPOSITIONS.includes(f.action)) b.disposed = true;
|
||||
blocking.set(id, b);
|
||||
}
|
||||
if (f.action === 'deferred') deferred.add(id);
|
||||
if (f.action === 'noted') noted.add(id);
|
||||
if (f.action === 'fixed' || f.action === 'auto-fixed') fixed.add(id);
|
||||
}
|
||||
}
|
||||
const out: ReviewLoopSummary = { passes: passes.length, blocking_found: blocking.size, deferred: deferred.size, noted: noted.size, fixed: fixed.size, scope };
|
||||
const groups = new Map<string, { rows: number; disposed: number; ledger: number }>();
|
||||
const tally = (g: string) => groups.get(g) ?? groups.set(g, { rows: 0, disposed: 0, ledger: 0 }).get(g)!;
|
||||
for (const b of blocking.values()) { const t = tally(b.group); t.rows++; if (b.disposed) t.disposed++; }
|
||||
for (const id of ledgers.flat()) tally(raiserGroup(id)).ledger++;
|
||||
let found = 0; let unrecorded = 0;
|
||||
for (const t of groups.values()) { const n = Math.max(t.rows, t.ledger); found += n; unrecorded += n - t.disposed; }
|
||||
const out: ReviewLoopSummary = { passes: passes.length, blocking_found: found, deferred: deferred.size, noted: noted.size, fixed: fixed.size, scope };
|
||||
if (unrecorded) out.unrecorded = unrecorded;
|
||||
if (ledgers.length) out.ledgers = ledgers.length;
|
||||
const fixChecks = loopRows.filter(r => r.skill === FIX_CHECK_SKILL).length;
|
||||
if (fixChecks) out.fix_checks = fixChecks;
|
||||
out.rounds = passes.length + fixChecks;
|
||||
@@ -390,5 +424,6 @@ export function dispatchTotal(d: Record<string, number> | undefined): number | u
|
||||
export function reviewLoopLine(s: ReviewLoopSummary): string {
|
||||
const total = dispatchTotal(s.dispatches);
|
||||
return `REVIEW_LOOP: passes=${s.passes} blocking_found=${s.blocking_found} deferred=${s.deferred} noted=${s.noted} fixed=${s.fixed} scope=${s.scope}`
|
||||
+ (s.unrecorded ? ` unrecorded=${s.unrecorded}` : '') + (s.ledgers ? ` ledgers=${s.ledgers}` : '')
|
||||
+ (s.fix_checks ? ` fix_checks=${s.fix_checks}` : '') + (total !== undefined ? ` dispatches=${total}` : '') + (s.est_input_tokens !== undefined ? ` est_input_tokens=${s.est_input_tokens}` : '');
|
||||
}
|
||||
@@ -328,6 +328,8 @@ export function parseReviewLoop(value: unknown): ReviewLoopReceipt | undefined {
|
||||
if (n('fix_checks') !== undefined) out.fix_checks = n('fix_checks');
|
||||
if (n('rounds') !== undefined) out.rounds = n('rounds');
|
||||
if (n('est_input_tokens') !== undefined) out.est_input_tokens = n('est_input_tokens');
|
||||
if (n('unrecorded')) out.unrecorded = n('unrecorded');
|
||||
if (n('ledgers')) out.ledgers = n('ledgers');
|
||||
if (v.dispatches && typeof v.dispatches === 'object' && !Array.isArray(v.dispatches)) {
|
||||
const d = Object.fromEntries(Object.entries(v.dispatches as Record<string, unknown>)
|
||||
.filter(([k, c]) => /^[a-z][a-z0-9-]{0,39}$/.test(k) && typeof c === 'number' && Number.isInteger(c) && c >= 0).slice(0, 12)) as Record<string, number>;
|
||||
|
||||
Reference in new issue
Block a user