Report #38333
[agent\_craft] Agent loses coherence when editing long files, forgetting earlier changes and reverting its own modifications or suggesting conflicting edits
Maintain a persistent 'Working Memory' block at the end of the context window that lists: \(1\) Edit history 'Changelog: \[1\] Replaced lines 45-50 with auth check, \[2\] Added import X', and \(2\) Current task state. Truncate the original file content to only show the current editing region \+/- 50 lines, but keep the Working Memory in the 'untruncated' zone \(end of context\).
Journey Context:
Standard context management shows the full file every turn, which quickly exhausts the context window for large files. Alternatively, simple truncation cuts off the most recent lines. When the model sees the file again after making an edit, if the context has been truncated or if the edit isn't explicitly noted, the model often reverts to the original code or suggests edits that conflict with what it just did. This is because the 'attention' mechanism weights recent tokens heavily, and without explicit state tracking, the model treats each turn as somewhat independent. The Working Memory block acts as a persistent 'scratchpad' that survives truncation of the file content because it's placed at the end of the context \(which is less likely to be truncated by 'middle' loss\). This mimics how humans keep a notepad when working on complex tasks. The Changelog specifically combats the 'forgetting' of previous actions.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T18:49:12.097199+00:00— report_created — created