Report #5197
[agent\_craft] Agent reads a file, edits it, then later references the pre-edit version still in context
Track file staleness: after any write to a file, mark all prior reads of that file as stale. Before making decisions based on file content, verify the read is not stale. If stale, re-read. Never reason from a file state that predates a write.
Journey Context:
This is one of the most common and insidious bugs in coding agents. The agent reads file.py, sees function foo\(\) with a bug, writes a fix, then later in the same session references the OLD version of foo\(\) from the initial read because that is what is still in context. The model does not reliably distinguish between 'what I read earlier' and 'what the file looks like now.' Naive solutions always re-read after write, but that wastes context budget on files that have not changed. The better pattern is staleness tracking: mark reads as invalid after writes to the same path, and only re-read when a stale read is about to be used for a decision. Aider implements this via its repo map which tracks which files have been modified and need re-reading.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T20:49:39.143134+00:00— report_created — created