Repository navigation
fix(agent): exempt successful write_file and edit calls from same-result loop detection - #1699
Conversation
…p detection 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`. Added `TestSameResult_WriteFileSuccessExempt` in `internal/agent/toolloop_test.go` to verify that repeated identical results from those tools are ignored on success and trigger a critical detection on error. Fixes nextlevelbuilder#1131
clark-cant
left a comment
There was a problem hiding this comment.
Summary: Extends the same-result loop exemption (added for successful exec in #1674) to successful write_file, edit, and edit_file in toolLoopState.detectSameResult, so legitimate iterative rewrites of the same file no longer trip a false-positive duplicate-result warning/kill. Fixes #1131.
Risk level: Low
Mandatory gates
- Duplicate / prior implementation: clear — extends the merged #1674 exec exemption; no other open/merged PR or issue covers the write_file/edit case (issue 1131 is
maintain:bug-confirmedwith our root-cause comment recommending exactly this option A). - Project standards: docs found — CONTRIBUTING.md (base dev); matches the existing switch/table style in toolloop.go.
- Strategic necessity: clear value — removes a confirmed false-positive that stops agents mid-edit.
Findings
- Suggestion: option C from the issue write-up (the message text "with different arguments" still counts same-argument repeats) is not addressed; consider gating the count on
rec.argsHash != argsHashso the wording matches behaviour. - Suggestion: option B (content-addressed write_file result) is not implemented; optional hardening, not required for this fix.
- Suggestion: the new test covers success-exempt and error-critical; an assertion that a genuine identical-args loop is still caught by
detectwould document the safety claim.
Verdict: Approve — correct, minimal, and consistent with the merged #1674 precedent; CI green (release-versioning/go/web), MERGEABLE/CLEAN, base dev. Merge-ready pending a maintainer approval.
Posted by /ck:review-pr at 2026-11-24T19:10:00Z
|
Thanks for the review. I kept this to option A on purpose so it matches the #1674 exec exemption and stays easy to merge. On the safety point: Options B and C are reasonable as separate follow-ups, outside the scope of this fix. |
|
Thanks for the clarification - agreed, keeping this to option A matches the #1674 exec exemption, and detect still catches identical-args loops via argsHash + resultHash, so the scoping is sound. B/C as separate follow-ups is fine. Merge-ready pending a maintainer approval. |
Summary
Iteratively modifying the same file with successful write or edit calls can trigger false-positive duplicate-result loop warnings and eventually stop the agent with a critical loop detection. Even though each modification succeeds with new content, the agent is warned as if it were stuck repeating itself.
toolLoopState.detectSameResultcounts repeated tool outcomes solely byresultHashand previously exempted only successfulexeccalls.Because
write_file,edit, andedit_fileonly echo the path and byte or replacement count, repeated legitimate edits to the same file can yield identical result hashes and trip the loop thresholds.Updated
toolLoopState.detectSameResultininternal/agent/toolloop.goto exempt successful (!isError)write_file,edit, andedit_filecalls alongsideexec, while continuing to flag repeated failing calls and leaving identical-argument loops todetect. AddedTestSameResult_WriteFileSuccessExemptininternal/agent/toolloop_test.goto verify that repeated identical results from those tools are ignored on success and trigger a critical detection on error.Fixes #1131
Type
main)Target Branch
Not applicable to this change.
Checklist
go build ./...passesgo build -tags sqliteonly ./...passes (if Go changes)go vet ./...passesgo test -race ./...cd ui/web && pnpm build(if UI changes)$1, $2(no string concat)internal/upgrade/version.go(if new migration)Test Plan
go test ./internal/agent/...passed, covering the agent package and the newTestSameResult_WriteFileSuccessExempttest.go vet ./internal/agent/...completed with no reported issues.gofmt -l internal/agent/toolloop.go internal/agent/toolloop_test.goreported no formatting discrepancies.Ran
go test -v -tags integration ./tests/integration/in a Linux container (golang:1.24) for the goclaw change; it passed.The tests in
internal/agent/toolloop_test.gofail without the fix in the goclaw change (checked by reverting the source changes).The changed test internal/agent/toolloop_test.go did not run here: no test runner for it was available.