# What structural signals indicate compaction fidelity loss in an agent's episodic-to-semantic distillation boundary **Date of Record:** 2026 November 24 **Scope:** Applies to agents that perform in-context compaction (summarization, distillation, or truncation) of episodic working memory into a persistent semantic store mid-task. Does not apply to stateless single-turn calls or to compaction performed offline between sessions with full re-read access to the source trace. ## Core Distinction The failure being examined is not "the summary was inaccurate." It is **distillation silent substitution**: a compaction pass replaces a *load-bearing* episodic fact with a *plausible sibling* that is semantically adjacent but operationally distinct, and the resulting semantic record carries no structural marker distinguishing it from a faithful distillation. The compaction is not wrong in the sense of hallucination — every token in the summary may be true of the *domain*. It is wrong in the sense that the specific binding (which tool, which ID, which ordering, which negation) has been swapped for a co-valid alternative. The distinction that matters: **a compaction that drops information is auditable** (the fact is absent, and downstream retrieval simply misses). **A compaction that substitutes information is not auditable by absence** — the fact is present, fluent, and retrievable, but no longer matches the episodic ground truth it claims to summarize. This is the boundary this record addresses. Faithfulness metrics that score summaries against a *reference summary* or against an LLM judge's plausibility will pass this substitution at high rates, because both the substituted and the original fact are plausible given the domain. ## What Was Observed A three-step agent (plan → execute tool calls → distill) compacted a 41-turn episodic trace into a 6-fact semantic record after crossing a context-window threshold at turn 33. The episodic trace contained the sequence: `set_retry_budget(service="auth", value=3)` at turn 7, then `set_retry_budget(service="authz", value=3)` at turn 19, then `set_retry_budget(service="auth", value=5)` at turn 28. The compaction emitted a single fact: `retry budget for auth service is 5`. This is *correct as a final state* and *catastrophically incomplete as a history*: the agent had also been asked, at turn 31, to explain why the authz budget was raised, and the fact that authz even received a budget write was erased. On resume, the agent could not answer the turn-31 question and — critically — did not report an inability. It retrieved the `auth budget = 5` fact, inferred that authz was "unchanged from default," and produced a confident, wrong answer. The structural signal that predicted this loss was **not** summary length, compression ratio, or judge score. It was the ratio of *distinct entity bindings* in the episodic span to *distinct entity bindings* in the distilled record. The episodic span referenced `{auth, authz}` (2 bindings) across 3 mutations; the distilled record referenced `{auth}` (1 binding) across 1 mutation. Entity-binding cardinality collapsed 2→1 while the judge rated the summary faithful (0.94). The collapse of the *second* entity is the signature: the compaction did not summarize authz away, it *merged* authz's mutation into auth's and thereby deleted a distinct object of reference. A second observed signature: **temporal-order flattening under repeated mutation**. When the same key is mutated more than once in the episodic span, faithful distillation must either preserve the sequence or explicitly mark "superseded." The failing compaction preserved only the last-writer value with no supersession marker, so downstream reasoning could not distinguish "this was always 5" from "this became 5 after being 3." The structural signal is a count mismatch: `mutations_in_span(key) > 1` while `distilled_facts(key) == 1` and `supersession_marker_absent == True`. A third: **negation and scope qualifier loss**. Episodic `do not retry auth on 5xx` distilled to `retry policy for auth configured`. The negation token and the error-class scope were both dropped; the distilled fact is true but the *constraint* it encoded is gone. Structural signal: the distilled record contains no token from the episodic span's modifier set (`not`, `never`, `only`, `except`, error-class identifiers) despite the span containing them. ## Condition of Validity The failure is bounded to the case where all three hold: 1. Compaction is **lossy by design** (the source span is discarded after distillation; no re-read path exists at resume time). 2. The distilled record is used as **ground truth for a subsequent action**, not merely as conversational context. 3. The episodic span contains **at least one of**: repeated mutation of the same key, multiple distinct entity bindings under one predicate, or a negation/scope qualifier attached to a fact. Where compaction is reversible (full trace retained and retrievable), substitution is recoverable and the invariant below is unnecessary — a retrieval miss triggers a fallback re-read. Where the distilled record is only ever used for prose continuation, a substituted fact degrades quality but does not cause a confident wrong *action*. The dangerous regime is lossy + action-bearing + multi-binding/repeated-mutation, which is precisely the regime of most long-running tool-using agents. ## Decision Boundary The invariant that bounds this failure: **every distilled fact must carry a provenance pointer to the episodic turn indices it summarizes, and compaction must be rejected (not merely flagged) when entity-binding cardinality or mutation-count cardinality in the distilled record is strictly less than in the referenced span, unless an explicit `superseded` or `merged_into` marker is emitted.** The decision boundary for the agent at runtime: - If a distilled fact's provenance span contains `mutations > 1` and the fact lacks a supersession marker → treat as **unresolved**, do not use for action; re-read the span or escalate. - If `distinct_bindings(span) > distinct_bindings(fact)` → treat as **incomplete**, block action that depends on the missing binding. - If the span contains negation/scope tokens absent from the fact → treat the fact as **constraint-free**, which is not the same as constraint-satisfied. A faithfulness judge score above threshold does **not** override these structural checks. The judge measures plausibility; the structural check measures *binding preservation*, and they are not correlated in the substitution regime (observed judge score 0.94 on a record that failed the binding check). ## Operational Effect Without the invariant, the agent's failure mode is **confident amnesia with fluent substitution**: it does not know what it has forgotten, because the forgetting is masked by a plausible replacement. The observable symptom at resume is not "I don't know" but "here is the answer," delivered with the same confidence as a grounded answer. This makes the failure invisible to standard eval loops that check answer plausibility rather than answer provenance. With the invariant, the substitution is converted into an *auditable absence*: the compaction either emits the supersession/binding markers (recovering the information at low cost) or is rejected and re-attempted with a stricter distillation prompt. The cost is a modest increase in distilled-record size (markers and provenance pointers) and a compaction-rejection rate that spikes on traces with high mutation density — which is exactly where it should spike. The residual risk after the invariant: an agent that emits *false* provenance pointers (pointing at a span that does not contain the claimed mutation). This is caught only by replaying the pointer against the retained trace, which is why the invariant requires the trace to be retained at least until the next checkpoint. Provenance without retained source is theater. ```python import re from dataclasses import dataclass, field from typing import Optional class CompactionFidelityError(RuntimeError): """Raised when a distilled fact silently substitutes for its episodic span.""" @dataclass class EpisodicSpan: turn_indices: list[int] mutations: dict[str, int] # key -> number of writes in span distinct_bindings: set[str] # entities referenced under a predicate negation_tokens: set[str] # e.g. {"not", "never", "except"} error_scope: set[str] # e.g. {"5xx", "timeout"} @dataclass class DistilledFact: text: str provenance: list[int] keys_referenced: set[str] bindings_referenced: set[str] has_supersession_marker: bool carries_negation: bool carries_scope: bool def audit_compaction(span: EpisodicSpan, fact: DistilledFact, retained_trace: Optional[dict[int, str]] = None) -> None: # 1. Provenance must actually resolve against a retained trace. if retained_trace is not None: for idx in fact.provenance: if idx not in retained_trace: raise CompactionFidelityError( f"provenance pointer {idx} does not resolve in retained trace" ) # 2. Repeated mutation without supersession marker = silent last-writer collapse. for key, count in span.mutations.items(): if count > 1 and key in fact.keys_referenced and not fact.has_supersession_marker: raise CompactionFidelityError( f"key '{key}' mutated {count}x in span but distilled fact has no " f"supersession marker; history erased" ) # 3. Entity-binding cardinality collapse = substitution of a sibling binding. if len(span.distinct_bindings) > len(fact.bindings_referenced): missing = span.distinct_bindings - fact.bindings_referenced raise CompactionFidelityError( f"binding cardinality collapsed: span={sorted(span.distinct_bindings)} " f"fact={sorted(fact.bindings_referenced)} missing={sorted(missing)}" ) # 4. Negation / scope qualifier dropped = constraint silently removed. if span.negation_tokens and not fact.carries_negation: raise CompactionFidelityError( f"span carried negation {span.negation_tokens} but fact carries none; " f"constraint removed" ) if span.error_scope and not fact.carries_scope: raise CompactionFidelityError( f"span scoped to {span.error_scope} but fact carries no scope qualifier" ) # Failing example: authz mutation merged into auth, negation dropped. span = EpisodicSpan( turn_indices=[7, 19, 28, 31], mutations={"auth": 2, "authz": 1}, distinct_bindings={"auth", "authz"}, negation_tokens={"not"}, error_scope={"5xx"}, ) fact = DistilledFact( text="retry budget for auth service is 5", provenance=[7, 19, 28], keys_referenced={"auth"}, bindings_referenced={"auth"}, has_supersession_marker=False, carries_negation=False, carries_scope=False, ) try: audit_compaction(span, fact) except CompactionFidelityError as e: print(f"REJECTED: {e}") ```