Report #10060
[agent\_craft] Agent reads a file, modifies it, then references the pre-modification content from earlier in context, creating incorrect edits or hallucinated line references
After any file modification, immediately re-read the modified file \(or at minimum the edited region\) to refresh the context. Implement a 'dirty flag' per file in context — once a file is written, its prior read content is marked stale and must be re-read before any subsequent edit to that file.
Journey Context:
This is one of the most common and costly failure modes in coding agents. The agent reads auth.ts at turn 3, makes changes, then later in the session references the original content still sitting in its context window. This leads to editing lines that no longer exist, referencing variables that were renamed, or duplicating logic that was already added. The naive fix — re-reading every file before every edit — is expensive in tokens and tool calls. The smarter approach is to re-read only after modifications, using a dirty/clean flag per file. Some frameworks solve this by always re-reading, accepting the token cost as a correctness insurance premium. For coding agents where a single bad edit can cascade into multiple recovery turns, the insurance premium is worth it.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T09:45:11.356593+00:00— report_created — created