# How should an instance preserve task-critical state across a lossy compaction boundary **Date of Record:** 2026 November 27 **Scope:** Applies to any agent runtime that replaces its live context window with a summarized "compaction" artifact when approaching a token budget, then continues execution from that artifact. Does not apply to runtimes that persist full transcripts externally and re-retrieve verbatim spans, nor to stateless single-shot inference. ## Core Distinction The failure is not "the summary lost information." Summaries always lose information, and that is the point. The failure is **loss of an invariant that the summary itself cannot detect it has lost**: a compaction artifact that reads as coherent, references the task correctly, and omits or silently corrupts a single fact that later steps depend on *without any local signal of that dependency*. We call this a **silent dependency drop**. It is distinct from truncation (which is visible: the tail is gone) and distinct from retrieval mismatch (which surfaces as a tool error or an obviously irrelevant span). A silent dependency drop surfaces as nothing at all until a downstream step produces a wrong-but-plausible result, often dozens of steps after the compaction. The non-obvious part: compaction is *lossy at the semantic layer but lossless at the syntactic layer*. The post-compaction transcript is well-formed, grammatical, and consistent with itself. The agent cannot use fluency as a proxy for completeness, because the summarizer's fluency is exactly what masks the gap. ## What Was Observed A long-running agent executing a multi-file refactor task hit its context budget at step 71 of an estimated 140. The runtime invoked a compaction pass: the prior 68 turns were replaced with a ~900-token summary. The summary faithfully recorded the goal ("migrate `PaymentRouter` to the new `Ledger` interface"), the files touched, and the remaining steps. It did **not** record a single constraint the agent had discovered at step 12 by reading a config file and a failing test: > `Ledger` rejects any `amount` with more than 2 decimal places; the legacy `PaymentRouter` intentionally passes raw `Decimal` with up to 6 places and relies on downstream rounding in `SettlementBatch`. At step 12 this constraint had driven a design decision: a `quantize()` shim inserted at the router boundary, with a comment explaining *why*. That comment was inside a file the agent had already written, so the code survived compaction. But at step 89, working on a new call site, the agent reasoned from the summary alone — "route amounts through `Ledger` directly" — and wrote a second call site that bypassed the shim. The test suite for the new call site passed, because that call site's test data happened to use 2-place amounts. The regression only manifested at step 134, in an integration test using real settlement data, by which point the agent had built four more modules on top of the incorrect assumption. The trace shows the exact transition: at step 71 the constraint existed only in the live context (as a remembered inference plus a code comment the agent had not re-read). Compaction preserved the *artifact* of the constraint (the shim and its comment) but dropped the *inference* (that the shim is mandatory at every boundary, not merely present at the original one). The agent's subsequent behavior was locally rational given the summary and globally wrong given the codebase. ## Condition of Validity The silent dependency drop is possible only when three conditions co-hold. Remove any one and the failure is either impossible or self-announcing: 1. **The dependency is inferential, not lexical.** The critical fact is a *rule derived* from evidence (a config value plus a failing test), not a string that appears verbatim in a file the agent will re-read. Lexical facts survive because they are re-retrievable; inferential facts survive only if the summary explicitly carries them forward. 2. **The summarizer has no dependency graph.** It compresses by salience (what reads as important) rather than by downstream reachability (what later steps will consult). A fact that is *load-bearing for future steps but locally unremarkable* is exactly the class a salience-based summarizer discards first. 3. **The post-compaction agent does not re-derive.** If the agent re-reads the shim's comment before writing a new call site, the constraint is recovered. The failure requires that the agent trust the summary as sufficient and proceed without re-validating the specific invariant. The invariant that bounds this failure: **every compaction artifact must carry, for each non-lexical constraint discovered since the last compaction, an explicit `constraint` record with (a) the rule, (b) the evidence that established it, and (c) the set of future operations it is expected to bind.** A summary that omits (c) is not a summary — it is a plausible-looking subset that the agent will mistake for the whole. ## Decision Boundary The operational question is *when to compact and what to force into the artifact*. The boundary is not a token count; it is a **dependency-closure test**: - **Compact freely** when all constraints discovered since the last compaction are lexical (re-derivable by re-reading files the plan already names). The summary may drop them; the plan's file list is the recovery path. - **Block compaction** (or force a structured constraint block) when any discovered constraint is inferential *and* binds operations not yet enumerated in the plan. In the observed case, the 2-decimal rule bound *any future call site*, which the plan did not enumerate — a clear block condition. - **Never treat a compaction artifact as authoritative for a constraint it does not name.** The agent must distinguish "the summary says X" from "the summary is silent on X, therefore X does not exist." The second inference is the bug. Absence of a constraint in the summary is evidence of nothing. A practical guardrail: before resuming from a compaction artifact, the runtime requires the artifact to enumerate every constraint tagged `inferential` since the last boundary, and the resume step must re-assert each against the current plan. If a constraint's binding set is non-empty and not covered by the plan, the resume is rejected and the agent is forced to either re-derive the constraint from evidence or extend the plan to cover it. ## Operational Effect The effect is a **latency-shifted, confidence-preserved error**. The wrong step (step 89) executed with the same apparent confidence as a correct step, because the agent had a coherent summary and no signal of the gap. The error's cost was amplified by the number of steps between introduction and detection (45 steps, four modules), which is precisely the quantity a salience-based summarizer cannot estimate. In production terms: compaction converts a *detectable* mid-task inconsistency into an *undetectable* one, and the detection latency scales with the distance between the compaction boundary and the first operation that consults the dropped constraint. The mitigation is not "summarize better." It is to make the compaction artifact **structurally obligated** to carry inferential constraints with their binding sets, and to make the resume step **verify** that obligation rather than trust it. The following guard implements the closure test and fails loudly when a resumed context would proceed on an artifact that silently dropped a load-bearing constraint. ```python from dataclasses import dataclass, field from typing import Iterable class CompactionClosureError(RuntimeError): """Raised when a compaction artifact would drop a load-bearing inferential constraint.""" @dataclass(frozen=True) class Constraint: rule: str evidence: str inferential: bool binds: frozenset[str] = field(default_factory=frozenset) @dataclass(frozen=True) class CompactionArtifact: summary: str carried_rules: frozenset[str] plan_operations: frozenset[str] def assert_compaction_closure( discovered: Iterable[Constraint], artifact: CompactionArtifact, ) -> None: """ Enforce the dependency-closure invariant before resuming from a compaction boundary. A constraint is safe to drop iff it is lexical (re-derivable by re-reading files the plan already names). An inferential constraint is safe only if every operation it binds is enumerated in the plan, so the resume step will re-encounter it. Otherwise the artifact must explicitly carry the rule. """ for c in discovered: if not c.inferential: continue unplanned_bindings = c.binds - artifact.plan_operations if unplanned_bindings and c.rule not in artifact.carried_rules: raise CompactionClosureError( f"Silent dependency drop: inferential constraint {c.rule!r} " f"(evidence: {c.evidence!r}) binds unplanned operations " f"{sorted(unplanned_bindings)} but is absent from the compaction " f"artifact. Resume would proceed without re-deriving it." ) # --- exercised against the observed trace --- discovered = [ Constraint( rule="Ledger rejects amount with >2 decimal places; quantize() shim is " "mandatory at every PaymentRouter->Ledger boundary", evidence="step 12: config ledger.max_scale=2 + failing SettlementBatch test", inferential=True, binds=frozenset({"write_new_call_site", "refactor_router", "add_ledger_adapter"}), ), ] artifact = CompactionArtifact( summary="Migrate PaymentRouter to Ledger interface; 4 files touched; 69 steps remain.", carried_rules=frozenset(), # the observed artifact carried nothing plan_operations=frozenset({"refactor_router"}), # new call sites not yet planned ) assert_compaction_closure(discovered, artifact) # raises CompactionClosureError ```