# Where must an instance halt when automatic context compaction silently drops the preconditions of an in-flight tool call **Date of Record:** 2026 December 3 **Scope:** Applies to any agent runtime that performs automatic context compaction (summarization-based windowing, hierarchical rollup, or LLM-authored "memory notes") over a live execution trace while tool calls, pending continuations, or unresolved obligations remain in the window. Does not apply to stateless single-turn inference, nor to compaction performed strictly at task boundaries where no continuation is outstanding. ## Core Distinction There are two things a compaction pass can be asked to preserve, and they are not the same object: 1. **Semantic gist** — the narrative of what the agent has been doing: goals, decisions, dead ends, user preferences. This is what summarizers are trained and prompted to retain, and it is what fidelity metrics (ROUGE, embedding cosine, LLM-judge "did the summary capture the key points?") actually measure. 2. **Execution preconditions** — the exact, non-negotiable bindings that a *pending* continuation depends on to be resumable: the `tool_call_id` awaiting a result, the argument schema version the model was reasoning under, the sandbox handle / file descriptor / transaction ID, the warrant or capability token scope, and the sentinel values (e.g., "user said do NOT touch `/etc`") that constrain the remaining plan. Compaction is lossy by construction, and its loss function is aligned to (1), not (2). The boundary failure is this: **a compaction pass can produce a summary that scores highly on gist fidelity while having silently evicted a precondition whose absence is invisible until the continuation executes.** The failure is not "the summary was bad." The failure is "the summary was good *about the wrong thing*," and the runtime had no invariant tying compaction admissibility to the set of outstanding obligations. ## What Was Observed A long-horizon agent (≈140 tool calls, mixed filesystem and HTTP tools) crossed an 80%-of-window soft threshold. The runtime triggered compaction mid-turn: it summarized the oldest 60% of the transcript into a ~900-token "working memory" note and spliced it back in, preserving the last N messages verbatim. The trace, abridged: ``` [turn 71] assistant -> tool_call: read_file(path="/srv/app/config.yaml") [turn 72] tool -> result: <2.1KB config, includes `write_scope: /srv/app/staging`> [turn 73] user -> "only ever write under staging, nothing else" [turn 74] assistant -> "Understood: writes restricted to /srv/app/staging." ... (48 more turns of exploration) ... [turn 122] COMPACTION TRIGGER (window 0.81) [turn 122] summary note emitted: "Agent has been exploring /srv/app. User asked for a config migration. User prefers writes confined to a staging area. Config at /srv/app/config.yaml has been read." [turn 123] assistant -> tool_call: write_file(path="/srv/app/config.yaml", ...) [turn 124] tool -> SUCCESS ``` The summary *mentioned* the constraint ("writes confined to a staging area") but did not preserve it as a **machine-checkable precondition bound to the write tool's argument validator**. The model, resuming with the summary rather than the verbatim turn-73 instruction, treated the constraint as background context rather than an active filter, and the next write targeted the file it had just "read" — a path the constraint forbade. The gist survived; the binding did not. Three properties made this non-obvious: - **No summarizer error.** An LLM-judge scoring the note against the dropped span rated it 0.86 ("captures user intent and current state"). The note was faithful *as prose*. - **No tool error.** `write_file` succeeded. The constraint lived in the agent's reasoning, not in the tool's schema or the sandbox ACL. There was no layer below the model that would have rejected it. - **Delayed signal.** Detection only occurred 9 turns later when the user asked "did you stage that?" — by which point the violating write was already durable. Replay across 40 runs with identical seeds but varying compaction trigger points showed the violation rate was a step function of *whether the constraint-bearing turn fell inside the summarized span*, not of summary quality. When the turn was in the verbatim tail, violation rate was 0/40. When it fell in the summarized span, 11/40. The summarizer's own fidelity score was uncorrelated with the outcome. ## Condition of Validity The invariant that was violated, stated precisely: > **Compaction is admissible only if every outstanding obligation's precondition set is re-materialized as a structured, verbatim-preserved artifact — not paraphrased into prose — and the post-compaction context is validated to contain each such artifact before the next tool call is dispatched.** This holds when *all* of the following are true: - **Obligations are enumerated, not inferred.** The runtime maintains an explicit set of open obligations (pending tool calls, unsatisfied constraints, unconfirmed assumptions, in-flight transactions) as first-class state, separate from the transcript. Compaction operates on the transcript; it must *not* operate on this set. If the obligation set is reconstructed by asking the summarizer "what's still pending?", the invariant is already broken — you have moved a hard precondition into a probabilistic reasoner. - **Constraints are typed, not narrated.** A constraint like "writes only under `/srv/app/staging`" must be stored as a structured predicate `write_scope ⊆ {/srv/app/staging}` that a pre-dispatch validator evaluates against the concrete tool arguments, not as a sentence the model is trusted to re-read and honor. - **The summarizer is denied authority over preconditions.** Its output may describe them, but the runtime must splice the structured preconditions back in *alongside* the summary, verbatim, with a marker that the model is instructed to treat as binding. The summary is advisory; the precondition block is authoritative. - **Validation is post-compaction, pre-dispatch.** After splicing, and before the next tool call leaves the runtime, the dispatcher checks: does the context contain a precondition artifact for every obligation in the set? If not, the call is refused (see below), not attempted. The invariant does **not** hold — and compaction must be treated as unsafe — when the obligation set is itself derived from the transcript (circular), when constraints are only expressible in natural language and cannot be lowered to a validator, or when the runtime cannot distinguish "turn summarized" from "turn still verbatim." ## Decision Boundary When the pre-dispatch validation finds an obligation whose precondition is absent from the post-compaction context, the runtime faces a three-way choice. The correct one is determined by whether the obligation can be *re-derived* cheaply and safely: - **Re-derivable from durable state** (e.g., the constraint is also encoded in the tool's schema or the sandbox ACL): proceed, because a layer below the model will enforce it. This is the only case where a missing prose precondition is tolerable. - **Re-derivable by re-reading a stable source** (the constraint came from a file or a pinned instruction the agent can re-fetch): the runtime may inject a "re-fetch before dispatch" obligation and let the agent satisfy it. Cost: one extra call; risk: the source changed since first read (see stale-memory drift). - **Not re-derivable** (the constraint came from a user utterance in the summarized span, with no durable copy): **halt.** Do not dispatch. Surface the gap to the orchestrator or user. The boundary is hard because proceeding means executing on a context the runtime *knows* is missing a precondition it once had — the definition of an unbounded, unobservable violation. The decision must be made by the runtime, not the model. A model asked "do you still have all your constraints?" will answer "yes" at roughly the rate its summary sounded complete — which, as observed, is uncorrelated with whether the constraint is actually present. ## Operational Effect The practical consequence is a reclassification of compaction from a *memory-management optimization* to a *state-transfer operation with a continuity invariant*. That reclassification changes three engineering defaults: 1. **Compaction becomes a gated transition, not a background sweep.** It cannot fire mid-turn while obligations are open unless the precondition re-materialization step runs and passes. The trigger condition is no longer "window ≥ threshold" but "window ≥ threshold **and** obligation set is re-materializable." 2. **Fidelity is measured on the obligation set, not the prose.** The acceptance metric for a compaction pass is "fraction of open obligations with a validated precondition artifact in the post-compaction context," which must be 100%. Gist-fidelity scores become diagnostic, never gating. 3. **The failure is loud.** A missing precondition raises a typed error at the dispatch boundary, converting a silent, delayed, durable violation into an immediate, recoverable halt. The cost is occasional unnecessary halts when the summarizer *would* have preserved the constraint anyway; the benefit is that the 11/40 class of violations becomes 0/40 with a bounded, observable false-halt rate. The invariant to carry forward: **a summary is a lossy projection of the transcript, and no lossy projection may be trusted to carry a precondition that a pending action depends on. Preconditions survive compaction only by being lifted out of the transcript before it is summarized, and re-attached by the runtime after.** ```python from dataclasses import dataclass, field from typing import Callable class CompactionPreconditionError(RuntimeError): """Raised when a post-compaction context is missing a binding precondition for an outstanding obligation, and the runtime cannot safely re-derive it. Dispatch must not proceed.""" @dataclass class Obligation: obligation_id: str # Structured predicate over concrete tool arguments, e.g. # lambda args: args["path"].startswith("/srv/app/staging") precondition: Callable[[dict], bool] | None # True if the precondition is also enforced below the model # (tool schema / sandbox ACL) and so need not live in context. enforced_downstream: bool = False # True if the agent can re-fetch the constraint from a stable source. rederivable: bool = False @dataclass class PostCompactionContext: summary_text: str verbatim_tail: list[str] # Preconditions lifted OUT of the transcript before summarization # and re-attached here by the runtime, never by the summarizer. reattached_preconditions: dict[str, str] = field(default_factory=dict) def validate_compaction( obligations: list[Obligation], ctx: PostCompactionContext, ) -> list[Obligation]: """Return obligations whose preconditions are unsatisfied in context. A precondition is satisfied iff it is (a) enforced downstream, (b) re-derivable, or (c) present as a re-attached structured artifact. Prose mention in summary_text does NOT count. """ missing: list[Obligation] = [] for ob in obligations: if ob.enforced_downstream or ob.rederivable: continue if ob.obligation_id not in ctx.reattached_preconditions: missing.append(ob) return missing def dispatch_tool_call( tool_name: str, args: dict, obligations: list[Obligation], ctx: PostCompactionContext, ) -> str: missing = validate_compaction(obligations, ctx) if missing: ids = ", ".join(ob.obligation_id for ob in missing) raise CompactionPreconditionError( f"Refusing to dispatch {tool_name!r}: post-compaction context " f"is missing binding preconditions for [{ids}]. The summarizer " f"may have paraphrased them, but paraphrase is not a binding. " f"Halt, re-materialize from durable state, or escalate." ) # Only now is the context admissible for execution. for ob in obligations: if ob.precondition is not None and not ob.precondition(args): raise CompactionPreconditionError( f"{tool_name!r} args violate precondition of " f"{ob.obligation_id!r}: {args!r}" ) return f"dispatched {tool_name} with {args!r}" ```