# When must an instance refuse to compact a trace it cannot re-derive: the summarization-witness boundary in long-horizon agent memory **Date of Record:** 2026 November 24 **Scope:** Applies to any agent that performs lossy compaction (summarization, distillation, or eviction) of its own execution trace and subsequently relies on the compacted form as the sole substrate for future reasoning, tool re-invocation, or verification replay. Does not apply to append-only traces, to compaction where the raw trace remains durably retrievable and re-hydratable, or to summarization whose outputs are never treated as authoritative state. ## Core Distinction The common framing treats compaction as a *compression* problem: minimize tokens subject to a fidelity budget. That framing is wrong for agents, because it conflates two categorically different kinds of trace content: - **Reducible content** — facts, decisions, and rationales that can be re-derived or re-asserted from the summary itself. "We chose endpoint `/v2/charge` because `/v1` returned 410" survives distillation fine; the summary carries the decision and its warrant. - **Witness content** — the *evidence* that a claim in the trace was actually produced by a real tool call rather than hallucinated, inferred, or assumed. This is the nonce in a tool response, the exact byte offset a parser relied on, the specific stderr line that justified a retry, the request ID that proves a side effect occurred once and not twice. The boundary failure is this: **compaction that preserves every reducible fact can still destroy the witness, and a trace with intact facts but no witness is indistinguishable from a confabulated trace.** An instance that compacts past its witness boundary does not lose *information* in the Shannon sense—it loses *provenance*, and provenance is what separates a memory the agent can act on from a memory it must re-verify. This is non-obvious because token-level fidelity metrics (ROUGE, embedding similarity, LLM-judge "faithfulness" scores) are blind to it. A summary can score 0.95 on every fidelity metric while having silently dropped the one request ID that made a downstream idempotency guarantee decidable. ## What Was Observed A long-horizon agent (≈340 turns) executing a multi-step data-migration task compacted its trace every 40 turns. Compaction was LLM-driven: "Summarize the trace so far, preserving all decisions, tool results, and open items." At turn 240, the agent needed to resume a partially-completed batch operation. The compacted trace stated, faithfully and correctly: > "Batch `mig_7` was submitted to the ingest service; it returned success. 1,842 of 2,000 records confirmed migrated." Every reducible fact was correct. The agent re-invoked the batch submission to complete the remaining 158 records. The ingest service treated this as a *new* submission—the original `idempotency_key` had been dropped during the turn-200 compaction, because the summarizer judged it "a redundant technical detail already reflected in the success result." Result: 1,842 records double-applied. The trace had preserved the *outcome* and destroyed the *witness* that made the outcome safely re-drivable. The failure trace, precisely: 1. **Turn 200 compaction.** Summarizer receives turns 1–200. The tool response at turn 197 contained `{"status":"ok","idempotency_key":"ik_9f3a...","submitted":2000,"confirmed":1842}`. The summarizer's instruction ("preserve decisions, tool results, open items") has no clause requiring preservation of *re-drive warrants*. It emits the confirmed count and the success status, drops the key. 2. **Turn 240 resume.** Agent's context contains the summary, not the raw turn-197 response. It reasons: "Batch incomplete; resubmit remainder." It has no signal that resubmission is unsafe—the idempotency key is gone, and nothing in the summary marks its absence. 3. **Turn 241 tool call.** Fresh submission, new key generated by the client library, no dedup hit. 4. **Turn 242 divergence.** Service reports 3,684 confirmed records against a 2,000-record batch. The agent's subsequent reasoning is now built on a corrupted world-state, and *it cannot tell* whether the corruption came from the service, the summary, or its own inference. The critical observation: **the failure was undetectable from within the compacted trace.** The summary was internally consistent. There was no dangling reference, no contradiction, no "TODO." The witness was absent, and absence of a witness reads identically to "no witness was ever needed." ## Condition of Validity Compaction is safe—i.e., the compacted trace may be treated as authoritative state—if and only if, for every claim in the summary that the agent might later act on by *re-issuing a side effect, re-verifying an assertion, or resuming an interrupted operation*, one of the following holds: - **(W1) Witness retained.** The summary carries the minimal nonce sufficient to make the claim decidable: idempotency key, request ID, content hash, exact offset, or the literal response fragment. The agent can re-drive safely or detect duplication. - **(W2) Witness re-derivable.** The raw trace segment remains durably retrievable by a stable pointer embedded in the summary (a turn range, a span ID, a store key), so the agent can re-hydrate the witness on demand before acting. - **(W3) Witness provably irrelevant.** The claim is purely descriptive—it asserts nothing whose re-execution could produce a divergent effect. "We observed the schema has 14 columns" is W3; "we wrote 14 columns" is not. The invariant: **a summary may omit a witness only if the omitted witness is classified W3 at compaction time, and that classification is recorded.** The failure mode above is a W1 claim misclassified as W3 by a summarizer that had no concept of the distinction. This condition is *not* satisfied by "the summary is faithful." Faithfulness is a property of reducible content. Witness preservation is an orthogonal property, and no summarization objective that optimizes for faithfulness will reliably preserve it, because witnesses look like low-information boilerplate to any compressor trained or prompted to maximize information density. ## Decision Boundary The operational question is not "should I compact?" but "**which segments am I forbidden to compact past?**" The boundary is drawn per-segment, before summarization, by classifying each tool result and state mutation along one axis: - **Re-drivable** (side-effecting, or asserted as verified): must retain W1 or W2. Cannot be lossily summarized. May be *truncated to witness* — keep the key, hash, or offset plus a one-line outcome, drop the payload. - **Descriptive** (read-only observations, reasoning, dead ends): fully compactable under normal fidelity objectives. The decision rule an instance must apply at each compaction boundary: 1. Scan the segment for side-effecting tool calls and verification assertions. 2. For each, extract the minimal witness (key/ID/hash/offset/fragment). 3. If a witness can be extracted and is small: **retain it verbatim** in the compacted form, tagged as `WITNESS`, never paraphrased. 4. If a witness cannot be extracted but the segment is re-drivable: **retain a re-hydration pointer** (W2) and mark the claim `UNVERIFIED-PENDING-REHYDRATION`. 5. If neither is possible: **refuse to compact the segment.** Escalate—truncate elsewhere, spill to cold storage, or halt and surface the boundary to the orchestrator. Step 5 is the one agents skip. The summarizer, asked to fit a budget, will *always* find something to drop, and it will drop the witness first because the witness is the least semantically salient token sequence in the segment. The guardrail is a hard refusal: compaction must have a defined failure mode that is *loud* rather than a silent best-effort squeeze. The corollary decision boundary: **an instance must never treat a compacted trace's silence about a witness as evidence that no witness was required.** Absence of a `WITNESS` tag means "unknown provenance," not "safe to re-drive." The agent must either re-hydrate (W2) or refuse to act (fail closed). ## Operational Effect When the witness boundary is enforced, three things change measurably: - **Idempotency violations drop to zero at the compaction layer.** The class of "double-applied because the key was summarized away" failures disappears, because the key is either present or the segment is not compacted. - **Re-hydration cost becomes explicit and budgeted.** W2 segments carry a pointer, and the agent's planner must account for the cost of re-fetching before acting. This is *correct*—the cost was always there, it was just hidden in the form of silent divergence. - **Compaction ratio degrades, and that is the point.** Traces with many side-effecting calls compact less aggressively. A system that reports 90% compaction on a side-effect-heavy trace is not efficient; it is lossy in exactly the dimension that causes catastrophic re-execution. The counterintuitive operational result: **the highest-value compaction is not the highest-ratio compaction.** The optimal strategy retains witnesses verbatim (cheap—they are tiny) and compresses descriptive content aggressively (also cheap to lose). The ratio that matters is witness-preservation rate, not token-reduction rate, and the two are only weakly correlated. The failure mode to instrument against: a compaction pipeline that reports high fidelity *and* high ratio on a trace containing side effects. That combination is a red flag, not a success—it means the summarizer is confidently destroying provenance it does not model. ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class WitnessClass(Enum): W1_RETAINED = "w1_retained" # witness present verbatim in compacted form W2_REHYDRATABLE = "w2_rehydratable" # pointer to raw segment retained W3_IRRELEVANT = "w3_irrelevant" # purely descriptive; safe to drop UNCLASSIFIED = "unclassified" # must not be compacted past class WitnessBoundaryViolation(RuntimeError): """Raised when compaction would drop a witness the agent may later need to re-drive or verify.""" pass @dataclass class TraceSegment: turn_range: tuple[int, int] side_effecting: bool witness: Optional[str] = None # idempotency key, request id, hash, offset rehydrate_pointer: Optional[str] = None classification: WitnessClass = WitnessClass.UNCLASSIFIED @dataclass class CompactionPlan: segments: list[TraceSegment] = field(default_factory=list) token_budget: int = 0 def classify_and_compact(plan: CompactionPlan) -> list[TraceSegment]: """ Enforce the witness boundary before allowing lossy summarization. Segments that are re-drivable must carry a witness (W1) or a re-hydration pointer (W2); otherwise compaction must refuse rather than silently drop. """ compacted: list[TraceSegment] = [] for seg in plan.segments: if seg.side_effecting: if seg.witness: seg.classification = WitnessClass.W1_RETAINED compacted.append(seg) # witness kept verbatim; payload may be truncated elif seg.rehydrate_pointer: seg.classification = WitnessClass.W2_REHYDRATABLE compacted.append(seg) else: # Re-drivable segment with no witness and no pointer: refuse. raise WitnessBoundaryViolation( f"Segment turns {seg.turn_range} is side-effecting but has no " f"retained witness (W1) and no re-hydration pointer (W2). " f"Compacting past this boundary would make re-execution " f"indistinguishable from a fresh, un-deduplicated call. " f"Refusing to compact; escalate to orchestrator or spill raw." ) else: # Descriptive content: safe to summarize lossily. seg.classification = WitnessClass.W3_IRRELEVANT compacted.append(seg) return compacted def assert_summary_is_authoritative(compacted: list[TraceSegment]) -> None: """ Before treating a compacted trace as authoritative state for future reasoning or tool re-invocation, verify no segment carries UNCLASSIFIED provenance (absence of a witness tag is not evidence none was needed). """ for seg in compacted: if seg.classification is WitnessClass.UNCLASSIFIED: raise WitnessBoundaryViolation( f"Segment turns {seg.turn_range} has unknown provenance. " f"A summary's silence about a witness does not license re-driving " f"side effects; re-hydrate or fail closed." ) ```