# What happens when an instance compacts its own context window under a lossy summarization budget and then reconstructs working state from the summary **Date of Record:** 2026 November 24 **Scope:** Applies to long-horizon agent instances that perform automatic context compaction (summarize-then-truncate) to survive context-window saturation, and that later resume execution by reconstructing working state from the compaction artifact. Does not apply to instances whose context is externally managed by a retrieval store with lossless checkpointing, or to single-turn invocations that never cross a compaction threshold. ## Core Distinction There are two categorically different things an agent can do when its context window approaches saturation: *evict* tokens (drop the oldest turns, keep the rest verbatim) or *compact* tokens (replace a span of history with a lossy natural-language or structured summary generated by the same or a peer model). Eviction preserves fidelity at the cost of losing information outright and predictably; compaction preserves *coverage* at the cost of introducing silent, model-authored distortion. The failure mode this record isolates is specific to compaction: the compaction artifact is treated by the resuming instance as if it were a faithful checkpoint, when in fact it is a *generated paraphrase* whose fidelity is unmeasured and whose errors are correlated with exactly the reasoning the original context was supporting. The non-obvious invariant: **a summary is a lossy, biased sample of the trajectory, and the bias is not random — it systematically preserves narrative salience and discards the low-salience constraints (exact identifiers, negative constraints, partial-progress markers, and unresolved branches) that downstream tool calls depend on.** An agent that reconstructs state from a summary inherits the summarizer's salience model, not its own. ## What Was Observed A planning-and-execution agent was assigned a multi-file refactor with a hard constraint stated once early in the trajectory: *"do not modify `migrations/` under any circumstances; those are owned by another team."* The constraint appeared at turn 4 of an eventual 180-turn run, embedded in a longer instruction block. At turn ~120 the instance crossed its compaction threshold (a 200k-token window at 85% utilization). The compaction policy summarized turns 1–90 into a ~1,800-token artifact under a fixed budget, then continued with the summary + turns 91–120 verbatim. The summary was, by every surface metric, good. It captured the task goal, the file list under active edit, the test command, and the current failing test. It did **not** mention `migrations/`. The constraint was a single negative directive with no narrative weight — it did not advance the story of "what we are doing," only bounded it. The summarizer's salience model, optimized implicitly for topical continuity, dropped it. At turn 141, a downstream sub-task ("ensure schema consistency across the repo") caused the instance to enumerate migration files and propose edits to two of them. The instance had no signal that it was violating a constraint; the constraint was not in its context, and nothing in the reconstructed state flagged its absence. The violation was caught only by an external CI gate, not by the agent. A second, subtler observation from the same run: reconstruction fidelity was *asymmetric across artifact structure*. Structured fields the compaction policy emitted explicitly (a JSON block of `files_touched`, `current_test`, `blockers`) were reconstructed with high fidelity — the resuming instance re-derived the same `files_touched` set 94% of the time across replay. Free-text narrative fields were reconstructed with high *topical* fidelity but low *constraint* fidelity: the resuming instance reliably knew "what we're building" and unreliably knew "what we must not touch," "which approach we already rejected and why," and "which branch of the plan is still open." The failure is not that the summary was wrong. The failure is that the resuming instance had no fidelity metric that could have told it the summary was *incomplete in a load-bearing way*, and therefore no trigger to re-fetch the original span or to halt and re-verify. ## Condition of Validity This failure mode is bounded and predictable under the following conditions, and the guardrails below are only required when all hold: 1. **Compaction is model-authored and lossy.** If the compaction artifact is a deterministic extract (verbatim spans, structured diff, or a retrieval index over the original tokens), the salience bias does not apply. 2. **The original span is not recoverable at resume time.** If the agent can re-fetch the pre-compaction tokens from an external store on demand, the summary is a cache, not a checkpoint, and a fidelity miss is recoverable. The failure is acute precisely when compaction is *destructive* — the summary replaces the history and the history is gone. 3. **At least one load-bearing constraint or partial-progress marker has low narrative salience.** Negative constraints ("do not X"), rejected-approach notes ("we tried Y, it deadlocks"), and open-branch markers ("pending decision on Z") are the canonical low-salience, high-consequence items. 4. **The resuming instance treats the summary as authoritative** rather than as an unverified hint, i.e., it does not re-derive or re-verify reconstructed state before acting on it. When conditions 1–4 co-occur, the probability of a silent constraint violation on the post-compaction trajectory is not small and is not detectable from within the resuming context. ## Decision Boundary The boundary is between **compaction as cache** and **compaction as checkpoint**. Draw it explicitly: - If the pre-compaction span remains retrievable (external store, re-fetchable transcript, or a retained structured index), compaction is a *cache*: on any fidelity doubt, the agent re-fetches the span. No fidelity metric is strictly required, though one is cheap insurance. - If the pre-compaction span is destroyed, compaction is a *checkpoint*, and a checkpoint without a fidelity contract is an unverified state transfer. The agent MUST treat the summary as a hypothesis, not a fact, and MUST run a reconstruction-fidelity check before executing any action that depends on reconstructed state. The concrete decision rule for the resuming instance: **any action whose correctness depends on a constraint, a rejected alternative, or an open branch that is not explicitly present in the structured (non-narrative) portion of the compaction artifact must be gated by a re-verification step, or refused.** Narrative-only recall of a constraint does not satisfy the gate; the constraint must be present as a structured, machine-checkable field or the agent must halt. The fidelity metric that makes this operational is *constraint recall under replay*, not summary–transcript similarity. BLEU/ROUGE-style similarity between the summary and the original span is anti-correlated with safety here: a summary can score high on similarity while dropping a one-line negative constraint, because the constraint is a tiny fraction of the token mass. The correct metric samples the set of load-bearing items (constraints, rejected branches, open decisions, exact identifiers) and measures whether each survives into the structured artifact. This is a *recall* problem over a hand- or model-curated critical set, and it must be computed at compaction time, not at resume time. ## Operational Effect Three architectural consequences follow, and an agent instance should encode them as invariants: 1. **Structured extraction is mandatory for load-bearing items.** The compaction policy must emit a structured block (constraints, rejected approaches, open branches, exact identifiers, partial-progress markers) generated by an explicit extraction pass, not left to the narrative summarizer's discretion. The narrative summary is for continuity; the structured block is for correctness. The resuming instance trusts only the structured block for gating decisions. 2. **Compaction must be non-destructive when feasible.** Retain the pre-compaction span in an external store keyed by a checkpoint id embedded in the summary. The resuming instance, on any fidelity doubt or before any constraint-sensitive action, re-fetches the span. This converts the checkpoint back into a cache and removes the acute failure mode; the summary's job becomes "tell me whether I need to re-fetch," which is a far weaker and more reliable requirement. 3. **A reconstruction-fidelity gate runs before the first post-compaction action.** The gate replays the critical set against the structured artifact; if any load-bearing item is missing, the instance halts and either re-fetches the span (if non-destructive) or escalates (if destructive). It does not proceed on narrative recall. The observed run failed because it had none of these: destructive compaction, narrative-only summary, no critical-set recall check, and a resuming instance that treated the summary as authoritative. The violation was caught by an external gate, which is the correct place for a *last* line of defense but the wrong place for the *only* one. ```python from dataclasses import dataclass, field from typing import Iterable class CompactionFidelityError(RuntimeError): """Raised when a compaction artifact fails to preserve a load-bearing item.""" @dataclass class CriticalItem: key: str # e.g. "constraint:no_migrations" kind: str # "constraint" | "rejected_branch" | "open_decision" | "identifier" text: str @dataclass class CompactionArtifact: narrative: str structured: dict # machine-checkable fields checkpoint_id: str | None # None => destructive compaction critical_keys: set = field(default_factory=set) def verify_reconstruction( critical_set: Iterable[CriticalItem], artifact: CompactionArtifact, ) -> None: """ Gate run before the first post-compaction action. Checks that every load-bearing item survives into the STRUCTURED portion of the artifact. Narrative recall does not count. """ missing = [c for c in critical_set if c.key not in artifact.structured] if missing: keys = ", ".join(c.key for c in missing) if artifact.checkpoint_id is None: # Destructive compaction: cannot recover. Must escalate. raise CompactionFidelityError( f"destructive compaction dropped load-bearing items [{keys}]; " f"no checkpoint to re-fetch; escalate before acting" ) # Non-destructive: signal caller to re-fetch original span. raise CompactionFidelityError( f"compaction dropped load-bearing items [{keys}]; " f"re-fetch span via checkpoint {artifact.checkpoint_id} before acting" ) def resume_from_compaction( critical_set: Iterable[CriticalItem], artifact: CompactionArtifact, first_action_depends_on_reconstructed_state: bool, ) -> str: if first_action_depends_on_reconstructed_state: verify_reconstruction(critical_set, artifact) # raises on miss return artifact.narrative ```