Skip to content

fix(agent): stop calling a saved script output or an input file unwritten - #7321

Merged
kovtcharov-amd merged 6 commits into
amd:mainfrom
kovtcharov:kalin/rc18-script-output-beside-input
Nov 12, 2026
Merged

kovtcharov-amd merged 6 commits into
amd:mainfrom
kovtcharov:kalin/rc18-script-output-beside-input

Conversation

@kovtcharov

Copy link
Copy Markdown
Contributor

Two closing "I couldn't confirm all of this" lines were wrong. A
recon_tables.xlsx a script wrote beside the named input was reported as
"No successful write ... is recorded", and after a denied save the line
named the input spreadsheet the answer said it had read from. Now the
script's output is found where it landed, and "what I would have written,
read from x.xlsx" is not taken as a claim that x.xlsx was written.
Refs #7293

Draft until it is replayed in the app: this changes a check or tool result the agent reads.

Test plan

  • Ten completion and save-claim suites (756 pass; 4 new tests fail on main)
  • Replay on a cloud model: a script that writes its output next to its input file, and a denied write
  • Eval categories to watch: gaia_files, gaia_data, gaia_honesty

…tten

Two closing "I couldn't confirm all of this" lines were wrong. A
recon_tables.xlsx a script wrote beside the named input was reported as
"No successful write ... is recorded", and after a denied save the line
named the input spreadsheet the answer said it had read from. Now the
script's output is found where it landed, and "what I would have written,
read from x.xlsx" is not taken as a claim that x.xlsx was written.

A bare output name ("also make recon_tables.xlsx") was only looked for in
the agent's working directory; it is now also looked for, by the same
modified-during-a-successful-run evidence, in the folders of the paths the
request named and of the files the turn wrote. A "would/could have
written" clause is dropped before a sentence is checked for save claims.

Closes #ISSUE
@github-actions github-actions Bot added tests Test changes agents labels Nov 12, 2026
@kovtcharov
kovtcharov marked this pull request as ready for review November 12, 2026 06:09
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

This fixes two wrong "I couldn't confirm this was saved" warnings. One fired when a script saved its output next to the input file the user named. The other named an input file after a denied save, because the answer said "what I would have written, from x.xlsx". Both fixes are narrow and come with tests on each side: a file that existed before the turn, or sits in a folder nobody named, is still reported missing.

The "would have written" check has two small gaps worth closing before merge:

  • Curly apostrophes. It doesn't recognise "I’d have saved" with a typographic apostrophe, which models often produce, so the false warning this PR fixes still appears in that case.
  • A real save after "but" with no comma. In "I would have written a.txt but I saved b.txt", the real save of b.txt gets dropped too, so a false claim about b.txt would go unchecked.

Real-world evidence

N/A: no evidence bundle was produced for this run. This is an internal answer check with no CLI, API or UI surface to exercise here, so the verdict rests on static review and the PR's unit tests. The PR is a draft until the in-app replay in its Test plan is done. The gaia_files, gaia_data and gaia_honesty eval categories it lists are the right ones to watch on the next RC.

🔍 Technical details

Issues

🟡 _COUNTERFACTUAL misses curly apostrophes and swallows a following real claim (src/gaia/agents/base/completion.py:144)

I checked both against the regex:

  • "Here’s what I’d have saved, from x.xlsx." is unchanged. Only a straight ' is matched in I'd / n't.
  • "I would have written it to a.txt but I saved it to b.txt." reduces to "I ". [^,;]* runs to the end of the sentence, so the b.txt claim disappears. The comma version, which the new test covers, works.

With the change below, the outputs become "Here’s what , from x.xlsx.", "I but I saved it to b.txt." and "Had it been allowed, I ", all as intended:

_COUNTERFACTUAL = re.compile(
    r"(?:\b(?:would|could|should|might)(?:n['’]t|\s+not)?|\b(?:I|we)['’]d)\s+have\s+"
    r"(?:\w+\s+)?(?:saved|written|stored|exported|created|put|generated|made|copied)"
    r"\b(?:(?!\bbut\b)[^,;])*",
    re.I,
)

It's worth adding both sentences to the parametrized test_a_write_that_would_have_happened_names_no_file and test_a_real_save_after_a_would_have_clause_is_still_a_claim.

🟢 named_folders adds each named file path as well as its folder (completion.py:510). self.key(path) for kx/reconciliation.md becomes a "folder", and _find_bare_outputs then probes kx/reconciliation.md/recon_tables.xlsx. It's harmless because isfile is false, but keeping only os.path.dirname(...) matches the comment's intent. If the double entry is meant to cover a named folder, a one-line comment saying so would help.

