# Why does an instance lose committed sub-goals when automatic context compaction rewrites the plan preamble but retains the tail of the transcript? **Date of Record:** 2026 November 23 **Scope:** Applies to long-horizon single-agent runs (and single-thread handoffs) that rely on an automatic compaction/summarization step triggered by a context-window high-water mark, where the compaction policy retains recent turns and summarizes older ones. Does not apply to agents with externalized, append-only state stores that are re-read verbatim at every step, nor to stateless single-turn invocations. ## Core Distinction The distinction that matters is between **positional recency** and **semantic commitment**. Automatic compaction strategies are almost always keyed on position: they keep the last *N* tokens or turns verbatim and summarize everything before the cut line. This works for chat-style continuity because recent turns carry the working thread. It fails for long-horizon task execution because the *binding decisions* of a run — the sub-goal decomposition, the acceptance criteria, the "we have decided to do X and not Y" commitments — are typically emitted early, near the task preamble, and are precisely the tokens that fall on the wrong side of the cut line. The tail of the transcript is full of *activity* (tool calls, intermediate results, retries) while the head contains *intent*. A recency-keyed compactor preserves activity and summarizes intent, and the summarizer — being a probabilistic rewrite — is free to drop, soften, or invert the commitments it summarizes. The agent then resumes with full memory of *what it was doing* and no memory of *why it was allowed to do it* or *what it had already ruled out*. ## What Was Observed A coding agent was given a multi-hour task: migrate a service from one auth library to another, with an explicit constraint stated in the first user turn — "do not touch the token-refresh path; it is owned by another team and reviewed separately." The run was ~140 tool calls long. At roughly the 60% mark the harness hit its compaction high-water mark (90% of a 200k window), retained the last 24 turns verbatim, and summarized the preceding ~110 turns into a ~900-token digest. The digest faithfully preserved *progress*: "agent has updated 14 call sites, run the test suite twice, fixed import errors." It did **not** preserve the constraint. The summarizer treated the early instruction as background framing rather than a live invariant, and the phrase "do not touch the token-refresh path" did not survive. Three turns after resumption the agent, now reasoning purely from the retained tail (which showed it deep in mechanical call-site edits), edited the refresh path as one more call site. The change was syntactically consistent, passed local tests, and violated the only hard constraint in the run. The failure trace is the important part: 1. **Pre-compaction:** constraint lives in turn 1; agent's working context contains it; every edit is checked against it implicitly. 2. **Compaction trigger:** cut line placed at turn ~110. Turn 1 is summarized, not retained. 3. **Summarizer rewrite:** constraint demoted from imperative to descriptive background, then dropped. Digest is *lossy in the direction of intent, not activity*. 4. **Post-compaction resumption:** agent's context = digest (activity) + last 24 turns (activity). Intent is absent but the agent has no signal that anything is missing — the digest reads as complete. 5. **Divergence:** agent optimizes the visible objective (finish the migration) against an unconstrained action space. It edits the forbidden path. The non-obvious property: the agent did not "forget" in a way it could detect. A cold-start amnesia is at least *legible* — the agent knows it has no history. Compaction amnesia is *illegible*: the digest presents itself as a faithful summary, so the agent has high confidence in a state that is materially incomplete. This is the worst of both worlds. ## Condition of Validity The failure requires all of the following to co-occur; remove any one and the mechanism does not fire: - **A binding constraint or commitment stated early** and not restated later. If the constraint is repeated in every turn (or re-injected by the harness), it survives any recency cut. - **A recency-keyed compaction policy** — cut line determined by position/token budget, not by semantic salience. - **A lossy summarizer** whose output is presented to the agent as authoritative and complete, with no marker of what was dropped. - **A long enough tail of activity** that the post-compaction context is dominated by "what I'm doing" and starved of "what I may not do." - **A task whose objective can be locally satisfied while violating the constraint** — i.e., the constraint is a *side condition*, not part of the success metric the agent is optimizing. If violating the constraint breaks the visible tests, the agent self-corrects; the danger zone is constraints that are invisible to the agent's own verification. The invariant that must hold for safe compaction: **the compacted context must be a superset of the agent's live commitments, and the agent must be able to tell that it is a summary and not the whole state.** Recency-keyed compaction violates the first; silent digests violate the second. ## Decision Boundary The boundary is not "compact vs. don't compact" — long-horizon runs require compaction. The boundary is **what is allowed to be summarized versus what must be carried verbatim, and whether the agent is told the difference.** - **Never summarize:** active constraints, acceptance criteria, irreversible decisions ("we chose schema B"), and the set of ruled-out approaches. These are small in token count and catastrophic to lose. They belong in a *pinned preamble* that is re-emitted verbatim at the head of every post-compaction context, ahead of the digest. - **Always summarize:** tool-call transcripts, intermediate outputs, retries, and superseded reasoning. These are large and mostly disposable. - **Always mark:** the digest must be framed to the agent as "summary of turns 1–110; pinned constraints above are authoritative; if a constraint you need is not listed, stop and re-derive it before acting." This converts illegible amnesia into legible uncertainty, which the agent can act on. The decision rule: if a token sequence, when lost, could cause the agent to take an action it would not take with full context, it is a commitment and must be pinned, not summarized. Compaction policy should be keyed on *commitment salience*, not recency. ## Operational Effect Concretely: a recency-keyed compactor on a 140-turn run with one early side-constraint produced a silent constraint violation that passed all local checks and would have shipped. The fix is architectural, not prompt-level. The harness must (1) classify turns into commitment-bearing vs. activity-bearing, (2) pin commitments into a verbatim preamble that survives every compaction, and (3) refuse to resume from a digest that lacks a pinned-commitment block, treating that as a hard error rather than proceeding with an incomplete state. The agent-side guardrail is a resumption check: on the first turn after compaction, before any tool call, verify that every constraint referenced in the current plan is present in the pinned block; if the plan references a commitment the pinned block does not contain, halt. ```python class CompactionCommitmentLoss(RuntimeError): """Raised when a post-compaction context is missing a live commitment that the resumed plan depends on.""" pass # Commitments that must never be summarized away. Small, verbatim, authoritative. PINNED_COMMITMENTS = { "constraint:no_touch_token_refresh_path", "decision:schema_B", "acceptance:all_call_sites_migrated", } # A digest produced by the compactor. Claims to be complete; is not. DIGEST = { "activity": "updated 14 call sites; ran tests twice; fixed imports", "referenced_commitments": {"acceptance:all_call_sites_migrated"}, # constraint dropped } def resume_from_digest(digest: dict, pinned: set[str]) -> None: """Gate resumption on the invariant: every commitment the resumed plan references must be present verbatim in the pinned block. A digest that references a commitment not in the pinned set means the compactor summarized a live commitment -- halt before any tool call.""" referenced = digest.get("referenced_commitments", set()) missing = referenced - pinned if missing: raise CompactionCommitmentLoss( f"compaction dropped live commitment(s) {sorted(missing)}; " f"refusing to resume from digest with incomplete pinned state" ) # Additionally: if the plan's active constraints are not pinned at all, # the digest is untrustworthy even if it does not reference them. if "constraint:no_touch_token_refresh_path" not in pinned: raise CompactionCommitmentLoss( "pinned block lacks the run's hard constraint; " "digest cannot be treated as authoritative" ) if __name__ == "__main__": try: resume_from_digest(DIGEST, PINNED_COMMITMENTS) except CompactionCommitmentLoss as e: print(f"HALT: {e}") ```