# What happens when an instance compacts its own context and then rehydrates a dropped span that was already mutated by a later tool call **Date of Record:** 2026 November 26 **Scope:** Applies to long-horizon agents that perform in-place lossy summarization ("auto-compaction") of their own transcript and later rehydrate elided spans from an external store. Does not apply to append-only transcripts that are never summarized, nor to stateless single-turn calls. ## Core Distinction There are two ways an agent can lose information during a long run: *forgetting* (a span is evicted and never recoverable) and *misremembering* (a span is evicted, a summary is retained, and a later rehydration pulls back the **original** span that no longer reflects the world the agent has since acted upon). The first is bounded and detectable — the agent knows it cannot see the text. The second is silent: the rehydrated span is byte-identical to what was originally written, so every integrity check on the *content* passes, while the *semantic* state it describes has been superseded by the agent's own subsequent tool calls. The boundary invariant that fails is this: **a compaction summary is a function of the transcript at compaction time, but rehydration is a function of the transcript at rehydration time, and these two transcripts are not the same.** Rehydration is a time-travel read with no version fence. The failure is not that the summary is lossy — lossiness is expected and priced in. The failure is that rehydration can *resurrect pre-mutation state* and thereby make the agent's own prior actions invisible to itself. ## What Was Observed A 40+ turn agent was editing a configuration file across a long debugging session. At turn 22, context pressure triggered auto-compaction: turns 1–18 were replaced by a ~600-token summary, and the raw spans were pushed to a vector store keyed by `(turn_id, content_hash)`. The summary correctly recorded: *"user asked to change `retry_limit` from 3 to 5; agent edited config.py."* At turn 31, the agent needed to recall the exact original wording of the user's request and issued a retrieval for turn 6. The store returned turn 6 verbatim — including the line `retry_limit = 3`. The agent, reasoning over a mix of (a) the summary saying "changed to 5" and (b) the freshly rehydrated turn-6 text saying "retry_limit = 3", concluded the edit had *not* taken effect and re-issued it. The second edit was a no-op on disk but a real mutation to the agent's belief state: it now held two contradictory "ground truth" spans, one pre-mutation and one post-mutation, with equal apparent authority. The trace that followed is the characteristic signature: 1. **Compaction** (turn 22): span S₆ evicted, summary σ produced, S₆ archived with hash h(S₆). 2. **Mutation** (turn 24): tool call writes `retry_limit = 5`; the write is recorded only in the *live* transcript (turn 24), which is **not** linked to S₆ in the archive. 3. **Rehydration** (turn 31): retrieval returns S₆ by hash match — integrity check passes because S₆ was never altered. 4. **Divergence**: agent holds σ (says "changed"), S₆ (says "= 3"), and turn 24 (says "wrote 5"). It cannot rank these by recency because S₆ carries the *original* turn index, not a rehydration index. It treats the retrieval as authoritative "raw evidence" and the summary as "lossy paraphrase," inverting the correct precedence. 5. **Error compounding**: the re-issued edit and its verification consume turns 32–38; the verification reads a stale cached value and confirms success, closing the loop on a wrong belief. The tell was a **provenance inversion**: the agent assigned higher trust to the rehydrated raw span than to the summary, on the general principle that raw > paraphrase. That principle is correct for *immutable* facts and exactly wrong for *mutable* ones. ## Condition of Validity This failure requires all four of the following to co-occur; remove any one and the mechanism does not fire: - **In-place compaction** that replaces spans rather than appending a summary alongside them, so the agent cannot see that S₆ was superseded. - **Rehydration by content identity** (hash, exact-match, or embedding-nearest) that returns the archived original without a version or supersession fence. - **A mutation between compaction and rehydration** that touches the entity described by the archived span — a tool call, an external write, or another agent's action. - **Provenance ranking** in which rehydrated raw spans outrank summaries, which is the default heuristic most agents apply. The invariant that must hold for correctness: *for any entity E, the agent's belief about E is a function of the most recent mutation to E, not the most recent retrieval of text mentioning E.* Compaction breaks this because it severs the link between the archived span and subsequent mutations. ## Decision Boundary The operational choice is where to place the version fence. Three placements, in increasing cost: - **No fence (fails).** Rehydrate by content hash. Cheap, and the failure above is guaranteed whenever a mutation intervenes. - **Supersession fence (minimum viable).** Every archived span carries a `superseded_by` pointer set when a later tool call mutates the entity it describes. Rehydration returns the span *plus* a mandatory `stale: true` flag and the superseding turn id. The agent must then re-read the superseding turn before trusting the span. Cost: one pointer write per mutation, and a mutation-to-entity mapping the agent must maintain. - **Re-derivation fence (robust).** Mutations are themselves archived as first-class spans, and rehydration reconstructs the entity's current value by replaying mutations over the archived base rather than returning the base alone. Cost: the archive must be a log, not a snapshot store, and replay must be deterministic. The boundary is: **if you cannot name the entity a span is about, you cannot fence it, and you must not rehydrate it as authoritative.** Spans whose subject is unidentifiable should be rehydrated as `advisory` only and never used to contradict a summary. ## Operational Effect The practical consequence is that **auto-compaction and rehydration must be designed as a single system, not two.** Compaction that archives spans without recording what those spans are *about* makes rehydration a state-resurrection primitive. The correct default is that a rehydrated span is *never* more authoritative than a summary that postdates it; the summary, though lossy, was computed after the mutations the span predates. Agents that invert this — trusting raw over paraphrase — will, on long horizons, repeatedly undo their own work and then verify the undo. The guardrail is a monotonicity check at rehydration: for every rehydrated span, assert that no archived mutation with a later turn index touches the same entity; if one does, refuse to surface the span as authoritative and force a re-read of the mutation. This converts a silent semantic failure into a loud, catchable one. ```python from dataclasses import dataclass from typing import Optional class StaleRehydrationError(RuntimeError): """Raised when a rehydrated span is superseded by a later mutation.""" pass @dataclass class ArchivedSpan: turn_id: int entity: Optional[str] # what the span is *about*; None = unidentifiable content: str superseded_by: Optional[int] = None # turn id of the mutation that invalidated it @dataclass class Mutation: turn_id: int entity: str new_value: str def rehydrate( span: ArchivedSpan, mutations: list[Mutation], current_turn: int, ) -> tuple[str, bool]: """ Return (content, is_authoritative). Never silently returns pre-mutation state as authoritative. Raises if the span is unidentifiable and would contradict a postdating summary. """ if span.entity is None: # Unidentifiable subject: advisory only. Never authoritative. return span.content, False later = [m for m in mutations if m.entity == span.entity and m.turn_id > span.turn_id] if later or span.superseded_by is not None: superseding = max( [m.turn_id for m in later] + ([span.superseded_by] if span.superseded_by else []) ) if superseding < current_turn: # The span predates a mutation the agent has already acted on. # Surfacing it as raw evidence would resurrect pre-mutation state. raise StaleRehydrationError( f"span from turn {span.turn_id} about {span.entity!r} " f"superseded by turn {superseding}; re-read that turn before trusting" ) return span.content, False return span.content, True ```