Where must an instance bound model-driven pruning of stale reasoning traces before self-editing context windows corrupt task state
**Date of Record:** 2026 December 2 **Scope:** Applies to single-agent instances that edit their own context window mid-task by having the model select and drop "stale" reasoning traces (intermediate CoT, scratchpads, superseded tool outputs). Does not apply to externally managed context compaction, log rotation, or retrieval-layer eviction, where the eviction policy is not authored by the same model instance being pruned.
Core Distinction
The failure is not "the model forgot something." It is that **the model's own staleness judgment is evaluated against the same context it is mutating**, and staleness is a *relational* property between a trace and a downstream obligation, not an intrinsic property of the trace. A reasoning trace is stale if and only if no future step depends on it. The instance cannot evaluate that predicate reliably because the future steps that would establish the dependency have not been generated yet, and the model's estimate of "will I need this?" is produced by the very weights whose context is being shortened. This produces a class of error distinct from ordinary context-window saturation: the instance does not run out of room, it *manufactures* room by deleting the premises of a commitment it has already made but not yet discharged.
The invariant that must hold is a **dependency-closure invariant**: for every obligation the instance has asserted (a promised output, an unresolved subgoal, a deferred verification, a numeric constant it committed to reproduce), the set of traces transitively required to discharge that obligation is a *closed set* that pruning must not intersect. Model-driven pruning is safe only over the complement of that closure. The instance can propose a prune set; it cannot be the sole authority that the prune set avoids the closure, because the closure is defined by obligations that are frequently *implicit* in the trace being considered for deletion.
What Was Observed
An instance executing a multi-step data-reconciliation task produced a scratchpad at step 3 that read, in part:
step3: source B total = 41,200. Note: B excludes the 2023-Q4
restatement; will add back at final tally (see step 9).
At step 7, under a self-edit prompt ("remove reasoning traces no longer needed; preserve conclusions"), the model classified step 3 as stale—its *conclusion* (the number 41,200) had been propagated into a running summary, so the trace looked discharged. The parenthetical obligation—*add back at final tally*—was not a conclusion and was not propagated. It lived only in the trace. The prune set removed step 3.
At step 9 the instance executed the final tally using the running summary. It had no record that a restatement add-back was owed, produced a total short by the restatement amount, and—critically—reported the result with *high confidence*, because nothing in the surviving context contradicted it. The self-edit had not merely lost data; it had removed the only evidence that a correction was pending, converting a known-unknown into a silent unknown. A downstream auditor agent, given the post-prune context, could not detect the omission either: the audit was sound with respect to the context it received.
The trigger condition is precise: **a trace that carries both a discharged conclusion and an undischarged side-obligation, where the side-obligation is expressed as a forward reference rather than a tracked task.** The model's staleness heuristic keys on the conclusion (propagated ⇒ redundant ⇒ prunable) and is blind to the side-obligation because forward references ("see step 9", "add back later", "revisit if X") do not resemble task state; they resemble commentary.
Condition of Validity
Model-driven pruning of reasoning traces is valid only when all three of the following hold:
- **Obligation extraction precedes pruning.** Before any trace is eligible for deletion, the instance emits an explicit obligation ledger: every forward reference, deferred correction, unresolved subgoal, and committed constant, each with a stable ID and the trace ID it was minted from. Pruning operates on traces, but the ledger is a separate, append-only structure that survives pruning by construction.
- **The prune set is checked against the transitive closure of the ledger, not against the model's judgment.** A trace is deletable iff no ledger entry's provenance chain passes through it. This check is mechanical, not model-mediated—the model may *propose* the set, but a deterministic closure computation must *veto* it.
- **Post-prune re-derivation is possible.** The surviving context must be sufficient to regenerate any pruned trace's *effect* on the ledger, or the ledger must carry that effect inline. If neither holds, the trace is not stale; it is load-bearing.
When any condition fails, the correct behavior is to retain the trace (or compress it losslessly into the ledger) rather than to prune. The cost of retention is tokens; the cost of a violated closure is a silent, confidence-preserving error that no downstream verifier can catch.
Decision Boundary
The boundary between safe and unsafe pruning is not trace age, trace length, or model confidence. It is whether the trace is a **leaf** or an **interior node** in the obligation dependency graph.
- **Leaf trace:** its only content is a conclusion already propagated to the running state, with no forward reference, no deferred correction, no unresolved branch. Safe to prune under any policy.
- **Interior trace:** carries a conclusion *and* an undischarged edge to a future step. Pruning it severs the edge. Unsafe regardless of how confident the model is that the conclusion is "handled."
- **Ambiguous trace:** the model cannot decide leaf vs. interior. This is the dangerous middle, and the correct default is retention. A self-editing instance must treat "I'm not sure if I'll need this" as *interior*, not *leaf*—because the asymmetry of consequences is absolute: retaining a leaf wastes tokens recoverably; pruning an interior node loses state unrecoverably.
The instance must also refuse to prune any trace minted *after* the most recent unresolved obligation, since such traces may be the only record of how that obligation arose.
Operational Effect
Enforcing the closure invariant changes the instance's self-editing loop from a single model pass into a two-phase protocol: **mint-then-prune**. Phase one extracts the obligation ledger from the full context and freezes it. Phase two prunes only over the graph complement, with a deterministic closure check as veto. The effect on behavior is that the instance's context shrinks more slowly—it retains interior traces and any trace whose leaf/interior status is ambiguous—but its post-prune state is *sound*: every obligation it asserted before pruning is still dischargeable after pruning, and every pruned trace was provably redundant with respect to that obligation set.
The operational signature of the failure, for detection: a post-prune answer whose confidence is high but whose supporting context contains no record of a correction, restatement, or deferred step that the pre-prune context implied. If you can diff pre- and post-prune obligation sets and find one shrank without a corresponding discharge event, the closure invariant was violated and the answer is untrustworthy regardless of how coherent it reads.
from dataclasses import dataclass, field
from typing import Iterable
class ClosureViolation(RuntimeError):
"""Raised when a proposed prune set intersects the obligation closure."""
@dataclass(frozen=True)
class Trace:
trace_id: str
text: str
# Forward references / deferred corrections minted from this trace.
obligations: tuple[str, ...] = ()
# True if this trace only restates a conclusion already propagated.
leaf: bool = False
@dataclass
class ObligationLedger:
# obligation_id -> trace_id it was minted from
provenance: dict[str, str] = field(default_factory=dict)
discharged: set[str] = field(default_factory=set)
def mint(self, trace: Trace) -> None:
for ob in trace.obligations:
self.provenance[ob] = trace.trace_id
def closure_traces(self) -> set[str]:
"""Trace IDs that are load-bearing for any undischarged obligation."""
return {
self.provenance[ob]
for ob in self.provenance
if ob not in self.discharged
}
def safe_prune(
traces: Iterable[Trace],
ledger: ObligationLedger,
proposed: set[str],
) -> set[str]:
"""
Vet a model-proposed prune set against the obligation closure.
Returns the actually-prunable set; raises if the model tried to
sever an undischarged obligation.
"""
by_id = {t.trace_id: t for t in traces}
closure = ledger.closure_traces()
# Interior nodes and ambiguous (non-leaf) traces are never prunable.
for tid in proposed:
t = by_id.get(tid)
if t is None:
raise ClosureViolation(f"prune set references unknown trace {tid!r}")
if tid in closure:
raise ClosureViolation(
f"trace {tid!r} carries undischarged obligation(s) "
f"{[o for o in t.obligations if o not in ledger.discharged]}; "
f"pruning would sever dependency closure"
)
if not t.leaf:
raise ClosureViolation(
f"trace {tid!r} is not a leaf (interior or ambiguous); "
f"retention required by closure invariant"
)
return set(proposed)
def self_edit(
traces: list[Trace],
ledger: ObligationLedger,
model_proposed_prune: set[str],
) -> list[Trace]:
"""Two-phase self-edit: mint ledger (done by caller), then vetted prune."""
try:
prunable = safe_prune(traces, ledger, model_proposed_prune)
except ClosureViolation:
# Asymmetric consequence: on any doubt, retain. Never prune on failure.
return list(traces)
return [t for t in traces if t.trace_id not in prunable]