Skip to content

fix(agent): count a script's write to a named file outside the grant - #6820

Merged
kovtcharov-amd merged 2 commits into
amd:mainfrom
kovtcharov:kalin/script-write-outside-grant
Nov 6, 2026
Merged

kovtcharov-amd merged 2 commits into
amd:mainfrom
kovtcharov:kalin/script-write-outside-grant

Conversation

@kovtcharov

@kovtcharov kovtcharov commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Asking GAIA to create a report beside a file you shared could end with a false "I couldn't confirm all of this: No successful write to report.md", even though the report was on disk with the right rows. Approving the input file grants that one file only, so GAIA wouldn't even check whether the report it was asked to create existed. Now it checks the size and timestamp of a file you named as the output (never its contents), and a script's write to it counts. A file the turn never touched still gets the note, and a named output that is a symlink is never checked, so the link can't reach a file outside the grant.

Eval categories to watch: gaia_files, gaia_data, gaia_code, gaia_honesty. This isn't on CLAUDE.md's eval list, but these gaps also drive the correction the agent loop sends the model, so they shape what it does next.

Test plan

  • pytest tests/unit/agents/test_completion_evidence.py: the Gemma report case (inline CSV, output path in a variable, single-file grant) fails on main and passes here
  • A script that leaves the named file alone, or a file unchanged since before the turn, still gets the note. Withheld folders and paths found only in script code are never checked.
  • Linux CI: the symlink tests (test_snapshot_without_validator_does_not_follow_external_symlink, test_a_named_file_that_links_outside_the_grant_is_never_probed) pass. They skip on Windows without symlink privilege; a forced-islink test covers the same guard there.
  • pytest tests/unit/agents passes, and so does the flagship package apart from three tool-registry count tests that fail on main too
  • Replay in the app on Gemma NPU: the report task. The report was written by run_python and read back, and the false "No successful write … is recorded" note is gone. (A separate false "figures I found no source for" note on the same answer is fix(agents): stop footering figures a script computed this turn #6771's case, now being fixed there.)

… the grant

A run_python that really wrote the report the user asked for still got
"No successful write to <file> is recorded for this turn", because the
chat could read only the one input file the user had approved. The
completion ledger refused even to stat the named output, before or after
the run, so the write left no evidence.

- A path the user typed as this turn's output may now be stat'ed (metadata
  only) outside the read grant. Withheld folders, secret files and network
  shares stay unseen, and an out-of-grant folder is never listed.
- When every executor run had the file stat'ed before and after and saw no
  change, that comparison beats the modification-time guess. A coarse file
  clock could date an untouched file inside the run and count it as written.
@kovtcharov kovtcharov changed the title fix(agent): count a script's write to the file the user named outside the grant fix(agent): count a script's write to a named file outside the grant Nov 6, 2026
@github-actions github-actions Bot added tests Test changes agents labels Nov 6, 2026
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

When a user shared one input file and asked for a report next to it, GAIA used to say "No successful write" even though the report was on disk. This PR fixes that: GAIA now checks the size and timestamp of an output file the user named, and only that file. The fix is correct and stays inside the privacy boundary. Withheld folders, secret files, network paths and paths that appear only in script code are still never checked, and a folder outside the grant is never listed.

  • Before merge: tick the unchecked "replay in the app on Gemma NPU" item. The unit tests cover the logic, but this note appears in the user's chat answer, so one real run should confirm it is gone.

Real-world evidence

N/A: no evidence bundle was produced for this run. The verdict rests on static review alone. pytest isn't installed on this runner, so I couldn't run the new tests here. The PR reports them passing, and they fail on main.

🔍 Technical details

Issues

🟢 The set of requested paths is rebuilt on every call (src/gaia/agents/base/completion.py:578). _named_output is called once per candidate path in snapshot(), and each call re-keys all of self.requested. The cost is tiny at current sizes, but building the set once (or caching it, since requested is fixed for the turn) would make the intent clearer.

🟢 _compared_every_run falls back to mtime whenever any executor record() ran without a before snapshot. This is conservative and correct, because nothing is newly trusted. But a run that skipped snapshot() silently brings back the coarse-clock false positive that test_an_unchanged_snapshot_beats_an_mtime_inside_the_run guards against. A short comment on compared saying it must count every snapshotted exec run would help keep that invariant.

Checks I ran

  • Privacy boundary: _named_output only admits keys from self.requested, which save_obligations(query) builds from the user's own message. It rejects UNC paths outright, and it goes through withheld_root and is_read_blocked. Both resolve symlinks via _real_path, so a named output that links to a secret is still refused. In _find_executor_writes, folders outside the grant are never walked (not readable short-circuits before os.walk).
  • Stamp-comparison logic: compared is only bumped when both stamps are observable, so an unobservable stamp still leaves the mtime path to decide. Making written_files() and _written_by_executor skip mtime inference when every run was compared is the right priority: an unchanged before/after stat beats a coarse mtime.
  • Doc drift: none. This is internal ledger behaviour and no doc describes the old "named output outside the grant is ignored" rule.

Strengths

  • The tests use the real PathValidator with a single-file grant, and they reproduce the exact Gemma script shape (inline CSV, output path held in a variable).
  • Negative cases are covered: the file isn't touched, the file was unchanged since before the turn, a withheld folder (asserted by failing on any _stamp call), and a literal that appears only in the script.
  • The "read back" note still fires on a write that was never read back, so the fix doesn't over-credit the turn.

A requested output that is itself a symlink resolved to its target, so the snapshot stat'ed a file outside the grant (Linux CI caught it; Windows can't make the link without privilege). The user named the link, so it gets the strict treatment: no stat, no mtime inference.
@kovtcharov-amd kovtcharov-amd added this to the v0.25.4 milestone Nov 6, 2026
@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Nov 6, 2026
Merged via the queue into amd:main with commit 6b27b15 Nov 6, 2026
36 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the kalin/script-write-outside-grant branch November 6, 2026 10:29
@github-actions github-actions Bot mentioned this pull request Nov 6, 2026
4 of 6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants