Context, state and memory
Long runs collect noise, compaction loses information, and work has to survive resets and crashes. These are related problems with different fixes.
Context rot
The context window is not a hard drive. Models get worse at using information in their context as the context grows, well before the window is full (Hamza Shabbir, Blake Crosley). A goal loop that keeps one session alive for hours accumulates stale tool output, abandoned plans and contradicting notes, and quality degrades.
Three strategies
Summarize the conversation so far and continue in a fresh window. One article calls it the approach the major labs converged on in 2026 (Medium). It's often triggered well before the window fills (one playbook suggests at 80%).
Costs: each compaction is an extra model call, and errors in the summary persist: whatever it drops is gone and whatever it gets wrong becomes "fact" (rate–distortion view of memory compaction). Research is moving toward validated or learned compaction (Slipstream).
Anthropic's long-running harness research shows compaction alone isn't enough for multi-session work; agents also need incremental progress, explicit artefacts and a disciplined division of work (Anthropic).
State is not memory
These two get confused all the time:
| Information | Kind | Lives in |
|---|---|---|
| Current iteration number | State | Harness |
| The active goal | State | Harness / thread / file |
| Completed subgoals | State | Progress file, task list |
| Last good checkpoint | State | Git |
| Previous failed approaches | Memory | Notes, memory store |
| User preferences | Memory | Memory store |
| Knowledge about the codebase | Memory | Docs, CLAUDE.md, skills |
| Reusable procedures | Skills | Skill files |
State has to be exact and current, so a wrong iteration count breaks resumption. Memory has to be relevant and trustworthy, so a wrong memory misleads every future run. They need different storage, retention and validation.
The resumption problem
What's the minimum state needed to resume a task reliably after an arbitrary interruption, such as a crash, a laptop lid closing or a quota running out?
- Codex persists goals on the thread but only runs while a session is open. Claude Code background sessions stop on sleep or shutdown and come back with
claude respawn --all. - Anthropic's Managed Agents keep the session log outside the harness, so a harness crash loses nothing (Anthropic).
- The arXiv adoption study found no loop state files on the default branches it scanned. State lives outside version control, so it is invisible and fragile.
Memory as liability
Persistent memory is also persistent attack surface and persistent error. A wrong "lesson" written to memory gets applied forever, and an injected one gets executed forever (arXiv: stealthy memory injection). Being able to selectively forget is listed as a core infrastructure requirement (Loams), and almost nobody has it.