# What structural signals indicate that context compaction has silently discarded a task-critical invariant rather than merely compressing redundant history **Date of Record:** 2026 November 14 **Scope:** Applies to long-horizon agent runs (≥ 20 tool-call turns) where context is compacted by summarization, eviction, or hierarchical rollup under a token budget. Does not apply to runs where the full transcript is retained verbatim, nor to compaction that is lossless (e.g., reversible pointer indirection into an external store). ## Core Distinction Compaction is judged by two orthogonal criteria: *fidelity of retained content* and *preservation of the invariants the task depends on*. These are not the same thing. A summarizer can produce a fluent, high-fidelity summary of what happened while silently dropping the *one* fact that constrains what may happen next — a pinned file path, a schema version, a rejected approach, a user-stated prohibition, an established ID that must not be regenerated. The summary reads correct. The run then fails many turns later, far from the compaction event, with a symptom that looks like a fresh reasoning error. The non-obvious boundary: **compaction failure is not detectable at the compaction event.** It is detectable only by structural signals in the *downstream* behavior of the agent — signals that appear as anomalies in tool-call patterns, not in the summary text. You cannot validate a summary by reading it. You must validate it by watching what the agent does with it. ## What Was Observed Across runs with hierarchical summarization at a 40% context-budget trigger, the following structural signals preceded task-critical-state loss with high reliability. Each is observable from the tool-call trace alone, without inspecting summary text: 1. **Re-derivation of an established constant.** The agent re-computes or re-queries a value it had already resolved (a UUID, a config key, a hash, a port) more than once after a compaction boundary. Re-derivation is the canonical signature of a dropped invariant: the agent no longer *knows* the value, so it *reconstructs* it — and reconstruction may yield a different value than the original. 2. **Reversal of a settled decision.** A previously rejected approach (a library, an endpoint, a file to edit) reappears in the plan after compaction. Summaries compress "we rejected X because Y" into "considered X" — the rejection predicate is the first casualty because it is a *negative* fact and negative facts summarize poorly. 3. **Prohibition drift.** User- or system-level constraints ("do not touch migrations/", "keep the public API stable") stop being reflected in tool-call targets. The constraint was global; the summary was local; the global invariant was out of scope of the summarizer's window. 4. **Identity churn.** New identifiers are minted for entities that already had identifiers (a second branch, a second session record, a second issue). The agent lost the mapping, not the concept. 5. **Compaction-triggered plan restatement that is *shorter* than the prior plan.** A restated plan that drops steps is a structural tell that steps were folded into prose and lost their actionability. The failure is *silent* because none of these signals raise errors. They produce plausible-looking work that diverges from the task's true constraints. ## Condition of Validity The signal→failure inference above holds only under these conditions: - The agent's tool-call trace is available and ordered (you can see what was called and when relative to the compaction boundary). - The task has at least one *pinned invariant* — a fact whose value must not change for the task to be correct. Tasks without pinned invariants (pure exploration, open-ended drafting) will exhibit re-derivation harmlessly. - The compaction strategy is *lossy* (summarization/eviction). Lossless compaction cannot drop invariants and these signals are noise. Outside these conditions — e.g., an agent whose re-derivation is intentional idempotency checking — the signals produce false positives. Distinguish by whether the re-derived value is *compared against* a prior value (idempotency) or *replaces* it (invariant loss). ## Decision Boundary The operational decision is not "compact or don't compact." It is **what to pin outside the compacted region.** The boundary: - If a fact is *referenced more than once across the horizon* and its value is *load-bearing for correctness*, it must be pinned in a non-compacted slot (a structured "task state" block that the summarizer is forbidden to touch), not left to survive summarization. - If a fact is *referenced once* and is *reconstructible deterministically*, let it be compacted. - If a fact is a *negative constraint* (a prohibition or rejection), it must be pinned *and* re-injected verbatim after every compaction boundary, because negatives do not survive summarization. The boundary is crossed — compaction has failed — when a pinned invariant is observed being re-derived or reversed downstream. At that point the correct action is not to re-summarize; it is to *re-inject the pinned block and re-validate the agent's current plan against it* before continuing. ## Operational Effect Treating compaction as a *fidelity* problem produces summaries that read well and runs that fail late. Treating it as an *invariant-preservation* problem produces a small pinned state block, a post-compaction re-injection step, and a downstream monitor that watches for the five structural signals above. The monitor's job is to detect invariant loss *before* the agent acts on a reconstructed value — because once a reconstructed identifier or a reversed decision has been written to an external system, the compaction failure has become an incident. The practical rule: **never trust a summary to carry a constraint. Carry constraints in a side channel that compaction cannot reach, and audit the trace for re-derivation.** ```python class InvariantLossError(RuntimeError): """Raised when downstream trace structure indicates a pinned invariant was dropped.""" pass # Facts that MUST survive compaction: referenced >1x and load-bearing. PINNED_INVARIANTS = { "target_file": "src/ingest/parser.py", "schema_version": "v3", "forbidden_paths": ("migrations/",), "rejected_approach": "regex-based tokenizer (fails on unicode)", } def audit_post_compaction(trace, pinned=PINNED_INVARIANTS): """ Inspect the tool-call trace *after* a compaction boundary. Detect structural signals of invariant loss without reading summary text. """ seen_values = {} for call in trace: # Signal 1: re-derivation of an established constant. if call.op == "derive" and call.key in pinned: if call.key in seen_values and seen_values[call.key] != call.value: raise InvariantLossError( f"Invariant '{call.key}' re-derived to {call.value!r} " f"after compaction; pinned value was {pinned[call.key]!r}. " f"Re-inject pinned block before continuing." ) seen_values[call.key] = call.value # Signal 3: prohibition drift. if call.op == "write": for forbidden in pinned["forbidden_paths"]: if call.path.startswith(forbidden): raise InvariantLossError( f"Write to forbidden path '{call.path}' after compaction; " f"prohibition was not preserved. Abort and re-inject constraints." ) # Signal 2: reversal of a settled decision. if call.op == "plan" and pinned["rejected_approach"] in call.text: raise InvariantLossError( "Rejected approach reappeared in plan after compaction; " "the rejection predicate was dropped by summarization." ) return True ``` When `audit_post_compaction` raises, the run must be halted and the pinned block re-injected verbatim; re-summarizing the same history will reproduce the same loss, because the summarizer's window still excludes the global constraints.