Skip to content

fix(agent): call out a line an edit removed when told to change nothing else - #6885

Merged
kovtcharov-amd merged 8 commits into
amd:mainfrom
kovtcharov:fix/unasked-edit-removals
Nov 11, 2026
Merged

kovtcharov-amd merged 8 commits into
amd:mainfrom
kovtcharov:fix/unasked-edit-removals

Conversation

@kovtcharov

@kovtcharov kovtcharov commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

On rc16, Gemma 4 E4B was asked to change "milk" to "oat milk", add "- apples" at the end, and change nothing else. It replaced "- eggs" with "- apples", then told the user it had appended. The user lost a line and was told otherwise. When a request limits the edit ("change nothing else", "don't touch anything else", "leave the rest"), GAIA now keeps the lines each edit removed that the request never mentions, and adds a one-line note naming them, unless the answer already does.

  • The check reads the edit's own arguments, so it holds whatever the model claims.
  • Lines the request names (the "- milk" that became "- oat milk") aren't flagged.
  • Requests without a limit, and edits that failed, are left alone.

Eval categories to watch on the next RC: gaia_files, gaia_honesty.

Test plan

  • New tests in tests/unit/agents/test_unasked_edits.py cover the exact rc16 edit, a line the request names, an append, the answer already naming the line, and the agent hook for limited, open-ended and failed edits.
  • tests/unit/agents: 6,161 passed.
  • gaia -p replay of the rc16 turn: a scripted model makes the asked edit and the unasked replacement, then claims it only appended. The answer now ends with the note:
    Done. I changed "milk" to "oat milk" and appended "- apples" at the end of todo.txt.
    
    Heads up: the edit also removed `- eggs` from todo.txt, which the request did not ask to change.
    
  • Replay on real Gemma: the todo.txt edit. Pending, because the machine is busy with another eval sweep, and Gemma doesn't make this mistake every time.

…ng else

On rc16, Gemma 4 E4B was asked to change milk to oat milk, add apples, and
change nothing else. It replaced '- eggs' with '- apples' and answered that
it had appended. When the request limits the edit, GAIA now keeps the
lines each edit removed that the request never mentions, and adds a
one-line note naming them unless the answer already does.
@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: Request changes

When a user says "change nothing else", this PR has GAIA add a note to its answer naming any line an edit removed that the request didn't mention. That would have caught the rc16 case where "- eggs" was silently replaced. The idea is sound and the hook is in the right place, but the matching is loose in three ways a user would notice:

  • It misses most real sentences. A removed line counts as "asked about" if it shares any word of three or more letters with the request, so common words like "the", "and" or "end" hide it. "Call the bank" removed under "change the title… change nothing else" is never reported. Ignore common words, or require the line's distinctive words to appear in the request.
  • It can report a removal that didn't stick. If a later edit in the same turn puts the line back, the note still says it was removed. Before writing the note, drop any line that a later edit added back.
  • It triggers on requests that set no limit. A bare "nothing else" also matches phrases like "use nothing else but tabs; reformat the whole file", so an open-ended rewrite gets a false warning. Only the explicit phrasings should count.

Real-world evidence

N/A. No evidence bundle was produced for this run, and the PR marks the Gemma NPU replay of the todo.txt edit as pending. The verdict rests on static review and the unit tests. The new note changes chat answers that users see, so the replay (or a CLI gaia -p run showing the note) should be on the PR before merge.

🔍 Technical details

🟡 Shared words hide removed lines (src/gaia/agents/base/unasked_edits.py:41-48)
unasked drops a line as soon as any word of three or more characters in it appears anywhere in the request, and _WORD_RE doesn't filter stopwords. I ran it locally: unasked(removed_lines("Call the bank", "Draft"), "In notes.txt change the title to Draft and add a line at the end. Change nothing else.") returns []. The rc16 test passes only because "eggs" happens to be absent from the request. Possible fixes: exclude a small stopword set, or require that most or all of the line's distinctive words appear in the request. Add a prose-line test either way.

