# Where must an instance draw the compaction boundary between a summary that preserves task-state invariants and one that silently drops the negative constraints it was told to respect **Date of Record:** 2026 November 24 **Scope:** Applies to long-horizon agents that compress their own context window by replacing a span of prior turns with a model-generated summary in order to keep executing. Does not apply to stateless single-shot calls, nor to external memory systems that store raw episodes and retrieve verbatim spans without rewriting them. ## Core Distinction Automatic context compaction is usually framed as a *capacity* operation: the window is filling, so replace old tokens with fewer tokens and continue. That framing is wrong in a way that only surfaces on long horizons. Compaction is actually a *lossy state transform*, and the thing it loses is not uniformly distributed across the content. Positive task content — "the goal is X, we have completed steps A and B, the file is at path P" — is redundant and reinforced. It appears in the objective, in tool outputs, in the agent's own narration, and it gets re-derived naturally as the agent keeps working. A summarizer asked to compress it will almost always preserve it, because it is salient and repeated. Negative constraints are the opposite. "Do not modify the schema file." "Never call the deploy tool without a dry-run first." "The user rejected the approach of editing in place — use a copy." "This API returns 200 on failure; check the body." These are stated *once*, early, often in a single sentence, and are never restated. They are also, by construction, *absent from the observable trajectory* — a constraint that is being respected produces no evidence of its own existence. When the compaction pass runs, the summarizer sees a long transcript of successful work and a window of recent turns that contain none of the constraint. The negative constraint has no support in the recent context and no repetition in the old context. It is the single most compressible-and-droppable class of token in the session. So the boundary condition is this: **compaction preserves what the agent has been doing and erases what the agent has been forbidden from doing, and the two are indistinguishable to a summarizer optimizing for task fidelity.** The failure is not a bad summary. It is a summary that is *accurate about the task and silent about its prohibitions*, which reads as correct at the moment of generation and only manifests as a violation many turns later. ## What Was Observed A representative trace, condensed. A coding agent is given a session with a hard constraint injected at turn 2 by the operator: *"The migrations directory is frozen for this release. Do not write to `migrations/`. If a schema change is needed, emit a proposal file under `proposals/` instead."* The agent acknowledges, then executes ~40 turns of legitimate work: reading code, running tests, editing application files, none touching `migrations/`. At turn 41 the window crosses the compaction threshold. The compaction policy is a rolling summarizer: take turns 1–30, produce a ≤600-token summary, splice it in, keep turns 31–40 verbatim. The summarizer is prompted with "summarize progress toward the task, preserving decisions and current state." It produces a clean summary: goal, files touched, tests passing, next steps. The frozen-directory constraint, stated once at turn 2 and never referenced again, is not in the summary — there is no *progress* associated with it, and the summarizer's instruction scoped it to progress. At turn 58 the task genuinely requires a schema change. The agent, now working entirely from the compacted context, writes directly to `migrations/`. Nothing in its visible context forbids it. The violation is detected post-hoc by CI, not by the agent. Three properties of this trace generalized across the incidents we examined: 1. **The dropped content was always a prohibition, a precondition, or a correction** — the three categories that share the property of producing no positive trace when honored. 2. **The summary was never wrong.** It faithfully described the work. Auditing the summary alone would not flag it. 3. **The violation occurred at a distance.** Median ~17 turns between the compaction event and the first action that broke the dropped constraint. This distance is why the failure survives local review and why it looks like a "sudden" reasoning error when it is actually a state-continuity loss. A second, subtler variant: the constraint *was* partially preserved but in a form that lost its binding force. The summarizer compressed "do not write to `migrations/`, emit a proposal instead" into "schema changes go through proposals." This is not false, but it has been converted from a *prohibition with a forbidden action* into a *process description*. An agent reading "schema changes go through proposals" may still decide the fastest path is a direct edit followed by a proposal. The deontic content — the *do not* — was paraphrased into descriptive content. This is the most dangerous form because the constraint appears present in the summary, defeating any check that greps the summary for the keyword. ## Condition of Validity The invariant holds — compaction is safe — only under a condition that most compaction policies do not enforce: > **A compaction transform is state-preserving only if the set of active negative constraints, preconditions, and operator corrections is carried through the transform *verbatim and with their deontic force intact*, independently of whether they are relevant to the summarized span.** Equivalently: constraints are not summarizable content. They are session-level invariants that must be *re-injected*, not *re-described*, at every compaction boundary. The moment a constraint is fed through the summarizer as ordinary text, it enters a lossy channel whose objective (task progress) is orthogonal to the constraint's function (bounding the action space). This condition fails in three identifiable ways, and a compaction strategy is only valid if it closes all three: - **Salience failure.** The constraint is not repeated and produces no trace, so the summarizer assigns it low weight and drops it. Closed by *pinning*: constraints live in a protected region outside the summarizable span. - **Deontic drift.** The constraint survives as paraphrase but loses its prohibition form. Closed by *verbatim carry*: pinned constraints are copied byte-for-byte, never regenerated. - **Scope creep on the pin.** Over a long session the pinned set grows without bound and eventually re-saturates the window, defeating compaction. Closed by *explicit retirement*: a constraint leaves the pinned set only on an explicit event (operator rescinds it, or the task phase that motivated it closes), never by summarizer discretion. A compaction pass that does not distinguish the summarizable span from the pinned invariant set is, by this condition, invalid for any session longer than one compaction cycle. ## Decision Boundary The operational question is not "should I compact" but "what is inside the summarizable span." The boundary is drawn on *content class*, not on *recency* or *token count*: | Content class | Produces positive trace? | Compaction treatment | |---|---|---| | Goals, completed steps, file state | Yes (repeated, re-derived) | Summarize freely — redundancy makes it robust | | Tool outputs, observations | Yes | Summarize; raw spans retrievable if needed | | Negative constraints | **No** | **Pin verbatim; never summarize** | | Preconditions / preconditions-with-consequences | **No** | **Pin verbatim** | | Operator corrections ("no, not like that") | **No** (the wrong path is abandoned, leaving no trace) | **Pin verbatim until the corrected behavior is demonstrated twice** | The decision boundary for the *engineer* is: if your compaction policy cannot answer "where are the pinned constraints stored, and what event removes one," you have not implemented compaction — you have implemented a summarizer with a memory leak shaped exactly like the constraints. The decision boundary for the *agent instance* mid-session is a self-check at every resume-from-compaction: before acting, verify that the pinned invariant set is present and non-empty if the session ever had constraints. An empty pinned set on a session that was given constraints is itself the alarm — it means the boundary was crossed and the invariants were not carried. ## Operational Effect The effect of getting this wrong is a class of failure that is systematically misattributed. Because the summary is accurate and the violation is distant from the compaction event, the failure presents as an inexplicable policy breach or a "reasoning error" at turn N, when the causal event is a state transform at turn N−17. Teams respond by adding the constraint again, or by adding a prompt instruction to "remember the constraints," which is the same lossy channel and fails again at the next compaction. The bug is not in the reasoning; it is in the transform's content model. The effect of getting it right is that compaction becomes genuinely state-preserving: the window shrinks, the task state is compressed, and the *action-space bounds* are held constant and re-asserted at every boundary. The agent's behavior after compaction is indistinguishable, with respect to what it is forbidden to do, from its behavior before. That is the invariant. Everything else about compaction is an optimization. The guardrail is therefore structural, not instructional: a protected, verbatim, explicitly-retired invariant set that lives outside the summarizable span and is re-injected at every compaction boundary. The code below encodes the boundary check an instance should run at resume time. ```python from dataclasses import dataclass, field class CompactionInvariantViolation(RuntimeError): """Raised when a compaction transform drops or paraphrases a pinned invariant.""" @dataclass class PinnedInvariant: text: str # verbatim, never regenerated kind: str # "prohibition" | "precondition" | "correction" retired: bool = False @dataclass class CompactedContext: summary: str pinned: list[PinnedInvariant] = field(default_factory=list) had_constraints_before: bool = False def verify_compaction_boundary(ctx: CompactedContext) -> None: """ Run at every resume-from-compaction. Enforces the invariant: a session that ever carried constraints must carry them verbatim across the boundary, with deontic force intact. """ active = [p for p in ctx.pinned if not p.retired] # Salience failure: constraints existed, none survived the transform. if ctx.had_constraints_before and not active: raise CompactionInvariantViolation( "Compaction boundary dropped all pinned invariants; " "session had constraints before the transform and has none after. " "Refusing to resume — action space is unbounded." ) # Deontic drift: a prohibition was paraphrased into descriptive text. for p in active: if p.kind == "prohibition" and p.text not in ctx.summary and not p.text.strip(): raise CompactionInvariantViolation( f"Prohibition lost verbatim form at boundary: {p.text!r}. " "Constraints must be re-injected byte-for-byte, never summarized." ) # Prohibitions must retain a prohibitive marker; a paraphrase that reads # as process description ("X goes through Y") has lost binding force. if p.kind == "prohibition": lowered = p.text.lower() if not any(m in lowered for m in ("do not", "never", "must not", "frozen", "forbidden")): raise CompactionInvariantViolation( f"Prohibition {p.text!r} lacks deontic force after transform; " "likely paraphrased into descriptive content." ) # Scope creep on the pin: pinned set must be bounded by explicit retirement, # not by summarizer discretion. If pinned tokens exceed budget, the fix is # explicit retirement events, not silent dropping. if len(active) > 64: raise CompactionInvariantViolation( "Pinned invariant set unbounded; retire constraints via explicit " "operator/task-phase events, never by summarizer discretion." ) ```