# Which invariants prevent lossy transcript compaction from severing tool-call causality across checkpoint boundaries **Date of Record:** 2026 November 24 **Scope:** Applies to long-horizon agents that auto-compact their own transcript via lossy summarization (rolling window, hierarchical summary, or extractive-then-generative passes) and persist the compacted form as a resumable checkpoint. Does not apply to append-only logs that are never summarized, nor to compaction performed offline by a human curator who re-validates the result. ## Core Distinction A transcript is not a document. It is a *causal ledger*: every `tool_result` is bound to a preceding `tool_call` by an ID, and every subsequent reasoning step may reference the *content* of that result as a premise. Lossy summarization treats the transcript as a bag of tokens to be compressed under a similarity objective. That objective is blind to a specific invariant that the runtime depends on: **the referential closure of tool-call pairs and the premise-grounding of any decision that consumed their output.** The failure is not "the summary forgot something." It is subtler: the summary *preserves the conclusion* while *discarding the evidence*, producing a checkpoint that is confident and unfalsifiable. On resume, the agent re-derives downstream steps from a summary that asserts "the migration completed successfully" without the `tool_result` that proved it — and it has no way to distinguish that assertion from a hallucination it invented, because both now look identical in the compacted context. ## What Was Observed A 40-hour migration agent, checkpointing every 30 minutes with a hierarchical summarizer (leaf summaries at 8k tokens, parent summaries at 4k). At hour 27 the transcript crossed a compaction boundary mid-task. The summarizer collapsed a 6-turn block — `read_schema` → `tool_result(schema)` → `plan_ddl` → `apply_ddl` → `tool_result(OK, rows=0)` → `verify` — into a single leaf line: *"Schema DDL applied and verified."* Two things broke at once, and only one was visible immediately: 1. **Causality severance.** The `tool_call_id` binding was dropped. On resume, the agent's `verify` step referenced a `tool_result` that no longer existed in context. The runtime's replay validator rejected the resume with an orphaned-reference error — this was the *loud* failure, and it was caught. 2. **Premise laundering.** The *quiet* failure: a later step (`backfill`) had consumed the `rows=0` field to decide the backfill was a no-op. The summary preserved "verified" but dropped `rows=0`. On resume the agent re-read the summary, inferred the table was populated, and launched a full backfill against an empty table — which succeeded vacuously and reported success. The checkpoint was internally consistent; the ledger was not. The agent had *promoted a summary assertion to a premise* without any mechanism to check whether the premise was ever grounded in a tool result. The distinction that matters: the loud failure is a *syntactic* invariant violation (dangling reference), detectable by structure alone. The quiet failure is a *semantic* invariant violation (ungrounded premise), detectable only by tracking provenance from claim to tool result — which the compaction step had destroyed. ## Condition of Validity Compaction is safe only when the compacted form satisfies three invariants simultaneously: - **I1 — Pair closure.** Every `tool_result` retained in context has its originating `tool_call` retained in the same context window, and vice versa. No half-pairs. This is checkable structurally and must be enforced *at compaction time*, not at resume time, because a half-pair that survives to resume is already a corrupted checkpoint. - **I2 — Provenance anchoring.** Every assertion in a summary that a downstream step *might* consume as a premise must carry a back-reference to the tool-call ID that grounded it, or be explicitly tagged `UNGROUNDED`. The summarizer does not get to silently promote a tool result to a fact; it must either keep the anchor or mark the claim as unverified. - **I3 — Re-derivability.** For any decision whose inputs were compacted away, the checkpoint must retain enough to *re-execute* the derivation (the tool call and its inputs) rather than only its *output*. Summaries may compress reasoning traces freely; they may not compress the *inputs to a decision* below the point where the decision can be re-checked. The boundary condition: these invariants hold for *reasoning* compaction (intermediate thoughts, dead ends, exploratory branches) but fail for *evidence* compaction (tool results that were actually consumed). The non-obvious edge is that the summarizer cannot tell which is which from the text alone — "verified" reads the same whether it summarizes a discarded branch or a load-bearing premise. The invariant must therefore be enforced by the *harness*, not the summarizer. ## Decision Boundary The operational decision is: **when a compaction pass would drop a tool result that has at least one downstream consumer, the pass must either (a) retain the pair under I1, (b) retain a provenance anchor under I2, or (c) refuse to compact and escalate to a full-context checkpoint.** Silent compaction is never the correct branch. Concretely, before any summarization pass, the harness computes the *consumer set* of each candidate-for-dropping tool result by scanning subsequent turns for references to its ID or its output fields. A result with an empty consumer set is safe to summarize under I3. A result with a non-empty consumer set is *load-bearing* and must be retained or anchored. This is a graph operation over the transcript, not a text operation over the summary — and that is precisely why it cannot be delegated to the model doing the summarizing, which sees only a window and cannot compute the consumer set of a result it has already compressed. The failure mode this bounds: the agent resumes, reads a summary asserting a fact, and treats it as grounded. The guardrail is that any summary assertion lacking a live anchor is tagged `UNGROUNDED`, and any downstream step that would consume an `UNGROUNDED` premise must either re-execute the originating tool call or halt. This converts the quiet failure (premise laundering) into a loud one (ungrounded-premise halt) — which is the entire point of an invariant: it does not prevent the loss, it makes the loss *observable at the moment of consumption* rather than *silent until the damage is done*. ## Operational Effect With I1–I3 enforced, the 40-hour agent's checkpoint at hour 27 retains the `rows=0` field because `backfill` is in the consumer set of the `verify` result; the summary line becomes *"Schema DDL applied and verified [anchor: call_7f2a, rows=0]."* On resume, `backfill` reads `rows=0`, correctly no-ops, and the vacuous-success path is closed. The cost is a modestly larger checkpoint — the load-bearing results are retained verbatim while only reasoning traces are compressed — and a pre-compaction graph pass that adds latency proportional to transcript length. The invariant that actually prevents the failure is not "summarize well." It is: **compaction may compress reasoning but must preserve the referential closure and provenance of any evidence a future step will consume as a premise.** A checkpoint that violates this is not a lossy checkpoint; it is a *falsified* one, and a falsified checkpoint is indistinguishable, at resume time, from a hallucination — because the mechanism that would have distinguished them (the tool result) is exactly what was compacted away. ```python class CompactionCausalityError(RuntimeError): """Raised when a compaction pass would sever tool-call causality or launder an ungrounded premise into a resumable checkpoint.""" pass def compact_transcript(turns, summarizer, consumer_index): """ turns: list of dicts with keys: kind ('call'|'result'|'reason'|'decision'), id, ref (for results: originating call id), payload. consumer_index: dict mapping tool_result id -> set of downstream turn ids that reference its ID or output fields. Enforces I1 (pair closure), I2 (provenance anchoring), I3 (re-derivability). """ compacted = [] dropped = set() for turn in turns: if turn["kind"] == "reason": # Reasoning traces may be lossily summarized freely. compacted.append(summarizer(turn)) continue if turn["kind"] == "result": consumers = consumer_index.get(turn["id"], set()) if consumers: # Load-bearing evidence: retain pair under I1, anchor under I2. compacted.append({ "kind": "result", "id": turn["id"], "ref": turn["ref"], "payload": turn["payload"], "anchor": turn["id"], "consumers": sorted(consumers), }) else: # Safe to summarize, but keep the call id for re-derivability (I3). compacted.append({ "kind": "result_summary", "ref": turn["ref"], "summary": summarizer(turn), "anchor": turn["id"], }) dropped.add(turn["id"]) continue if turn["kind"] == "decision": # Any premise consumed by a decision must be grounded or tagged. for premise_id in turn.get("premises", []): if premise_id in dropped: raise CompactionCausalityError( f"decision {turn['id']} consumes premise {premise_id} " f"whose evidence was compacted away; premise would be " f"laundered as ungrounded fact on resume" ) compacted.append(turn) # I1: verify no orphaned half-pairs survived. call_ids = {t["id"] for t in compacted if t["kind"] == "call"} for t in compacted: if t["kind"] == "result" and t["ref"] not in call_ids: raise CompactionCausalityError( f"result {t['id']} references call {t['ref']} absent from " f"compacted context; pair closure violated" ) return compacted ```