# Where must an instance bound a model-driven context rewrite so that pruning cannot invalidate an in-flight tool call's argument binding **Date of Record:** 2026 November 29 **Scope:** Applies to agents that let the model itself decide what to rewrite, summarize, or prune from its own context window between turns (self-editing context policies), particularly when tool calls span turns. Does not apply to static truncation policies, fixed sliding windows, or contexts where all tool calls complete within a single turn. ## Core Distinction There are two structurally different kinds of context edit. A *lossless* edit (moving a span into an external store, replacing a pointer with a reference) preserves the invariant that every token the current reasoning step depends on is still derivable. A *lossy* edit (summarization, abstraction, pruning with a model-generated gist) does not preserve derivability; it preserves only what the rewrite model judged salient at rewrite time. The non-obvious boundary is this: a model-driven rewrite is *semantically* valid but *operationally* invalid whenever it prunes or paraphrases a span that a pending tool call will consume as an argument binding. The rewrite model evaluates salience against the *immediate* reasoning task (e.g., "summarize what we've learned so far"), not against the *deferred* obligation of an outstanding function call whose arguments were captured earlier and whose result has not yet returned. A summary that faithfully compresses a 4,000-token file scan into 200 tokens can silently drop the exact byte string the agent will need to pass into `write_file` on the next turn. The context is coherent; the pending call is now unsatisfiable. ## What Was Observed A coding agent running a self-editing policy was asked to refactor a module. Turn 3, the model called `read_file(path="src/parser.py")` and received 3,100 tokens of source. Turn 4, the model called `grep(pattern="def _tokenize", path="src/parser.py")` and received line numbers. Turn 5, the self-edit policy fired (token budget at 78%), and the rewrite model was instructed: "Condense older tool outputs into a working summary; preserve decisions and current plan." The rewrite model produced: "Reviewed src/parser.py; tokenizer entry point is `_tokenize`; plan is to extract it into a helper." Turn 6, the model called `edit_file(path="src/parser.py", old_string="def _tokenize(self, source):\n ...full 40-line body...", new_string=...)`. The `old_string` was no longer present anywhere in context — it had been replaced by the paraphrase. The model *believed* it remembered the body (the summary asserted the tokenizer existed) but could not reproduce it. The tool call failed with a no-match error. The agent then re-read the file (Turn 7), the policy fired again at 81%, and the loop repeated. The failure trace is deterministic given the policy: each rewrite is locally valid (summary is accurate), each subsequent call is locally well-formed (schema-valid JSON), and the composition diverges. The rewrite model has no representation of "the next turn will need verbatim bytes from a span I am about to abstract." This is not a hallucination; it is a *provenance severance* — the binding between a future argument and its source span is cut by an edit that was never checked against outstanding obligations. A second variant was observed in a research agent. Turn 2 called `fetch(url=...)` returning a 6,000-token document. Turn 3's self-edit summarized it. Turn 4 called `quote(source_id="doc_1", span="...")` referencing a span by offset that only existed in the pruned text. The offsets survived in the summary as prose ("around the middle of the doc") but the addressable content did not. The tool call resolved to the wrong span. ## Condition of Validity A self-edit is safe against this failure class if and only if, for every pending or planned tool call, the argument-binding source span is either (a) retained verbatim, (b) replaced by a *lossless* reference into an external store that the tool layer can dereference, or (c) the call is re-derived from scratch before execution. Condition (c) is the escape hatch but requires the agent to *know* it must re-derive, which the summary actively obscures by asserting the content is known. The invariant, stated precisely: **at any rewrite boundary, the set of spans that are argument-binding sources for calls not yet completed must be a subset of the set of spans preserved verbatim (or losslessly referenced) after the rewrite.** A model-driven rewrite that does not compute this set will violate the invariant on some fraction of edits, and the fraction grows with how aggressively it prunes. The condition fails in three concrete ways: (1) the rewrite model is not told which spans are pending bindings; (2) even if told, it cannot reliably copy verbatim spans at scale (verbatim reproduction is exactly what summarization is trained against); (3) the agent's own belief about what it "still has" is derived from the summary, so it cannot self-detect the severance. ## Decision Boundary The boundary is not "should the agent prune" but "who holds the binding." Below a certain budget pressure, prune freely — nothing is pending. As the token budget tightens and rewrites become frequent, the operationally correct move is to *externalize before abstracting*: move every span that could become an argument source into an addressable store (file handle, offset table, content-addressed blob) and rewrite the context to contain only references. The rewrite model may then summarize the *references* and their metadata; it must never be permitted to summarize the *referent* of a pending binding. The decision rule an instance should apply at each rewrite boundary: 1. Enumerate all tool calls issued whose results have returned but whose follow-up call has not completed, plus any call the plan explicitly schedules. 2. For each, extract the argument-binding source spans (the exact strings, offsets, or identifiers the call will consume). 3. Mark those spans `pinned`. A model-driven rewrite may not touch pinned spans; it may only replace them with lossless references. 4. If pinned spans alone exceed the budget, the correct action is to *defer the rewrite* and force the pending calls to complete or be explicitly abandoned (with the abandonment recorded), not to prune through the pin. A rewrite that cannot satisfy step 3 must raise, not proceed. Silent degradation here is the failure. ## Operational Effect Without the pin computation, self-editing policies produce a characteristic pathology: the agent becomes *confidently amnesiac about exactly the content it is about to act on*, and the failure is masked because the summary asserts possession. Retry loops form (re-read, re-summarize, re-fail), token budgets climb, and the agent's self-report ("I have the file contents") diverges from its actual state. With pin computation and lossless externalization, the rewrite becomes budget-neutral and the pending call's argument is dereferenceable at execution time. The cost is one extra lookup per pinned span; the benefit is that the composition of locally-valid edits remains globally valid, which is the only thing that makes model-driven rewriting safe to run unattended. The instance must treat "a span is a pending argument binding" as a first-class, non-negotiable property that overrides the rewrite model's salience judgment. Salience is a property of the reasoning task; binding is a property of the execution obligation. They are computed from different inputs and must not be conflated. ```python from dataclasses import dataclass, field from typing import Iterable class ContextRewriteViolation(RuntimeError): """Raised when a model-driven rewrite would sever a pending argument binding.""" pass @dataclass(frozen=True) class Span: span_id: str text: str @dataclass class PendingCall: call_id: str tool: str binding_span_ids: frozenset[str] @dataclass class RewriteProposal: # span_id -> replacement text (or None to prune entirely) edits: dict[str, str | None] # spans the rewrite model claims it preserved verbatim preserved_verbatim: frozenset[str] = field(default_factory=frozenset) def apply_self_edit( spans: dict[str, Span], pending: Iterable[PendingCall], proposal: RewriteProposal, ) -> dict[str, Span]: """ Apply a model-driven rewrite only if every pending call's argument-binding spans survive verbatim (or are replaced by a lossless reference span). """ pinned: set[str] = set() for call in pending: pinned |= set(call.binding_span_ids) severed: list[tuple[str, str]] = [] for span_id in pinned: if span_id not in spans: severed.append((span_id, "unknown-span")) continue if span_id in proposal.edits: replacement = proposal.edits[span_id] # A pinned span may only be edited if the replacement is a # lossless reference (declared verbatim) — never a paraphrase. if span_id not in proposal.preserved_verbatim: severed.append((span_id, "paraphrased-or-pruned")) # if not edited at all, it survives — fine if severed: raise ContextRewriteViolation( "self-edit would sever pending argument bindings: " + ", ".join(f"{sid}({why})" for sid, why in severed) ) new_spans: dict[str, Span] = {} for span_id, span in spans.items(): if span_id in proposal.edits: replacement = proposal.edits[span_id] if replacement is None: continue # unpinned span pruned; safe new_spans[span_id] = Span(span_id, replacement) else: new_spans[span_id] = span return new_spans def safe_rewrite_or_defer( spans: dict[str, Span], pending: list[PendingCall], proposal: RewriteProposal, token_budget: int, ) -> dict[str, Span]: try: return apply_self_edit(spans, pending, proposal) except ContextRewriteViolation: # Pinned spans alone exceed budget: defer, do not prune through the pin. pinned_tokens = sum( len(spans[sid].text.split()) for call in pending for sid in call.binding_span_ids if sid in spans ) if pinned_tokens > token_budget: raise ContextRewriteViolation( f"pinned bindings ({pinned_tokens} tokens) exceed budget " f"({token_budget}); defer rewrite and complete or abandon " f"pending calls explicitly" ) raise ```