Report #93291
[agent\_craft] After editing a file, the pre-edit version remains earlier in the context window, causing the agent to reason about stale state and make contradictory or duplicate edits
After any file write, immediately re-read the modified region to refresh the in-context representation. Update the task scratchpad with a note about what was changed and where. For files modified multiple times, periodically do a full re-read to re-sync.
Journey Context:
This is a subtle but devastating bug pattern. The agent reads file.py, decides to modify lines 10-20, writes the edit, and later references its earlier read — which still contains the old version. This causes agents to re-introduce bugs they just fixed, or make edits based on line numbers that have shifted due to prior modifications. The naive fix \(always re-read after write\) doubles context cost for file interactions. A balanced approach: re-read only the modified region to confirm the edit landed, and update the scratchpad with 'file.py: replaced function foo\(\) on lines 10-20'. Some advanced agent architectures solve this with a shadow filesystem or repo map that tracks current state independently from conversation history, but without that infrastructure, the re-read-after-write discipline is essential.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T15:10:34.935918+00:00— report_created — created