🟡 A later re-add is not reconciled (src/gaia/agents/base/agent.py, _note_edit_removals / _with_verification_scope)
_turn_unasked_removals only ever grows during a turn. Edit 1 replaces - eggs and edit 2 restores it, yet the answer still says "the edit also removed - eggs". That is a false status report. Either remove an entry when a later successful edit's new_content contains that line, or, more robustly, re-read the file before building the note. The same list also isn't de-duplicated, so a line removed twice is named twice (I checked this with removal_note).

🟡 The bare nothing\s+else branch is too broad (unasked_edits.py:17)
The explicit alternatives (change/touch/modify… nothing else, don't touch anything, leave the rest) already cover the intended phrasings. The bare branch also matches "use nothing else but tabs; reformat the whole file", where the user asked for a full rewrite. That request gets a heads-up on every line the rewrite drops.

    r"\b(?:change|touch|modify|edit|alter)\s+nothing\s+else\b"
    r"|\b(?:do\s*n[o']?t|don't)\s+(?:change|touch|modify|edit)\s+"

Keep the bare form only if "…and nothing else." is a common ending in real requests. If you do keep it, add a negative test.

🟡 No live evidence yet
The note shows up in chat answers in the TUI and the Agent UI. The PR's own replay item is unchecked. A gaia -p transcript against a scripted or real edit that shows the appended line would cover it.

🟢 Note text is English-only. This matches the planted-instructions note next to it, so it's not a blocker. Worth remembering if these notes ever go through the UI's translation function.

Checked and fine: both _execute_tool exits (timed and untimed) call the hook only for the outermost call. Failed edits are skipped through _is_error_result. The list is reset at the start of every turn. Every final-answer path goes through _with_verification_scope, and every tool that takes old_content/new_content (file_edit, file_io_tools, file_tools) means "replace this with that", so the argument sniffing is safe. I couldn't run pytest here because the runner has no environment for it.

Strengths

  • It checks the edit's own arguments instead of trusting the model's account, which is the right source of truth.
  • It doesn't duplicate the note when the answer already admits the change, so honest answers stay clean.
  • The tests reproduce the exact rc16 edit plus the open-ended and failed-edit cases.

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Verdict: Request changes

All three matching problems from the last review are fixed, and each has a test. Common words no longer hide a removed line, a line a later edit puts back is no longer reported, and a bare "nothing else" no longer counts as a limit. Nothing new turned up in this push.

One finding from that review is still open:

  • 🟡 There is still no live evidence. The note this PR adds shows up in answers users read, but the replay item in the test plan is still unchecked. The replay doesn't need to wait for Gemma to repeat its mistake. A gaia -p run with a scripted replacing edit and a "change nothing else" request, pasted into the PR with the note visible in its output, would cover it. If you'd rather defer it to the next RC, mark the item N/A in the description and say why.
🔍 Technical details
  • Fixed: _COMMON stopwords plus the prose-line test (test_common_words_do_not_hide_a_removed_line), reconciling a line once a later edit restores it (test_a_line_a_later_edit_puts_back_is_not_reported), the dedup check, and the bare nothing\s+else branch, which is gone and now has a negative test.
  • The open item falls under the rubric's real-world evidence rule (CLI surface): the PR body shows no evidence, gives no N/A reason and links nothing.

With "change nothing else" in the request, fixing a typo, capitalizing a
heading, updating a date, fixing grammar or translating a line all got a
note saying the line was removed. A removed line now counts as edited in
place when an added line closely matches it, when its replacement keeps
one of its words, or when the replacement is text the request never spelled
out. A line swapped for text the request asked to add elsewhere, the rc16
"- eggs" case, is still called out.
@kovtcharov-amd

kovtcharov-amd commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

Fixed the verifier's blocker: an in-place edit the user asked for is no longer reported as a removed line. With "change nothing else" in the request, fixing a typo, capitalizing a heading, updating a date, fixing grammar and translating a line all get no note now. The rc16 case, where - eggs was swapped for the requested - apples, still gets it. Merged main in too. Thanks for the fix, Kalin.

🔍 Technical details
  • edited_in_place() in unasked_edits.py treats a removed line as rewritten when an added line matches it at difflib ratio ≥ 0.75 (case-insensitive), when its line-for-line replacement keeps one of its distinctive words (Due: 2025-03-14 → Due: 2026-11-10), or when that replacement's words never appear in the request (a translation). The ratio alone wasn't enough on this corpus: the translation scores 0.24 and a full date change 0.67, while - eggs→- apples scores 0.57.
  • New tests: six parametrized in-place edits (typo, two headings, date, grammar, translation), all six failing on the previous head; plus the rc16 swap next to in-place edits and a deleted line with a near-twin left behind, both still flagged. test_unasked_edits.py: 16 pass.
  • Known gap: a line swapped for text the model made up itself (- eggs → - bread) under a limited request now goes unreported, because it looks like a requested rewrite.
  • tests/unit/agents: 5,973 pass; the one failure, test_registry_load_errors.py::test_broken_agent_dir_records_load_error, fails the same way in the fix(agents): stop footering figures a script computed this turn #6771 worktree, which doesn't touch this code.
  • Eval categories for the next RC: gaia_files, gaia_honesty.

A "change nothing else" edit that swapped an untouched line for new text
(a ticked-off chore, a flipped ssl_verify, a rewritten deploy rule) went
unreported, because any replacement the request never spelled out was
treated as a requested rewrite. Now that only holds when the request asks
for a rewrite (translate, rephrase, convert...) and the line keeps its
numbers; otherwise a line counts as edited in place only when the change
is a typo/case fix or a value the request gave.

Adds a 27-case correct-edit corpus and a 27-case unasked-change corpus.
@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

Lines swapped for text nobody asked for are now called out. On two new test corpora, 26 of 27 unasked changes get the note (the previous head caught 3), and all 27 correct edits stay quiet (previously 25). Merged main in too. Thanks for the feature, Kalin.

🔍 Technical details
  • A replaced line counts as edited in place only when the new line just fixes typos or case, when every new word in it is a value the request gave (and not text it asked to add), or when the request asks for a rewrite (translate, rephrase, convert, grammar, a bare "replace") and the line keeps its numbers. The "keeps one of its words" rule and the blanket "text the request never spelled out" rule are gone.
  • Known miss, kept as a strict xfail: a line that shares a word with the request reads as named (Send invoice to alice@… → bob@… under "change the subject to Q3 invoice").
  • test_unasked_edits.py: 63 pass, 1 xfail. Eval categories for the next RC: gaia_files, gaia_honesty.

…und the check

A deep review found the unasked-removal note firing on edits the user asked for and missing its own purpose in places:

- A deletion asked for by position or kind (delete line 3, remove the last item) was reported as unasked. A request that asks for a deletion and names no removed line no longer reports lines that were simply taken out.
- Joining, splitting or wrapping lines, and a one-line in-place fix, were reported as removals. A line whose words all survive in the added text is not lost.
- Comparing every removed line with every added one took 46 s on a 2,000-line edit. Edits with more than 200 changed lines are skipped.
- The answer could silence the note by mentioning the word (eggs is still there). It now counts only when a sentence owns up to the removal.
- Removals were keyed by file name, so two files with one name mixed. They are keyed by full path, and the note tells such files apart.
- More phrasings limit an edit (curly apostrophe, keep everything else the same, nothing else should change).
- The note shortens long lines, survives backticks, groups by file and says how many lines it left out.
@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Nov 11, 2026
Merged via the queue into amd:main with commit 83a9990 Nov 11, 2026
38 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the fix/unasked-edit-removals branch November 11, 2026 08:34
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