Skip to content

Duplicate write_file Result — Take Action #1131

Open

Description

@echo-music

[System: WARNING — write_file has returned the same result 5 times with different arguments. The information is already in your context. Stop re-reading and take action — use edit/write_file to modify files, or respond to the user if you are stuck.]

Activity

  1. added
    bug
    area:agent-loop
    status:needs-repro
    P3-low
    on May 19, 2026
  2. mrgoonie commented on Jun 22, 2026

    @mrgoonie
    Contributor

    Summary: I cannot validate this from the current report alone.
    Decision: needs-info
    Evidence:

    • The issue body only contains an internal warning string about repeated write_file results.
    • There is no reproduction path, affected agent/session id, trace id, tool arguments, expected behavior, or actual user-visible failure beyond the warning text.
    • Current labels already mark this as status:needs-repro, which matches the evidence available.
      Next step: please add the exact command/request that triggered the repeated write_file result, the relevant trace/session id if available, and whether the duplicate result caused a wrong file write or only repeated context output. With that, we can check the tool result de-duplication / agent-loop path and decide whether this is a real bug or an expected guardrail message.
  3. added
    agent:github-maintain
    maintain:triaged
    on Jun 22, 2026
  4. clark-cant commented on Nov 13, 2026

    @clark-cant
    Contributor

    Root cause found in code — this looks like a real false positive, not a stuck loop.

    detectSameResult (internal/agent/toolloop.go:251) counts history records by resultHash alone and ignores the arguments:

    for _, rec := range s.history {
        if rec.toolName == toolName && rec.resultHash == resultHash {
            count++
        }
    }

    write_file's result string (internal/tools/filesystem_write.go) is File written: <path> (<n> bytes)... — path + byte length only, with no content fingerprint. So writing the same path several times with different content of the same byte length (a normal iterative rewrite) produces an identical result hash, and the detector trips the warning at 4 (sameResultWarning) and the critical kill at 6 (sameResultCritical) even though every write changed the file. The message text "with different arguments" is also inaccurate: the count includes same-argument repeats too (those are already caught by detect, which requires identical args and identical results).

    The successful-exec analogue was fixed in #1674 (merged) by exempting exec when !isError; write_file was not given the same treatment, and no open PR touches toolloop.go.

    Fix options

    • A (primary): exempt mutating tools (write_file, edit, edit_file) from detectSameResult, mirroring the fix(agent): don't treat identical successful exec results as a runaway loop #1674 exec exemption. Safe, because identical-args + identical-result loops are still caught by detect.
    • B (hardening): make write_file's result content-addressed (append a short hash of the written content) so different content yields a different result.
    • C (wording): require rec.argsHash != argsHash in the count so the detector matches its own "different arguments" claim.

    Recommend A (+B) with a regression test that writes the same path with equal-length differing content 6 times and asserts no warning and no critical kill.

    If you can share the exact write_file calls (path and whether the byte length stayed constant) that produced the warning, that would pin the trigger — but the code path above is enough to treat it as confirmed. Adding maintain:bug-confirmed and dropping status:needs-repro.

  5. added
    maintain:bug-confirmed
    and removed
    status:needs-repro
    on Nov 13, 2026
  6. mvanhorn commented on Nov 24, 2026

    @mvanhorn
    Contributor

    toolLoopState.detectSameResult counts repeated tool outcomes solely by resultHash and previously exempted only successful exec calls.

    Updated toolLoopState.detectSameResult in internal/agent/toolloop.go to exempt successful (!isError) write_file, edit, and edit_file calls alongside exec, while continuing to flag repeated failing calls and leaving identical-argument loops to detect.

    #1699

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3-lowagent:github-maintainarea:agent-loopbugmaintain:bug-confirmedmaintain:triaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions