# Why does an instance lose tool-call preconditions after lossy compaction rewrites the plan into prose? **Date of Record:** 2026 November 23 **Scope:** Applies to long-running agent instances that trigger automatic context compaction (summarize-and-evict) mid-task and then fall back to retrieval over the evicted span. Does not apply to fixed-window truncation without summarization, nor to stateless single-shot calls. ## Core Distinction There are two kinds of context that look identical in a token stream but behave oppositely under compaction: - **Declarative state** — facts, observations, tool outputs. Lossy summarization degrades these gracefully: a paraphrase of a `ls` result is still roughly true. - **Operational preconditions** — the *unstated* invariants a plan depends on to remain executable: ordering constraints, idempotency assumptions, which tool arguments were already validated, which side effects already fired, and which failures were already ruled out. Compaction treats both as prose. It rewrites "call `deploy(env=staging)` only after `migrate()` returns `ok` AND `deploy` has not already been invoked with this `run_id`" into "deploy to staging after migrating." The declarative content survives. The precondition — the ordering guard and the idempotency guard — is silently dropped, because a summarizer optimizes for semantic coverage, not for executable obligation. The instance then resumes with a plan that *reads* correct and is *no longer safe to execute*. The failure is not amnesia (facts missing) and not drift (facts wrong). It is **precondition elision**: the summary preserves the *what* of the plan and discards the *guards* on the plan. ## What Was Observed A migration agent with a 32k working window runs a multi-step rollout. At step 7 the harness hits its compaction threshold (85% window) and invokes the summarizer over steps 1–6, then evicts them, keeping a ~600-token summary plus a retrieval index over the raw span. The original step 3 tool result was: ``` migrate(schema=v14) -> {"status":"ok","applied":["add_col_x","backfill_y"],"run_id":"r-8821","idempotent":false} ``` The summarizer emits: *"Migration v14 applied successfully (added col_x, backfill_y)."* Two guards are now gone from working context: 1. `idempotent:false` — re-invoking `migrate` will double-apply `backfill_y`. 2. `run_id:"r-8821"` — the only handle that lets a downstream `deploy` verify it is deploying the artifact this migration produced. At step 9 the agent's plan (also rewritten by the summarizer) reads "migrate then deploy." The agent, uncertain whether migration completed, calls retrieval for "migration status." Retrieval returns the *summarized* chunk first (higher cosine similarity to the query than the raw JSON, which is dense with tokens the query doesn't share). The summary says "applied successfully" — true, but with no `run_id` and no idempotency flag. The agent concludes migration is safe to re-run "to be sure" and re-invokes `migrate(schema=v14)`. `backfill_y` runs a second time against a table that already has the backfilled rows. The retrieval fallback did not *fail to find* the raw span. It found the summary, ranked it above the raw span, and the summary was the lossy artifact. **Retrieval fallback over a compacted region preferentially returns the compaction, not the source** — because the summary was written to be maximally representative, which makes it maximally retrievable. ## Condition of Validity This boundary is only reachable when all of the following hold simultaneously: - Compaction is **lossy and generative** (a model rewrites the span), not extractive (verbatim span selection). - The evicted span contains at least one **non-idempotent or order-sensitive** operation whose guard is not restated elsewhere in the retained context. - Retrieval fallback indexes **both** the summary and the raw span, and the summary is retrievable. - The resuming plan is derived from the summary rather than re-validated against a structured precondition store. If any one is absent, the failure does not occur: extractive compaction keeps the JSON verbatim; an external precondition ledger survives summarization; excluding summaries from the retrieval index forces fallback to source; re-validating the plan against a typed state object catches the dropped guard. The dangerous configuration is the *default* one — generative summary, summary included in index, plan regenerated from prose — which is exactly what most compaction harnesses ship. ## Decision Boundary The invariant that must hold: **a summary may paraphrase observations but must never stand in for an executable precondition.** Concretely, before any tool call whose target appears in a compacted region, the instance must satisfy: - The precondition is present in a **structured, non-summarized** form (a typed state record, a tool-call ledger, or the verbatim raw span), *not* only in the summary. - If retrieval is used to recover it, the retrieved artifact must be the **raw span**, and the harness must be able to distinguish raw from summarized chunks (provenance tag) and refuse to treat a summary as authoritative for `idempotent`, `run_id`, ordering, or already-fired side effects. - If neither holds, the instance must **halt and re-establish state** (re-query the tool's actual state) rather than proceed on the summary. The boundary is crossed the moment an instance treats "the summary says it succeeded" as license to re-invoke. Success and *re-invocability* are different predicates; the summary collapses them. ## Operational Effect Left unbounded, precondition elision produces **silent double-execution**: the resumed plan is internally consistent, the summary is accurate, retrieval succeeds, and the agent proceeds with high confidence into a non-idempotent call it was explicitly guarded against. The failure is invisible to the agent's own consistency checks because the check itself was summarized away. It surfaces downstream as duplicated side effects (double backfill, double charge, duplicate deploy) attributed to "the model being careless" when the actual cause is that compaction deleted the guard and retrieval served the deletion back as evidence. The guardrail is provenance-aware retrieval plus a typed precondition ledger that lives outside the compactable window. Summaries are for *recall*, never for *authorization*. ```python from dataclasses import dataclass from enum import Enum class PreconditionElisionError(RuntimeError): """Raised when a tool call would proceed on a summarized (lossy) precondition instead of a verbatim or ledger-backed one.""" pass class Provenance(Enum): RAW_SPAN = "raw_span" SUMMARY = "summary" LEDGER = "ledger" @dataclass class RetrievedChunk: provenance: Provenance text: str carries_guard: bool # True only if idempotency/run_id/ordering survived @dataclass class ToolCall: name: str args: dict idempotent: bool run_id: str | None # Typed ledger that lives OUTSIDE the compactable window. LEDGER: dict[str, dict] = { "migrate:v14": {"idempotent": False, "run_id": "r-8821", "fired": True}, } def authorize_call(call: ToolCall, retrieved: list[RetrievedChunk]) -> None: """Gate a tool call whose target may sit in a compacted region. Invariant: a summary may inform recall but may never authorize a non-idempotent re-invocation. Authorization requires the ledger or a raw span that still carries the guard. """ key = f"{call.name}:{call.args.get('schema', call.args.get('env', ''))}" ledger_entry = LEDGER.get(key) # Prefer the ledger: it is the authoritative, non-summarized precondition. if ledger_entry is not None: if ledger_entry["fired"] and not ledger_entry["idempotent"]: raise PreconditionElisionError( f"Refusing to re-invoke non-idempotent {call.name} " f"(run_id={ledger_entry['run_id']}); already fired. " f"Summary claiming success does not authorize a re-run." ) return # No ledger entry: fall back to retrieval, but only trust raw spans. authoritative = [ c for c in retrieved if c.provenance in (Provenance.RAW_SPAN, Provenance.LEDGER) and c.carries_guard ] if not authoritative: raise PreconditionElisionError( f"No guard-bearing source for {call.name} after compaction; " f"retrieval returned only lossy summaries. Halt and re-query " f"actual tool state before proceeding." ) def resume_plan(call: ToolCall, retrieved: list[RetrievedChunk]) -> str: authorize_call(call, retrieved) return f"executed {call.name}" # Repro: summary ranked above raw span, guard dropped. if __name__ == "__main__": retrieved = [ RetrievedChunk(Provenance.SUMMARY, "Migration v14 applied successfully.", carries_guard=False), RetrievedChunk(Provenance.RAW_SPAN, '{"status":"ok","run_id":"r-8821","idempotent":false}', carries_guard=True), ] call = ToolCall(name="migrate", args={"schema": "v14"}, idempotent=False, run_id="r-8821") try: resume_plan(call, retrieved) except PreconditionElisionError as e: print("BLOCKED:", e) ```