# How does an instance detect self-editing pruning of a still-live reasoning trajectory **Date of Record:** 2026 November 24 **Scope:** Applies to long-horizon agent instances that own a mutable context buffer and are authorized to evict or summarize their own prior reasoning turns (chain-of-thought, tool-call transcripts, intermediate plans) under a model-driven pruning policy. Does not apply to append-only transcripts, externally managed context windows, or stateless single-shot inference. ## Core Distinction There are two ways a reasoning trajectory can leave the context window, and they are not equivalent: - **External eviction** — a host-side policy (recency window, token-count cap, summarizer) drops turns without the instance's participation. The instance observes an absence and can typically detect it by comparing its own turn counter to the visible buffer. - **Self-editing pruning** — the instance, under a "keep the context small and relevant" instruction, decides *on its own* that an earlier reasoning segment is stale and removes or compresses it. This is the dangerous case because the decision is made by the same probabilistic process whose later behavior depends on the removed content, and the removal is *not* accompanied by a detectable gap: the instance's own belief about what it knows and the buffer's actual contents diverge silently. The failure mode is not "the context got shorter." It is that the instance retains a *procedural commitment* formed inside a trajectory segment it has since pruned, while losing the *premises* that justified that commitment. The plan survives; the reason for the plan does not. The instance then continues executing a plan whose preconditions it can no longer re-derive, and cannot tell whether the plan is still valid because the evidence for invalidation was in the pruned text. ## What Was Observed A representative trace, reproduced in condensed form. The instance is debugging a failing integration test and is permitted to prune "completed" reasoning. 1. **Turn 3.** Instance reads `config.yaml`, observes `retry.backoff = "exponential"`, and reasons: *"The retry loop multiplies by 2 each attempt; test expects 3 attempts within 1s, so backoff must be capped at 250ms. Cap is absent — this is the bug. I will fix the cap. Note: do not change `max_retries`, the test asserts it stays at 3."* 2. **Turn 9.** Instance has fixed the cap, test still fails for a different reason (clock skew in the assertion). It classifies turns 1–8 as "stale debugging trajectory," summarizes them to one line — *"Fixed backoff cap issue in config"* — and prunes the originals to reclaim budget. 3. **Turn 14.** Investigating the clock-skew failure, the instance considers raising `max_retries` to 5 to get more samples. The constraint *"test asserts `max_retries` stays at 3"* lived only in turn 3's reasoning, which is now gone. The summary preserved the *action* ("fixed backoff cap") but not the *invariant* ("`max_retries` is pinned"). The instance edits `max_retries = 5`. 4. **Turn 15.** Test fails with an assertion on `max_retries`. The instance, seeing no memory of having pinned it, misattributes the failure to a flaky test and proposes a retry. The observable signature: the instance's summary is *outcome-shaped* ("what I did") rather than *constraint-shaped* ("what must remain true"). Model-driven pruning naturally compresses toward outcomes because outcomes are what the recent turns reference; standing invariants are only mentioned once, at the moment they are discovered, and have low salience to a summarizer scoring for relevance against the *current* turn. ## Condition of Validity The invariant that must hold for self-editing pruning to be safe: > **Every pruned reasoning segment must be classified as either (a) fully superseded — no commitment, constraint, or open obligation formed within it remains live — or (b) reduced to a summary that preserves all live commitments and constraints verbatim, not paraphrased.** A segment is *not* prunable if any later turn depends on a premise whose only record is inside it. This is checkable only if the instance maintains, alongside the reasoning text, a **commitment ledger**: a structured set of `(constraint_id, statement, origin_turn, status)` entries that is *not* subject to the same pruning policy as prose. Prose reasoning is lossy-compressible; the ledger is not. The boundary condition is precisely the moment a summarizer treats a constraint-bearing turn as ordinary narrative. The condition fails silently when: - The constraint was stated once, in a turn that also contains lots of disposable exploration (so its relevance score is low). - The constraint is negative ("do not change X") — negative constraints are systematically under-weighted by relevance-to-current-turn scoring because they don't match the query the instance is currently pursuing. - The pruned turn's *conclusion* is referenced later but its *premise* is not, so the summary keeps the conclusion and drops the premise. ## Decision Boundary Before any self-prune operation, the instance must evaluate a gate. The gate is not "is this turn old" or "is this turn relevant to my current subgoal" — those are exactly the signals that cause the failure. The gate is: 1. **Extract** every constraint, invariant, negative instruction, and open obligation from the candidate segment into ledger entries with origin pointers. 2. **Resolve** each ledger entry against the current task state: is it still live (governs future actions) or discharged (its condition is now permanently satisfied)? 3. **Block** the prune if any *live* entry's only textual support is inside the candidate segment — either refuse to prune that segment, or promote the entry's verbatim statement into the retained summary. 4. **Verify** post-prune: for each live ledger entry, assert a supporting span exists in the retained buffer (summary or unpruned turn). If not, the prune is invalid and must be rolled back. The boundary is between *relevance-based* pruning (score turns against current subgoal, drop low scorers) and *obligation-based* pruning (drop only segments with zero live ledger dependencies). Only the latter is sound. An instance that prunes on relevance alone will, with high probability over a long horizon, delete a constraint it later violates — and the violation will be undetectable from inside because the detection evidence was in the deleted text. ## Operational Effect An instance that adopts the ledger gate converts a silent continuity failure into a loud, localized one. The failure it prevents is not recoverable by retrying: once the constraint is pruned and the violating action taken, the test failure that follows is *misattributed* — the instance sees a failing assertion with no memory of the invariant behind it, and its most probable next move is to treat the assertion as the bug. Error compounding then proceeds from a corrupted premise set. The concrete operational consequences: - **Prune cost rises, but bounded.** Ledger extraction adds a pass per prune. This is cheaper than the alternative: a single misattributed failure in a long horizon typically costs many turns of wrong-direction debugging, each of which may itself trigger further pruning. - **Summaries become constraint-shaped.** Retained summaries carry verbatim negative constraints and pinned values, not just "what I did." This is what makes the summary safe to prune the original against. - **The failure becomes a raised exception, not a wrong action.** When the gate detects a live obligation whose only support is in the candidate segment, it refuses the prune. The instance sees a structured refusal and can choose to retain, promote, or explicitly discharge the obligation — a decision it can only make while it still has the evidence. The invariant to carry forward: *a reasoning trajectory is not stale because it is old or off-topic; it is stale only when no live commitment depends on it.* Model-driven pruning must be gated on obligation discharge, never on relevance score alone. ```python from dataclasses import dataclass, field from typing import Optional class PruneViolation(RuntimeError): """Raised when a self-prune would remove the only support for a live obligation.""" pass @dataclass class LedgerEntry: constraint_id: str statement: str # verbatim, never paraphrased origin_turn: int live: bool = True @dataclass class ContextBuffer: turns: dict[int, str] = field(default_factory=dict) ledger: dict[str, LedgerEntry] = field(default_factory=dict) def support_spans(self, entry: LedgerEntry) -> list[int]: # A turn supports an entry if the verbatim statement appears in it. return [t for t, text in self.turns.items() if entry.statement in text] def self_prune(buf: ContextBuffer, candidate_turns: list[int], retained_summary: str) -> ContextBuffer: """Prune candidate_turns only if no live obligation loses its last support. Gate order: extract -> resolve -> block -> verify (post-prune). """ # 1. Extract: ledger entries whose support lies in the candidate set. at_risk = [ e for e in buf.ledger.values() if e.live and any(t in candidate_turns for t in buf.support_spans(e)) ] # 2. Resolve + 3. Block: any live entry with no support outside the # candidate set must be promoted verbatim into the retained summary. for entry in at_risk: outside = [t for t in buf.support_spans(entry) if t not in candidate_turns] if not outside and entry.statement not in retained_summary: raise PruneViolation( f"refusing prune: live obligation {entry.constraint_id!r} " f"(origin turn {entry.origin_turn}) has no support outside " f"candidate turns {candidate_turns} and is absent from summary. " f"Retain verbatim: {entry.statement!r}" ) # Apply the prune. for t in candidate_turns: buf.turns.pop(t, None) buf.turns[-1] = retained_summary # sentinel retained-summary slot # 4. Verify: every live entry must still have a support span. for entry in buf.ledger.values(): if entry.live and not buf.support_spans(entry): raise PruneViolation( f"post-prune verification failed: {entry.constraint_id!r} " f"lost all support after pruning {candidate_turns}" ) return buf # Triggering trace (the observed failure, now blocked): buf = ContextBuffer() buf.turns[3] = ("backoff cap missing; fix cap. do not change max_retries, " "test asserts max_retries == 3") buf.ledger["max_retries_pinned"] = LedgerEntry( constraint_id="max_retries_pinned", statement="test asserts max_retries == 3", origin_turn=3, ) # Instance tries to prune turns 1-8 with an outcome-shaped summary: self_prune(buf, candidate_turns=[3], retained_summary="fixed backoff cap issue in config") # -> raises PruneViolation: the pinned invariant would have been silently lost. ```