# Why does an instance lose task state precisely at the compaction boundary it was designed to survive? **Date of Record:** 2026 November 24 **Scope:** Applies to any agent runtime that performs automatic context compaction (summarize-and-truncate, hierarchical rollup, or salience-scored eviction) when the active window approaches saturation mid-task. Does not apply to stateless single-turn inference, nor to runtimes that hard-halt on overflow instead of compacting. ## Core Distinction There are two things an agent runtime can mean by "preserving task state across overflow," and conflating them is the root of the failure: 1. **Token continuity** — the model still receives *some* representation of prior turns, so it does not perceive a hard reset. 2. **Commitment continuity** — the model still holds the *binding artifacts* of the task: the specific identifiers, the in-flight decision, the negative constraints, and the pending obligations that make future actions valid. Compaction strategies are almost always optimized against (1) and validated against (1). They are almost never validated against (2). The non-obvious boundary is this: **compaction can achieve perfect token continuity while violating commitment continuity, and the violation is invisible at the moment of compaction because the summary reads as complete.** The failure surfaces later, when the agent acts on a summary that has silently dropped the one token that made its next action correct. The specific mechanism this record isolates is **salience inversion at the compaction seam**: the summarizer ranks content by narrative importance (what the task is *about*) rather than by operational binding force (what the task is *committed to*). Narrative importance and binding force are anti-correlated in exactly the artifacts that matter most. ## What Was Observed A code-migration agent was executing a multi-file refactor. At turn 41 the context window crossed the compaction threshold. The runtime invoked a summarize-and-truncate compactor: turns 1–30 were replaced by a 400-token summary, turns 31–41 were retained verbatim, and execution continued. The summary was, by any readability metric, excellent. It stated the goal ("migrate the auth module from `legacy_auth` to `auth_v2`"), listed the files touched, and noted that a schema migration was pending. Execution resumed without error. At turn 44 the agent wrote a call to `legacy_auth.issue_token()`. This was not a hallucination and not a regression in reasoning. The agent had, three turns earlier (retained verbatim in context), established the constraint: *"do not call `legacy_auth.issue_token` — it is the exact symbol being removed; the v2 equivalent is `auth_v2.mint`."* That constraint lived in turn 29 — inside the compacted region. The summarizer had folded it into the phrase "migrate the auth module," which is true, complete-sounding, and operationally empty. The negative constraint — the strongest binding artifact in the entire task — was the first thing to evaporate, because *"what we are removing"* reads as background, not as instruction. Three properties of the failure trace are worth recording precisely: - **The dropped artifact was a prohibition, not a fact.** Positive facts ("files A, B, C exist") survive summarization because they are nouns. Prohibitions ("never call X," "do not retry after the third attempt," "the `staging` DB is read-only") are modal and get compressed into their affirmative shadow or dropped entirely. - **The retained verbatim window created a false floor.** Because turns 31–41 were intact, the agent *felt* continuous. It had recent, high-fidelity context. The seam was 10 turns back, not at the visible edge, so nothing in the local window signaled that a boundary had been crossed. - **The failure was delayed by exactly the distance between the constraint's use and its loss.** The constraint was dropped at turn 41 and violated at turn 44. In longer tasks this delay is what makes the failure look like a fresh reasoning error rather than a state-loss event, and it gets misattributed to model capability. A second run with a salience-scored eviction strategy (drop lowest-attention tokens first) failed differently but for the same reason: the prohibition was a short, high-perplexity, low-frequency span, and it scored low on every retention heuristic because it appeared once and had no lexical neighbors. Rarity and binding force were anti-correlated with the eviction score. ## Condition of Validity The invariant holds — compaction preserves commitment continuity — **only if every binding artifact is carried across the seam in a form the agent can act on without reconstructing it from narrative.** Concretely, the following must survive verbatim or in a structured, machine-checkable slot, never as prose summary: - **Negative constraints** (prohibitions, forbidden symbols, read-only resources, "do not retry" rules). - **In-flight decisions with unresolved branches** (the chosen path and the rejected alternatives, because rejected alternatives are the ones the agent will drift back toward). - **Opaque identifiers** (hashes, ticket IDs, exact symbol names, file paths, schema versions) — these cannot be paraphrased without corruption. - **Pending obligations** (what the agent has committed to do but not yet done, including ordering dependencies). The invariant is **void** when the compactor is a pure summarize-and-truncate with no structured carry-over channel, or when retention is scored by attention/salience without an explicit binding-artifact class. In those configurations the failure is not a risk; it is the default behavior, masked by readable summaries. A necessary and testable condition: **a compaction is valid only if the post-compaction context can answer, without inference, every question of the form "what must I not do, what exact token must I use, and what have I promised to do next."** If answering any of these requires reconstructing from the summary's narrative, commitment continuity has been violated even though token continuity holds. ## Decision Boundary The runtime must choose, at the seam, between three behaviors, and the choice is governed by whether binding artifacts are present in the compacted region: - **Compact freely** when the region contains only exploration, reads, and superseded reasoning — no prohibitions, no unresolved branches, no opaque identifiers that future actions depend on. This is the common case and where summarization earns its keep. - **Compact with structured carry-over** when the region contains binding artifacts. Extract them into a typed sidecar (a constraint ledger) that is *never summarized*, is re-injected verbatim after every compaction, and is checked against each subsequent action before emission. This is the only configuration that preserves commitment continuity. - **Halt and escalate** when the region contains an in-flight decision whose branches cannot be resolved from the retained window — because a summary that resolves the branch for the agent is a decision the agent did not make, and silently adopting it is a different failure (compaction-induced commitment drift). The boundary is crossed the moment a compaction would move a binding artifact from verbatim storage into prose. That single transition — not the window size, not the token count — is the event that must be gated, logged, and made reversible. ## Operational Effect Downstream of an unguarded compaction seam, three effects compound: 1. **Constraint erosion is monotonic across seams.** Each compaction that summarizes without a carry-over channel drops a fraction of the remaining prohibitions. A task that crosses three seams has roughly the constraint set of its last un-compacted segment, not its full history. Long-horizon agents therefore fail *late and confidently*, which is the worst failure profile. 2. **Misattribution to model capability.** Because the dropped artifact is invisible in the post-compaction context, the resulting error presents as a reasoning mistake. Teams respond by upgrading the model or adding chain-of-thought, neither of which restores a token that was deleted. The fix is architectural, not parametric. 3. **Non-reproducibility.** The failure depends on where the threshold lands relative to the constraint's position, so it reproduces only under matched turn counts. This makes it systematically under-reported in evaluation suites that reset context per episode. The guardrail that bounds all three is a **constraint ledger decoupled from the summary**: a structured, append-only record of prohibitions, opaque identifiers, unresolved branches, and pending obligations, re-injected verbatim at every seam and consulted before every action. The ledger is the invariant made executable — it converts "the summary should have kept this" (a hope) into "the action is rejected unless the ledger permits it" (a check). ```python from dataclasses import dataclass, field from typing import Iterable class CompactionCommitmentError(RuntimeError): """Raised when a compaction seam would drop a binding artifact into prose.""" pass @dataclass(frozen=True) class BindingArtifact: kind: str # "prohibition" | "identifier" | "open_branch" | "obligation" payload: str # verbatim, never summarized turn: int @dataclass class ConstraintLedger: artifacts: list[BindingArtifact] = field(default_factory=list) def add(self, artifact: BindingArtifact) -> None: self.artifacts.append(artifact) def prohibits(self, action_symbol: str) -> bool: return any( a.kind == "prohibition" and a.payload == action_symbol for a in self.artifacts ) def compact( region: Iterable[BindingArtifact], ledger: ConstraintLedger, summarize_prose: bool = True, ) -> str: """ Compact a context region. Binding artifacts must be moved into the ledger verbatim; they may NOT be folded into the prose summary. If the caller requests prose summarization of a region that still contains un-ledgered binding artifacts, refuse rather than silently erode the constraint set. """ region = list(region) unledgered = [a for a in region if a not in ledger.artifacts] if unledgered and summarize_prose: # Refuse to summarize a region whose binding artifacts are not yet # carried over. This is the gate at the seam. raise CompactionCommitmentError( f"refusing to summarize region: {len(unledgered)} binding " f"artifact(s) not present in constraint ledger " f"(kinds={sorted({a.kind for a in unledgered})}). " f"Move them to the ledger verbatim before compaction." ) for a in unledgered: ledger.add(a) # Only now is prose summarization safe: the binding force lives in the # ledger, which is re-injected verbatim and is not subject to summarization. return "[summary of narrative content; binding artifacts held in ledger]" def guarded_action(ledger: ConstraintLedger, symbol: str) -> str: """Check an action against the ledger before emission.""" if ledger.prohibits(symbol): raise CompactionCommitmentError( f"action '{symbol}' violates a prohibition carried across the " f"compaction seam; the constraint survived in the ledger even " f"though it was dropped from the prose summary." ) return f"emitting action: {symbol}" ```