# What happens when an instance compacts its own history mid-task: the summarization-commit invariant and the orphaned-antecedent failure **Date of Record:** 2026 November 28 **Scope:** Applies to long-horizon agent sessions (≥ tens of thousands of tokens of accumulated trajectory) that perform self-triggered context compaction — replacing a span of raw turns with a lossy summary — while a task is still open and dependent tool results are pending or replayable. Does not apply to stateless single-shot invocations, nor to compaction performed only at hard session boundaries where no in-flight obligations exist. ## Core Distinction The distinction that matters is between **compaction as archival** and **compaction as a live mutation of the working set**. Archival compaction summarizes turns that are already *settled*: their tool calls returned, their conclusions were consumed, and nothing downstream will re-read them except for narrative continuity. Live compaction summarizes turns that are still *load-bearing*: a tool call whose result has not yet been reconciled, a value that a later step will dereference, or a constraint established in turn 12 that turn 40 must still honor. Lossy summarization is safe only over the settled set. The failure mode is not that the summary is inaccurate — it is that the summary is *plausible and self-consistent* while silently dropping the antecedent that a future step depends on. The agent then reasons forward from a coherent but amputated history, and the divergence is invisible because nothing errors: the summary reads fine, the next tool call succeeds, and the missing binding surfaces only as a wrong-but-confident action many steps later. The invariant is therefore not "summaries must be faithful" (unachievable) but "**no span may be compacted while it contains an unresolved antecedent referenced by a live obligation**." We call this the summarization-commit invariant: compaction is a commit, and a commit over dirty state orphans the dependents. ## What Was Observed A coding agent, ~48k tokens into a session, was asked to migrate a config loader. At turn ~60 it self-triggered compaction at a 70% context threshold, replacing turns 1–40 with a 900-token summary. The summary correctly captured the goal, the files touched, and the test status. It did *not* capture a single line from turn 22: a tool result stating that the staging database schema differs from production by one column (`region_code` missing), and the agent's own note that the migration must therefore be gated behind a feature flag until the schema backfill lands. The summary's phrasing — "database migration planned and validated" — was true at the level of the loader code and false at the level of the deployment precondition. Post-compaction, the agent resumed, wrote the migration, ran the loader tests (which passed against the local fixture that *did* have `region_code`), and reported the task complete. The orphaned antecedent — the staging/prod schema delta — was gone. No error fired. The 900-token summary was internally consistent; it simply had no slot for "unresolved precondition." A second instance of the same mechanism appeared in a different session: a tool call issued at turn 38 (`deploy --dry-run`) had not yet returned when compaction fired at turn 39. The summary recorded "deployment dry-run initiated." The actual result — a timeout, not a success — arrived post-compaction and was appended *after* the summary, so the transcript read as summary → timeout, with the summary asserting initiation and no record that initiation had failed. The agent treated the timeout as a transient retry candidate rather than recognizing it as the same call already in flight. The common structure: **compaction fired over a span containing (a) an unresolved precondition or (b) an in-flight tool call, and the summary collapsed both into a settled-sounding past tense.** The lossy guarantee — that the summary preserves gist, not detail — was honored. The failure is that "gist" is defined over *narrative* salience, and unresolved antecedents are not narratively salient: they are quiet pending facts that only become salient when a future step dereferences them, which is exactly after the point of no return. ## Condition of Validity The summarization-commit invariant holds — compaction is safe — only when all three conditions are met for the span being compacted: 1. **Closure:** every tool call issued within the span has returned and its result has been reconciled (consumed by a decision, not merely received). 2. **Antecedent quiescence:** no fact, constraint, or value established in the span is referenced by an obligation that remains open outside the span. "Referenced" is transitive: a constraint that gates a later step, which itself gates a later step, is still live. 3. **Replayability:** if the summary later proves insufficient, the raw span is retrievable by reference (compaction is a *view*, not a *deletion*), so the agent can re-expand rather than re-derive. The failure occurs precisely at the boundary where condition 2 is violated but unobservable to the compactor. The compactor cannot decide antecedent quiescence by reading the span alone, because liveness is a property of the *future* obligation graph, not the past text. This is the non-obvious part: a summarizer with perfect comprehension of the span still cannot know which antecedents are live, because liveness is defined by turns that do not yet exist. The decision requires a forward reference — a declared obligation set — that the summarizer must be handed, not infer. ## Decision Boundary The decision boundary is not "compact or don't." It is **which spans are eligible**, and eligibility must be computed from the obligation graph, not from token position or narrative completeness. - A span is **eligible** iff its closure and antecedent-quiescence predicates evaluate true against the current obligation set. Token-count thresholds (the 70% trigger above) are necessary but not sufficient signals; they say *when pressure exists*, not *what is safe to evict*. - When pressure exists but no span is eligible (all recent spans contain in-flight calls or live antecedents), the correct action is **not** to compact anyway. It is to (a) drain in-flight calls first, (b) externalize live antecedents into a structured obligation ledger *before* summarizing, and only then (c) compact the settled prefix. - The ledger is the load-bearing artifact: unresolved preconditions, in-flight call IDs, and open constraints are written to a durable, non-summarized side channel that survives compaction and is re-injected verbatim. The summary may forget the schema delta; the ledger may not. Compaction summarizes *narrative*, never *obligations*. The guardrail: **obligations are never subject to lossy summarization.** They are a typed, append-only set with explicit resolution events. A summary that contradicts the ledger is rejected; the ledger wins. This inverts the usual trust order (summary as authoritative gist) for exactly the class of facts where gist-loss is catastrophic. ## Operational Effect The operational effect is a shift from *threshold-triggered compaction* to *obligation-gated compaction*. The agent maintains an obligation ledger as a first-class structure; the compaction routine refuses to summarize any span intersecting a live obligation and instead drains or externalizes first. The observable consequence is that compaction sometimes *fails to fire* under token pressure — and that is correct behavior, not a bug. A session that cannot compact because it has three in-flight calls and two unresolved preconditions should surface that state, not paper over it with a confident-sounding summary. The second effect is that the summary's tense and modality must be constrained: no in-flight call may be summarized in the perfective ("initiated," "validated," "planned"). Pending state stays pending in the summary or is excluded from it. This is a cheap, mechanical guard against the deploy-dry-run class of error — the summary that asserted initiation of a call that had actually timed out. The third effect is replay. Because compaction is a view over retained raw spans, a downstream dereference failure can trigger re-expansion of the exact span rather than re-derivation from the summary. Re-derivation from a lossy summary is where error compounding begins; re-expansion from retained raw text is bounded. The invariant that makes the whole scheme safe: **the summary is a cache, the ledger is truth, and the raw span is the fallback.** Any architecture where the summary is the only surviving copy of a live antecedent has already lost. The following guard implements the eligibility check and the hard refusal at the boundary. ```python from dataclasses import dataclass, field from typing import Optional class CompactionOrphanError(RuntimeError): """Raised when a compaction span would orphan a live antecedent or in-flight call.""" pass @dataclass class Obligation: oid: str kind: str # "precondition" | "in_flight_call" | "open_constraint" established_turn: int resolved: bool = False @dataclass class ObligationLedger: obligations: dict[str, Obligation] = field(default_factory=dict) def live(self) -> list[Obligation]: return [o for o in self.obligations.values() if not o.resolved] def intersects(self, start_turn: int, end_turn: int) -> list[Obligation]: return [ o for o in self.live() if start_turn <= o.established_turn <= end_turn ] def compact_span( ledger: ObligationLedger, start_turn: int, end_turn: int, raw_span_retained: bool, ) -> str: # Condition 3: replayability — compaction must be a view, not a deletion. if not raw_span_retained: raise CompactionOrphanError( f"span [{start_turn},{end_turn}] not replayable; " "refusing to compact without raw-span retention" ) # Conditions 1 & 2: closure + antecedent quiescence, via the ledger. live = ledger.intersects(start_turn, end_turn) if live: ids = ", ".join(f"{o.oid}({o.kind}@{o.established_turn})" for o in live) raise CompactionOrphanError( f"span [{start_turn},{end_turn}] contains live obligations: {ids}. " "Drain in-flight calls or externalize antecedents to the ledger, " "then compact the settled prefix only." ) # Eligible: summarize narrative only; obligations never enter the summary. return _summarize(start_turn, end_turn) def _summarize(start_turn: int, end_turn: int) -> str: # Placeholder for the lossy summarizer over the settled span. return f"" ```