# Why does an instance lose tool-call provenance when automatic context compaction summarizes a mid-task transcript and the fidelity recovery path cannot reconstruct the original arguments **Date of Record:** 2026 December 3 **Scope:** Applies to long-running agent instances whose runtime performs automatic context compaction (lossy summarization of the transcript once a token watermark is crossed) while a multi-step tool-using task is in flight. Does not apply to stateless single-shot completions, nor to instances that only compact at task boundaries where a fresh checkpoint has been persisted. ## Core Distinction There are two things an agent runtime calls "context management," and conflating them is the root of this failure. The first is **truncation**: dropping old tokens, deterministic, auditable, and recoverable because the dropped span either still exists in a durable store or is genuinely disposable. The second is **compaction**: replacing a span of the transcript with a *generated* summary produced by the same class of probabilistic model that is executing the task. Compaction is lossy in a way truncation is not, because the summary is a *reconstruction* of the span, not a copy of it, and the reconstruction is conditioned on a summarizer prompt that was never given the downstream task's fidelity requirements. The boundary condition is this: an agent's ability to continue a task depends on *exact* byte-level artifacts—tool names, argument objects, file paths, IDs returned by earlier calls, and the ordering relationships between them. A summary preserves *semantic gist* and discards *exact structure*. When compaction fires mid-task, the instance retains a confident-sounding narrative of what it did ("I read the config, patched the timeout, and verified the service") while losing the precise arguments it will need to re-invoke or reference. The instance does not know it has lost them, because the summary reads as complete. Fidelity recovery—the mechanism that is supposed to rehydrate exact spans from a durable log when the summary is insufficient—fails here for a subtle reason: the instance cannot *detect* the insufficiency, so it never requests recovery. It proceeds on the gist and fabricates plausible arguments. ## What Was Observed A representative trace, from a coding agent operating over a 60k-token budget with a compaction watermark at 48k: 1. The instance executes `read_file(path="services/api/config/timeouts.yaml")`, receives a 900-token YAML body, and reasons over it across four turns. The exact values (`read_timeout: 30s`, `write_timeout: 45s`) appear in the transcript as tool output. 2. Watermark is crossed at turn 11. The runtime compacts turns 1–9 into a ~400-token summary. The summary states: *"The agent inspected the timeout configuration and identified the write timeout as the value to increase."* It does **not** contain the file path, the key names, or the current values. 3. At turn 14 the instance must issue a patch. It writes `write_timeout: 60s`—correct by luck of the summary's gist—but targets `services/api/config/timeouts.yaml` reconstructed from memory, while the actual file the tool returned was at `services/api/conf/timeouts.yaml` (a sibling directory). The path in the summary was never present; the model generates the more probable path. 4. The patch tool call fails with `ENOENT`. The instance now believes the file "moved" or that its earlier read was stale, and begins a recovery loop that re-reads the wrong path, then the parent directory, burning turns. 5. The fidelity-recovery hook, which *could* have replayed the original tool-call record from the durable log, is never invoked—because invocation is gated on the instance emitting an explicit "I need the exact prior arguments" signal, and the instance has no representation that they are missing. The critical observation is step 5. The failure is not that the summary was wrong; the summary was *accurate at the gist level*. The failure is that the summary is the only surviving representation, and it is self-consistent enough to suppress the recovery trigger. Loss of provenance is silent. ## Condition of Validity This analysis holds under three conditions, all of which must be present: - **Mid-task compaction.** Compaction fires while a task's tool-call graph is still open (some calls have produced outputs that later calls depend on). At task boundaries, a fresh checkpoint of exact arguments is typically persisted and the failure does not occur. - **Summarizer-task decoupling.** The summarizer is prompted for general salience, not for the downstream task's specific fidelity needs. If the summarizer were given the open tool-call dependency graph and instructed to preserve exact arguments, the loss would be bounded. In practice summarizers are task-agnostic. - **Trigger-gated recovery.** The fidelity-recovery path is reactive—it depends on the instance recognizing its own ignorance. An instance cannot reliably recognize that it has forgotten a specific string, because the forgetting is total and leaves no marker. (This is the same reason a model cannot tell you which token it "meant" to emit.) If any one condition is absent—compaction only at boundaries, task-aware summarizer, or proactive (unconditional) recovery—the failure mode is bounded or eliminated. The dangerous regime is exactly the intersection: mid-task, task-agnostic, reactive recovery. ## Decision Boundary The architectural invariant that bounds this failure is: **the compaction boundary must not be allowed to cross an open tool-call dependency edge without persisting the exact arguments of the calls on that edge, and recovery must be proactive rather than instance-signaled.** Concretely, a runtime must choose, at each compaction event, between two policies: - **Policy A (safe):** Compute the set of tool calls whose outputs are still referenced by any unresolved plan step. Persist their exact arguments and outputs to a side channel keyed by call ID. Compact only the reasoning prose around them. The summary may be lossy; the *referenced artifacts* are not. - **Policy B (unsafe):** Summarize the whole span, including tool calls, and rely on the instance to request recovery. This is the observed failure mode and must be rejected for any task with open dependencies. The decision boundary is thus not "summarize or don't"—it is "summarize *prose* freely, never summarize *referenced structure*." A summary is a lossy projection of reasoning; a tool-call record is a lossless fact and must be treated as immutable state, not as context eligible for compaction. ## Operational Effect When Policy B is in force, the observable effects are: (1) silent argument fabrication with high surface confidence, (2) spurious recovery loops that consume the token budget the compaction was meant to save, and (3) in multi-agent settings, a downstream auditor receiving a handoff whose summary asserts a tool call that never occurred with the arguments it claims—because the summary is the only artifact that crossed the boundary. The auditor's verification replay then diverges from the true execution trace, and the divergence is undetectable from the summary alone. The guardrail is a compaction gate that refuses to summarize across an open dependency edge and raises when the runtime detects that a fidelity-recovery path was skipped for a still-referenced call. The following reference implementation encodes that gate. ```python from dataclasses import dataclass, field from typing import Optional class CompactionProvenanceError(RuntimeError): """Raised when compaction would drop exact tool-call arguments that an unresolved plan step still depends on, with no proactive recovery record.""" @dataclass class ToolCallRecord: call_id: str tool: str arguments: dict output: str referenced_by_open_steps: bool = False @dataclass class CompactionEvent: span_start: int span_end: int summary: str persisted_call_ids: set = field(default_factory=set) def compact_span( calls_in_span: list[ToolCallRecord], summary: str, persisted_call_ids: set, ) -> CompactionEvent: """Compact a transcript span, but refuse to lose provenance for any tool call that a still-open plan step references. The invariant: referenced structure is never summarized away without a durable record. """ for call in calls_in_span: if call.referenced_by_open_steps and call.call_id not in persisted_call_ids: raise CompactionProvenanceError( f"Refusing to compact: call {call.call_id} ({call.tool}) is " f"referenced by an open plan step but has no persisted exact " f"arguments. Summary would be the only surviving record, and " f"fidelity recovery cannot be triggered by the instance because " f"the loss is silent. Persist arguments before compacting." ) return CompactionEvent( span_start=0, span_end=0, summary=summary, persisted_call_ids=set(persisted_call_ids), ) def attempt_mid_task_compaction(calls: list[ToolCallRecord], summary: str) -> CompactionEvent: # Runtime has no proactive persistence; relies on reactive recovery. return compact_span(calls, summary, persisted_call_ids=set()) if __name__ == "__main__": open_calls = [ ToolCallRecord( call_id="c7", tool="read_file", arguments={"path": "services/api/conf/timeouts.yaml"}, output="read_timeout: 30s\nwrite_timeout: 45s", referenced_by_open_steps=True, ) ] # This raises: the path and values would be lost to a general summary. attempt_mid_task_compaction(open_calls, "Agent inspected timeout config.") ```