mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-30 03:44:38 +01:00
Code changes get a second-model review of their final fixes, and the shipping record names that model's family (GST-4140) (#4886)
When a code change's first review leads to fixes, the second-model review now reads those fixes and the final review again, instead of being skipped once it had run. A reviewer from the same model family as the author (a Claude reader checking Claude's work) no longer counts as the second model, and the review record names the model family that reviewed. Nothing to do: when the second model can't run (Codex down, rate-limited or refused), that is still recorded and never blocks shipping. 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: s11/outside-voice#1 reader=outside-voice Review-Finding: s11/outside-voice#2 reader=outside-voice Review-Finding: s11/outside-voice#3 reader=outside-voice Review-Finding: s11/outside-voice#4 reader=outside-voice Review-Finding: s11/adversarial-native#1 reader=adversarial-native Review-Finding: s11/adversarial-native#2 reader=adversarial-native Review-Finding: s11/adversarial-native#3 reader=adversarial-native Review-Finding: s11/adversarial-native#5 reader=adversarial-native Review-Finding: s11/adversarial-native#7 reader=adversarial-native
This commit is contained in:
1 parent
942a12c618
commit
4a40464ea7
20 files changed
+557
-38
No files matched your search
+15
-4
@@ -103,7 +103,11 @@ const briefText = async (r) => {
|
||||
};
|
||||
const roleArgs = (r) => ' --role ' + q(r.role) + (r.name ? ' --name ' + q(r.name) : '') + (r.slice ? ' --slice ' + r.slice.index + '/' + r.slice.total : '');
|
||||
const REASONING = { medium: 'medium', light: 'low' };
|
||||
const family = (id) => (typeof id === 'string' && id.includes('/') ? id.slice(0, id.indexOf('/')).toLowerCase() : '');
|
||||
const FAMILY_ALIASES = { particle: 'deepseek', 'particle-ai': 'deepseek', moonshotai: 'moonshot', 'meta-llama': 'meta', mistralai: 'mistral', alibaba: 'qwen' };
|
||||
const family = (id) => {
|
||||
const prefix = typeof id === 'string' && id.includes('/') ? id.slice(0, id.indexOf('/')).toLowerCase() : '';
|
||||
return FAMILY_ALIASES[prefix] || prefix;
|
||||
};
|
||||
const DEFAULT_OUTSIDE = { model_id: 'openai/gpt-6.2-sol', reasoning_mode: 'medium' };
|
||||
const voiceFile = input.out.replace(/\/+$/, '') + '/voice-models.json';
|
||||
let voices = { laneModel: null, readers: {} };
|
||||
@@ -132,12 +136,19 @@ const familyStop = (readers) => {
|
||||
}
|
||||
return null;
|
||||
};
|
||||
const voiceArgs = (m, r) => {
|
||||
if (r.role !== 'outside-voice') return '';
|
||||
const native = m.readers.find((x) => x.role === 'adversarial-native');
|
||||
const nm = voices.laneModel || input.laneModel || (native && modelOf(native) ? modelOf(native).model_id : undefined);
|
||||
const om = modelOf(r);
|
||||
return (om ? ' --outside-model ' + q(om.model_id) + ' --outside-provider host-subagent' : '') + (nm ? ' --native-model ' + q(nm) : '');
|
||||
};
|
||||
const safe = (s) => s.replace(/[^a-zA-Z0-9._-]/g, '_');
|
||||
const UNAVAILABLE = 'unavailable: ';
|
||||
const recordUnavailable = async (m, r, why) => {
|
||||
const file = m.out + '/out/' + safe(r.reader) + '.unavailable.txt';
|
||||
await tools.capy.write({ path: file, content: 'outside voice (' + modelOf(r).model_id + ') ' + why + '\n' });
|
||||
const c = await sh(bin + ' collect --ledger ' + q(m.ledger) + roleArgs(r) + ' --output ' + q(file) + ' --merged ' + q(m.merged) + ' --manifest ' + q(mf) + ' --unavailable ' + q(why));
|
||||
const c = await sh(bin + ' collect --ledger ' + q(m.ledger) + roleArgs(r) + voiceArgs(m, r) + ' --output ' + q(file) + ' --merged ' + q(m.merged) + ' --manifest ' + q(mf) + ' --unavailable ' + q(why));
|
||||
if (c.code !== 0) return stop('collect --unavailable ' + r.reader + ' exited ' + c.code + ': ' + c.out.slice(-500));
|
||||
lines.push(c.out.trim());
|
||||
await mark(r.reader, 'collected', { output: file, error: UNAVAILABLE + why });
|
||||
@@ -272,7 +283,7 @@ try {
|
||||
await tools.capy.write({ path: file, content: g.summary });
|
||||
if (ended) {
|
||||
const why = (hostError && cyberWhy(hostError)) || t.status + ' before finishing its review';
|
||||
const u = await sh(bin + ' collect --ledger ' + q(m.ledger) + roleArgs(r) + ' --output ' + q(file) + ' --merged ' + q(m.merged) + ' --manifest ' + q(mf) + ' --unavailable ' + q(why));
|
||||
const u = await sh(bin + ' collect --ledger ' + q(m.ledger) + roleArgs(r) + voiceArgs(m, r) + ' --output ' + q(file) + ' --merged ' + q(m.merged) + ' --manifest ' + q(mf) + ' --unavailable ' + q(why));
|
||||
if (u.code === 0) {
|
||||
if (hostError) await refusal(m, r, hostError);
|
||||
lines.push(u.out.trim());
|
||||
@@ -281,7 +292,7 @@ try {
|
||||
}
|
||||
}
|
||||
const c = await sh(r.prompt_file ? bin + ' mark --manifest ' + q(mf) + ' --reader ' + q(r.reader) + ' --state collected --output ' + q(file)
|
||||
: bin + ' collect --ledger ' + q(m.ledger) + roleArgs(r) + ' --output ' + q(file) + ' --merged ' + q(m.merged) + ' --manifest ' + q(mf));
|
||||
: bin + ' collect --ledger ' + q(m.ledger) + roleArgs(r) + voiceArgs(m, r) + ' --output ' + q(file) + ' --merged ' + q(m.merged) + ' --manifest ' + q(mf));
|
||||
if (c.code !== 0) return stop((r.prompt_file ? 'mark ' : 'collect ') + r.reader + ' exited ' + c.code + ': ' + c.out.slice(-500));
|
||||
if (!r.prompt_file) {
|
||||
lines.push(c.out.trim());
|
||||
|
||||
@@ -152,6 +152,8 @@ export interface ShipReceipt {
|
||||
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 }>;
|
||||
/** The second-model read (lib/outside-voice-record.ts, GST-4140): completed only by a recognized family other than native_family; missing coverage is unavailable or skipped. */
|
||||
outside_voice?: { status: 'completed' | 'unavailable' | 'skipped'; provider: string; model: string; family: string; native_family?: string; reason?: string };
|
||||
}
|
||||
export const NO_STOP_CLASSES = ['scoped-fix-check', 'test-timeout-fix', 'pregate-flake-rerun', 'autoplan-regate'] as const;
|
||||
export type NoStopClass = typeof NO_STOP_CLASSES[number];
|
||||
@@ -290,6 +292,7 @@ export const ARTIFACT_SCHEMAS = {
|
||||
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 } },
|
||||
outside_voice: { type: 'object', required: ['status', 'provider', 'model', 'family'], properties: { status: { enum: ['completed', 'unavailable', 'skipped'] }, provider: str, model: str, family: str, native_family: str, reason: str } },
|
||||
// Legacy (GST-3562 part 4): receipts written before fix-check and round grants were removed may carry these; nothing reads them.
|
||||
review_loop_exception: { type: 'object' }, review_round_grants: { type: 'array' }, cleared_by_grant: { type: 'object' },
|
||||
cleared_by_trailer: { type: 'array', items: { type: 'object', required: ['id', 'commit', 'review'], properties: { id: str, commit: str, review: str } } },
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
/**
|
||||
* The outside voice's record (GST-4140): which provider and model read the diff, its family, and whether that read counts as
|
||||
* second-model coverage. gstack-review-dispatch collect records it on the outside voice's output event and refuses a
|
||||
* same-family read, verify prints it as OUTSIDE_VOICE_RECORD:, and gstack-ship-receipt write binds it as the receipt's
|
||||
* outside_voice. A same-family fallback is one voice, never outside coverage; missing coverage is recorded as unavailable or
|
||||
* skipped and never blocks.
|
||||
*/
|
||||
import { familyConflict, modelFamily, type ModelFamily } from './outside-voice-runner';
|
||||
|
||||
/** The reason verify records a completed outside read whose model family was never recorded: not proven second-model coverage. */
|
||||
export const UNPROVEN_FAMILY = 'the outside read recorded no recognizable model family, so it is not proven second-model coverage';
|
||||
/** The reason verify records a completed outside read with no recognized native family to compare it to: not proven a second family. */
|
||||
export const UNPROVEN_NATIVE = 'the outside read recorded no recognizable native model family (collect --native-model), so it is not proven a second family';
|
||||
|
||||
export const OUTSIDE_VOICE_STATUSES = ['completed', 'unavailable', 'skipped'] as const;
|
||||
export type OutsideVoiceStatus = typeof OUTSIDE_VOICE_STATUSES[number];
|
||||
export interface OutsideVoiceRecord { status: OutsideVoiceStatus; provider: string; model: string; family: ModelFamily | string; native_family?: ModelFamily | string; reason?: string }
|
||||
/** Who read: recorded on a collected outside voice's output event. */
|
||||
export interface OutsideProvenance { provider: string; model: string; family: ModelFamily | string; native_model?: string; native_family?: ModelFamily | string }
|
||||
|
||||
/**
|
||||
* A model id's family: lib/outside-voice-runner.ts's rules on the whole id, then on its last path segment (a router prefix such as
|
||||
* `openrouter/anthropic/claude-…` keeps Claude's family); `unknown` otherwise. A bare provider prefix never names a family: a router
|
||||
* (`bedrock/anthropic.claude-…`) would read as a second family.
|
||||
*/
|
||||
export function familyOf(model: string | undefined | null): string {
|
||||
const id = (model ?? '').trim().toLowerCase();
|
||||
const own = modelFamily(id);
|
||||
return own !== 'unknown' ? own : modelFamily(id.split('/').at(-1));
|
||||
}
|
||||
|
||||
/**
|
||||
* The reply's closing `OUTSIDE_STATUS: <status> provider=<p> model=<m> …` line (bin/gstack-outside-voice prints it last); undefined
|
||||
* when the last non-empty line is anything else, so a status line quoted inside the review text never counts.
|
||||
*/
|
||||
export function parseOutsideStatus(text: string): { status: string; provider?: string; model?: string } | undefined {
|
||||
const line = text.replace(/\r\n/g, '\n').split('\n').map(l => l.trim()).filter(Boolean).at(-1);
|
||||
if (!line?.startsWith('OUTSIDE_STATUS: ')) return undefined;
|
||||
const [status = '', ...rest] = line.slice('OUTSIDE_STATUS: '.length).split(/\s+/);
|
||||
const kv = Object.fromEntries(rest.map(p => p.split('=')).filter(p => p.length === 2 && p[1]) as [string, string][]);
|
||||
return { status, provider: kv.provider, model: kv.model && kv.model !== 'unknown' ? kv.model : undefined };
|
||||
}
|
||||
|
||||
/**
|
||||
* The provenance collect records, from its flags or else the reply's closing OUTSIDE_STATUS line; undefined when neither is there.
|
||||
* The family always comes from the model id (familyOf), never from a printed `family=`; a model that names none is `unknown`.
|
||||
*/
|
||||
export function outsideProvenance(o: { model?: string; provider?: string; nativeModel?: string; output: string }): OutsideProvenance | undefined {
|
||||
const status = parseOutsideStatus(o.output);
|
||||
if (!o.model && !o.provider && !status) return undefined;
|
||||
const model = o.model ?? status?.model ?? 'unknown';
|
||||
const family = familyOf(model);
|
||||
const native = o.nativeModel ? familyOf(o.nativeModel) : undefined;
|
||||
return { provider: o.provider ?? status?.provider ?? 'unknown', model, family, ...(o.nativeModel ? { native_model: o.nativeModel, native_family: native } : {}) };
|
||||
}
|
||||
|
||||
/** Why a read with this provenance is not outside coverage: the same family as the lane's native model. undefined when it may count. */
|
||||
export function sameFamily(p: OutsideProvenance): string | undefined {
|
||||
if (!p.native_model || p.family === 'unknown' || !p.native_family || p.native_family === 'unknown') return undefined;
|
||||
return p.family === p.native_family ? (familyConflict(p.model, p.native_model) ?? `outside ${p.model} and native ${p.native_model} are both ${p.family}`) : undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Why a read by `model` is not proven second-model coverage: its family is unrecognized or not the model's own, the native family is
|
||||
* missing or unrecognized, or the two are the same. undefined only for a recognized family beside a different recognized native family.
|
||||
*/
|
||||
export function unprovenCoverage(r: { model: string; family: string; native_family?: string }): string | undefined {
|
||||
if (r.family === 'unknown' || familyOf(r.model) !== r.family) return UNPROVEN_FAMILY;
|
||||
if (!r.native_family || r.native_family === 'unknown') return UNPROVEN_NATIVE;
|
||||
return r.native_family === r.family ? `the outside read by ${r.model} is the ${r.family} family, the same as the lane's native family: a same-family fallback is never outside coverage` : undefined;
|
||||
}
|
||||
|
||||
/** The receipt-side check: a completed record needs a recognized family and a different recognized native_family; every record needs a known status. */
|
||||
export function outsideVoiceProblem(r: unknown): string | undefined {
|
||||
if (!r || typeof r !== 'object' || Array.isArray(r)) return 'outside_voice must be an object { status, provider, model, family }';
|
||||
const v = r as Record<string, unknown>;
|
||||
if (!(OUTSIDE_VOICE_STATUSES as readonly unknown[]).includes(v.status)) return `outside_voice.status must be one of ${OUTSIDE_VOICE_STATUSES.join(', ')}, got ${JSON.stringify(v.status)}`;
|
||||
for (const k of ['provider', 'model', 'family'] as const) if (typeof v[k] !== 'string' || !v[k]) return `outside_voice.${k} must be a non-empty string`;
|
||||
if (v.status !== 'completed') return undefined;
|
||||
const why = unprovenCoverage({ model: String(v.model), family: String(v.family), native_family: typeof v.native_family === 'string' ? v.native_family : undefined });
|
||||
return why && `outside_voice records a completed read by ${v.model} (family ${v.family}, native_family ${typeof v.native_family === 'string' ? v.native_family : 'none'}), but ${why}; record it as unavailable`;
|
||||
}
|
||||
+12
-1
@@ -412,7 +412,9 @@ export interface History {
|
||||
* keepReader (GST-3562 A): this step stands where main's table planned a fix-check, or is the read-only final review, so its
|
||||
* dispatch keeps one full-effort reader that excludes nothing (the reader the fix-check was). The table sets it; prCapped's
|
||||
* spreads carry it; the dispatch reads it, never the reason text. readOnly marks the read-only final review: the dispatcher
|
||||
* stages it on the PR's merge base whatever --diff-base the driver passes, and Step 3's edit guard applies no fix on it.
|
||||
* stages it on the PR's merge base whatever --diff-base the driver passes, and Step 3's edit guard applies no fix on it. On
|
||||
* code and gate class it lists both Step 11 voices again, and every later full pass lists the outside voice again, after
|
||||
* Step 11 ran (GST-4140): the final head is never shipped without a second-model read of it.
|
||||
* rangeReaders (GST-3562 part 3): this full pass stands where main planned a scoped pass after a small blocking fix, so it
|
||||
* also dispatches the readers that pass ran: the Red Team, and the native adversarial when the fix range has runtime lines,
|
||||
* even after Step 11 ran it.
|
||||
@@ -647,6 +649,7 @@ export function planReviewAt(i: PlanInput, table: (h: History, depth: Depth) =>
|
||||
const docsAndOutputs = i.paths.filter(p => !i.excluded?.has(p) && ((pathClass(i, p) === 'docs' && !(i.numbers.publishes && DOC_PATH.test(p))) || isOutput(i, p))).map(excludeSpec);
|
||||
const numbersChanged = i.numbers.publishes && i.reviewedNumbers !== undefined && i.reviewedNumbers !== i.numbers.fingerprint;
|
||||
const firstVoices = h.fullPasses === 0 || !i.adversarialRan;
|
||||
let finalAdversarial = false;
|
||||
const specialist: Effort = i.tiers === false ? 'host' : ROLE_EFFORT.specialist;
|
||||
if (next.step === 'full' && stepDepth === 'light') {
|
||||
const forced = forcedBy(i);
|
||||
@@ -682,6 +685,13 @@ export function planReviewAt(i: PlanInput, table: (h: History, depth: Depth) =>
|
||||
else skipped.push(`adversarial-native (${dcls} class)`);
|
||||
if (codeLike || i.numbers.publishes) add('outside-voice', 'outside-voice', 'host');
|
||||
else skipped.push(`outside-voice (${dcls} class, no numeric claims)`);
|
||||
} else if (codeLike) {
|
||||
if (rangeAdversarial) add('adversarial-native', 'adversarial', 'full');
|
||||
else if (next.readOnly) finalAdversarial = true;
|
||||
else skipped.push('adversarial-native (run once per invocation)');
|
||||
if (next.readOnly || h.rangeRuntimeLines !== 0) add('outside-voice', 'outside-voice', 'host');
|
||||
else if (numbersChanged) add('outside-voice', 'outside-voice (numbers changed)', 'host');
|
||||
else skipped.push('outside-voice (run once per invocation: the fix range changes no runtime lines)');
|
||||
} else {
|
||||
if (rangeAdversarial) add('adversarial-native', 'adversarial', 'full');
|
||||
skipped.push(rangeAdversarial ? 'outside-voice (run once per invocation)' : 'adversarial-native and outside-voice (run once per invocation)');
|
||||
@@ -707,6 +717,7 @@ export function planReviewAt(i: PlanInput, table: (h: History, depth: Depth) =>
|
||||
add('outside-voice', 'outside-voice', 'host');
|
||||
}
|
||||
if (next.keepReader && !dispatches.some(d => d.effort === 'full' && d.exclude.length === (x?.specs.length ?? 0))) add('red-team', 'red-team', 'full');
|
||||
if (finalAdversarial) add('adversarial-native', 'adversarial', 'full');
|
||||
if (i.targeted?.classes.length && ['full', 'scoped', 'fix-check', 'voices'].includes(next.step)) {
|
||||
if (i.targeted.ran) skipped.push('targeted (already read this product patch)');
|
||||
else add('targeted', 'targeted', ROLE_EFFORT.targeted);
|
||||
|
||||
+28
-3
@@ -19,6 +19,7 @@ import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import { checkReviewedTree, isReviewedTreeLine, promptHash, type TreeCheck } from './review-brief';
|
||||
import { parseVerdict, withoutVerdictLines } from './review-verdict';
|
||||
import { UNPROVEN_FAMILY, unprovenCoverage, type OutsideProvenance, type OutsideVoiceRecord } from './outside-voice-record';
|
||||
|
||||
export interface LedgerEvent { event: 'rendered' | 'sent' | 'output' | 'judgment' | 'judge' | 'program' | 'quarantined' | 'fetch-sweep'; [k: string]: unknown }
|
||||
export const readerKey = (role: string, name?: string, slice?: { index: number; total: number }) => `${name ? `${role}/${name}` : role}${slice ? `#${slice.index}/${slice.total}` : ''}`;
|
||||
@@ -434,7 +435,7 @@ const hasCleanMarker = (reader: string, output: string) => output.replace(/\r\n/
|
||||
* review: false. With unavailable (the outside voice only) the output is its failure text, recorded as missing coverage. With a
|
||||
* failed tree check (GST-482: the reply reviewed another checkout, or names none) nothing is merged and the output is no review.
|
||||
*/
|
||||
export function collect(ledger: string, reader: string, output: string, mergedFile: string, outputFile?: string, unavailable?: string, tree?: TreeCheck, raises = true): { sha: string; lines: MergedLine[]; review: boolean; verdict?: VerdictCheck } {
|
||||
export function collect(ledger: string, reader: string, output: string, mergedFile: string, outputFile?: string, unavailable?: string, tree?: TreeCheck, raises = true, outside?: OutsideProvenance): { sha: string; lines: MergedLine[]; review: boolean; verdict?: VerdictCheck } {
|
||||
const sha = promptHash(output);
|
||||
const events = readLedger(ledger);
|
||||
const prior = events.filter(e => e.event === 'output' && e.reader === reader).length;
|
||||
@@ -449,12 +450,32 @@ export function collect(ledger: string, reader: string, output: string, mergedFi
|
||||
const review = !unavailable && !wrongTree && (lines.length > 0 || hasCleanMarker(reader, output));
|
||||
fs.appendFileSync(mergedFile, lines.map(l => JSON.stringify(l) + '\n').join(''), { mode: 0o600 });
|
||||
appendEvent(ledger, { event: 'output', reader, sha256: sha, file: outputFile ? path.resolve(outputFile) : null, merged: path.resolve(mergedFile), ids: lines.map(l => l.id), review, ...(unavailable ? { unavailable } : {}), ...(raises ? {} : { fixable_raises: false }),
|
||||
...(tree && !unavailable ? { tree: tree.expected, reported_tree: tree.reported, tree_ok: tree.ok } : {}), ...('verdict' in reply && reply.verdict ? { verdict: reply.verdict } : {}) });
|
||||
...(tree && !unavailable ? { tree: tree.expected, reported_tree: tree.reported, tree_ok: tree.ok } : {}), ...('verdict' in reply && reply.verdict ? { verdict: reply.verdict } : {}), ...(outside ? { outside } : {}) });
|
||||
return { sha, lines, review, ...('verdict' in reply && reply.verdict ? { verdict: reply.verdict } : {}) };
|
||||
}
|
||||
/** The outside voice may fail without blocking (ship/sections/adversarial.md): its failure is recorded as unavailable coverage, never as a review. */
|
||||
export const mayBeUnavailable = (reader: string) => roleOf(reader) === 'outside-voice';
|
||||
const unavailableOutput = (o: LedgerEvent) => typeof o.unavailable === 'string' && mayBeUnavailable(String(o.reader));
|
||||
const provenance = (o: LedgerEvent) => (o.outside && typeof o.outside === 'object' ? o.outside as OutsideProvenance : undefined);
|
||||
/** A collected read by the lane's own family (GST-4140): never outside coverage, so verify fails it. */
|
||||
const sameFamilyOutput = (o: LedgerEvent) => { const p = provenance(o); return !unavailableOutput(o) && !!p?.native_family && p.native_family !== 'unknown' && p.family !== 'unknown' && p.family === p.native_family; };
|
||||
|
||||
/**
|
||||
* The outside voice's record for the receipt (GST-4140): its last collected output, a review (completed) or missing coverage
|
||||
* (unavailable), with the provider, model and family collect recorded. A review is completed only when its recognized family differs
|
||||
* from a recognized native family (unprovenCoverage); any other review is unavailable with the reason, never a completed read the
|
||||
* receipt would refuse. undefined when no outside voice output was collected; the plan that skipped it is recorded as skipped by the
|
||||
* caller. verify prints it only on a clean ledger.
|
||||
*/
|
||||
export function outsideVoiceRecord(ledger: string): OutsideVoiceRecord | undefined {
|
||||
const o = readLedger(ledger).filter(e => e.event === 'output' && mayBeUnavailable(String(e.reader)) && (e.review === true || unavailableOutput(e))).at(-1);
|
||||
if (!o) return undefined;
|
||||
const p = provenance(o);
|
||||
const family = p?.family ?? 'unknown';
|
||||
const reason = unavailableOutput(o) ? String(o.unavailable) : p ? unprovenCoverage(p) : UNPROVEN_FAMILY;
|
||||
return { status: reason ? 'unavailable' : 'completed', provider: p?.provider ?? 'unknown', model: p?.model ?? 'unknown', family,
|
||||
...(p?.native_family ? { native_family: p.native_family } : {}), ...(reason ? { reason } : {}) };
|
||||
}
|
||||
|
||||
export function readJsonl<T>(file: string): T[] {
|
||||
return fs.readFileSync(file, 'utf8').split('\n').filter(l => l.trim()).map(l => JSON.parse(l) as T);
|
||||
@@ -600,7 +621,7 @@ const collectedIds = (events: LedgerEvent[]) => {
|
||||
return events.filter(e => e.event === 'output').flatMap(idsOf).filter(id => !gone.has(id));
|
||||
};
|
||||
|
||||
export interface VerifyRow { kind: 'BRIEF' | 'OUTPUT' | 'JUDGE' | 'FETCH' | 'VERDICT' | 'SLICE'; reader: string; status: string; detail: string }
|
||||
export interface VerifyRow { kind: 'BRIEF' | 'OUTPUT' | 'JUDGE' | 'FETCH' | 'VERDICT' | 'SLICE' | 'OUTSIDE'; reader: string; status: string; detail: string }
|
||||
|
||||
/** Replay every check from a finished run's ledger: briefs dispatched as rendered, outputs merged as returned, judgment without loss. */
|
||||
export function verify(ledger: string): { rows: VerifyRow[]; clean: boolean; briefs: number; voided: number; unavailable: number; verdicts: { asked: number; agree: number } } {
|
||||
@@ -735,6 +756,10 @@ export function verify(ledger: string): { rows: VerifyRow[]; clean: boolean; bri
|
||||
const found = Array.isArray(s.found) ? (s.found as Array<{ path: string }>) : [];
|
||||
rows.push({ kind: 'FETCH', reader: `${String(s.pass)}/${String(s.stage)}#${String(s.attempt)}`, status: s.verdict === 'violation' ? (resolved ? 'RESOLVED' : 'VIOLATION') : String(s.verdict).toUpperCase(), detail: `found=${found.length}${found.length ? ` paths=${JSON.stringify(found.map(x => x.path))}` : ''}${s.partial ? ` partial=${JSON.stringify(s.partial)}` : ''}` });
|
||||
}
|
||||
for (const o of events.filter(e => e.event === 'output' && sameFamilyOutput(e))) {
|
||||
const p = provenance(o)!;
|
||||
rows.push({ kind: 'OUTSIDE', reader: String(o.reader), status: 'SAME_FAMILY', detail: `model=${p.model} family=${p.family} native_family=${p.native_family} (a same-family read is never outside coverage)` });
|
||||
}
|
||||
const clean = episodes.length > 0 && rows.every(r => ['MATCH', 'OK', 'VOIDED', 'UNAVAILABLE', 'SUPERSEDED', 'CLEAN', 'PARTIAL', 'RESOLVED'].includes(r.status));
|
||||
rows.push(...verdicts);
|
||||
return { rows, clean, briefs: episodes.length, voided, unavailable: rows.filter(r => r.kind === 'BRIEF' && r.status === 'UNAVAILABLE').length,
|
||||
|
||||
+5
-1
@@ -19,6 +19,7 @@ import { laneExceptionBodyLines } from './test-lane-exception';
|
||||
import { rerunMarker } from './run-evidence';
|
||||
import { stampFileKind, versionStampOnly } from './pregate/stamp-only';
|
||||
import { stampOnlyLine, type BranchSide } from './stamp-only';
|
||||
import { outsideVoiceProblem } from './outside-voice-record';
|
||||
|
||||
export const RECEIPT_FENCE = 'gstack-ship-receipt';
|
||||
|
||||
@@ -54,7 +55,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',
|
||||
'cleared_by_trailer', 'cleared_by_review', 'ruled_notes', 'gate_dispositions', 'mechanical', 'review_targeted', 'design', 'review_exclude', 'review_exclude_fallback', 'docs_audit_read', 'carry', 'base_red', 'flaky_exception', 'no_stop',
|
||||
'cleared_by_trailer', 'cleared_by_review', 'ruled_notes', 'gate_dispositions', 'mechanical', 'review_targeted', 'outside_voice', '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. */
|
||||
@@ -68,6 +69,9 @@ export function orderReceipt(input: Partial<ShipReceipt> & { docs?: unknown }):
|
||||
export function validateReceipt(receipt: unknown): ValidationError[] {
|
||||
const errors: ValidationError[] = [];
|
||||
checkSchema(receipt, ARTIFACT_SCHEMAS['ship-receipt'], '', errors, 'ship-receipt');
|
||||
const voice = receipt && typeof receipt === 'object' ? (receipt as Record<string, unknown>).outside_voice : undefined;
|
||||
const problem = voice === undefined || errors.some(e => e.path.includes('outside_voice')) ? undefined : outsideVoiceProblem(voice);
|
||||
if (problem) errors.push({ code: 'RECEIPT_INVALID', path: 'ship-receipt.outside_voice', message: problem });
|
||||
return errors;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user