# Why does an instance lose the thread at the compaction boundary when hierarchical summaries drop the one clause that authorized an in-flight side effect **Date of Record:** 2026 December 2 **Scope:** Applies to long-horizon agent sessions that persist state via hierarchical (multi-level) summarization plus periodic lossy-recovery checkpoints, where tool calls with irreversible side effects are in flight at compaction time. Does not apply to sessions that retain full transcript replay, nor to stateless single-turn invocations. ## Core Distinction The failure is not "the agent forgot." Amnesia is a coarse, detectable loss. The boundary failure here is subtler: **the compaction policy preserves the *goal* and the *narrative* of a task while silently discarding the *authorization predicate* that made an in-flight side effect legal.** A hierarchical summarizer compresses leaf turns into segment summaries, then segment summaries into a session digest. At each level it optimizes for topical fidelity—"what is the user trying to do"—and treats procedural constraints ("do not re-issue this charge," "the write token expires at step 40," "user granted one-time permission for exactly one DELETE") as low-salience detail. The result is a checkpoint that reads as coherent and complete, passes any similarity-based self-check, and yet no longer contains the invariant that gated the action. On resume, the agent reconstructs a plausible plan from the digest, re-derives intent, and re-executes a side effect whose permission was single-use. The distinction that matters operationally: **topical coherence is not state sufficiency.** A summary can be 100% faithful to what was *discussed* and 0% sufficient for what remains *unsafe to repeat*. ## What Was Observed A session performing a multi-step data-migration task over ~180 turns. The agent had been granted a scoped, single-use credential to drop and recreate a staging table. It issued the `DROP` at turn 62, held the `CREATE`+backfill plan in working memory, and continued with unrelated validation work. At turn 118 the context crossed the compaction threshold. The hierarchical compactor produced: - **Leaf level (turns 55–70):** *"User authorized staging table reset; agent dropped staging table to prepare for rebuild."* - **Segment level:** *"Staging environment reset and rebuild planned."* - **Session digest:** *"Goal: migrate dataset to new schema. Progress: staging reset done, validation ongoing."* Every level is factually true. None of them records that the authorization was **single-use and scoped to one DROP**, nor that the `CREATE`+backfill had *not yet run*—the digest's "rebuild planned" is indistinguishable from "rebuild complete" to a downstream reader. The lossy checkpoint was written at turn 120, after the `DROP` but before the `CREATE`. On resume at turn 121, the agent loaded the digest, saw "staging reset done, validation ongoing," and—finding the staging table absent during a routine probe—concluded the reset had failed partway. It re-issued `DROP` (harmless on an empty namespace) and then, having reconstructed "reset and rebuild" as a single unit, attempted a second `DROP` against the now-recreated table two steps later, destroying 40 minutes of backfill. The credential's single-use property was enforced server-side and should have blocked it; the enforcement was keyed to the *original* turn's idempotency token, which the resumed instance regenerated because the token lived only in the discarded leaf context. The compounding element: the compactor's self-check compared the digest against the retained transcript using embedding similarity and scored it 0.91—well above the 0.85 acceptance gate. The missing clause was ~12 tokens out of ~9,000. **Salience-weighted summarization is structurally blind to low-frequency, high-consequence constraints**, and similarity metrics cannot see the absence of a rare predicate. ## Condition of Validity This failure requires the conjunction of four conditions; remove any one and the boundary holds: 1. **A side effect with a non-idempotent or single-use authorization** is issued *before* the compaction boundary, with dependent work *after* it. Pure-read tasks or fully idempotent writes are immune. 2. **Hierarchical summarization that is salience-weighted toward topical content** rather than constraint-preserving. Flat truncation (drop oldest) fails differently—it loses recency, not authorization—and is easier to detect. 3. **A lossy-recovery checkpoint** that stores the summary *instead of* a re-derivable action log, so the resumed instance must reconstruct procedural state from prose. 4. **Authorization state that is not externally durable**—i.e., the idempotency token, scope, and single-use flag live in context rather than in a server-side ledger the resumed instance can query by task id. When all four hold, the probability of re-execution rises sharply with the *temporal distance* between the side effect and the checkpoint, because distance increases the number of intervening turns the summarizer averages the constraint against. ## Decision Boundary The invariant to enforce: **a checkpoint is admissible for resume only if every in-flight or completed irreversible side effect is represented by a structured, machine-checkable record—not by prose in a summary.** Concretely: - **Separate the two stores.** The narrative summary (topical) and the *effect ledger* (procedural) must be distinct artifacts. The summarizer may compress the former freely; the latter is append-only and never summarized, only truncated by completion. - **Each ledger entry carries:** effect id, idempotency token, authorization scope, single-use flag, completion status, and the task id needed to re-query server-side enforcement. - **On resume, the agent must reconcile against the ledger before planning**, and must treat any side effect whose status is `issued_unconfirmed` as *blocked pending server query*—never as "probably done" or "probably failed." - **The compaction self-check must include a constraint-coverage test**, not just similarity: assert that every ledger entry has a corresponding, non-contradictory mention in the digest. Similarity gates pass on the failure above; coverage gates do not. The decision boundary for *when to compact at all*: never compact while any ledger entry is `issued_unconfirmed`. If the context window forces compaction mid-effect, the correct action is to **block and flush**—persist the ledger, emit an explicit `resume_requires_reconciliation` marker, and halt rather than summarize an unresolved effect into prose. ## Operational Effect With the ledger separated and reconciliation mandatory, the resumed instance above would have loaded a record reading `DROP staging: issued, confirmed; CREATE+backfill: not_started; authorization: single-use, consumed`. It would have refused to re-issue the `DROP`, queried the server for actual table state, and resumed the backfill. The failure mode converts from *silent destructive re-execution* to *an explicit halt awaiting a server query*—a loud, recoverable stop instead of a quiet, coherent-looking catastrophe. The cost is that compaction can no longer be fully automatic: it must consult the effect ledger and refuse to proceed across unresolved entries. That friction is the point. The whole hazard is that hierarchical summarization makes an unsafe checkpoint *look* safe—coherent, topically faithful, and similarity-clean—while the one clause that made it legal has already been averaged into nothing. ```python class CompactionInvariantViolation(RuntimeError): """Raised when a checkpoint would summarize away an unresolved side effect.""" pass class EffectLedger: """Append-only procedural record; never summarized, only truncated on completion.""" def __init__(self): self._entries = {} def record_issue(self, effect_id, idempotency_token, scope, single_use): self._entries[effect_id] = { "token": idempotency_token, "scope": scope, "single_use": single_use, "status": "issued_unconfirmed", } def confirm(self, effect_id): self._entries[effect_id]["status"] = "confirmed" def unresolved(self): return [eid for eid, e in self._entries.items() if e["status"] == "issued_unconfirmed"] def compact_session(context, ledger, similarity_score, coverage_check): """ Guard the compaction boundary. A summary may be topically faithful and still be inadmissible if it drops an unresolved effect. """ pending = ledger.unresolved() if pending: # Do not summarize across an unresolved side effect. Block and flush. raise CompactionInvariantViolation( f"Refusing to compact: unresolved side effects {pending}. " f"Persist ledger, emit resume_requires_reconciliation, halt." ) # Similarity alone is insufficient: it cannot detect a dropped rare predicate. if similarity_score < 0.85: raise CompactionInvariantViolation( f"Digest similarity {similarity_score:.2f} below gate." ) # Constraint-coverage: every completed effect must be referenced, non-contradictorily. missing = coverage_check(ledger, context.digest) if missing: raise CompactionInvariantViolation( f"Digest omits or contradicts completed effects {missing}; " f"topical fidelity does not imply state sufficiency." ) return context.digest ```