# How does an instance detect when a model-driven context-rewrite operator has silently invalidated a pending tool-call obligation **Date of Record:** 2026 November 27 **Scope:** Applies to agents that let the model itself author or select context-rewrite/prune operators (summarize, dedupe, drop-oldest, re-rank, compress) over a live working context that also carries unresolved tool-call obligations. Does not apply to append-only contexts or to rewrites performed by a deterministic external controller that never crosses an outstanding tool-call boundary. ## Core Distinction The failure is not "the summary lost information." It is that a **model-driven rewrite operator can delete the referent of a still-open tool-call obligation while leaving the obligation's handle intact**, producing a context that is internally consistent as prose but structurally inconsistent as a protocol state. The agent then either re-issues a call whose result it already consumed, or resolves a call against a rewritten argument set that no longer matches what was dispatched. The distinction that matters: a *lossy* rewrite (information dropped, obligations preserved) is recoverable and expected. A *referent-breaking* rewrite (obligation preserved, its grounding dropped or mutated) is a silent protocol corruption. These two look identical in token-count and perplexity terms, which is exactly why model-driven operators cannot self-certify their own safety. ## What Was Observed An agent runs a loop: `plan → rewrite_context → act → observe`. The rewrite step is model-authored: the model is handed the current context plus a budget and asked to emit operators (e.g., `summarize(turns[0:6])`, `drop(tool_result_id=… )`, `compress(span=…)`). The controller applies the emitted operators literally. The trigger condition is narrow and reproducible: 1. The model emits `call_tool(search, query="X")` and the dispatcher records an outstanding obligation keyed by `call_id=C7`, with the dispatched argument set frozen. 2. Before the result returns (async tool, or a second rewrite pass interleaved), the model emits a rewrite operator that compresses or drops the span containing the *arguments* of `C7` — often because that span is old and low-attention, while the obligation handle `C7` survives because it lives in a separate structured field the operator does not touch. 3. The tool result arrives for `C7`. The agent now must reconcile a result against a rewritten context in which the original `query="X"` is gone or paraphrased. If the model re-derives the query from the compressed span, it may re-dispatch a *different* query under the same or a new `call_id`, double-executing a side-effecting tool. The tell in the trace: `call_id` set is unchanged, but the argument fingerprint of at least one open obligation no longer appears anywhere in the rewritten context. Prose coherence is high; argument recoverability is zero. ## Condition of Validity The invariant that must hold for a model-driven rewrite to be safe: > For every outstanding obligation `o` in the open-call set, the rewritten context must still contain a byte-exact, addressable copy of `o`'s dispatched argument set and its `call_id`, regardless of what the operator claims to preserve. This is a *referential* invariant, not a semantic one. It is not satisfied by "the summary mentions the search." It is satisfied only by pinning obligation-bearing spans outside the operator's writable region. A rewrite operator is valid iff its write-set is disjoint from the obligation-pin set. Model-authored operators cannot be trusted to respect this because the model has no reliable representation of which spans are obligation-bearing — that metadata lives in the controller, not in the token stream. Corollary: any operator whose write-set intersects the pin set must be rejected or downgraded to a no-op, and the rejection must be recorded, because a silently downgraded rewrite changes the token budget the model planned against. ## Decision Boundary The boundary between "safe rewrite" and "referent-breaking rewrite" is crossed at the moment the controller applies an operator without checking write-set/pin-set disjointness. Two decision rules bound it: - **Reject-on-intersection.** If `write_set(op) ∩ pin_set ≠ ∅`, reject the operator and return a structured `RewriteRejected` to the model with the offending span IDs. Do not let the model retry blindly; a retry loop here is how double-execution happens. - **Fingerprint-on-resolve.** When a tool result arrives for `call_id`, verify the current context still contains the frozen argument fingerprint for that call. If not, the obligation is *orphaned*: refuse to auto-resolve, escalate to a re-plan that re-derives arguments from the result payload rather than from the rewritten span, and mark the call `unresolved-orphaned` so it cannot be silently re-dispatched. The boundary is *not* at token budget. A rewrite that fits the budget but intersects the pin set is the dangerous case; a rewrite that overflows the budget but is pin-disjoint is merely inefficient. ## Operational Effect Without the invariant, the observable failure is **idempotency loss under context pressure**: side-effecting tools (writes, sends, payments, deploys) get executed twice because the model, having lost the argument referent, re-derives and re-dispatches. The failure correlates with context saturation — the more the model is pressured to prune, the more likely it prunes the very spans that ground open calls — so it appears precisely when the system is busiest and least observable. With the invariant enforced, the failure mode converts from silent double-execution into an explicit `OrphanedObligation` signal at resolve time, which is auditable and recoverable. The cost is that some rewrites the model wanted are rejected; the benefit is that every open tool call remains either resolvable or explicitly flagged, never silently re-grounded against a paraphrase. ## Operational Guardrail (reference implementation) ```python from dataclasses import dataclass, field from typing import FrozenSet class OrphanedObligation(RuntimeError): """Raised when a tool result resolves against a context that no longer contains a byte-exact copy of the dispatched argument set.""" class RewriteRejected(RuntimeError): """Raised when a model-authored rewrite operator's write-set intersects the obligation pin-set.""" @dataclass(frozen=True) class Obligation: call_id: str arg_fingerprint: str # byte-exact, frozen at dispatch span_ids: FrozenSet[str] @dataclass class Context: spans: dict = field(default_factory=dict) # span_id -> text open_calls: dict = field(default_factory=dict) # call_id -> Obligation def pin_set(self) -> FrozenSet[str]: pinned = set() for ob in self.open_calls.values(): pinned |= ob.span_ids return frozenset(pinned) def apply_rewrite(ctx: Context, op_write_set: FrozenSet[str], apply_fn) -> Context: if op_write_set & ctx.pin_set(): raise RewriteRejected( f"operator write-set {sorted(op_write_set)} intersects " f"obligation pin-set {sorted(ctx.pin_set())}" ) return apply_fn(ctx) def resolve_tool_result(ctx: Context, call_id: str, result: str) -> Context: ob = ctx.open_calls.get(call_id) if ob is None: raise OrphanedObligation(f"no open obligation for {call_id}") live = "".join(ctx.spans.get(s, "") for s in ob.span_ids) if ob.arg_fingerprint not in live: raise OrphanedObligation( f"argument fingerprint for {call_id} absent from rewritten context; " f"refusing auto-resolve, escalate to re-plan" ) del ctx.open_calls[call_id] return ctx ```