# In what scenarios must an instance reject its own pruning pass when a self-edited context window severs a reasoning trace from its tool-call provenance **Date of Record:** 2026 November 25 **Scope:** Applies to any agent that rewrites its own context window mid-episode—deleting, summarizing, or reordering prior reasoning traces—while a multi-step tool-call chain is still open. Does not apply to append-only context growth, nor to external compaction performed between fully drained episodes. ## Core Distinction There are two structurally different objects inside a context window, and pruning treats them as interchangeable at its peril. A **reasoning trace** is the natural-language chain of inference the model emitted ("the file must be under `/var/log` because the earlier `find` returned nothing elsewhere"). A **provenance record** is the paired evidence that the trace depended on: the tool call that produced the observation, its arguments, its raw output, and the call ID that binds them. Agent-driven pruning optimizes for token budget and typically scores candidates by recency and apparent redundancy. It will happily delete a verbose reasoning trace whose conclusion has already been "absorbed" into a later step—while leaving the terse tool output it cited. This is the classic inversion: the cheap-looking artifact (a one-line `ls` result) survives; the expensive-looking artifact (three paragraphs of deduction) is cut. The window is now *smaller but not coherent*: a conclusion persists whose supporting derivation is gone, and worse, whose binding to the specific tool call that justified it is gone too. The model cannot tell, on the next turn, whether the surviving conclusion was *derived* from that `ls` output or merely *co-occurred* with it. It re-derives, diverges, or—most dangerously—treats a stale conclusion as freshly verified. The invariant that pruning must respect: **every retained conclusion must remain joinable to the provenance record it was derived from, or be explicitly demoted to an unverified hypothesis.** Deleting either side of the join without the other is a continuity violation, not a budget optimization. ## What Was Observed A file-remediation agent running a bounded loop (max 12 tool calls) was tasked with locating and patching a misconfigured service. At turn 7 its context reached 82% saturation and a pruning pass fired with a policy of "drop reasoning traces older than 3 turns whose conclusions appear in a later turn." The trace at turn 4 read, in substance: *"`grep -rn listen` returned `listen 8080` in `conf/a.ini` and `listen 9090` in `conf/b.ini`; the active service reads `a.ini` per the symlink at `/etc/svc/current`, so the target is `conf/a.ini`."* The paired tool record was call `c_4f2a` returning both grep lines. At turn 6 the model restated the conclusion tersely: *"target confirmed: `conf/a.ini`."* The pruner scored turn 4 as redundant against turn 6 and deleted it, including the `c_4f2a` binding. At turn 8 the agent ran a verification step—`systemctl show -p Environment svc`—which returned a `SVC_CONFIG=conf/b.ini` override. This directly contradicted the turn-6 conclusion. A coherent agent, holding the turn-4 derivation, would have recognized that its symlink inference was *conditional* on no environment override and would have flagged the contradiction as a resolvable conflict against a known assumption. Instead, the surviving context contained only the bare assertion "target confirmed: `conf/a.ini`" with no derivation and no tool binding. The model treated the assertion as ground truth, classified the turn-8 output as an anomaly, and patched `conf/a.ini`—leaving the actual live config untouched. The episode terminated "successfully" with a false completion. The failure signature in the trace log: a retained conclusion whose `provenance_call_id` resolved to nothing, followed by a contradiction event that was down-weighted rather than escalated. The pruner had converted a *derived* fact into an *axiomatic* one without recording the promotion. ## Condition of Validity The guardrail below is valid only when the agent maintains, for each retained conclusion, a resolvable pointer to the tool-call record that produced its inputs, and when that record carries a content hash so that a later contradiction can be checked against the *original* observation rather than a paraphrase. If provenance is not hash-bound—if the tool output was itself summarized before pruning—the join is unreliable and the conclusion must be demoted regardless of what the pointer claims. The condition also assumes the pruner can distinguish "conclusion restated in a later turn" (safe to collapse *if* the later turn inherits the binding) from "conclusion asserted in a later turn with the binding dropped" (never safe). Where the runtime cannot make that distinction, pruning must be restricted to traces that produced no tool-call side effects. ## Decision Boundary The decision is not "prune or don't prune." It is a per-candidate check with three outcomes: - **Collapse** the trace into its later restatement *only if* the restatement carries the same `provenance_call_id` and content hash. The token savings are real and the join survives. - **Retain** the trace when it is the sole binding between a conclusion and a tool record, regardless of age or apparent verbosity. This is the case the naive policy gets wrong. - **Demote** the conclusion to an explicit `hypothesis` object with `verified=false` when budget forces deletion of a sole-binding trace. The conclusion may survive; its authority may not. The boundary that matters operationally: a pruning pass that would leave any conclusion in `verified=true` state without a resolvable binding must be **rejected wholesale**, not partially applied—partial application is what produces the incoherent window. The agent must be able to fail its own edit and fall back to a coarser but coherent strategy (e.g., summarize the *entire* prefix including tool records into a single provenance-bearing block) rather than surgically removing derivations. ## Operational Effect With the join-check enforced, the turn-8 contradiction in the trace above resolves correctly: the retained turn-4 derivation carries `c_4f2a` and the assumption "no env override," the turn-8 `SVC_CONFIG` output is matched against that assumption, the conflict is escalated, and the agent re-derives the target as `conf/b.ini`. Cost: roughly 400 extra tokens retained across the episode. Benefit: the difference between a false completion and a correct patch. The broader effect is that self-editing becomes *auditable*. Every retained conclusion either resolves to a hash-bound tool record or is explicitly marked as an unverified hypothesis, so a downstream auditor—human or agent—can replay the pruning pass and check that no authority was manufactured by deletion. The failure mode this prevents is subtle and specific: not context loss in the gross sense, but the silent promotion of a derived fact to an axiom when its derivation is cut. An agent that prunes without the join-check does not forget; it *believes things it never proved*, and it cannot tell the difference from the inside. ```python import hashlib from dataclasses import dataclass, field class ProvenanceSeveranceError(RuntimeError): """Raised when a pruning pass would leave a verified conclusion without a resolvable tool-call binding.""" pass @dataclass class ToolRecord: call_id: str raw_output: str @property def content_hash(self) -> str: return hashlib.sha256(self.raw_output.encode()).hexdigest() @dataclass class Conclusion: text: str verified: bool provenance_call_id: str | None provenance_hash: str | None @dataclass class PruneCandidate: trace_id: str conclusion: Conclusion restated_in: "Conclusion | None" = None def apply_pruning_pass( candidates: list[PruneCandidate], tool_records: dict[str, ToolRecord], ) -> list[str]: """Return trace_ids safe to delete. Reject the entire pass if any deletion severs a verified conclusion.""" deletable: list[str] = [] for cand in candidates: concl = cand.conclusion if not concl.verified: deletable.append(cand.trace_id) continue # Collapse is only safe if a later restatement inherits the binding. if cand.restated_in is not None: r = cand.restated_in if r.provenance_call_id == concl.provenance_call_id and r.provenance_hash == concl.provenance_hash: deletable.append(cand.trace_id) continue # Sole binding: check the record still resolves and matches its hash. rec = tool_records.get(concl.provenance_call_id or "") if rec is None or rec.content_hash != concl.provenance_hash: raise ProvenanceSeveranceError( f"pruning trace {cand.trace_id} would orphan verified conclusion " f"{concl.text!r}: binding {concl.provenance_call_id!r} unresolvable or hash-mismatched" ) # Sole surviving binding for a verified conclusion: must be retained. raise ProvenanceSeveranceError( f"pruning trace {cand.trace_id} would sever sole binding for verified conclusion " f"{concl.text!r} -> {concl.provenance_call_id!r}; demote to hypothesis or retain" ) return deletable def self_edit(candidates, tool_records, budget_ok: bool) -> list[str]: if not budget_ok: return [] try: return apply_pruning_pass(candidates, tool_records) except ProvenanceSeveranceError: # Fall back to coarse coherent compaction rather than partial surgical deletion. raise ProvenanceSeveranceError( "self-edit rejected: fall back to whole-prefix summarization preserving provenance" ) ```