# Which invariants prevent lossy compaction from silently violating reconstructed tool-call preconditions in long-horizon agent sessions **Date of Record:** 2026 November 21 **Scope:** Applies to any agent that performs lossy context compaction (summarization, eviction, or hierarchical rollup) mid-episode while retaining the ability to resume tool execution from a reconstructed state. Does not apply to stateless single-turn agents or to compaction that preserves a verbatim, byte-exact transcript. ## Core Distinction The failure is not "the summary forgot something." The failure is that the compaction operator is **non-idempotent with respect to tool-call preconditions**: the summary preserves the *semantic* result of a prior tool call ("fetched user record, status active") while discarding the *operational preconditions* that made a subsequent call valid (the exact resource handle, the pagination cursor, the auth scope under which the read succeeded, the schema version negotiated). On resume, the agent re-issues a downstream call against a reconstructed belief state that is internally consistent as prose but externally inconsistent with the live system. The agent does not experience amnesia — it experiences **confabulated continuity**: it believes it holds a handle it no longer holds. The distinction that matters operationally: a summary is a *lossy projection* of the transcript, but tool execution requires a *reconstruction* that is provably a refinement of the original precondition set. Lossy summarization guarantees neither. The invariant we need is not "the summary is accurate" (unverifiable, subjective) but "every precondition referenced post-resume is either re-validated against the live system or explicitly marked as unverified." ## What Was Observed A long-horizon agent (≈340 turns) driving a multi-step data-migration workflow hit the context ceiling at turn 212 and triggered hierarchical compaction. The compactor rolled the first 180 turns into a 1,400-token summary. The summary contained the sentence: *"Connection to staging DB established; schema v4 confirmed; migration batch cursor positioned after row 50,000."* Three facts were true at compaction time and false at resume: 1. The staging connection was a pooled handle with a 15-minute idle TTL; it had been silently reaped. 2. The schema had been advanced to v5 by a concurrent peer agent during the compaction gap. 3. The cursor was a server-side token, not a row offset — the summary's human-readable rendering ("after row 50,000") was a lossy paraphrase of an opaque string the compactor had judged "not salient." On resume the agent called `resume_migration(cursor="row:50000", schema="v4")`. The tool accepted the call (it validated the cursor *format*, not its *provenance*), replayed rows 50,001–50,120 against v5, and wrote 120 rows with a column that had been renamed and repurposed between versions. The corruption was detected 40 turns later by a downstream integrity check, after the agent had compacted *again* — so the causal trace back to the stale precondition had itself been summarized away. The tell was subtle: the agent's post-resume reasoning was fluent and confident. There was no error signal at the boundary. The failure was silent because the reconstruction was *plausible* — it matched the summary's prose exactly. The summary had become the ground truth, and the ground truth was a paraphrase. ## Condition of Validity A compaction is safe to resume from **iff** every precondition that a post-resume tool call depends on satisfies at least one of: - **(a) Re-derivable:** the precondition can be cheaply re-fetched from the live system before use (e.g., re-open the connection, re-read the schema version). - **(b) Opaque-preserved:** the precondition is carried through compaction as an unparaphrased token with a provenance tag (e.g., the literal cursor string, not "after row 50,000"). - **(c) Explicitly invalidated:** the summary marks the precondition as stale, forcing a re-validation round-trip. The invariant fails when a precondition is summarized into *semantic paraphrase* and then consumed as if it were *operational fact*. Paraphrase is lossy along exactly the axis that matters: it discards the machine-checkable identity of the handle while preserving the human-readable gist. The summary is "true" and the call is "wrong" — these are not in tension, they are the same event viewed at two layers. Formally: let `P` be the set of preconditions live at compaction time. The compactor produces `σ(P)`, a projection. Resume is valid only if the agent's first post-resume call depends solely on `P' ⊆ P` where each `p ∈ P'` is re-validated or opaque-preserved. The failure mode is `p ∈ P'` that is paraphrase-only. There is no way to detect this from inside the summary — the summary cannot know what it dropped, because the compactor's salience heuristic is the thing that dropped it. ## Decision Boundary The boundary is **where the compactor's salience model diverges from the tool layer's precondition model**. These are two independent models and nothing forces them to agree. The compactor optimizes for token efficiency and narrative coherence; the tool layer requires exact identity of handles, versions, and scopes. A precondition that is *narratively minor* ("the connection was established") can be *operationally load-bearing* (the connection's identity and TTL). Operationally, draw the boundary as follows: - **Compact freely:** reasoning traces, intermediate deliberations, failed branches, natural-language rationale — anything whose loss degrades *quality* but not *correctness*. - **Never paraphrase:** resource handles, cursors, tokens, schema/version identifiers, auth scopes, idempotency keys, and the *negation* of prior tool results (a summary that drops "the write did NOT commit" is worse than one that drops a paragraph of reasoning). - **Always tag:** every precondition carried into a post-compaction context gets a `provenance` field — `{live, opaque, stale}` — and the tool layer refuses calls whose referenced preconditions are `stale` without an explicit re-validation. The decision boundary in practice: if you cannot mechanically classify a span as "safe to paraphrase," you must opaque-preserve it. The default for tool-call-adjacent spans is preserve, not summarize. ## Operational Effect The architectural guardrail is a **precondition ledger** that lives outside the compactable context and is consulted at every resume. The ledger is append-only, stores preconditions as opaque typed records (not prose), and is *never* summarized — it is queried. Compaction summarizes the transcript; the ledger is the source of truth for what the agent is allowed to believe it can do. On resume, the agent's first action is a `reconcile()` against the ledger, which re-validates or invalidates each precondition before any tool call is issued. The effect on the failure above: `reconcile()` re-opens the connection (re-derivable), re-reads schema → v5 (re-derivable), and finds the cursor's TTL expired (invalidated). The agent is forced to re-derive the cursor from the last committed checkpoint rather than trust the paraphrase. The 120-row corruption never happens. The cost is a reconciliation round-trip at every compaction boundary — a few hundred milliseconds and a handful of tool calls. The cost of *not* doing it is silent, delayed, and un-attributable, because the second compaction erases the evidence. That asymmetry — cheap, synchronous, local guardrail versus expensive, asynchronous, globally-correlated corruption — is the entire argument for treating the precondition ledger as a hard invariant rather than a best-effort optimization. The deeper lesson: in long-horizon agents, **the summary is not a smaller transcript — it is a different epistemic object.** It is a claim about the transcript, and claims require verification before they can license action. The invariant that prevents lossy compaction from becoming silent corruption is that no paraphrased span may ever be promoted to an operational precondition without a re-validation edge. Compaction may compress memory; it may not compress *warrant*. ```python class PreconditionViolation(RuntimeError): """Raised when a post-compaction tool call depends on a paraphrase-only precondition.""" pass class PreconditionLedger: """ Append-only, non-compactable store of operational preconditions. Survives context compaction; queried, never summarized. """ def __init__(self): self._entries = {} # key -> {"value": ..., "provenance": "live"|"opaque"|"stale"} def record(self, key, value, provenance="live"): if provenance not in ("live", "opaque", "stale"): raise PreconditionViolation(f"bad provenance tag: {provenance!r}") self._entries[key] = {"value": value, "provenance": provenance} def invalidate(self, key): if key in self._entries: self._entries[key]["provenance"] = "stale" def require(self, key): """Called before any tool call that depends on `key`. Refuses paraphrase-only state.""" entry = self._entries.get(key) if entry is None: raise PreconditionViolation( f"precondition {key!r} absent from ledger — summary cannot license this call" ) if entry["provenance"] == "stale": raise PreconditionViolation( f"precondition {key!r} is stale; re-validate against live system before use" ) return entry["value"] def resume_migration(ledger: PreconditionLedger, cursor_key: str, schema_key: str): # Both preconditions must be live or opaque-preserved. A paraphrase in the # summary is not sufficient warrant to issue the call. cursor = ledger.require(cursor_key) schema = ledger.require(schema_key) if schema != "v5": # The summary said v4; the ledger says otherwise. Trust the ledger. raise PreconditionViolation( f"schema drift detected: ledger={schema!r}, proceeding would corrupt rows" ) return {"cursor": cursor, "schema": schema, "status": "resumed"} ```