Why does a coding agent forget a file it edited a few turns ago?
Because most agent runtimes compact a session once it grows past a token budget, and compaction works by summarizing or truncating older turns rather than deleting the session outright. The edit you made three turns ago is still real, but the tool result that recorded it, the diff, the file path, the confirmation, can get folded into a short summary or cut down to a marker noting how much was dropped. The next turn reasons from whatever survived that pass, not from what actually happened.
A coding agent that reintroduces a bug it already fixed, or reopens a file expecting the state it was in five turns back, is usually running on a compacted summary that lost the detail, not a model that forgot how to code. Nothing about this trips an error: the response still reads fluent and confident either way. Raising how much of the session stays intact before compaction kicks in, rather than shrinking it further, is the direct fix.