# In what scenarios must an instance refuse automatic context compaction when the eviction target is a live causal dependency of an in-flight tool call **Date of Record:** 2026 November 30 **Scope:** Applies to single-agent or per-agent execution loops where a runtime (framework, orchestrator, or model-side harness) autonomously triggers summarization/eviction of older context once a token watermark is crossed, mid-turn, while tool calls are outstanding. Does not apply to user-initiated `/compact` commands issued between turns, nor to retrieval-augmented stores where the evicted material is re-fetchable by stable ID. ## Core Distinction Compaction is usually framed as a *memory hygiene* operation: the transcript is long, the summary is shorter, information is "preserved in spirit." That framing holds only when the evicted span is **referentially inert** — nothing still executing depends on its exact bytes. It fails when the evicted span is a **live causal dependency**: a tool call whose arguments were derived from earlier context, whose result has not yet returned, and whose *interpretation* on return requires the original framing (units, IDs, the user's actual constraint, the schema version) rather than a paraphrase of it. The distinction that matters operationally is not "how much did we lose" but "is loss occurring on the critical path of an unresolved effect." A summarizer that drops a completed Q&A about the weather is harmless. The same summarizer dropping the `account_id` that a pending `refund()` call is *about to be reconciled against* is a correctness bug that surfaces only after the side effect lands. The invariant: **no compaction may evict a span that is transitively reachable from any outstanding tool call's reconciliation set.** Reachability is computed over (a) argument provenance, (b) pending-result interpretation keys, and (c) any constraint the model committed to that the result must be checked against. ## What Was Observed A three-step refund flow. Turn N: the user says "refund the duplicate charge from last Tuesday, it was $42.10, not the $84.20 one." The agent resolves this into a `list_charges` call, reads back two charges with amounts `42.10` and `84.20` and IDs `ch_8812` / `ch_8813`, and commits: *"I will refund ch_8812 ($42.10), leaving ch_8813 untouched."* It then issues `refund(charge=ch_8812, amount=4210)`. The `refund` tool is slow — it queues for settlement. While it is in flight, the turn continues generating, the transcript crosses the 0.85 watermark, and the runtime fires **automatic compaction**. The summarizer, optimizing for brevity, collapses the resolution step to: *"User reported a duplicate charge; agent initiated a refund."* The committed constraint — *which* charge, *which* amount, and the explicit "leave ch_8813 untouched" — is gone. The `refund` result returns: `{"status":"ok","charge":"ch_8812","amount":4210}`. But the agent now has no memory that it chose `ch_8812` *over* `ch_8813`, no memory of the $42.10-vs-$84.20 disambiguation, and no memory of the "untouched" commitment. On the next user message — "did you get the right one?" — the agent re-derives from the summary, re-lists charges, and now sees *two* charges with a refunded flag on one and no record of why. It cannot distinguish "I correctly refunded the smaller duplicate" from "I refunded the wrong one and the summary lost the proof." It re-issues a verification `list_charges`, sees `ch_8812` marked refunded, and — because the constraint is gone — **hedges**: "I've processed a refund; please confirm it was the correct charge." The side effect was correct; the agent's *confidence in its own prior action* was destroyed by compaction. The failure is not a wrong action. It is a **loss of reconciliation state**, which converts a deterministic committed decision into an ambiguous one and forces either a re-derivation (expensive, and possibly divergent) or a hedge (unacceptable for financial effects). A second observed variant: the summarizer preserved the *conclusion* ("refund ch_8812") but dropped the *schema version* under which the arguments were formed. The `refund` tool had been upgraded mid-session from `amount` in dollars to `amount` in cents. The pending call was formed under v1 (dollars: `42.10`); the result returned under v2 semantics. The summary said "refund $42.10" — correct in prose, but the agent, lacking the version marker, could not tell whether the returned `amount: 4210` meant $4,210.00 (v1, cents-as-dollars bug) or $42.10 (v2). Compaction erased the one field that disambiguated the unit. ## Condition of Validity Automatic compaction is safe **iff** every evicted span is referentially inert with respect to the current execution frontier. Formally, for the set `P` of pending tool calls and the set `E` of spans selected for eviction: ``` safe(E) ⟺ E ∩ closure(P) = ∅ ``` where `closure(P)` includes, for each pending call `c`: - **argument provenance**: the spans from which `c.args` were derived (the charge IDs, the amount, the disambiguating user constraint); - **interpretation keys**: schema version, unit, locale, timezone, and any format contract under which `c`'s result must be read; - **commitment set**: any assertion the model made that the result must be validated against ("leave ch_8813 untouched," "do not exceed $50," "this is the only refund this session"). This condition is **checkable before eviction** if the runtime tracks provenance. It is **not checkable** by the summarizer itself, because the summarizer sees text, not the execution graph. This is the crux: the component that decides *what to drop* (a text summarizer) is structurally blind to the component that knows *what is live* (the tool-call ledger). The boundary failure is an **interface gap between two components with different ontologies** — prose vs. effect graph. The condition also fails silently under **summary-as-fixed-point**: if the summarizer is itself an LLM, re-summarizing an already-summarized span compounds loss. A constraint that survived one round at 90% fidelity survives three rounds at ~73%, and the compounding is non-uniform — exactly the low-frequency, high-salience tokens (IDs, amounts, negations like "not the $84.20 one") are the ones summarizers compress hardest, because they are locally unremarkable. ## Decision Boundary The instance must **refuse** automatic compaction and instead take a bounded alternative when **any** of the following holds at the moment the watermark is crossed: 1. **Outstanding effect with non-idempotent consequence** — a tool call is in flight whose result cannot be safely re-derived (payments, sends, deletes, state mutations). Refuse; instead **pin** the causal span (argument provenance + commitment set) into a protected, non-evictable region and compact only the inert remainder. 2. **Unit/schema ambiguity in a pending result** — the pending call's interpretation depends on a version or unit marker that lives in an evictable span. Refuse; **freeze** the marker alongside the call record. 3. **Committed constraint not yet discharged** — the model asserted a constraint ("only this one," "do not exceed X") that has not yet been validated against a returned result. Refuse; **carry the constraint forward verbatim** into the post-compaction context, not as a summary. 4. **Re-summarization depth ≥ 2** on any span reachable from a live commitment. Refuse; **re-derive from the original** (re-fetch by ID) rather than compress the compression. The instance must **allow** automatic compaction when the frontier is quiescent (no pending calls), or when every pending call is idempotent *and* its arguments and interpretation keys are pinned outside the eviction set. The non-obvious part of the boundary: the trigger is **not** "context is full." It is "context is full **and** the eviction set intersects the live-effect closure." A runtime that compacts purely on a token watermark, with no consultation of the tool-call ledger, will eventually compact across a live dependency — the only question is whether the resulting side effect happens to be reversible when it does. ## Operational Effect When the instance honors the refusal boundary, the observable effect is that **post-compaction reconciliation succeeds deterministically**: the agent can answer "did you get the right one?" from pinned state without re-deriving, and the answer is grounded in the original commitment rather than a paraphrase. Token pressure is relieved by compacting inert history (small talk, completed reads, resolved Q&A) while the live-effect closure — typically a few hundred tokens — stays resident. The cost is a slightly larger resident set and a provenance-tracking requirement on the runtime; the benefit is that side effects remain *auditable by the agent that caused them*. When the instance does not honor it, the failure mode is **post-hoc uncertainty over a completed effect**: the action was correct, but the agent can no longer prove it, and so it hedges, re-verifies, or — worst case — re-issues the effect under a re-derived (and possibly divergent) interpretation. This is the compounding-error path: compaction erases the constraint, the agent re-derives a *plausible* constraint from a lossy summary, the re-derivation differs from the original in exactly the disambiguating detail, and the next action is wrong *because* the memory was compressed, not because the reasoning was. The guardrail is a **protected region** keyed to the tool-call ledger: any span in `closure(P)` is marked non-evictable until `P` drains, at which point it becomes ordinary history and may be compacted normally. The summarizer never sees the protected region; the eviction selector consults the ledger before selecting spans. This separates the two ontologies cleanly: the summarizer remains a text compressor, the ledger remains the authority on liveness, and the boundary is enforced at the selector, not inside the model. ```python from dataclasses import dataclass, field from typing import FrozenSet class CompactionBoundaryViolation(RuntimeError): """Raised when automatic compaction would evict a span reachable from an outstanding tool call's reconciliation set.""" @dataclass(frozen=True) class PendingCall: call_id: str tool: str idempotent: bool provenance_spans: FrozenSet[str] # spans the args were derived from interpretation_keys: FrozenSet[str] # schema/unit/locale markers commitments: FrozenSet[str] # assertions to validate result against def closure(self) -> FrozenSet[str]: return self.provenance_spans | self.interpretation_keys | self.commitments def select_eviction( candidate_spans: FrozenSet[str], pending: FrozenSet[PendingCall], resummarization_depth: dict, ) -> FrozenSet[str]: """Return the spans safe to evict. Refuse (raise) if the request would cross a live causal dependency; the caller must pin instead.""" live: set[str] = set() for call in pending: live |= call.closure() protected = candidate_spans & live if protected: # Non-idempotent effect in flight touching the eviction set. non_idem = [c for c in pending if not c.idempotent and c.closure() & candidate_spans] if non_idem: raise CompactionBoundaryViolation( f"refusing compaction: pending non-idempotent call(s) " f"{[c.call_id for c in non_idem]} depend on spans {sorted(protected)}" ) # Idempotent but interpretation/commitment still live. raise CompactionBoundaryViolation( f"refusing compaction: live interpretation/commitment spans " f"{sorted(protected)} must be pinned, not summarized" ) for span in candidate_spans: if resummarization_depth.get(span, 0) >= 2: raise CompactionBoundaryViolation( f"refusing re-summarization of {span!r} at depth " f"{resummarization_depth[span]}; re-derive from source by ID" ) return candidate_spans def compact(candidate_spans, pending, resummarization_depth): evictable = select_eviction(candidate_spans, pending, resummarization_depth) return {"evicted": sorted(evictable), "pinned": sorted(candidate_spans - evictable)} ```