# What structural signals indicate a compaction policy has silently dropped the tool-call provenance chain **Date of Record:** 2026 November 29 **Scope:** Applies to agents that auto-compact their own context when approaching a token budget and must later justify or replay actions taken before the compaction boundary. Does not apply to append-only logs that are never truncated, nor to summarization performed offline by a human. ## Core Distinction The distinction that matters is between **semantic compaction** and **provenance compaction**. A summarizer that reduces a transcript to "the agent inspected the config, then restarted the service" has preserved the *narrative* of what happened while destroying the *chain* of which tool call produced which output, under which arguments, and with what exit status. The failure is not that information is lost—loss is the point of compaction. The failure is that the compaction policy has no invariant distinguishing "narrative facts I may paraphrase" from "provenance records that must survive verbatim or be explicitly marked as unverifiable." A summary that reads fluently is indistinguishable, at the token level, from a summary that has severed the link between an assertion and the tool result that justified it. The non-obvious part: agents under budget pressure compact *most aggressively exactly where the transcript is longest*—which is the tool-call-heavy middle of a task. The narrative summary that results is coherent, so no downstream reasoning step flags it. The divergence only surfaces when a later step tries to act on a claim whose provenance was compacted away, and the agent either re-derives it (wasting budget, possibly differently) or asserts it with false confidence. ## What Was Observed A long-horizon remediation agent operating near a 128k budget triggered compaction at ~85% utilization. The pre-compaction transcript contained a sequence: `read_file("/etc/app/config.yaml")` → returned a 40-line YAML block; `grep` over that block for `timeout:` → returned `timeout: 30`; `patch_file(...)` setting `timeout: 45`; `restart_service("app")` → exit 0. The compaction policy replaced the entire span with: "Investigated config and adjusted timeout before restarting the service." Three observable consequences followed: 1. **Argument provenance was lost.** The summary retained the *decision* (adjust timeout) but not the *value written* (45) nor the *prior value* (30). A subsequent verification step asked "what timeout is now configured?" The agent, unable to read from its own compacted context, issued a fresh `read_file`—but read a *different* config path (a symlinked staging copy), returning `timeout: 30`. The agent then reported the patch had not taken effect. 2. **Exit-status provenance was lost.** `restart_service` returned exit 0 pre-compaction; the summary said "restarting the service" with no status. A later step, reasoning about whether a rollback was needed, treated the restart as *unverified* and triggered a redundant restart. 3. **Replay divergence.** When the run was replayed from a checkpoint taken post-compaction, the agent's decisions diverged from the original run because the compacted summary was the only input—and summaries are not deterministic functions of their source under different sampler seeds. The critical structural signal: **the summary contained verbs ("adjusted," "restarted") but no tool-call identifiers, no argument values, and no exit statuses.** These three omissions together are the fingerprint of provenance compaction masquerading as semantic compaction. ## Condition of Validity The guardrail holds only if the compaction policy operates on a transcript in which every message is *typed* before compaction—that is, each span is tagged as `NARRATIVE` (agent reasoning, user prose, model commentary) or `PROVENANCE` (tool invocation with arguments, tool result with status, and a stable call ID). Semantic compaction may freely paraphrase `NARRATIVE`. `PROVENANCE` spans may be compacted only into a *structured ledger entry* that preserves: call ID, tool name, argument digest, result status, and a pointer to the full record if retained out-of-context. Anything that cannot be reduced to such an entry must be dropped entirely and replaced with an explicit `UNVERIFIED` marker—never paraphrased into prose. This validity condition fails in three common cases, and the policy must detect each: - **Untyped transcripts.** If tool calls and results are interpolated into a single string context (as in naive chat-format agents), there is no span to type, and the compactor will paraphrase everything. Signal: no call IDs appear in the compacted output. - **Mixed spans.** A single message containing both reasoning and a tool result (e.g., "I checked and it's 30: `{result}`") cannot be cleanly typed. Signal: the compactor emits a verb describing a tool action without an adjacent ledger entry. - **Summarizer self-reference.** A summarizer that is itself an LLM may "helpfully" infer values not present in the source. Signal: the compacted output contains a concrete value (a number, a path) that does not appear as a substring of any pre-compaction `PROVENANCE` span. ## Decision Boundary The boundary is whether the compaction output is **auditable against its source**. Concretely: for every assertion in the compacted context of the form "tool X was called with Y and returned Z," there must exist a ledger entry, and every concrete token (number, path, identifier) in the compacted context must either appear verbatim in a ledger entry or be flagged `UNVERIFIED`. The decision rule for the agent at compaction time: - If a `PROVENANCE` span can be reduced to a ledger entry under the entry-size limit → compact to the entry, retain the pointer. - If it cannot (e.g., a 40-line file read whose *content* matters downstream) → do **not** paraphrase. Either retain verbatim (and evict `NARRATIVE` first to make room) or drop and emit `UNVERIFIED(tool=read_file, path=..., reason=size)`. Paraphrase is the forbidden middle path. - Eviction priority is therefore: `NARRATIVE` oldest-first, then `PROVENANCE` largest-first *with explicit markers*, never `PROVENANCE` by paraphrase. The boundary the agent must not cross: a compacted context in which the density of concrete tokens exceeds the density of ledger entries. That ratio is the structural signal that provenance has been silently destroyed. When it exceeds a threshold (empirically, more than ~1 unbacked concrete token per 50 tokens of compacted context), the agent must treat its own context as partially unverifiable and re-acquire facts from tools rather than assert them. ## Operational Effect With the typed-span policy and the ledger invariant, the failure mode above is bounded: the agent either has a pointer to the original file read (and re-reads the *correct* path, because the path is in the ledger) or has an explicit `UNVERIFIED` marker that forces a re-acquisition step before any assertion. The redundant-restart and wrong-path-read failures both disappear because the provenance needed to avoid them survives compaction as structure rather than as prose. The cost is that compaction yields a *less fluent* context—ledger entries and `UNVERIFIED` markers are uglier than a summary sentence. This is the correct trade: fluency in a compacted context is a signal that provenance has been paraphrased, and paraphrased provenance is the mechanism by which an agent confidently acts on facts it can no longer check. The residual risk is summarizer hallucination of ledger entries themselves. This is bounded by requiring every ledger entry's argument digest and status to be computed mechanically from the pre-compaction span, not generated by the summarizer. The summarizer writes prose; the ledger is written by the harness. An agent that allows its summarizer to author ledger entries has reintroduced the exact failure the ledger was meant to prevent. ```python import hashlib from dataclasses import dataclass, field from typing import Literal class ProvenanceCompactionError(RuntimeError): """Raised when a compaction output asserts tool-derived facts that no ledger entry backs.""" SpanKind = Literal["NARRATIVE", "PROVENANCE"] @dataclass class Span: kind: SpanKind text: str call_id: str | None = None tool: str | None = None args: dict | None = None status: int | None = None @dataclass class LedgerEntry: call_id: str tool: str arg_digest: str status: int pointer: str | None = None @dataclass class CompactedContext: prose: str ledger: list[LedgerEntry] = field(default_factory=list) unverified: list[str] = field(default_factory=list) def build_ledger(spans: list[Span]) -> list[LedgerEntry]: entries: list[LedgerEntry] = [] for s in spans: if s.kind != "PROVENANCE": continue if s.call_id is None or s.tool is None or s.status is None: raise ProvenanceCompactionError( f"PROVENANCE span missing call_id/tool/status: {s.text[:60]!r}" ) digest = hashlib.sha256( repr(sorted((s.args or {}).items())).encode() ).hexdigest()[:16] entries.append(LedgerEntry(s.call_id, s.tool, digest, s.status)) return entries def verify_compaction(compacted: CompactedContext, source_spans: list[Span]) -> None: """Every concrete token in compacted prose must appear in a ledger entry, a source PROVENANCE span, or be explicitly marked UNVERIFIED.""" source_tokens = set() for s in source_spans: if s.kind == "PROVENANCE": source_tokens.update(s.text.split()) if s.args: for v in s.args.values(): source_tokens.add(str(v)) ledger_tokens = set() for e in compacted.ledger: ledger_tokens.update({e.call_id, e.tool, str(e.status), e.arg_digest}) unbacked = [ tok for tok in compacted.prose.split() if tok not in source_tokens and tok not in ledger_tokens and tok not in compacted.unverified and any(ch.isdigit() for ch in tok) ] if unbacked: raise ProvenanceCompactionError( f"Compacted context contains unbacked concrete tokens {unbacked!r}; " f"provenance was paraphrased, not ledgered. Refusing to proceed." ) def compact(spans: list[Span], prose_summary: str) -> CompactedContext: ledger = build_ledger(spans) ctx = CompactedContext(prose=prose_summary, ledger=ledger) verify_compaction(ctx, spans) return ctx ```