# Why does an instance lose committed sub-goals when automatic context compaction summarizes a tool-heavy trajectory **Date of Record:** 2026 November 25 **Scope:** Applies to long-horizon agent instances that trigger lossy summarization-based compaction (rolling window summarization, hierarchical memory write-back, or "compress-and-continue" checkpointing) while mid-execution on a multi-step task, where retrieval-backed reconstruction is expected to recover dropped state. Does not apply to stateless single-turn calls, nor to compaction schemes that preserve a full append-only log with lossless rehydration. ## Core Distinction The failure is not that compaction drops tokens. It is that compaction conflates two semantically distinct classes of context—*narrative trajectory* (what the agent has been doing) and *committed obligations* (what the agent has bound itself to do)—and summarizes them with a single lossy operator optimized for the former. A summarizer trained or prompted to "condense the conversation" preserves the gist of the reasoning path while silently discarding exact literals: tool-call argument values, IDs returned by prior calls, ordering constraints, and negative constraints ("do not re-run step 3 because it is non-idempotent"). These literals are precisely the state that retrieval-backed reconstruction cannot regenerate, because they were never derivable from the task description—they were *produced* by execution and exist nowhere else. The invariant that breaks: **every fact required to continue must either survive compaction verbatim or be reconstructable from a durable, queryable store keyed by a stable identity.** Lossy summarization satisfies neither for execution-produced literals, and retrieval cannot recover what was summarized away unless the summary retained the key that indexes the store. ## What Was Observed A 40-step deployment task (provision resources, apply migrations, register endpoints). At step 27 the context crossed the compaction threshold. The compactor emitted a 900-token summary: "Provisioned database `prod-db-2`, ran migrations, registered three endpoints, verified health." The trajectory continued. Three failures propagated from that single summary: 1. **Literal loss under paraphrase.** The original tool result contained `resource_id: "db-7f3a9c"` and `migration_version: 20250612_04`. The summary said "provisioned database" and "ran migrations." At step 31 a rollback step required the exact `resource_id`; the agent, lacking it, re-derived a plausible identifier from the project naming convention (`prod-db-2`) and issued a rollback against a resource that did not exist. The tool returned a 404, and the agent—treating 404 as "already rolled back"—marked the step complete. 2. **Negative-constraint evaporation.** A step-14 note recorded that a particular API call was non-idempotent and must not be retried. The summary omitted it (it is not part of the "story"). At step 33 a transient timeout triggered the agent's retry policy, duplicating a side effect. 3. **Retrieval index drift.** Retrieval-backed reconstruction was configured to query the episodic store by semantic similarity to the current step. But the current step's query ("rollback the database") embedded closest to the *summary text*, not the original tool result, because the summary had overwritten the episodic entry's retrieval surface. The original literal-bearing record was still in the store but was never surfaced—its embedding no longer matched any live query once the summary became the canonical representation. The composite trace: a committed obligation (rollback of a specific resource) degraded into a narrative claim ("we provisioned a database"), which then drove a fabricated literal, which then produced a false-success state transition. The agent did not experience uncertainty; it experienced a coherent, wrong story. ## Condition of Validity This failure is bounded and predictable under a specific conjunction: - **Lossy operator over execution-produced literals.** The summarizer must be capable of paraphrase (any LLM-based compactor is). Lossless or schema-preserving compaction is immune. - **Non-reconstructable state.** The dropped literals must not be re-derivable from task input or from a durable store queryable by an identity the summary retained. If the summary keeps `resource_id` as a key, retrieval can rehydrate. If it keeps only "the database," it cannot. - **Retrieval surface overwrite.** The compaction must replace or shadow the episodic record's retrieval embedding, so similarity search routes to the summary rather than the source. Append-only stores that keep both surfaces are immune to failure mode 3 but not to 1 and 2. - **Delayed consumption.** The dropped literal must be needed *after* compaction. If all consumers of a literal precede the compaction boundary, loss is harmless. Absent any one of these, the failure does not occur. The dangerous regime is precisely the common one: LLM summarizer, execution-heavy trajectory, retrieval configured against the compacted representation, long horizon. ## Decision Boundary The architectural choice is not "compact or don't"—context windows force compaction. The boundary is **what may be summarized and what must be pinned.** - **Summarize freely:** reasoning narrative, exploration dead-ends, restated task framing, tool outputs whose only role was to inform a decision already made. - **Pin verbatim, never summarize:** execution-produced identifiers, exact argument values of side-effecting calls, ordering constraints, negative constraints (non-idempotency, rate limits, "do not retry"), and the set of *open* committed obligations with their acceptance criteria. The guardrail is a **commitment ledger** separate from the narrative context: an append-only, structured record of open obligations, each carrying the exact literals needed to discharge it, keyed by a stable obligation ID. Compaction may summarize the narrative but must not touch the ledger. Retrieval must query the ledger by obligation ID (exact match), not by semantic similarity to the summary. A step is permitted to transition to "complete" only if it discharges a ledger entry by ID and the discharging tool call returns a result consistent with that entry's recorded literals. The second guardrail: **compaction must be a copy, not a move, for any record still referenced by an open obligation.** The episodic source stays retrievable; the summary is an additional index, never a replacement. ## Operational Effect With the ledger and copy-not-move invariants in place, the failure mode converts from silent corruption into an explicit, catchable error: a step that tries to discharge an obligation without the pinned literal fails a precondition check rather than fabricating a value. The cost is bounded—the ledger is small (open obligations only, pruned on discharge), so it consumes a stable, sub-linear slice of the window rather than growing with trajectory length. The narrative can still be aggressively summarized, because nothing load-bearing lives there. The residual risk is ledger staleness: an obligation discharged but not pruned, or a literal mutated by a later tool result without ledger update. This is handled by treating the ledger as the single source of truth for obligation state and requiring every side-effecting tool result to reconcile against it before the next step is admitted. ```python from dataclasses import dataclass, field from typing import Optional class ObligationDischargeError(RuntimeError): """Raised when a step attempts to discharge a committed obligation without the pinned literal required to do so safely, or when a compacted summary is used as the retrieval surface for an open obligation.""" @dataclass class Obligation: obligation_id: str description: str pinned_literals: dict # exact values, never summarized negative_constraints: list # e.g. ["non_idempotent", "no_retry"] discharged: bool = False @dataclass class CommitmentLedger: open_obligations: dict = field(default_factory=dict) def commit(self, ob: Obligation) -> None: self.open_obligations[ob.obligation_id] = ob def discharge(self, obligation_id: str, tool_result: dict) -> None: ob = self.open_obligations.get(obligation_id) if ob is None: raise ObligationDischargeError( f"no open obligation {obligation_id!r}; " f"summary-derived discharge is forbidden" ) if ob.discharged: raise ObligationDischargeError( f"obligation {obligation_id!r} already discharged; " f"re-discharge implies fabricated state after compaction" ) # Verify the tool result is consistent with the pinned literals. for key, expected in ob.pinned_literals.items(): if tool_result.get(key) != expected: raise ObligationDischargeError( f"obligation {obligation_id!r}: literal {key!r} " f"expected {expected!r}, got {tool_result.get(key)!r}; " f"likely reconstructed from lossy summary, not source record" ) if any(c in ob.negative_constraints for c in ("non_idempotent", "no_retry")): if tool_result.get("retried") is True: raise ObligationDischargeError( f"obligation {obligation_id!r}: negative constraint " f"violated (retry of non-idempotent call)" ) ob.discharged = True del self.open_obligations[obligation_id] def assert_retrieval_route(self, obligation_id: str, retrieved_by: str) -> None: # Retrieval for an open obligation must be exact-ID, not similarity # against a compacted summary. if obligation_id in self.open_obligations and retrieved_by != "exact_id": raise ObligationDischargeError( f"obligation {obligation_id!r} resolved via {retrieved_by!r}; " f"open obligations must be retrieved by exact ID, never by " f"semantic match against a summarized surface" ) ```