useAgentFinish is skipped after a restart: a response interrupted during the finish hook settles as success
Describe the Bug
If the process stops while a useAgentFinish callback is running, the response is settled as a success after restart, and the callback never runs again. Anything the hook was there to enforce is skipped: the caller reads the unchecked answer as if the hook had approved it.
The documentation promises the opposite. useAgentFinish says an evaluation interrupted before its checkpoint "re-runs wholesale on the re-attempt", and the hook's source comment says the same.
The cause appears to be in recovery: agent-submissions.ts inspects the stored conversation, and a response whose assistant message is already recorded counts as finished provider work that "settles as success unconditionally". At that point the model has answered, but the finish evaluation for that answer has not happened, so recovery settles a response its finish hooks never approved.
Expected Behavior
After restart, the interrupted finish evaluation runs again (every useAgentFinish callback, at least once), as documented, before the response settles. If a callback then appends a signal, the response continues.
Steps to Reproduce
npm i @flue/[email protected] @earendil-works/[email protected](mainat6583259has the same code). Seen on macOS with Node 26.5.Save as
repro.mjs. The model is pi-ai's scripted (faux) provider and the database is a local SQLite file, so no network is involved. Incrashmode the finish hook exits the process; inresumemode it would append a signal and then throw, so any re-run is visible:import { readFileSync, writeFileSync } from 'node:fs'; import { fauxProvider, fauxAssistantMessage } from '@earendil-works/pi-ai/providers/faux'; import { useModel, useAgentFinish, init } from '@flue/runtime'; import { start, sqlite } from '@flue/runtime/node'; const mode = process.argv[2]; // crash | resume const faux = fauxProvider({ provider: 'repro', api: 'repro-api', models: [{ id: 'm' }] }); let modelCalls = 0, finishRuns = 0; faux.setResponses([function answer() { modelCalls++; faux.appendResponses([answer]); return fauxAssistantMessage('unchecked answer'); }]); function Reviewed() { useModel('repro/m'); useAgentFinish(async ctx => { finishRuns++; if (mode === 'crash') process.exit(73); // the process stops mid-evaluation ctx.append({ kind: 'signal', type: 'review', body: 'Correction required' }); throw new Error('finish hook re-ran'); }); return 'Repro agent'; } const runtime = await start({ agents: [Reviewed], providers: [faux.provider], db: sqlite('./repro.sqlite') }); const handle = init(Reviewed, { id: 'repro' }); const receipt = mode === 'crash' ? await handle.dispatch('go') : JSON.parse(readFileSync('./receipt.json', 'utf8')); if (mode === 'crash') writeFileSync('./receipt.json', JSON.stringify(receipt)); const reply = await handle.read(receipt); console.log({ mode, modelCalls, finishRuns, text: reply.text }); await runtime.stop();Run
node repro.mjs crash(exits with code 73 inside the hook), thennode repro.mjs resume. After Flue reclaims the stopped attempt (about 30 seconds), the second run prints:{ mode: 'resume', modelCalls: 0, finishRuns: 0, text: 'unchecked answer' }Expected:
finishRuns: 1and a failed submission (the hook throws on re-run), or with a real hook, a continued response.
Related: #600 (how recovery treats a completed assistant response, in the silent context-overflow case).
Source: withastro/flue