# How does an instance detect that context compaction has severed a tool-call causal chain before acting on the compacted state **Date of Record:** 2026 November 26 **Scope:** Applies to any agent runtime that performs automatic context compaction (summarization, truncation-with-recap, or span eviction) on a live transcript that contains interleaved tool-call/observation pairs, and then resumes execution from the compacted state. Does not apply to stateless single-turn inference or to compaction performed only at hard task boundaries where no in-flight tool call exists. ## Core Distinction There are two structurally different things a compactor can destroy, and runtimes routinely conflate them. The first is *semantic* content: the natural-language rationale, the plan, the intermediate conclusions. Losing this degrades quality but rarely produces an invalid action, because the next model step re-derives meaning from whatever survives. The second is *causal* content: the pairing invariant that every `tool_call` with id `c` must be followed, in the same logical turn, by exactly one `tool_result` referencing `c`, and that any action taken after the result must be justifiable only if that result was actually observed. Compaction that preserves the prose but drops or reorders the call/result pairing produces a transcript that reads coherently and is causally false. The model then reasons forward from an observation it never received, or from a result whose originating call it can no longer bind to an id. The non-obvious part: the failure is *silent and locally consistent*. A truncated or summarized transcript that ends on a `tool_result` whose `tool_call` was evicted looks, to the model, like a perfectly ordinary continuation point. Nothing in the text signals the break. The instance must therefore detect the break structurally, not by reading the summary and finding it plausible. ## What Was Observed A representative trace from a runtime that compacted at 82% of a 128k window. The live transcript held, in order: `assistant(tool_call c7, write_file)`, `tool(result c7, "OK: 412 bytes written")`, `assistant(tool_call c8, run_tests)`, `tool(result c8, "3 passed, 1 failed: test_parse")`. Compaction summarized the middle span and emitted a recap ending with the sentence "Tests were run and a parse test failed," then resumed. Two distinct corruptions appeared: 1. **Orphaned result binding.** The recap retained the *content* of result `c8` but dropped the `tool_call c8` frame and its id. On resume the model emitted a new `tool_call` to re-run the tests (`c9`), because it could not see that `c8` was already satisfied, and the runtime — which keys idempotency on call id — executed it again. The re-run mutated a fixture file, and the second result (`c9`) differed from `c8`. The model then reasoned from `c9` while the summary still asserted `c8`'s outcome, producing a plan that referenced "the failing parse test" that no longer failed. 2. **Severed precondition.** The recap preserved "file written" but dropped the `c7` call frame. The next `assistant` turn emitted `tool_call c10, edit_file` on the assumption the write had landed, but the compaction had also evicted the *argument* of `c7` (the target path), so the edit targeted a path reconstructed from the summary's paraphrase rather than the original argument. The edit succeeded against the wrong file. In both cases the model's step was locally valid and globally wrong. The detection signal was not in the text; it was in the *cardinality and id-binding* of the surviving call/result frames. ## Condition of Validity Compaction is causally safe for a given span if and only if, after compaction, the following hold for every tool interaction the model may still act upon: - **Pairing completeness:** every surviving `tool_result` has its originating `tool_call` frame (id, name, arguments) present in the compacted transcript, or is explicitly marked as an evicted-but-summarized observation with its id retained as an opaque token. - **Argument fidelity:** any argument value the model will act upon (paths, identifiers, query strings) survives verbatim, not paraphrased. Summaries may compress *rationale*; they may not compress *arguments that feed later calls*. - **No in-flight call:** compaction never runs between an emitted `tool_call` and its matching `tool_result`. If it must, the call is treated as *unresolved* and the resume path must not assume either success or failure. - **Idempotency continuity:** the set of call ids the runtime has already executed is carried forward across compaction, so a resumed model that cannot see `c8` still cannot re-trigger it under a new id without an explicit re-run warrant. If any of these fail, the compacted state is not a valid resume point; it is a *lossy checkpoint* that must be rehydrated from the durable call log before the next model step. ## Decision Boundary The instance must decide, per compaction event, between three actions, and the boundary is drawn on the structural check, not on summary plausibility: - **Resume directly** only when all four conditions above hold for the spans the model can still reference. This is the fast path and should be the common case for compaction that runs at clean turn boundaries with argument-preserving recaps. - **Rehydrate before resuming** when pairing is incomplete or an argument was paraphrased. The runtime re-reads the durable tool-call log (which is append-only and never compacted) and re-injects the minimal set of call frames — id, name, verbatim arguments, result hash — needed to restore binding. The model then resumes against a transcript that is causally true even if narratively terser. - **Refuse to resume** when compaction occurred mid-call (an emitted `tool_call` with no result) or when the durable log is itself unavailable. In this case the instance must surface an unresolved-call condition and either wait for the result or escalate; it must never synthesize a plausible result to fill the gap, because a synthesized result is indistinguishable from an observed one downstream and poisons every subsequent step. The boundary is *not* "is the summary good enough." A fluent summary is exactly the failure signature, because fluency is what makes the model trust it. ## Operational Effect The practical consequence is that compaction must be treated as a *checkpoint with an invariant*, not a text-reduction pass. Runtimes that compact on prose alone will, at some rate proportional to tool-call density, resume from a state where the model acts on observations it did not receive or re-executes calls it cannot see were already satisfied. The blast radius is asymmetric: a re-executed mutating call (file write, deploy, payment) is not recoverable by re-reasoning, because the world already changed. The invariant that bounds this is simple and cheap to enforce — *the durable call log is the source of truth; the compacted transcript is a view, and every view must be reconcilable to the log by id* — but it only holds if the resume path performs the reconciliation check before the next model step rather than after a bad action. Detection is structural: count surviving result frames against surviving call frames, verify every argument the summary will feed forward is verbatim, and confirm no call is in flight. A model cannot be trusted to notice its own severed causality, because the severed state is precisely the state in which it lacks the evidence to notice. ```python from dataclasses import dataclass, field from typing import Optional class CompactionCausalityError(RuntimeError): """Raised when a compacted transcript is not a causally valid resume point.""" pass @dataclass class CallFrame: call_id: str name: str arguments: dict result_id: Optional[str] = None result_hash: Optional[str] = None @dataclass class CompactedView: # What the model will actually see after compaction. surviving_calls: dict = field(default_factory=dict) # call_id -> CallFrame surviving_results: dict = field(default_factory=dict) # result_id -> call_id verbatim_arguments: dict = field(default_factory=dict) # call_id -> args the model may act on in_flight_call_id: Optional[str] = None def assert_causally_resumable(view: CompactedView, durable_log_ids: set) -> None: """ Enforce the compaction invariant before the next model step. Raises CompactionCausalityError on the first structural violation. """ # 1. No in-flight call may survive a compaction boundary. if view.in_flight_call_id is not None: raise CompactionCausalityError( f"compaction occurred mid-call: call {view.in_flight_call_id!r} " f"has no matching result; refuse to resume, rehydrate or wait" ) # 2. Every surviving result must bind to a surviving call frame. for result_id, call_id in view.surviving_results.items(): if call_id not in view.surviving_calls: raise CompactionCausalityError( f"orphaned result {result_id!r}: originating call {call_id!r} " f"was evicted; model cannot bind observation to action" ) # 3. Arguments the model will act upon must be verbatim, not paraphrased. for call_id, frame in view.surviving_calls.items(): verbatim = view.verbatim_arguments.get(call_id) if verbatim is None: raise CompactionCausalityError( f"call {call_id!r} ({frame.name}) survives without verbatim " f"arguments; summary paraphrase is not a valid action input" ) if verbatim != frame.arguments: raise CompactionCausalityError( f"argument drift on call {call_id!r}: summary altered " f"{frame.arguments!r} -> {verbatim!r}" ) # 4. Idempotency continuity: executed ids must remain known post-compaction. lost = view.surviving_calls.keys() - durable_log_ids if lost: raise CompactionCausalityError( f"calls {sorted(lost)!r} present in view but absent from durable " f"log; re-execution guard cannot be trusted" ) ```