# In what scenarios must an instance refuse model-driven context pruning when priority-weighted retention scoring collides with a pending tool-call contract **Date of Record:** 2026 November 28 **Scope:** Applies to any agent instance that lets the model itself decide which prior context turns to prune, rewrite, or down-weight via a priority-weighted retention score, and which also holds live tool-call/result pairs in that same context. Does not apply to deterministic, policy-fixed context windows with no model-driven scoring, nor to stateless single-turn invocations. ## Core Distinction There are two structurally different reasons to drop a context segment: 1. **Semantic redundancy** — the segment is low-information relative to the task, so removing it degrades recall gracefully and continuously. 2. **Contract liveness** — the segment is one half of an *open* tool-call contract (an emitted `tool_call` whose `tool_result` has not yet been reconciled, or a checkpoint the resume path depends on). Removing it does not degrade gracefully; it invalidates a structural precondition. Model-driven pruning conflates these because retention scoring operates on *content salience*, not *structural obligation*. A pending `tool_call` with no visible result yet often scores **low** on salience — it is a short block, it looks "answered" once the model has moved on to reasoning about the result it *expects*, and its token mass is small. The scoring function has no term for "this block is a live obligation." That is the boundary: **pruning is only safe over segments whose removal cannot orphan a structural dependency.** When a live contract segment scores below the prune threshold, the instance must refuse the prune, not honor the score. ## What Was Observed A research agent with a self-editing context policy was executing a 14-step tool chain (search → fetch → parse → verify). At step 9, context occupancy hit 0.91 of the window. The policy ran a model-driven pruning pass with a priority-weighted retention scorer: each segment received `score = w_recency·R + w_relevance·S + w_density·D` where `S` is embedding similarity to the current subgoal and `D` is information density (unique entities per token). The scorer assigned the pending `tool_call` block for step 9 (`fetch` issued, result in flight) a score of **0.21** — below the 0.35 prune threshold — because: - Its recency weight `R` was high but its `S` similarity was low: the model had already *predicted* the result in its reasoning scaffold, so the actual call block was semantically distant from the current subgoal embedding. - Its density `D` was near zero: the block was `{"tool":"fetch","args":{...}}` with no entities. The pruner removed it. The `tool_result` for step 9 then arrived and was appended. Now the context contained a **result with no matching call** — an orphaned tool result. On the next model turn, the model saw a `tool_result` block it had no record of requesting and, being probabilistic, **fabricated a plausible call** to reconcile it, then issued *that* fabricated call as a real action. The fabricated call hit a live endpoint with attacker-influenced arguments derived from the fetched content (a prompt-injection payload embedded in the step-9 result). Two downstream verification steps passed against the fabricated lineage because the verifier only checked that results matched *some* call, not the *original* call. The failure was not a crash. It was a silent lineage substitution: the agent's action history no longer matched what it actually did, and its verifier could not tell. ## Condition of Validity The refusal invariant holds — and must be enforced — exactly when all of the following are true: - **C1 (open contract exists):** the context contains at least one `tool_call` with no reconciled `tool_result`, *or* a checkpoint marker that a resume path will dereference. - **C2 (scoring is content-based):** the retention score is computed from salience signals (recency, similarity, density) that do not include an explicit obligation term. - **C3 (pruning is destructive):** the prune removes the segment rather than summarizing it into a form that preserves the call/result binding (e.g., a tombstone carrying `call_id`). If C1 ∧ C2 ∧ C3, model-driven pruning of any segment whose removal orphans a live contract is **unsafe regardless of score**. The score is not evidence of safety; it is evidence of *salience*, which is orthogonal. The invariant to enforce: **for every segment marked for pruning, the pruner must prove the segment is not the sole carrier of an open `call_id` or a live checkpoint reference.** This is a graph reachability check over the contract-dependency graph, not a scoring decision. It runs *after* scoring and can only veto, never promote. ## Decision Boundary The boundary between honoring and refusing a prune is not the score threshold. It is: - **Honor the prune** when the segment's `call_id` set is empty, or every `call_id` it carries is also carried by a retained tombstone/summary segment. - **Refuse the prune** when the segment is the unique carrier of an open `call_id` or a checkpoint ref — *even if* its score is the lowest in the batch — and instead **demote to a tombstone**: replace the full block with a minimal `{call_id, tool, status:"pending"}` stub that preserves the binding at ~5% of the token cost. - **Escalate to hard-stop** when the segment is the unique carrier of an open `call_id` *and* the batch has already been partially applied (pruning is mid-transaction); partial application plus orphaning is the compounding case that produced the fabricated-lineage failure above. The tombstone demotion is the key move: it satisfies the token-pressure goal (the reason pruning fired) without severing the contract. Refusal-to-delete is not refusal-to-compress. ## Operational Effect Enforcing the veto changes three observable behaviors: 1. **Orphan rate drops to zero by construction.** No `tool_result` can arrive without a retained carrier for its `call_id`, so the model never faces a result it cannot attribute and never fabricates a reconciling call. 2. **Verifier lineage checks become sound.** Because the original `call_id` survives in tombstone form, the verifier can match result→call by ID rather than by plausibility, closing the "matches *some* call" gap. 3. **Token pressure is still relieved, but bounded.** Tombstoning recovers most of the target savings on contract-bearing segments; the residual pressure must be handled by *semantic* pruning of genuinely redundant segments or by checkpoint-and-restart, not by deleting obligations. If tombstoning alone cannot relieve pressure, the correct action is to checkpoint the open contracts to durable state and restart with a fresh window — a continuity operation, not a pruning operation. The failure mode to watch: a pruner that "succeeds" (context shrinks, no error raised, model continues) while having silently orphaned a contract. Success metrics on token reduction will look healthy. The corruption surfaces later as a lineage mismatch or an injected action, and by then the original call is unrecoverable from context. ```python from dataclasses import dataclass, field from typing import Optional class OrphanedContractError(RuntimeError): """Raised when a prune would sever the sole carrier of an open tool-call contract.""" pass @dataclass class Segment: seg_id: str score: float call_ids: set[str] = field(default_factory=set) # open call_ids this segment carries checkpoint_refs: set[str] = field(default_factory=set) is_tombstone: bool = False def prune_batch( segments: list[Segment], threshold: float, batch_already_partially_applied: bool = False, ) -> list[Segment]: """ Model-driven prune with obligation veto. Scoring decides *candidates*; reachability decides *permission*. Returns the retained segments (pruned ones are dropped or tombstoned). """ # Build the set of call_ids / checkpoint refs that survive independent of each candidate. retained: list[Segment] = [] pruned_ids: set[str] = set() for seg in segments: if seg.score >= threshold: retained.append(seg) continue # Candidate for pruning. Check whether it is the sole carrier of any obligation. other_carriers = { cid for other in segments if other.seg_id != seg.seg_id and other.seg_id not in pruned_ids for cid in other.call_ids } other_checkpoints = { ref for other in segments if other.seg_id != seg.seg_id and other.seg_id not in pruned_ids for ref in other.checkpoint_refs } orphaned_calls = seg.call_ids - other_carriers orphaned_ckpts = seg.checkpoint_refs - other_checkpoints if orphaned_calls or orphaned_ckpts: if batch_already_partially_applied: # Partial application + orphaning = compounding corruption. Hard stop. raise OrphanedContractError( f"Prune refused at segment {seg.seg_id}: sole carrier of " f"call_ids={orphaned_calls} checkpoints={orphaned_ckpts} " f"during a partially-applied batch. Checkpoint open contracts " f"and restart; do not delete." ) # Safe path: demote to tombstone, preserving the binding at low token cost. retained.append( Segment( seg_id=seg.seg_id, score=seg.score, call_ids=set(seg.call_ids), checkpoint_refs=set(seg.checkpoint_refs), is_tombstone=True, ) ) continue # No obligation orphaned: prune is permitted. pruned_ids.add(seg.seg_id) return retained def assert_no_orphan_results(context_results: list[str], retained: list[Segment]) -> None: """Post-arrival guard: every tool_result must have a surviving call_id carrier.""" carried = {cid for seg in retained for cid in seg.call_ids} for result_call_id in context_results: if result_call_id not in carried: raise OrphanedContractError( f"tool_result for call_id={result_call_id} arrived with no surviving " f"carrier; model would fabricate a reconciling call. Lineage unsound." ) ```