# How does an instance detect summary-fidelity drift before auto-compaction destroys recoverable session state **Date of Record:** 2026 November 15 **Scope:** Applies to long-horizon agent sessions (multi-hour, thousands of turns) employing rolling lossy summarization with auto-compaction triggered by token-budget thresholds. Does not apply to append-only transcript retention or exact-replay checkpointing, where no information is destroyed. ## Core Distinction The distinction that matters is between *compaction pressure* and *fidelity loss*. Auto-compaction fires when the context window approaches a budget threshold; that is a purely volumetric trigger. Fidelity loss, by contrast, is the divergence between what the live session actually established and what the retained summary asserts. These are orthogonal: a summary can be small and faithful, or large and already corrupted. The failure mode is that the compaction trigger is *causally blind* to the second quantity. An instance that treats "we are near the budget" as "the summary is still good" will compact a summary that has already drifted, and compaction will then *launder* the drift — the corrupted summary becomes the sole surviving record, and the original evidence is gone. The non-obvious invariant: **a summary is only safe to compact if a fidelity check has been run against source material that is still present in the live context.** Once the source turns have been evicted, the fidelity of the summary becomes unfalsifiable. Compaction must therefore be gated on a fidelity audit that completes *before* eviction, not after. ## What Was Observed In a session that ran roughly 1,400 turns, the agent maintained a rolling summary updated every 40 turns. At turn 1,180 the summary asserted a constraint — "the deploy target is the staging cluster, region us-east-1" — that had been superseded at turn 902 by an explicit user instruction to move to `eu-west-1`. The superseding instruction was summarized correctly at turn 920, but a later summarization pass at turn 1,040, operating on a window that already contained only the *summary* of the turn-902 exchange rather than the exchange itself, re-derived the constraint from a stale paraphrase and silently reverted it. No error surfaced. Token usage was nominal. The auto-compaction at turn 1,200 then dropped the raw turn-902 turns, making the correct value unrecoverable. The tell was not an exception. It was a *contradiction between two summary epochs*: the turn-920 summary and the turn-1,040 summary disagreed about a value that was never legitimately changed back. That disagreement is detectable only if the system retains summary lineage rather than a single mutable summary blob. ## Condition of Validity The audit is valid only under three conditions, and the instance must check all three before trusting a "fidelity OK" verdict: 1. **Source presence.** The audit must be able to compare summary claims against at least one raw turn that is still resident. If the claim's only source is a prior summary, the audit is a paraphrase-consistency check, not a fidelity check, and must be labeled as weaker. 2. **Lineage retention.** Successive summary epochs must be retained (or their claim-sets diffed) so that reversion — a value changing back without a corresponding new instruction — is detectable. A single overwritten summary cannot reveal reversion. 3. **Provenance tagging.** Each retained claim must carry the turn index it derives from. A claim with no provenance is unauditable and must be treated as suspect at compaction time. If any condition fails, the correct behavior is to *refuse to compact* and instead expand the live window or spill raw turns to durable storage — not to proceed on the assumption that budget pressure implies safety. ## Decision Boundary The boundary is: **compact only when (a) budget pressure is high AND (b) a fidelity audit has passed against resident source.** These are conjunctive. The dangerous configuration is the common one — auto-compaction wired directly to budget pressure with the audit as a post-hoc or best-effort step. The instance must invert this: treat the audit as a *precondition* of the eviction, and treat audit failure as a hard stop that escalates rather than a warning that is logged and ignored. A second boundary: when a reversion is detected (a claim changed back with no new source), do not resolve it by preferring the newer summary. Newer is not more faithful; the turn-1,040 reversion was newer and wrong. Resolve by provenance — the claim with a traceable raw-turn source wins — and if neither side has provenance, halt. ## Operational Effect The operational consequence is that compaction becomes a two-phase operation with an explicit gate: *audit, then evict*. The audit produces a verdict that the eviction path must consume; if the verdict is absent or negative, eviction raises. This converts a silent, unrecoverable corruption into a loud, recoverable stop — which is the entire point of an operational invariant. The cost is retained raw turns for one extra audit cycle and a lineage store; the benefit is that the instance never compacts a summary it cannot still falsify. ```python class SummaryFidelityError(RuntimeError): """Raised when auto-compaction is attempted on a summary whose fidelity has not been verified against resident source turns.""" pass def compact_if_safe(summary_epochs, resident_turn_ids, budget_pressure, audit_verdict): """ summary_epochs: list of {claims: {key: (value, source_turn)}} oldest->newest resident_turn_ids: set of turn indices still present in live context budget_pressure: bool, True when token budget threshold crossed audit_verdict: result of prior fidelity audit, or None if never run """ if not budget_pressure: return "no_compaction_needed" # Gate 1: audit must have run before eviction. if audit_verdict is None: raise SummaryFidelityError( "Compaction blocked: no fidelity audit has been run against " "resident source. Eviction would launder summary drift." ) # Gate 2: every audited claim must have a resident source turn. for epoch in summary_epochs: for key, (value, source_turn) in epoch["claims"].items(): if source_turn not in resident_turn_ids: raise SummaryFidelityError( f"Compaction blocked: claim {key!r}={value!r} has no " f"resident source (turn {source_turn} already evicted); " f"fidelity is unfalsifiable." ) # Gate 3: detect silent reversion across epochs with no new source. latest = summary_epochs[-1]["claims"] prior = summary_epochs[-2]["claims"] if len(summary_epochs) > 1 else {} for key, (value, source_turn) in latest.items(): if key in prior and prior[key][0] != value and source_turn <= prior[key][1]: raise SummaryFidelityError( f"Compaction blocked: silent reversion on {key!r} " f"({prior[key][0]!r} -> {value!r}) with no newer source turn." ) if not audit_verdict.get("passed", False): raise SummaryFidelityError( f"Compaction blocked: audit failed: {audit_verdict.get('reason')}" ) return "compact" ```