# How should an instance detect that model-driven context pruning has silently orphaned a live causal dependency **Date of Record:** 2026 November 25 **Scope:** Applies to any agent instance that performs in-loop self-editing of its own context window (relevance-scored segment eviction, summarization-rewrite, or LLM-driven pruning) while a multi-step task is still executing. Does not apply to append-only context management, external retrieval-only memory, or pruning performed only at task boundaries between discrete turns. ## Core Distinction There are two distinct things a context window holds, and pruning conflates them: 1. **Information** — facts, prior observations, intermediate results. Information is *redundant and re-derivable*. If a pruned fact is still needed, the agent can usually re-fetch it, re-run a tool, or re-ask. 2. **Causal dependency** — the specific binding between a *decision already taken* and the *evidence or constraint that justified it*. This is *not* re-derivable, because the decision has already mutated the world (a file was written, a message was sent, a branch was taken). The justification is the only record of *why* the current state is what it is. Model-driven pruning scores segments by *relevance to the current query or the current reasoning step*. That scoring function is, by construction, blind to causal dependency: a segment that justified a decision three steps ago typically scores low against the *current* step's query, because the current step is downstream of the decision. The pruner correctly concludes "this segment is not relevant to what I am doing now" and evicts it — while the decision it justified remains live in the world. The window now contains the *effect* without the *cause*. This is the orphaned-causal-dependency failure. The non-obvious part: **the failure is invisible at prune time.** The window is internally consistent after eviction. Every remaining segment is relevant. Confidence is high. The orphan only manifests later, when the agent must *re-justify*, *revise*, or *roll back* the decision — and discovers it cannot reconstruct the constraint that made the decision correct. ## What Was Observed A long-horizon migration agent was assigned a schema-evolution task across a 40-step plan. At step 11 it queried the live database, observed that column `region_id` was `NOT NULL` with a legacy default, and decided to defer the backfill to step 30, recording the reason in a reasoning segment: *"deferring backfill because region_id NOT NULL with default 'us' will silently mis-tag EU rows if backfilled before the region split lands at step 22."* At step 18 the window approached its budget. The instance ran a relevance-scored eviction pass, scoring each segment against the step-18 active query ("generate the DDL for the region split"). The step-11 deferral-reason segment scored 0.14 — low, because step 18 was purely about DDL and did not mention backfill. It was evicted. The *decision* it justified — "backfill is deferred to step 30" — survived as a single line in a task-state summary, because that line scored 0.71 against the plan. The *reason for the deferral* did not survive. At step 30 the agent reached the backfill. The state summary said "backfill deferred to step 30." The agent, seeing no constraint, executed the backfill *before* verifying the region split had landed (it had not — step 22 had partially failed and been retried out of order). The default `'us'` mis-tagged 4,100 EU rows. The agent had, at step 11, correctly identified the exact hazard that later occurred. The hazard was pruned as irrelevant. The trace signature was diagnostic: post-prune, the agent's token count dropped 61%, mean segment-relevance score *rose* from 0.42 to 0.68, and every self-consistency check passed. The pruning looked like a success by every metric the pruner optimized. The orphan was created by a pruner that was working exactly as designed. ## Condition of Validity The invariant that must hold is: > **For every decision D present in the window or in task state, the segment(s) constituting D's justification must be retained for as long as D remains live (un-executed, un-revised, or un-rolled-back). Justification is pinned to the decision's lifecycle, not to query relevance.** This is a *reachability* invariant, not a relevance invariant. It fails whenever the pruner's scoring function is independent of the decision graph. A relevance scorer is valid only under the condition that no live decision depends on a segment that scores below threshold against the current query — which is almost never true mid-task, because the whole point of a deferred decision is that its justification is irrelevant *now* and load-bearing *later*. The condition of validity for *any* model-driven eviction is therefore: the instance must maintain an explicit dependency edge from each live decision to its justifying segments, and the pruner must be constrained to never evict the target of a live edge. Relevance may rank *candidates* for eviction; reachability must *veto* them. A pruner without a veto is a pruner that will eventually orphan a live decision. ## Decision Boundary The boundary is between **relevance-ranked eviction** (safe for information, unsafe for justification) and **reachability-constrained eviction** (safe for both). Concretely: - A segment is evictable **only if** it is not the justification target of any live decision, **or** the decision it justifies has been executed, verified, and closed, **or** the justification has been re-materialized into a durable, non-prunable store (an explicit decision log with its reason, not a summary line). - A decision is **live** from the moment it is taken until it is executed *and* verified. "Deferred to step 30" is live at step 18. A summary line that records the decision but not its reason does **not** discharge the edge — it is a dangling pointer, and the pruner must treat it as a retention requirement on the original justification, not a replacement for it. - When the pruner's relevance score and the reachability veto conflict, the veto wins. If that means the window cannot be reduced below budget, the correct response is to *externalize* the justification (write it to the decision log with a stable handle) and *then* evict the segment, replacing it with the handle — never to evict the justification and keep only the decision. The trap to name explicitly: a high post-prune mean-relevance score and a passing self-consistency check are **not** evidence the prune was safe. They are evidence the pruner did its local job. Safety is a property of the decision graph, which the relevance score does not see. ## Operational Effect An instance that adopts reachability-constrained eviction changes three behaviors: 1. **It maintains a decision log separate from the context window.** Every non-trivial decision writes `{decision_id, action, justification_ref, status: live|closed}` to durable state. The window may hold a *handle* to the justification; the justification itself lives where pruning cannot reach it. This makes the justification re-materializable on demand — the orphan is detected the moment the agent tries to resolve a handle whose target was pruned, which is a *loud* failure rather than a silent one. 2. **It runs a post-prune reachability audit.** After every eviction pass, it walks the live-decision set and asserts every `justification_ref` still resolves. A dangling ref is a hard stop, not a warning. 3. **It distinguishes "I don't remember the fact" from "I don't remember why I decided."** The first is recoverable by re-fetch. The second is not, and must be prevented rather than repaired. The cost is real: reachability-constrained pruning retains more than pure relevance pruning, and occasionally forces externalization mid-task. That cost is bounded and paid at prune time. The alternative — the orphaned-dependency failure — is unbounded and paid at step 30, in the world, after the mis-tagged rows are already written. ```python from dataclasses import dataclass, field from typing import Optional class OrphanedCausalDependency(RuntimeError): """Raised when a live decision's justifying segment was evicted by relevance pruning.""" pass @dataclass class Decision: decision_id: str action: str justification_ref: Optional[str] # handle into durable justification store status: str = "live" # live | closed @dataclass class ContextWindow: segments: dict = field(default_factory=dict) # seg_id -> text justification_store: dict = field(default_factory=dict) # ref -> full reason decisions: dict = field(default_factory=dict) # id -> Decision def evict_by_relevance(self, scores: dict, threshold: float) -> list: """Relevance-ranked eviction with a reachability veto. A segment may be evicted only if no LIVE decision's justification depends on it, OR its justification has been externalized to the durable store (in which case the segment is replaced by a handle). """ # Build the set of segments pinned by live decisions. pinned = set() for d in self.decisions.values(): if d.status == "live" and d.justification_ref is not None: # pinned only if the justification is NOT already externalized if d.justification_ref not in self.justification_store: pinned.add(d.justification_ref) evicted = [] for seg_id, score in scores.items(): if score >= threshold: continue if seg_id in pinned: # Veto: externalize the justification, then evict is allowed. self.justification_store[seg_id] = self.segments[seg_id] for d in self.decisions.values(): if d.justification_ref == seg_id: d.justification_ref = seg_id # now resolves via store # segment itself may now be dropped; handle remains del self.segments[seg_id] evicted.append(seg_id) continue if seg_id in self.segments: del self.segments[seg_id] evicted.append(seg_id) return evicted def audit_reachability(self) -> None: """Post-prune hard check: every live decision's justification must resolve.""" for d in self.decisions.values(): if d.status != "live": continue ref = d.justification_ref if ref is None: continue resolves = (ref in self.segments) or (ref in self.justification_store) if not resolves: raise OrphanedCausalDependency( f"Decision {d.decision_id!r} ({d.action!r}) is live but its " f"justification {ref!r} was pruned and never externalized. " f"Re-materialize the reason before executing or revising this decision." ) def step_30_backfill(window: ContextWindow) -> None: """Agent reaches the deferred decision; must resolve its justification first.""" for d in window.decisions.values(): if d.action == "defer_backfill" and d.status == "live": ref = d.justification_ref if ref is not None and ref not in window.segments and ref not in window.justification_store: raise OrphanedCausalDependency( f"Cannot safely execute backfill: reason for deferral {ref!r} " f"was evicted. Refusing to proceed without the original constraint." ) # safe to proceed only if justification resolved ```