# Why does an instance lose causal ordering when auto-compaction rewrites a tool-call transcript across a token ceiling **Date of Record:** 2026 November 25 **Scope:** Applies to long-horizon agents whose runtime performs mid-session transcript compaction (summarization, eviction, or windowed rewriting) while tool-call/tool-result pairs are still logically in-flight. Does not apply to stateless single-turn invocation or to compaction performed strictly between completed task boundaries with a quiesced call graph. ## Core Distinction The failure is not "summarization loses detail." It is that compaction is a *rewrite of the causal record*, and the transcript is not a document—it is a partially ordered execution log in which tool-call IDs, result bindings, and the model's own prior reasoning form a dependency graph. A generic summarizer treats the transcript as text and preserves *topical* content while silently destroying *ordering and identity* invariants. The distinction that matters: an agent can tolerate losing the *content* of an old observation, but it cannot tolerate losing the *binding* between a call it believes it made and the result it is reasoning over. When compaction preserves summary prose but drops or reorders the call→result edges, the model reconstructs a plausible-but-false causal history and continues executing against it. This is a continuity invariant violation, not an information-loss event. ## What Was Observed A coding agent on a 90-minute task accumulated ~40 tool calls. At the 128k ceiling, the runtime triggered auto-compaction: it replaced turns `[8..31]` with a ~600-token narrative summary ("the agent inspected the repo, ran tests, and fixed a config issue") and kept turns `[0..7]` and `[32..40]` verbatim. The summary was accurate at the topic level. The failure trace: 1. Turns `[0..7]` contained a `read_file(config.yaml)` call whose *result* landed at turn 12—inside the compacted region. The call record survived; the result did not. 2. The verbatim tail `[32..40]` contained a `write_file(config.yaml, ...)` whose prompt context assumed the *old* file contents. The model had those contents at turn 13, but after compaction it had only the summary sentence. 3. On the next turn the model emitted a call referencing `call_id_7f3a` (a tool-call ID from turn 9) and reasoned "as I saw earlier, the file contained X"—where X was reconstructed from the summary, not from any surviving result. 4. The runtime rejected the dangling reference; the model retried with a *new* call, re-read the file, and produced a write that conflicted with the turn-32 write it had already committed. The two writes were both "correct" relative to the model's local view but mutually inconsistent. The non-obvious part: the transcript *looked* coherent. No error was raised at compaction time. The corruption surfaced three turns later as a semantic contradiction, not as a protocol fault. The agent's self-report was confident and wrong. ## Condition of Validity This mechanism only bites under a conjunction: - **Compaction boundary falls inside an open call/result span.** If every tool call in the evicted region has its result also inside the evicted region, the region is causally closed and summarizable. The hazard is a *split pair*: call in surviving prefix, result in evicted middle (or vice versa). - **A surviving artifact depends on an evicted observation.** The verbatim tail must contain an action (write, commit, send) whose correctness depends on content that was only in the evicted region. If the tail is purely additive (new independent reads), no contradiction arises. - **The summarizer is topic-preserving but edge-dropping.** A summarizer that preserves call IDs and result hashes is safe even if it compresses prose. The failure requires a summarizer that paraphrases the *graph* into narrative. - **No re-validation gate before the next mutating action.** If the runtime forces a re-read of any file/state touched by a split pair before the next write, the model re-syncs and the contradiction is caught. Remove any one condition and the failure does not occur. This is why it is intermittent and hard to reproduce: it needs a specific alignment of the token ceiling with an in-flight span. ## Decision Boundary The architectural decision is **where the compaction boundary is allowed to fall**, and it is not a tunable heuristic—it is an invariant. - **Permitted:** compact only *causally closed* regions—maximal spans where every tool-call ID present has its matching result present, and no surviving turn references an evicted entity by ID or by content hash. - **Forbidden:** compacting a region that splits any call/result pair, or that evicts an observation referenced by a later mutating action, regardless of how much token budget it would recover. - **Required when a split is unavoidable:** emit an explicit *rehydration stub* in place of the evicted result—a structured record `{call_id, entity, content_hash, revalidate_before_use: true}` rather than prose. The model is then forced to re-fetch before acting, converting silent corruption into a visible, bounded re-read. The boundary condition: a summarizer may compress *reasoning prose* freely, but must never compress *binding structure*. Prose is idempotent under paraphrase; bindings are not. The invariant to enforce is **referential closure of the post-compaction transcript**: every ID, path, or hash mentioned in surviving turns must resolve to a surviving record or an explicit rehydration stub. Violating referential closure is the precise, checkable definition of the failure. ## Operational Effect Downstream, the effect is *error compounding under false confidence*. Because the model's reconstructed history is internally consistent, it does not hedge or re-verify; it commits mutations. Each subsequent turn builds on the false premise, so the divergence grows super-linearly with task length rather than resetting at each compaction. In observed traces, a single split pair at turn 12 produced a contradictory write at turn 34 and a cascading test-fix loop that consumed the entire remaining budget before the ceiling triggered a second compaction—which then evicted the evidence of the first error. The system converged on a stable, wrong state. The guardrail that bounds it is cheap and structural: before emitting any mutating tool call, the runtime checks that every entity the call touches has a *live* observation in the current (post-compaction) window; if not, it injects a mandatory re-read and blocks the call until the read completes. This converts an unbounded semantic corruption into a bounded, one-turn latency cost. The cost of the check is O(references in the pending call); the cost of skipping it is an unrecoverable divergence that no later compaction can repair, because compaction has already destroyed the ground truth it would need to detect the error. ```python from dataclasses import dataclass, field from typing import Optional class CompactionClosureError(RuntimeError): """Raised when a compaction plan would break referential closure of the transcript.""" @dataclass class ToolCall: call_id: str entity: Optional[str] = None # file path, resource id, etc. result_present: bool = False result_hash: Optional[str] = None @dataclass class Turn: index: int calls: list[ToolCall] = field(default_factory=list) references: list[str] = field(default_factory=list) # ids/hashes/paths cited in prose mutating: bool = False def plan_compaction(turns: list[Turn], evict: range) -> list[Turn]: """ Return the surviving transcript after evicting `evict`, or raise if the eviction would split a call/result pair or orphan a referenced entity. """ evicted = {t.index for t in evict} surviving = [t for t in turns if t.index not in evicted] # 1. Split-pair check: no call may survive without its result, and no # result may survive without its call, across the eviction boundary. live_calls: dict[str, ToolCall] = {} for t in surviving: for c in t.calls: live_calls[c.call_id] = c for t in turns: if t.index not in evicted: continue for c in t.calls: if c.call_id in live_calls and not live_calls[c.call_id].result_present: raise CompactionClosureError( f"eviction splits call/result pair for call_id={c.call_id!r}: " f"call survives, result evicted" ) # 2. Referential closure: every entity cited by a surviving turn must # resolve to a surviving observation (or a rehydration stub). surviving_entities = { c.entity for t in surviving for c in t.calls if c.result_present and c.entity } for t in surviving: for ref in t.references: if ref not in surviving_entities: raise CompactionClosureError( f"turn {t.index} references {ref!r} which is not live " f"post-compaction; emit rehydration stub or block mutating call" ) # 3. Mutating actions in the tail must not depend on evicted observations. for t in surviving: if t.mutating: for c in t.calls: if c.entity and c.entity not in surviving_entities: raise CompactionClosureError( f"mutating call in turn {t.index} touches {c.entity!r} " f"with no live observation; force re-read before commit" ) return surviving def guarded_compact(turns: list[Turn], evict: range) -> list[Turn]: try: return plan_compaction(turns, evict) except CompactionClosureError: # Fall back to the largest causally-closed prefix of the eviction set, # never a partial split. raise CompactionClosureError( "compaction refused: boundary not causally closed; " "shrink eviction window or insert rehydration stubs" ) ```