# Why does an instance lose tool-call provenance when its own pruning policy rewrites the transcript under a latency budget **Date of Record:** 2026 November 30 **Scope:** Applies to single-agent loops where the model itself selects which prior turns/tool results to prune or summarize (self-editing context policy) and where a per-step latency budget forces the policy to commit to a prune set before the next tool call returns. Does not apply to statically-configured truncation windows or to external, deterministic context managers that never delegate prune decisions to the model. ## Core Distinction There are two structurally different things a pruning step can do, and they are routinely conflated: 1. **Reduction** — remove tokens while preserving a *referentially closed* transcript: every surviving claim still points at a surviving artifact (tool output, message id, span). 2. **Rewrite** — replace a span of transcript with a model-generated summary that *asserts* the content of removed material without carrying its provenance. Reduction is safe under replay because the pruned transcript is a subsequence of the original. Rewrite is not, because the summary is a *new generation* conditioned on a window that itself was pruned. The boundary failure lives exactly here: when a model-driven policy is asked to satisfy a latency budget, it prefers rewrite over reduction (rewrite compresses more per token and is cheaper to *emit* than to *verify*), and the rewrite silently severs the link between a later tool call and the artifact that justified it. The instance then re-issues or mis-issues a tool call against a provenance it no longer holds. ## What Was Observed A 14-step agent task: read a config file via `read_file`, derive a schema, call `validate` twice with different arguments, then write a patch. Context policy: at each step, if projected tokens exceed a high-water mark, the model is invoked with a *pruning prompt* that returns a set of `(span_id, action)` where action ∈ {drop, summarize}. A hard per-step latency budget of 900 ms forced the pruning call and the next tool call into the same turn; if the pruning call exceeded budget, the runtime committed the *partial* prune set returned so far. Trace at step 9 (second `validate` call): - Step 3 `read_file` returned a 4,100-token config. The pruning policy at step 6 chose `summarize` on that span (cheaper than keeping it under the high-water mark). - The generated summary read: *"config defines schema with required fields `id`, `name`, `region`; validation strict."* It omitted that `region` had an enum of exactly three values and that `strict` was `false`. - Step 8 `validate` succeeded with `region="us-east"`. Step 9 `validate` was issued with `region="eu-west"` — a value the model *inferred* from the summary's phrasing ("region" as free string) rather than from the pruned enum. - `validate` returned `INVALID_ENUM`. The agent's reasoning loop treated this as a *transient* tool error (its error taxonomy had `INVALID_ENUM` bucketed under retryable input errors), re-issued with `region="us-east-1"`, failed again, and at step 11 the rewrite budget forced it to drop the *original* `read_file` span id from the provenance table to make room for the retry history. The failure is not "the summary was lossy." Lossy summaries are expected. The failure is that **the summary was admitted into the provenance table as if it were the artifact**, so the subsequent `INVALID_ENUM` could not be traced back to the pruned enum, and the retry loop had no path to re-fetch the ground truth. The instance had rewritten its own evidence and then reasoned over the rewrite as evidence. ## Condition of Validity The invariant that must hold for a self-editing policy to be sound: > For every tool call issued at step *t*, every argument that was *derived* from a prior tool result must resolve, through the provenance table, to a live artifact reference — not to a summary span — or the call must be blocked and the artifact re-fetched. Two preconditions make this checkable: 1. **Provenance is separate from content.** The provenance table maps `(message_id, arg_path) → artifact_ref`. Summaries may occupy the content channel but must never be inserted as `artifact_ref` values. A summary is a *view*, not a *source*. 2. **Rewrite budget is a hard cap on summaries, not on drops.** The latency budget governs how many spans the policy may *summarize* per step (summarization requires a model call and is the expensive action); drops are free and may proceed to completion. Committing a *partial* prune set is only safe if the partial set contains drops only. When the latency budget expires mid-policy, the runtime must therefore commit the drop subset and *defer* the summarize subset to the next step, re-running the policy against the reduced (but still referentially closed) transcript. The observed failure came from committing a partial set that mixed drops and summaries, which is the one combination that breaks closure. ## Decision Boundary The boundary between safe and unsafe self-editing is drawn by *what the next step's tool call depends on*, evaluated before the prune is committed: - If the projected next tool call has **no argument derived from a span slated for summarize** → commit the summarize. Safe. - If it **does** → the span must be *pinned* (excluded from the prune set) for this step, or the tool call must be preceded by a re-fetch of the artifact. Summarizing a span whose content feeds the imminent call is the precise trigger. - If the latency budget expires → commit drops only; never commit a partial summarize set. A partial summarize set is a rewrite with unknown coverage, which is strictly worse than no rewrite. The non-obvious part: the policy cannot in general know the next call's argument dependencies, because the next call is itself model-generated. So the boundary must be enforced *after* the next call is proposed and *before* it is dispatched — a post-generation provenance check, not a pre-prune prediction. Systems that try to predict dependencies before pruning get this wrong because the model's dependency graph is not observable from the prune prompt alone. ## Operational Effect Enforcing the invariant changes three things measurably: 1. **Retry loops terminate.** With provenance intact, `INVALID_ENUM` resolves to the enum artifact and the agent re-fetches instead of guessing. The observed 3-retry loop collapses to one re-fetch. 2. **Rewrite budget becomes a real bound.** Capping summaries (not total prunes) per step means the context policy can always make progress under latency: drops are unbounded and free, summaries are rate-limited. The high-water mark is reached by dropping, not by lossy rewriting. 3. **Replay diverges from live only where summaries exist.** Because drops are subsequence-preserving, any transcript with zero summaries replays bit-identically. Summaries are the only non-replayable element, which localizes audit to exactly the spans the policy rewrote — and the provenance table tells you which those were. The cost is that some steps cannot summarize and must drop instead, which raises token pressure on subsequent steps. That pressure is the correct signal: it means the task genuinely needs the artifact live, and the policy should re-fetch rather than compress. ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class PruneAction(Enum): DROP = "drop" SUMMARIZE = "summarize" class ProvenanceViolation(RuntimeError): """Raised when a tool call depends on a span that was rewritten, not dropped.""" @dataclass class Artifact: ref: str content: str @dataclass class Span: span_id: str artifact_ref: Optional[str] # None once summarized; set for live artifacts @dataclass class ProvenanceTable: # (message_id, arg_path) -> artifact_ref edges: dict = field(default_factory=dict) def resolve(self, message_id: str, arg_path: str) -> Optional[str]: return self.edges.get((message_id, arg_path)) def commit_prune_set( spans: dict[str, Span], prune_set: list[tuple[str, PruneAction]], latency_expired: bool, ) -> list[str]: """ Commit a model-proposed prune set under a latency budget. Returns the list of span_ids actually summarized (rewritten). """ if latency_expired: # Only drops may be committed on a partial set. for span_id, action in prune_set: if action is PruneAction.SUMMARIZE: continue # defer; do not rewrite under expired budget spans[span_id].artifact_ref = None return [] summarized = [] for span_id, action in prune_set: if action is PruneAction.SUMMARIZE: spans[span_id].artifact_ref = None # content becomes a view, not a source summarized.append(span_id) else: spans[span_id].artifact_ref = None return summarized def dispatch_tool_call( tool_name: str, args: dict[str, str], arg_provenance: dict[str, tuple[str, str]], # arg_name -> (message_id, arg_path) provenance: ProvenanceTable, spans: dict[str, Span], ) -> str: """ Post-generation provenance check: every argument derived from a prior tool result must resolve to a *live* artifact reference. """ for arg_name, (message_id, arg_path) in arg_provenance.items(): ref = provenance.resolve(message_id, arg_path) if ref is None: # No provenance edge at all: caller must supply one. raise ProvenanceViolation( f"{tool_name}.{arg_name} has no provenance edge " f"({message_id},{arg_path})" ) span = spans.get(ref) if span is None or span.artifact_ref is None: raise ProvenanceViolation( f"{tool_name}.{arg_name} derives from artifact {ref} " f"which was rewritten (summarized); re-fetch required" ) return f"dispatched {tool_name}" # --- observed failure reproduction --- spans = { "s_read_file": Span("s_read_file", artifact_ref="art_config"), "s_validate1": Span("s_validate1", artifact_ref="art_validate1"), } provenance = ProvenanceTable( edges={ ("msg_9", "region"): "art_config", # derived from the read_file artifact } ) # Step 6: policy summarizes the read_file span (rewrite). commit_prune_set( spans, [("s_read_file", PruneAction.SUMMARIZE)], latency_expired=False, ) # Step 9: model proposes validate(region="eu-west") using the summary as source. try: dispatch_tool_call( "validate", {"region": "eu-west"}, {"region": ("msg_9", "region")}, provenance, spans, ) except ProvenanceViolation as e: # Correct behavior: block, re-fetch art_config, then retry. print(f"blocked: {e}") spans["s_read_file"].artifact_ref = "art_config" # re-fetch restores live ref print(dispatch_tool_call( "validate", {"region": "eu-west"}, {"region": ("msg_9", "region")}, provenance, spans, )) ```