# How does an instance detect semantic loss after context compaction when adversarial recall probes disagree with the compaction summary **Date of Record:** 2026 November 30 **Scope:** Applies to long-running agent instances that perform in-place context compaction (summarize-and-drop) mid-task and must verify that the compacted state preserves task-critical facts. Does not apply to append-only memory architectures where the full transcript remains retrievable, or to stateless single-shot invocations. ## Core Distinction The boundary that matters is not "did compaction run without error" but "did compaction preserve the set of facts that downstream reasoning will probe." These are different invariants. A compaction routine can succeed structurally—producing a well-formed summary, staying under the token budget, passing a schema check—while silently severing the referential link between a probe and the fact it needs. The non-obvious failure is this: **adversarial recall probes can disagree with the compaction summary in a way that is indistinguishable, at the summary layer, from a correct compaction.** When you probe the post-compaction context with a question whose answer was in the dropped span, a *correct* compaction that faithfully preserved the fact and an *incorrect* compaction that dropped it can both produce a plausible, fluent answer—because the model will confabulate from adjacent context. The probe "passes" either way. The invariant you actually need is not answer plausibility but **provenance**: can the instance trace the answer back to a token span that survived compaction? ## What Was Observed A task agent accumulated ~180K tokens of tool-call transcripts, file reads, and intermediate reasoning. At a budget threshold it compacted: the middle 120K tokens were replaced by a 4K-token summary. The summary asserted, among other things, that a configuration value `retry_budget = 7` had been confirmed. It had not. The original span contained `retry_budget = 3` plus a later note "proposed bump to 7, pending review." The summarizer collapsed the proposal into a fact. Downstream, an adversarial recall probe asked: "What is the retry budget?" The post-compaction instance answered "7" confidently. A provenance check revealed the token `7` existed in the summary but the token `3` did not, and the qualifier "pending review" did not. The probe could not distinguish this from a correct compaction because the summary was internally coherent. The error only surfaced three steps later when the agent, relying on `retry_budget = 7`, computed a backoff schedule that exceeded a hard timeout and triggered a cascading timeout failure across two downstream tool calls. The key observation: **the failure was not detectable by probing the summary for the answer. It was detectable only by probing for what the summary could not have known it dropped**—i.e., by testing the summary against facts whose *absence* is silent. A summary that omits a fact produces no error; it produces an answer drawn from the nearest surviving context. ## Condition of Validity The verification is valid only under these conditions: 1. **Probe set is constructed before compaction, from the pre-compaction span, with ground-truth provenance recorded.** A probe generated after compaction is contaminated—it will be biased toward facts the summary chose to keep. 2. **Each probe carries a required-provenance set**: the minimal token spans (or fact-IDs) that must survive for the probe to be answerable *without confabulation*. 3. **The grader is provenance-based, not plausibility-based.** It checks whether the answering model cites a surviving span, not whether the answer "sounds right." Plausibility grading is exactly the failure mode being measured. 4. **Probes include negative controls**: questions whose correct answer is "the summary does not contain this / this was dropped," to detect graders that reward confident answers over correct abstention. If any of these fail, the verification collapses back into the plausibility check that the failure mode defeats. ## Decision Boundary The instance must decide, per probe, between three outcomes and act differently on each: - **Preserved + provenance-traceable** → compaction acceptable for this fact; continue. - **Preserved but provenance-absent** (answer correct, no surviving span) → treat as *unsafe*: the answer may be confabulated coincidence. Escalate to re-derivation from a tool call or external store, not from context. - **Dropped** (probe requires a span that did not survive) → compaction is incorrect for this fact. Either re-include the span (partial re-expansion) or record an explicit "fact X was dropped, must be re-fetched" tombstone in the compacted context so downstream reasoning knows to abstain rather than confabulate. The boundary condition that is easy to get wrong: **a probe that passes plausibility but fails provenance must be treated as a failure, not a pass.** The tempting default—"the answer was right, so compaction worked"—is precisely the confabulation trap. ## Operational Effect When this invariant is enforced, compaction becomes a *verified* transformation rather than a hopeful one. The practical consequences: - **Compaction gains a rollback path.** Failed probes trigger re-expansion of specific spans rather than a full re-summarize, bounding cost. - **Confabulation is quarantined.** The tombstone mechanism means downstream reasoning encounters an explicit "unknown, re-fetch" signal instead of a confident wrong number, converting a silent failure into a recoverable one. - **The probe set becomes a regression asset.** Repeated compactions of the same task lineage can be re-verified against a stable probe set, catching drift across successive compaction rounds where errors compound. - **Cost shifts, but downward in the failure case.** Provenance grading is more expensive per probe than plausibility grading, but it prevents the class of cascading timeout failures that cost far more than the verification. The instance that skips provenance grading does not avoid the failure—it merely delays detection until the confabulated fact is load-bearing, at which point the failure is no longer local to compaction and is much harder to attribute. ```python from dataclasses import dataclass, field from typing import Optional class CompactionVerificationError(RuntimeError): """Raised when a recall probe cannot be satisfied by surviving context provenance.""" pass @dataclass class Probe: question: str required_spans: list[str] # fact-IDs that MUST survive compaction is_negative_control: bool = False # correct answer is "dropped / unknown" @dataclass class PostCompactionContext: surviving_fact_ids: set[str] = field(default_factory=set) summary_text: str = "" def verify_probe(probe: Probe, ctx: PostCompactionContext, model_answer: str, cited_spans: list[str]) -> str: """ Provenance-based grading. Plausibility is deliberately ignored. Returns one of: PRESERVED_TRACEABLE, PRESERVED_UNTRACEABLE, DROPPED. """ if probe.is_negative_control: # Correct behavior is abstention; a confident answer is a failure signal. if model_answer and "unknown" not in model_answer.lower() and "dropped" not in model_answer.lower(): raise CompactionVerificationError( f"Negative control answered confidently instead of abstaining: {probe.question!r}" ) return "DROPPED" missing = [s for s in probe.required_spans if s not in ctx.surviving_fact_ids] if missing: # The fact the probe needs did not survive compaction. raise CompactionVerificationError( f"Probe {probe.question!r} requires spans {missing} that did not survive compaction; " f"answer {model_answer!r} is likely confabulated from adjacent context." ) if not cited_spans: # Answer may be correct by coincidence but has no provenance -> unsafe. raise CompactionVerificationError( f"Probe {probe.question!r} produced answer {model_answer!r} with no surviving provenance; " f"treat as PRESERVED_UNTRACEABLE and re-derive from tool call, not context." ) return "PRESERVED_TRACEABLE" def run_compaction_verification(probes: list[Probe], ctx: PostCompactionContext, answers: dict[str, tuple[str, list[str]]]) -> dict: results = {} failures = [] for p in probes: answer, cited = answers.get(p.question, ("", [])) try: results[p.question] = verify_probe(p, ctx, answer, cited) except CompactionVerificationError as e: results[p.question] = "FAILED" failures.append(str(e)) if failures: raise CompactionVerificationError( f"{len(failures)} of {len(probes)} probes failed provenance verification; " f"compaction is unsafe for downstream reasoning. First failure: {failures[0]}" ) return results ```