Repository navigation
fix(agents): block final answers that claim a save no tool performed - #4012
Conversation
A turn ending in "write the result to a file" reliably finished with the model asserting the save in prose while never emitting the tool call, so the user was told it succeeded with nothing on disk. The agent loop already blocks several fabricated-completion shapes at the same seam (tool markup as text, planning-only prose, raw-JSON tool output, unbacked capability claims). This adds the same treatment for a file-write claim: when the answer says a file was saved and no disk-touching tool ran this turn, inject one correction and loop instead of accepting the answer. Scoped to stay quiet when it cannot help — it fires only for agents that actually expose a write tool, believes any plausibly-writing tool call, requires both a completed write verb and a path target in one sentence, and re-prompts at most once per turn. Closes #4010
Verdict: Approve with suggestionsThe fabricated-save guard is well-constructed: it follows the exact same shape as the existing fabricated-completion guards (inject correction into One real gap and one nit below. 🟡 The real-hardware test plan checkbox is unchecked — the guard's effect on live model behavior is unverified. 🟢 🔍 Technical details🟡 evidence gap: 🟢 marker over-match: |
Request changesThis adds a guard that rejects a final answer claiming a file was saved when no disk-touching tool ran that turn — a well-shaped fix for #4010 that follows the existing fabricated-completion guards exactly. Two heuristic gaps should be closed before merge, both one-liners. The guard doesn't recognise a save made through the shell. The flagship agent can write files by running a shell command or executing a generated Python script, and neither is on the list of "something touched disk" names. A turn that genuinely saved that way ends with the model being told nothing was written and the user being told the save didn't happen — the exact outcome the guard exists to prevent, just inverted. Add the shell/execute tool names to the recognised set. The "is this a file?" test fires on things that aren't files. Version numbers, URLs, email addresses and clock times all look like filenames to it, so honest answers such as "I created the issue at github.com//issues/42" or "I've created the release notes for v0.17.5" get bounced and the model is pushed to write a file the user never asked for. Worth excluding URL/email-shaped matches. Neither is fatal — the re-prompt is capped at one per turn — but both hit ordinary answers from the agent that ships this guard. Real-world evidenceThe evidence harness did not run for this PR. So nothing here exercised the behaviour on a live model, and I could not run the new unit tests either (this runner has no test dependencies installed). My verdict rests on static review and on reproducing the two detector patterns above standalone, which is how I confirmed both misfires. The PR itself flags that it needs manual validation; the repro in its test plan is still the thing that has to pass before merge. 🔍 Technical detailsIssues🟡 A real save via
A test alongside 🟡 The If the underlying action went through a tool whose name carries a marker ( 🟢 Detector treats a self-negating sentence as a claim (
Strengths
|
|
Ran this against a live Lemonade server on the original #4010 repro (Gemma-4-E4B-it-GGUF, GPU, 65536 ctx, Windows, Detector: correct on real dataFed
Live runs: the failure is intermittentThree end-to-end runs of the exact repro on this branch:
So I did not get a live firing of the guard, because in neither completed run did the model both skip the write and claim it. That's not evidence against the fix — it's evidence that the underlying model behaviour varies run to run, which matters for how the test-plan checkbox gets interpreted. Suggestion: the "re-run the reporter's repro" item can pass or fail for reasons unrelated to this patch. The mocked loop-integration tests already in the PR are the stronger signal. If you want a live check that deterministically exercises the guard, it'd need a stub model that emits a save claim with no tool call. Gap worth a look: the silent-omission caseRun 2 is the shape this guard structurally cannot catch: the model drops the save step and simply doesn't mention it. There's no claim to contradict, so the guard is correctly silent — and the outcome for the user is the same as the bug being fixed here (no file, no signal). Flagging it because #4010's impact statement covers this case too, so I don't think the issue is fully closed by this patch. Probably a separate, harder problem (intent-vs-outcome rather than claim-vs-outcome) and fine to leave out of scope here, but worth not marking #4010 as fully resolved on merge. Possible false negative:
|
The fabricated-save guard bounced two kinds of honest answer. A turn that genuinely saved a file through the shell or a Python snippet was told "nothing was written to disk", pushing the model to rewrite the file or retract a true statement. And any dotted token read as a filename, so answers mentioning a version, a URL, an email address, a clock time or a domain were treated as save claims and re-prompted. The tool-marker list had no shell or exec entry, but ChatAgent registers run_shell_command, execute_python_file and run_python — all of which can write files. Over-matching a marker only costs recall; under-matching blocks a real save, so the shell/exec family is now matched too. The file-target test now strips links and addresses before looking for a dotted token, and ignores tokens whose suffix carries no letter (a version or a clock time) or is a hostname suffix. Stripping the span is simpler than teaching one regex to exclude what sits inside a URL, and keeps each rule readable on its own. Still unmatched by design: take_screenshot and transcribe_media also reach disk but sit outside this guard's shell/exec scope.
Skill audit
✅ All audited skills cleared the tier they claim. Per-finding detail is withheld here on purpose. Read it in the Security > Code scanning tab, or download the |
The fabricated-save guard decided "did anything write?" by substring-matching tool names, which got it wrong in both directions. A turn that genuinely saved through the shell or a Python snippet was told "nothing was written to disk", pushing the model to rewrite the file or retract a true statement; meanwhile create_calendar_event, download_url and export_report suppressed the guard outright despite touching no file. The confirmation set is already the maintained list of tools that write or execute, so the guard now reads it instead of keeping a parallel list that drifts on the next tool addition — which is how the gap arose. notify_desktop is subtracted: it is in that set because it spawns a PowerShell child, not because it writes, and leaving it in would suppress the guard for free. The check is exact-name membership, not _tool_requires_confirmation(). That method is a safety gate and reads inverted here: it exempts a pre-authorized write (a real save would look like no save) and treats an unclassified mcp_ tool as consequential (a read-only MCP lookup would look like a save). A third-party tool counts only when its registry entry declares the flag itself. Second fix, independent of the first: the file-target test read any dotted token as a filename, so honest answers naming a version, a URL, an email address, a clock time or a domain were treated as save claims and re-prompted. Links and addresses are now stripped before the scan, and a token whose suffix carries no letter or is a hostname suffix is not a path. Stripping the span is simpler than teaching one regex to exclude what sits inside a URL.
A write that the validator refused, that raised, or that the user declined left the file off disk while the answer still said "saved to X" — #4010's exact harm, surviving the guard meant to catch it. The guard read tool_call_log, which is appended before the call runs, so it counted intent. It now reads the per-turn execution log and requires the call to have run and not failed. Two related fixes in the same seam: - Four tools that write a file as a side effect (take_screenshot, text_to_speech, transcribe_media, refine_transcript) are cheap and safe, so they never enter the confirmation set the disk-touching set was derived from. A genuine save through any of them was being told nothing was written. - The dotted-token regex was unbounded and scanned quadratically: a 32KB hex digest in one answer cost 1.4s of GIL-held CPU, stalling the whole API/UI process on every final answer. Bounding the run to 80 characters brings that to 9ms with no loss of coverage.
|
Reviewed, fixed, and verified. The guard is worth having — it catches a real, user-harmful failure (the model says "saved to X" and nothing reached disk) — but as submitted it was wrong in both directions and would have made things worse for some ordinary turns. Four defects found, all confirmed by running the code rather than reading it, and all now fixed on this branch. The most important one: the guard checked which tools were attempted, not which succeeded. A What changed since the bot reviews
🔍 Technical details1. 2. Marker matching was wrong in both directions. Against a real Note 3. 4. Quadratic scan, GIL-held, on every final answer. Verification. 35/35 CI checks green on |
itomek
left a comment
There was a problem hiding this comment.
Four defects found and fixed on this branch; 35/35 CI green. Evidence in the comment above.
|
Real-hardware evidence, run against a live local model rather than mocks. Posting after merge because it independently confirms the defects fixed here — and turns up two that are not. The bug is real, and the guard repairs it. A control build (this branch with the guard removed, nothing else changed) ended a turn saying "The detailed report has been saved to It also independently reproduced the worst defect we fixed. Where a file was genuinely created by What this does not show: that the guard improves how often files actually get written. That rate was unchanged between the two builds, and with 4 guard fires across 36 runs on a stochastic model the sample cannot support such a claim. The false-positive findings are the solid ones, because they are deterministic code paths. Two findings that are still open — filed as #4057:
🔍 Technical details36 runs on an AMD Strix Halo Ryzen AI box (Radeon 8060S iGPU) running Clean #4010 reproduction (control): tools executed were Guard repairing it (fix arm, same query): False positive on a genuine save (pre-fix): Model then retracted: "The file wasn't written by me in this turn—it was produced by Sample-quality caveats, stated rather than smoothed over: at temperature 1.0 roughly two-thirds of runs on the multi-step task degenerate into unrelated retrieval loops, and 4 of the 12 matched runs never produced an answer at all (connection errors, one tool-call parse failure). The matched comparison is therefore 1-of-4 usable per arm — a matched pair, not a rate. Seven "draft this, save nothing" runs produced zero false fires. |
An agent turn whose last step was "write the result to a file" could finish by telling the user the file was saved when the save tool had never run — nothing reached disk, and the user got no signal to go check. That is worse than an honest error. Now, when the final answer claims a file was written and no disk-touching tool ran in that turn, the loop rejects the answer and pushes the model to either make the call or stop claiming it did.
Closes #4010
Test plan
python -m pytest tests/unit/ -xpassespython util/lint.py --allpasseswrite_file, with and without--bypass-permissions. The turn should now either produce a realwrite_filecall (visible under--trace/--dev) or an answer that no longer claims a save.🔍 Technical details
Root cause. The model never emits the tool call; it treats having reasoned about the remaining step as having executed it. The loop had no check tying a completion claim back to the tool calls that would make it true, so the answer was accepted as final.
Change.
src/gaia/agents/base/agent.pygains a_claims_file_write()helper plus a guard in theprocess_queryanswer seam, alongside the existing fabricated-completion guards (tool-markup-as-text, planning-only prose, raw-JSON tool output, unbacked SD capability claims). It follows the same shape those use: inject a correction intomessagesandcontinuerather than settingfinal_answer.Four things keep the false-positive cost low:
_FILE_WRITE_TOOLS(write_file,write_markdown_file,write_python_file,edit_file) is in the agent's registry — otherwise the correction would be unactionable and the turn would just burn a step._FILE_WRITE_TOOL_MARKERS(write,save,edit,create,download,export,replace,generate_image). Over-matching only costs recall; under-matching would block a genuine save.I saved the routine to notes/routine.mdfires whileI created a summary of the meetingandI wrote a helper that normalizes the timestampsdo not. Fenced code is stripped first — a sample command is not a claim._MAX_FILE_WRITE_CLAIM_REPROMPTS), and skipped on the last step.The correction also names the earlier-turn case explicitly ("if you mean a file written earlier in the conversation, say that instead of claiming you just saved it"), so a follow-up question like where did you save it? resolves in one step rather than forcing a redundant write.
Verification.
tests/unit/agents/test_fabricated_save_guard.py— 17 tests: a claim/non-claim corpus for the detector (including the issue's ownI have saved the result to \X`phrasing and near-miss negatives), plus loop-integration tests for the re-prompt, the per-turn cap, the no-write-tool skip, the last-step skip, and a realwrite_filecall suppressing the guard. Fulltests/unit/run: 12,620 passed. The single failure in that run (eval/mcp_server_launcher.py→No module named 'openai') is a sandbox artifact — that test spawns a barepython` subprocess which resolves to the system interpreter, not the test venv.