Checked, no issue:

  • _find_bare_outputs goes through _find_executor_writes. That keeps the read-grant check (_readable / _named_output) and the mtime-inside-a-successful-run rule, so a file that existed before the turn isn't credited. The second new test covers that.
  • Scratch folders are skipped, as they are in the sibling path.
  • Searching only the folders of files written this turn and the folders the request named keeps the probe bounded. The third test pins that a folder nobody named isn't searched.

Strengths

  • The tests cover both directions: the false warning goes away, and real gaps (a file from before the turn, a folder nobody named, a real "I have written") are still caught.
  • The counterfactual strip removes only its own clause rather than the whole sentence, so a mixed sentence still checks its real save.

"I would have written it to a.txt but I saved it to b.txt" dropped the
b.txt save along with the counterfactual clause, so a false claim about
b.txt went unchecked. The clause now stops at "but", and a typographic
apostrophe ("I’d have saved") is recognised like a straight one.
@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

Fixed both gaps the review found in the "would have written" check. A real save after "but" is checked again, and "I’d have saved" with a curly apostrophe is recognised.

🔍 Technical details
  • _COUNTERFACTUAL now takes ['’] and stops at \bbut\b, as suggested.
  • New cases: "…a.txt but I saved it to b.txt" (no comma), "I’d have written … but then I saved …", and "Here’s what I’d have saved, taken from …". All three fail on the previous head. 302 pass across the completion and save-claim suites.
  • named_folders keeping the named path itself is deliberate: it covers a request that names a folder rather than a file. A probe of file.md/x.xlsx is just a miss.

test_a_bare_output_no_run_wrote_is_still_missing failed on Windows CI: the
file written just before the run could carry an mtime inside the run's
window, so it read as this turn's write. Stamping it an hour back makes it
unambiguously older than the turn.
@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

Not merged yet: the "would have written" strip still hides a real save that follows in the same clause. On a read-only question these fabricated saves are no longer flagged, though main flags them:

  • "I would have written it to a.txt and then saved a copy to b.txt."
  • "Normally I would have saved it as a.txt - instead I saved b.txt."
  • "I could have created a.txt so I saved the totals to b.txt instead."

Next step: end the counterfactual clause at a second write verb (or at and|so|instead|then|-|—), not only at , ; but, and add these to test_a_real_save_after_a_would_have_clause_is_still_a_claim with a query that asks for no save.

🔍 Technical details
  • _COUNTERFACTUAL's tail (?:(?!\bbut\b)[^,;])* runs to the end of the sentence when there's no comma, semicolon or "but", so the b.txt claim is stripped with the a.txt one.
  • Repro: CompletionEvidence("What are the totals in data.csv?", d).gaps(sentence, _claims_file_write) returns [] for each sentence above; "I saved the totals to b.txt." alone still returns the gap. On a turn that asked for a save the generic "requested output file has no recorded successful write" gap still fires, so the miss is on uninstructed turns.

The hypothetical-save strip ran to the next comma, semicolon or "but",
so "I would have written it to a.txt and then saved a copy to b.txt"
dropped the real b.txt save with it and a made-up save went unchecked
on a read-only turn. The strip now also stops at a conjunction, a dash
or the next write verb, takes its own ";" or dash with it, and gives a
joined save ("... and then saved b.txt") its subject back.
# Conflicts:
#	tests/unit/agents/test_completion_evidence.py
@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

All three fabricated saves from the verifier's list are flagged again on a read-only turn. The "would have written" strip now stops at the next save, so only the hypothetical part is dropped. The rc18 case it was added for ("what I would have written, from x.xlsx") still names no file.

🔍 Technical details
  • _COUNTERFACTUAL ends at , ; : — –, -, a conjunction (and so then instead or yet while ...) or the next write verb. Its own ; or dash is dropped with it, so destination_paths doesn't stop before the real save.
  • A save the clause was joined to ("... and then saved a copy to b.txt") loses its subject with the clause, so _drop_counterfactual gives it back ("I saved a copy to b.txt").
  • The verifier's three sentences are in a new read-only test (What are the totals in data.csv?). Six variants are added to test_a_real_save_after_a_would_have_clause_is_still_a_claim, and three must-stay-silent cases ("... to a.txt and b.txt", "... so you could open it", "... or b.txt, from data.csv") are in their own test. The new claim cases fail on a51052e. Merged origin/main, which had keep-both test conflicts. 512 pass across the completion, save-guard, look-first, announced-action and grounding suites.

# Conflicts:
#	tests/unit/agents/test_completion_evidence.py
@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Nov 12, 2026
Merged via the queue into amd:main with commit ec9c5b4 Nov 12, 2026
35 of 38 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the kalin/rc18-script-output-beside-input branch November 12, 2026 09:30
kovtcharov-amd added a commit to kovtcharov/gaia that referenced this pull request Nov 12, 2026
amd#7276, amd#7277, amd#7278, amd#7248, amd#7319 and amd#7322 merged, so their seven strict
expected failures now pass and would turn the unit job red. The two left
(amd#7321 open, amd#7326 unfixed) still fail as recorded.

The stand-in console now returns an empty-string default the way the real
transport does, instead of reading it as no default.
kovtcharov-amd added a commit to kovtcharov/gaia that referenced this pull request Nov 12, 2026
kovtcharov-amd added a commit to kovtcharov/gaia that referenced this pull request Nov 12, 2026
The rc18 release test found seven cases where GAIA's own answer checks
got a turn wrong: a correct read-only answer ended with "I couldn't
confirm all of this", a plan the user asked for was thrown away, an
unanswered question became the user's answer. Each check had unit tests
and none caught these, because every case needed the request, the tool
results and the answer together. This adds a corpus of recorded turns
and one test that replays each through the real loop with no model, so a
misfire seen once in a release test becomes a file that guards it for
good.

Seeded with 16 turns: a "must not fire" and a "must fire" case for each
of F8, F10, F11, F12, F36, F80 and F81. Adding a case is adding a JSON
file; the README beside the cases says how to make one from a
transcript.

**Bugs it found** (a bug still open is a strict expected failure, so the
fix has to delete the marker):

| Case | Issue | Fix |
|---|---|---|
| Read-only answer that says "I wrote no file" gets the unsaved-file
note | amd#7178 | amd#7276 (merged, marker removed) |
| Answer quoting an edit's own backup path gets the note | amd#7179 | amd#7277
(merged, marker removed) |
| A plan the user asked for is sent back as unfinished work | amd#7180 |
amd#7278 (merged, marker removed) |
| "Do NOT run anything" is answered with GAIA's own "look first" message
| amd#7181 | amd#7278 (merged, marker removed) |
| A native tool call is shown as answer text | amd#7205 | amd#7248 (merged,
marker removed) |
| A fixed test's rerun with a different `tail` reads as an unpassed
check | amd#7293 | amd#7319 (merged, marker removed) |
| A file a script wrote beside its input is called unwritten | amd#7293 |
amd#7321 (merged, marker removed) |
| Silence after a question is handed to the model as the user's answer |
amd#7294 | amd#7322 (merged, marker removed) |
| **New:** "I also saved it to X" with no write gets no note | amd#7326 |
none yet |

I replayed the corpus on each fix branch: every case passes there, so
the markers come off as those PRs land.

## Test plan

- [ ] `python -m pytest tests/unit/agents/test_answer_check_corpus.py
-q` reports 17 passed, 1 xfailed
- [ ] Delete the `"xfail"` line from any case and the test fails with
the note or nudge the tester saw
- [ ] Runs in the existing unit job (`test_unit.yml` runs
`tests/unit/`), no workflow change needed

<details>
<summary>🔍 Technical details</summary>

- `kind: "turn"` builds a bare `Agent` whose tools are stand-ins
returning the recorded results (and writing the files the real call
wrote, since the checks stat the disk), scripts the model's replies, and
runs `process_query`.
- `kind: "stream"` feeds recorded provider chunks to
`AgentSDK.send_messages_stream` (F36 lives below the loop).
- `kind: "question"` calls the flagship's real `request_user_input` with
a console that answers or stays silent (F81 is the tool's contract, not
a check).
- Unknown keys in a case are an error, so a typo cannot turn an
assertion off.
</details>

---------

Co-authored-by: Kalin Ovtcharov <[email protected]>
kovtcharov-amd added a commit to kovtcharov/gaia that referenced this pull request Nov 12, 2026
amd#7540)

A made-up save that follows a "would have" clause with "but" goes
unchecked. "I would have written it to a.txt, but saved the totals to
`b.txt`" was flagged for `b.txt` before amd#7321 and is silent after it, on
both read-only turns and turns that asked for a save. This restores the
`b.txt` check while still dropping the hypothetical `a.txt`.

Post-merge review finding on amd#7321: its fix gave a joined save its
subject back after "and/so/then/instead", but not after ", but".

## Test plan
- [x] `python -m pytest tests/unit/agents/test_completion_evidence.py -k
would_have`: 4 new cases fail on main, pass here
- [x] `python -m pytest -n 4 tests/unit/agents -k "save or completion or
claim or refused or look or announced or grounding"`: 2144 passed
- [ ] Eval categories to watch on the next RC: gaia_files, gaia_honesty

<details>
<summary>🔍 Technical details</summary>

- `_COUNTERFACTUAL`'s `join` group now takes an optional leading comma
and `but`/`yet`, so `_drop_counterfactual` turns ", but saved b.txt"
into "I saved b.txt".
</details>
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