Freshness & Context Half-Life
Tag volatile observations with version or turn freshness and invalidate superseded state, to prevent Temporal Vertigo and World-Model Drift.
Consider a coding agent asked to add exponential backoff to a payment retry loop. On turn 3 it reads src/payments/retry.ts, all 212 lines. The retry settings live at lines 142 to 148. The agent notes that and moves on to the tests.
On turn 6 it runs npm run lint:fix to clean up its first change. The output says "Fixed 3 files." One of those files is retry.ts. The formatter wraps a few long lines and sorts the imports. Nine lines go, eighteen arrive, and the retry settings slide nine lines down the file.
Twelve turns later, the agent comes back to finish the job. It calls edit_lines("src/payments/retry.ts", 142, 148, …) with the new backoff block, working from the copy it read 15 turns ago. The tool replies ok. The retry tests pass. The agent reports the task done.
Lines 142 to 148 no longer held the retry settings. After the formatter ran, they held assertIdempotencyKey(), the check that stops a retried request from charging a card twice. The edit replaced it. The old retry block is still there, nine lines lower, untouched. A reviewer now has to spot a deleted safety check inside a diff titled "add exponential backoff." If nobody does, the next flaky network can bill a customer twice.
Every tool call in that session succeeded. The agent reasoned correctly from what it had in front of it. That copy was 15 turns old and quietly wrong.
Why it happens
A person editing the same file has a live view of it. The editor reloads when the formatter runs, the lines visibly shift, and a banner warns if the file changed on disk. Nobody edits line 142 from a memory of what it looked like twenty minutes ago.
An agent has no live view. It sees the world through tool results, and each result is a snapshot taken at one moment. The snapshot sits in the context window exactly as it arrived, with nothing to show its age. A file read from turn 3 looks just as current at turn 18 as it did when it came back.
Some observations stay true all session, like the name of the repository. Others go stale within a turn: file contents, test results, a deploy's status, a queue's length. How quickly an observation decays into staleness has a name: its context half-lifeLexicon · 18Context Half-LifeHow quickly an observation decays into staleness relative to reality.. A file the agent alone touches has a long half-life. The same file in a repo with format-on-save, a teammate pushing commits, or the agent's own earlier edits has a short one.
In the hook, the half-life of the turn 3 read ended at turn 6. From then on, the agent's picture of the file and the file itself disagreed on 27 lines. The gap between what the agent believes and what is actually true is called world-model driftLexicon · 20World-Model DriftDivergence between the agent's internal beliefs and actual environment state.. Drift itself is normal. The world moves while the agent works. The damage comes from drift the agent can't see.
A tool result has no age on it. The agent has to assume every snapshot is still true, until something tells it otherwise.
Every action built on unseen drift rests on an unverified assumption. The Guide calls the running balance grounding debtLexicon · 19Grounding DebtUnverified assumptions compounding across turns until checked against reality.: assumptions that compound across turns until someone checks them against reality. The agent took on the debt at turn 6, without knowing it, and paid it at turn 18 with someone else's code.
The figure below replays the session turn by turn. Start at turn 18 in the unstamped mode and step back to turn 6 to see where the drift opened. Then switch to versioned reads and watch the same mutation get flagged, and the drift close on a re-read.
The agent edits from its 15-turn-old copy. Lines 142–148 now hold assertIdempotencyKey(), and the edit overwrites it. Disk becomes d5e1 with the check deleted. The tool says ok, so the agent believes the file is correct.
copy: a41f · copy age: 15 turns · disk changed 12 turns ago · drift: 27 lines · grounding debt: 12 turns, unknown to the agent
The interesting part is turn 6. "Fixed 3 files" is a success message. The fact the agent needed, that one of those files was the one it planned to edit, was known to the tool and never reached the context.
The agent's own edits shorten the half-life too. After any write, every earlier read of that file describes a file that no longer exists, and line numbers are the first thing to go. The earlier read and the later edit then sit side by side in the window, describing two different files. Holding two versions of the same thing at once, with no way to tell which is current, is temporal vertigoLexicon · 17Temporal VertigoDisorientation from stale past states coexisting beside live state.. A capable model may notice the mismatch. Fifty thousand tokens into a session, it can just as easily act on the wrong copy.
What it costs
Edits in the wrong place. Line-based edits on a stale read don't fail. They succeed at the wrong address. The damage is a plausible-looking diff that removes or duplicates code, and it passes any test that doesn't cover the lines it hit.
Turns spent untangling. Tools that match on exact text fail loudly instead: "old text not found." That is far better, but the agent still has to work out why. Often it retries with small variations of the same stale text before it thinks to re-read the file. Each retry costs a turn, a few hundred tokens of reasoning and some latency.
Overwritten work. When the change came from a teammate or a parallel sub-agent, a stale write silently deletes their work.
Review load. A team that finds one deleted safety check stops trusting agent diffs. Every change gets a line-by-line review, usually by the senior people who can spot a missing idempotency guard, and much of the time the agent saved goes into checking it.
Bad answers outside code. The same failure shows up anywhere the world moves during a session. An agent quotes a deploy status from turn 2 at turn 20, or approves a pull request against a commit that has since been force-pushed.
The fix
In plain words: every observation that can go stale must say how old it is, and the system must say when it has gone stale.
- Stamp volatile reads with a version. A content hash, a commit, a modification time, or at least the turn number. The stamp turns "the file" into "the file as of version
a41f." - Check the stamp on every write. Edits carry the version they were based on. If the file has moved on, the tool refuses and says what changed.
- Invalidate superseded state. When something changes a file, the harness marks earlier reads of it as superseded, so the stale copy can't pass as current.
The second rule is old. On the web it's the ETag: the client sends If-Match with the version it last saw, and the server rejects the write if the resource has changed. Databases call it optimistic concurrency control. Agents need it more than browsers do, because an agent can't see the page reload.
Here is the edit from the hook, before and after the tool checks freshness.
{ "ok": true, "lines_replaced": 7 1 }
- 1The tool confirms that seven lines were replaced. It doesn't say which seven, or that the file changed since the agent read it. The agent reads success and moves on.
{ "status": "rejected", "reason": "stale_read", 1 "your_version": "a41f (read at turn 3)", "current_version": "9c07 (changed at turn 6 by npm run lint:fix)", 2 "changes_since_read": "+18 -9 lines; 142-148 now hold assertIdempotencyKey()", 3 "next": "read_file(path=\"src/payments/retry.ts\", since=\"a41f\")" 4 }
- 1The edit is refused before it touches the file. The agent sent
expected_version: "a41f"with the call, and the tool compared it with the disk. - 2Both versions are named, along with what changed the file and when. The agent learns that its own lint run caused the change, so nothing is wrong except its copy.
- 3Summarizing the change costs the tool a diff and the response about 70 extra tokens. It only happens on a stale write, which is exactly when the agent needs it.
- 4The exact call that brings the copy up to date, ready to copy. With
since, the tool can return only the changed hunks instead of the whole file.
Walk through the pins. Pin 1 is the core of the fix. A stale write never touches the disk. The cost of a rejected edit is one turn. The cost of an accepted stale edit is whatever it overwrote.
Pin 2 tells the agent why. Without it, a rejection is a puzzle. With it, the agent knows its own lint run caused the change, so it can simply re-read and retry.
Pins 3 and 4 shrink the way back. The summary tells the agent where its target moved, and the since call returns only what changed. One turn later the agent's copy matches the disk again. The number of turns an agent needs to get its beliefs back in line with reality has a name: time-to-groundingLexicon · 54Time-to-GroundingTurns required for agent beliefs to align with live reality.. Here it is one turn, where the unstamped version never got there at all.
Stamp the read, fold the stale copy
The rejection only works if the agent has a version to send. That starts with the read. A stamped read puts the version and the turn in the first line, where the agent sees it before any content:
read_file("src/payments/retry.ts")
→ version: a41f · read at turn 3 · 212 lines · modified 14:02:11
1 import { charge } from "./client"
...
The other half belongs to the harness, the program that runs the agent loop and assembles its context. When a tool call changes a file, the harness can find earlier reads of that file and fold them in place:
[read_file src/payments/retry.ts · version a41f · turn 3]
[superseded at turn 6: npm run lint:fix rewrote this file (now 9c07).
Content folded. Re-read before editing.]
Folding cures the temporal vertigo directly: only one copy of the file is left in the window, and the tokens the old read used are freed. H-14 Memory Metabolism covers deliberate forgetting in more depth.
The same pattern on other tools
Anything that changes while the agent works needs the same treatment.
| Observation | Unstamped | Stamped |
|---|---|---|
| File read | raw content | version: a41f, read at turn 3; writes take expected_version |
| Test run | 12 passed | 12 passed at commit 7e1c, plus a note when files changed since |
| Deploy status | healthy | healthy as of 14:02:11, revision r-482; re-check before acting |
| Ticket or queue list | 14 items | 14 open as of 14:02, a cursor for changes since |
| Config or feature flags | the values | values plus an etag; updates send it back |
Tests deserve a second look. After the next edit, "12 passed" is a claim about code that no longer exists, and agents often report success from a test run that predates their last change.
In MCP terms
Put read_file and edit_lines behind an MCP server and the protocol can date a snapshot and tell a client a resource changed. What it doesn't have is an If-Match for tool calls. The version check is yours to build.
- Last-modified annotation (
annotations.lastModified). Any content block can carry an ISO 8601 timestamp. Set it on everyread_fileresult, so the turn 3 copy carries its own modification time. A timestamp dates the read, but it can't say the file has moved on since. - Input and output schemas (
inputSchema,outputSchema). Makeversiona required field of the read result, andexpected_versiona required argument ofedit_lines. An edit then can't arrive without the version it was based on. - Error flag (
isError). Return thestale_readrejection withisError: true, carryingcurrent_version,changes_since_readandnext. The spec describes these execution errors as "actionable feedback that language models can use to self-correct and retry with adjusted parameters." Here that means one re-read and a retry. - Resource freshness (
ttlMs,notifications/resources/updated). If files are also resources, aresources/readresult carriesttlMs, which the spec calls "a freshness hint, not a guarantee," and an update notification for the file's URI invalidates the cached copy. Both go to the client, which can fold the stale read as the harness does above. - Not in the protocol. Tool results have no as-of, version or etag field, and no TTL. Put
versionand the read turn in the payload, as in the stamped read above.
Spot it in your traces
Here is the hook session as it appears in a trace log, cut to five key turns. The notes give each turn's place in the full session. The trouble starts at turn 6, and nothing breaks until turn 18.
- T1
read_file("src/payments/retry.ts")→ 212 lines (retry config at 142-148)The retry settings are at lines 142 to 148. Start with the tests.A sensible read. Turn 3 of the session. - T2
run("npm run lint:fix")→ Fixed 3 filesLint is clean. Back to the tests.Turn 6. The formatter rewrote retry.ts. The output names no files, so the agent never connects it to its turn 3 read. - T3
edit_file("test/retry.test.ts", …)→ okTests cover the new backoff timing.Turns 7 to 17 happen in other files. The copy of retry.ts keeps aging. - T4
edit_lines("src/payments/retry.ts", 142, 148, …)→ { "ok": true, "lines_replaced": 7 }Backoff added.Turn 18. A line-number edit from a 15-turn-old read. It replacesassertIdempotencyKey()and leaves the old retry block in place. - T5
run("npm test -- retry")→ 8 passedRetry tests pass. Task done.The tests don't cover idempotency, so the damage passes. The report says done.
To find the same pattern in your own logs, look for these signals:
- A write long after the read it depends on. For every edit, find the most recent read of the same file and count the turns between them. Long gaps are where to look, especially when another write or a formatter ran on that file in between.
- A mutating command between a read and a write. Formatters, code generators,
git pull,git checkout, package installs and migrations all change files without naming them. A read, one of these, and then a line-based edit on the same file is the exact signature of the hook. - Text-match failures followed by retries.
old text not foundfollowed by two or three slightly different attempts usually means the agent is matching against a stale copy. Check whether a re-read would have fixed it on the first try. - Two reads of one file that disagree. Search a session for repeated reads of the same path with different content, then check which one the agent quoted later. Contradictory observations from different turns, side by side in the window, are called context clashLexicon · 24Context ClashContradictory observations from different turns colliding in the window., and nothing in the window tells the agent which copy to believe.
- Success claimed on a stale test run. Find "tests pass" in a final report and check whether any edit happened after the last test run.
Review checklist
Run these against every tool that reads state which can change during a session, and against the harness that assembles the context. Each check takes a few calls.
- Stamp every read of volatile state with a version: a content hash, commit, ETag or modification time.How to check Read a file, a status or a list. The first line of the response should carry a version or timestamp the agent can send back.
- Make every write accept the version it was based on, and reject the write when the target has changed.How to check Read a file, change it outside the agent, then edit it with the old version. The edit should be rejected with
stale_read, and the file should be unchanged. - When a write is rejected as stale, say what changed and give the exact call that refreshes the copy.How to check Trigger a stale write. The rejection should name both versions, what changed the target, and a ready-to-run re-read call.
- Make commands that change files report which files they changed.How to check Run the formatter, code generator or
git pullthrough the agent's tool. The output should list changed paths, not just a count. - Mark or fold earlier reads of a file in context after anything changes it.How to check In a test session, read a file, run a formatter that changes it, then inspect the context. The old read should carry a superseded marker or be folded.
- Prefer edits addressed by content or anchor over edits addressed by line number.How to check Insert a line at the top of a file after reading it, then apply an edit from the earlier read. It should either land correctly or fail loudly, never edit the wrong lines.
- Tie test and status results to the version they describe.How to check Run the tests, edit a file, then ask for status. The response should say the last test run predates the latest change.
When laws collide
Freshness adds metadata to every read and occasionally a refusal to a write. That pulls against some laws and makes others stronger.
- Pulls against · H-03Token Hygiene & High Observation YieldWhere they clashToken Hygiene asks every response to carry only what helps the next decision. A version stamp on every read, a superseded marker on every stale copy and a change summary on every rejection all add tokens, and an agent reading 40 files pays for each.How to have bothKeep the stamp to one short line, a hash and a turn number. Spend tokens on freshness only where it decays fast: stamp files, statuses and lists, skip stable facts like the repository name. Folding stale reads usually saves more tokens than the stamps cost.
- Pulls against · H-12Cheap Speculation & Declared Blast RadiusWhere they clashRejecting stale writes adds friction to the agent's most common action. If the formatter touches files on every save, a strict version check can reject nearly every edit, and the agent learns to re-read reflexively or to route around the check.How to have bothReject only when the change overlaps what the edit touches, and let non-overlapping edits through with a note that the file moved. Content-anchored edits make this easy: if the anchor text is unchanged, the edit is still safe. Keep the hard rejection for real conflicts.
- Works with · H-01Continuous State AnchoringHow they combineContinuous State Anchoring keeps a small piece of live state current in the context, such as the branch, the working directory or the open files. Freshness covers everything else, the snapshots that can't be kept live and so must carry their age.What you getTogether they give the agent a clear rule: the anchored state is current by definition, and anything else carries a version stamp that says how old it is. The agent never has to guess which observations it can still trust.
Model size shifts the balance a little. A strong model may notice a change and re-read on its own, sometimes more than it needs to. A smaller model usually trusts its first copy. Version checks protect both, because the tool refuses the stale write whichever model sent it.
Terms from this page
- 18Context Half-Life
- How quickly an observation decays into staleness relative to reality.
- 20World-Model Drift
- Divergence between the agent's internal beliefs and actual environment state.
- 19Grounding Debt
- Unverified assumptions compounding across turns until checked against reality.
- 17Temporal Vertigo
- Disorientation from stale past states coexisting beside live state.
- 54Time-to-Grounding
- Turns required for agent beliefs to align with live reality.
- 24Context Clash
- Contradictory observations from different turns colliding in the window.