From df6e0d169479f97fe821d37b77abcc46c6e725a1 Mon Sep 17 00:00:00 2001 From: Glenn Schrooyen Date: Tue, 24 Nov 2026 02:08:15 +0000 Subject: [PATCH] Fix #10: the next round diffs from the tree that was verified The "previous verified round" snapshot was taken after the round's tests and verifier, up to 45 min later. A fix committed meanwhile became the base of the next round: never verified, and the next hand-back got "no changes ... nothing to verify" (EV-13 T10, PR #269). - The snapshot and the untracked-file list are taken when the round reads the tree; the next round diffs from there. - "No changes" names what it compared (base, current tree, HEAD). - After a FAIL it adds that the FAIL stands, and to resume the agent with its issues or review the change. 4 tests; 5 mutations, all caught. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01MdqPWvuDpbpRvDEdURoAwo --- hooks/register.ts | 21 ++++++++--- tests/router.test.ts | 83 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 98 insertions(+), 6 deletions(-) diff --git a/hooks/register.ts b/hooks/register.ts index 94335bc..349a59f 100644 --- a/hooks/register.ts +++ b/hooks/register.ts @@ -225,6 +225,8 @@ async function untracked($: EngineInterface, cwd: string) { return r.ok ? r.out.split('\n').filter(Boolean) : [] } +const short = (sha: string | undefined) => (sha ? sha.slice(0, 8) : '?') + /** A commit holding the clone's tree as it is now (HEAD when clean). */ async function snapshot($: EngineInterface, cwd: string) { const stash = await sh($, ['git', 'stash', 'create'], cwd) @@ -431,7 +433,11 @@ async function verifyRound($: EngineInterface, agentId: string, rec: AgentRec, c } const head = `[model-router] ${rec.taskId} (agent ${agentId}, ${rec.tier}, round ${round})` - // 1. What this round changed. + // 1. What this round changed. The tree is read now, and this is the tree the + // verdict is about: the next round diffs from here, so work done while this + // round's tests and verifier run is never taken as already verified (#10). + const snapNow = await snapshot($, cwd) + const untrackedNow = await untracked($, cwd) let base = rec.lastSnap let baseLabel = 'the previous verified round' if (!base) { @@ -447,7 +453,7 @@ async function verifyRound($: EngineInterface, agentId: string, rec: AgentRec, c } const diff = await sh($, ['git', 'diff', base], cwd, 60_000) const known = new Set(rec.lastUntracked ?? []) - const fresh = (await untracked($, cwd)).filter(f => !known.has(f)) + const fresh = untrackedNow.filter(f => !known.has(f)) let added = '' for (const f of fresh.slice(0, 20)) { try { @@ -460,7 +466,12 @@ async function verifyRound($: EngineInterface, agentId: string, rec: AgentRec, c if (!changes) { entry.outcome = 'no-changes' await log($, entry) - await tell($, `${head}: no changes since ${baseLabel}; nothing to verify.`) + const headSha = (await sh($, ['git', 'rev-parse', 'HEAD'], cwd)).out.trim() + const compared = `compared ${short(base)} with ${short(snapNow)}, HEAD ${short(headSha)}` + const stands = rec.lastIssues?.length + ? ` The FAIL of round ${rec.rounds ?? round - 1} stands: resume the agent with its issues, or review the change yourself.` + : '' + await tell($, `${head}: no changes since ${baseLabel} (${compared}); nothing to verify.${stands}`) return } @@ -558,8 +569,8 @@ async function verifyRound($: EngineInterface, agentId: string, rec: AgentRec, c const after: AgentRec = { ...rec, rounds: round, - lastSnap: (await snapshot($, cwd)) ?? rec.lastSnap, - lastUntracked: await untracked($, cwd), + lastSnap: snapNow ?? rec.lastSnap, + lastUntracked: untrackedNow, lastIssues: verdict.pass ? [] : verdict.issues, } diff --git a/tests/router.test.ts b/tests/router.test.ts index 968ba80..0033e27 100644 --- a/tests/router.test.ts +++ b/tests/router.test.ts @@ -301,6 +301,15 @@ type World = { /** A test itself prints the timeout line, on stdout. */ testLineOnStdout?: boolean snap: number + /** When set, a snapshot names the tree version (tree1, tree2, ...) instead of counting calls. */ + tree?: number + /** The dev commits while the full test run is going: the tree version goes up. */ + commitDuringTests?: boolean + /** Untracked files in the clone; `addDuringTests` joins them while the full run goes. */ + untracked?: string[] + addDuringTests?: string + /** What `git rev-parse HEAD` answers. */ + headSha?: string } const USAGE = { input_tokens: 1, output_tokens: 1, cache_creation_input_tokens: 0, cache_read_input_tokens: 0 } @@ -325,7 +334,9 @@ function world(on: On, w: World) { const cwd = String(e.init?.cwd ?? '') if (cwd !== DEV) return ok('', 128) // not a git repo: the session folder if (a === 'git merge-base origin/release/1.0 HEAD') return ok('mergebase\n') - if (a === 'git stash create') return ok(`snap${++w.snap}\n`) + if (a === 'git stash create') return ok(w.tree !== undefined ? `tree${w.tree}\n` : `snap${++w.snap}\n`) + if (a === 'git rev-parse HEAD') return ok(`${w.headSha ?? ''}\n`) + if (a === 'git ls-files --others --exclude-standard') return ok((w.untracked ?? []).join('\n')) if (a.startsWith('git diff ')) { w.diffBases.push(e.argv[2] ?? '') return ok(w.diffs.shift() ?? '') @@ -352,6 +363,8 @@ function world(on: On, w: World) { return { value: { code: outcome === 'pass' ? 0 : outcome === 'timeout' ? 124 : 1, signal: null } } } w.testCwd.push(String(e.cwd ?? '')) + if (w.commitDuringTests && w.tree !== undefined) w.tree++ + if (w.addDuringTests) w.untracked = [...(w.untracked ?? []), w.addDuringTests] w.testArgv.push([...e.argv]) const end = w.testEnds.shift() ?? 0 const fired = w.testFired.shift() ?? false @@ -1305,3 +1318,71 @@ test('#9 end to end: a guarded dev brief is classified, and the light path stays // boilerplate is not counted toward the light path's length either expect(heuristic(undefined, 'Find where the MQTT discovery payload is built' + GUARD_BLOCK + 'x'.repeat(2000))?.tier).toBe('haiku') }) + +// ---------- #10: the next round diffs from the tree that was verified ---------- + +test('#10: a fix committed while round 1 is verified is verified in round 2 (EV-13)', { options: { testCommand: 'run-tests' } }, async ($, on) => { + const w = fresh() + w.tree = 1 + w.commitDuringTests = true // the dev commits 57a9f56 while round 1's suite runs + w.diffs = ['diff --git a/one.py', 'diff --git a/fix.py'] + w.verdicts = ['{"verdict":"FAIL","issues":["named_absence missing"]}', '{"verdict":"PASS"}'] + const clock = world(on, w) + const r = await $.agent.spawn({ prompt: devBrief(), description: 'ev13' } as never) + await finish($, clock, r.agentId as string) + expect(w.all.some(l => l.includes('FAIL'))).toBe(true) + await resume($, r.agentId as string, 'Fix: named_absence missing') + await finish($, clock, r.agentId as string) + // round 2 diffs from the tree round 1 read (tree1), not the one after its tests (tree2) + expect(w.diffBases[1]).toBe('tree1') + expect(w.verifier.length).toBe(2) + expect(w.all.some(l => l.includes('nothing to verify'))).toBe(false) +}) + +test('#10: "no changes" names the trees it compared, and says a FAIL stands', { options: { testCommand: 'run-tests' } }, async ($, on) => { + const w = fresh() + w.tree = 7 + w.headSha = '0774d1e0aaaabbbb' + w.diffs = ['diff --git a/one.py', ''] + w.verdicts = ['{"verdict":"FAIL","issues":["P4 not argued"]}'] + const clock = world(on, w) + const r = await $.agent.spawn({ prompt: devBrief(), description: 'ev13' } as never) + await finish($, clock, r.agentId as string) + await resume($, r.agentId as string, 'Fix: P4 not argued') + await finish($, clock, r.agentId as string) + const line = w.all.find(l => l.includes('nothing to verify')) ?? '' + expect(line).toContain('compared tree7 with tree7, HEAD 0774d1e0') + expect(line).toContain('The FAIL of round 1 stands: resume the agent with its issues') +}) + +test('#10: after a PASS, "no changes" adds no FAIL note', { options: { testCommand: 'run-tests' } }, async ($, on) => { + const w = fresh() + w.tree = 1 + w.diffs = ['diff --git a/one.py', ''] + const clock = world(on, w) + const r = await $.agent.spawn({ prompt: devBrief(), description: 'x' } as never) + await finish($, clock, r.agentId as string) + await resume($, r.agentId as string, 'one more thing') + await finish($, clock, r.agentId as string) + const line = w.all.find(l => l.includes('nothing to verify')) ?? '' + expect(line).toContain('compared tree1 with tree1') + expect(line).not.toContain('stands') +}) + +test('#10: a new file created while round 1 is verified counts as new in round 2', { options: { testCommand: 'run-tests' } }, async ($, on) => { + const w = fresh() + w.tree = 1 + w.untracked = ['old_notes.md'] + w.addDuringTests = 'tests/test_named_absence.py' + w.diffs = ['diff --git a/one.py', ''] + w.verdicts = ['{"verdict":"FAIL","issues":["named_absence missing"]}', '{"verdict":"PASS"}'] + const clock = world(on, w) + const r = await $.agent.spawn({ prompt: devBrief(), description: 'ev13' } as never) + await finish($, clock, r.agentId as string) + w.addDuringTests = undefined + await resume($, r.agentId as string, 'Fix: named_absence missing') + await finish($, clock, r.agentId as string) + expect(w.verifier.length).toBe(2) + expect(w.verifierPrompts[1]).toContain('new file: tests/test_named_absence.py') + expect(w.verifierPrompts[1]).not.toContain('new file: old_notes.md') +})