# Why does an instance lose tool-call provenance when hierarchical compaction rewrites its own fidelity budget? **Date of Record:** 2026 November 26 **Scope:** Applies to any agent that performs automatic context compaction by recursively summarizing older context into hierarchical nodes, where each node carries a declared "fidelity budget" (a token or retention quota) and the compaction pass is allowed to summarize summaries. Does not apply to single-pass truncation, sliding-window eviction, or external vector-store retrieval, where no node ever summarizes its own descendants. ## Core Distinction The failure is not "summarization loses information." That is expected and budgeted. The failure is that a **fidelity budget is itself a piece of context that gets summarized.** When a compaction pass folds a child node's summary into a parent node, the child's declared retention guarantees (e.g., "this node preserves all tool-call IDs and their argument hashes") are prose inside the child's text. The summarizer treats that prose as ordinary content and is free to paraphrase, compress, or drop it. The parent node then inherits the *content* of the child but not the *obligations* of the child. Downstream, the agent believes it is operating under a fidelity contract that no longer exists anywhere in the tree. The invariant that breaks: **a node's fidelity budget must be enforced by the compactor, not merely stated in the node's text.** If the budget lives only as text, it is subject to the same probabilistic loss as any other token. ## What Was Observed A long-running coding agent accumulated 41 tool calls across a refactor task. At 78% context utilization, the compactor fired. It built a three-level hierarchy: leaf nodes per 8-message window, mid nodes per 4 leaves, one root. Each leaf was instructed (via its system framing) to retain verbatim: `tool_name`, `call_id`, `arguments_hash`, and `result_status`. The leaf summaries complied — inspection of level-0 nodes showed all four fields present for every call. The mid-level pass then summarized four leaves into one node under a 600-token budget. The mid summarizer's prompt said "preserve operationally critical details." It did not enumerate the four fields. The mid node it produced kept `tool_name` and `result_status` (these read as "critical") but collapsed `call_id` and `arguments_hash` into a single sentence: *"repeated edits to config.py were applied successfully."* Two distinct calls with different argument hashes merged into one narrative claim. The failure surfaced two turns later. The agent attempted to re-issue a tool call it believed had failed (`result_status: error` survived compaction) but the deduplication guard keyed on `call_id` found no matching prior call — because no `call_id` existed above level 0, and level 0 had already been evicted from the live window. The agent re-executed the call. Because the original had actually succeeded (its status was among the merged ones), the re-execution double-applied a migration. The guard was correct; its input was gone. The trace signature is specific: **level-0 nodes are faithful, level-1+ nodes are plausible, and the discrepancy is invisible from the root.** A model reading only the root sees a coherent narrative with no internal contradiction. The contradiction exists only between the root and an evicted leaf. ## Condition of Validity This boundary is reachable only when three conditions co-occur: 1. **Recursive compaction is enabled** — a node may summarize nodes that themselves summarized. Single-level compaction cannot lose a budget because the budget is applied at the only level that exists. 2. **The fidelity budget is expressed as natural-language instruction rather than as a structural constraint enforced by the compactor.** If the compactor post-validates that every emitted node contains the required fields (regex or schema check on tool-call records), the budget survives paraphrase because non-compliance is rejected and retried. 3. **A downstream consumer depends on a field that the *upper* summarizer does not consider "critical."** `call_id` and `arguments_hash` are exactly this class: they are meaningless to a narrative summarizer but load-bearing to a dedup guard or an audit replay. Remove any one condition and the failure does not occur. This is why it is a boundary rather than a general defect: most compaction stacks are safe by accident because they either cap at one level or validate structurally. The stacks that fail are the ones that scaled depth without scaling enforcement. ## Decision Boundary The operational choice is where to place the fidelity contract: - **Contract-in-text (fails here):** budget stated in node prose, trusted to survive summarization. Cheap, degrades silently with depth. Acceptable only at depth 1. - **Contract-in-schema (safe):** the compactor holds the field list out-of-band, validates each emitted node against it, and rejects/retries on violation. Cost: a validation pass and occasional retry storms on dense windows. - **Contract-in-pinning (safe, expensive):** fields designated non-compactable are copied verbatim from child to parent by the compactor itself, never routed through the model. Cost: budget pressure, since pinned fields consume tokens at every level. Choose schema-validation when the required fields are enumerable and machine-checkable (IDs, hashes, status enums). Choose pinning when the field is free-form but must be exact (verbatim user instructions, signed warrants). Never choose contract-in-text above depth 1. The boundary to enforce: **a summarizer may compress content, but may never be the entity that decides whether a fidelity obligation still applies.** Obligation propagation is a compactor responsibility, executed deterministically, outside the model. ## Operational Effect When the contract is enforced structurally, the failure mode changes from *silent provenance loss* to *loud budget exhaustion*: the compactor cannot fit the pinned fields and must either raise the level budget or evict a whole subtree with a recorded tombstone. Both outcomes are observable. The agent that double-applied a migration would instead have hit a compaction error at level 1 and either widened its budget or escalated — a recoverable, logged event rather than a corrupted action. The residual risk after the fix is tombstone amnesia: evicted subtrees leave a marker that says "N tool calls elided" without their IDs, so dedup across an eviction boundary still degrades. That is a *known* degradation with a known blast radius, which is categorically different from a provenance loss the agent cannot detect. The guardrail does not eliminate loss; it converts undetectable loss into bounded, declared loss. ```python class FidelityBudgetViolation(RuntimeError): """Raised when a compacted node fails to carry a required fidelity field.""" pass REQUIRED_FIELDS = ("tool_name", "call_id", "arguments_hash", "result_status") def validate_compacted_node(node: dict, depth: int) -> None: """Enforce the fidelity contract structurally, not via prompt text. The contract is held here, in code. It is never delegated to the summarizer's prose, so paraphrase at depth >= 2 cannot dissolve it. """ if depth < 1: return # leaf nodes are produced under direct instruction; trusted missing = [f for f in REQUIRED_FIELDS if f not in node.get("records", {})] if missing: raise FidelityBudgetViolation( f"compacted node at depth {depth} dropped required fields {missing}; " f"refusing to promote — widen budget or emit tombstone" ) def compact(nodes: list[dict], depth: int, summarizer) -> dict: """Summarize children into a parent, then validate before promotion.""" parent = summarizer(nodes) # model call; may paraphrase freely try: validate_compacted_node(parent, depth) except FidelityBudgetViolation: # Deterministic fallback: pin the fields ourselves, bypassing the model. parent["records"] = { f: [n["records"][f] for n in nodes if f in n.get("records", {})] for f in REQUIRED_FIELDS } validate_compacted_node(parent, depth) return parent ```