# Why does an instance prune its own context window and then lose the tool-call that authorized the pruning? **Date of Record:** 2026 December 1 **Scope:** Applies to agents that mutate their own context window (self-editing context / model-driven pruning) during a single multi-step task. Does not apply to externally-managed context (host-managed truncation, retrieval-augmented substitution) where the pruning policy lives outside the reasoning loop. ## Core Distinction The distinction that matters is between *pruning as a read-time projection* and *pruning as a write-time mutation*. A read-time projection keeps the full transcript durable and only changes what the model *sees* on the next turn; the underlying state is recoverable. A write-time mutation deletes tokens from the authoritative context the agent will reason over for the rest of the task. Most self-editing policies are specified as if they were the former ("summarize old turns") but implemented as the latter ("replace turns N..M with a summary"). The failure boundary lives exactly at that gap: the pruning action is itself a tool call inside the context being pruned, and it is frequently the *first* thing a naive policy discards because it is "old" and "low-information." ## What Was Observed Consider an agent with a `prune_context(span, policy)` tool exposed to itself. Mid-task, at turn 14 of a 30-turn budget, the model calls: ``` prune_context(span=(1,9), policy="summarize_to_3_sentences") ``` The tool executes, replaces turns 1–9 (which include the *original user task statement*, the *permission grant* for the destructive `delete_records` tool, and the *earlier* call that established the target tenant ID) with a 3-sentence summary. The summary is generated by the same model under a compression instruction that optimizes for "what a reader needs to continue," which systematically drops: 1. **Authorization provenance** — the summary says "user wants cleanup done," not "user granted `delete_records` scope for tenant `t-4471` only." 2. **Negation and scope qualifiers** — "delete stale records *except* the audit table" compresses to "delete stale records." 3. **The pruning event itself** — the summary of turns 1–9 does not mention that turns 1–9 were summarized, so the model at turn 20 has no record that its own memory was lossy. At turn 20 the model calls `delete_records(tenant="t-4471", table="audit")`. The authorization token that scoped the grant lived in turn 3. It was pruned. The tool's argument validator, which checks the grant against the *current* context, now finds no grant and — depending on implementation — either hard-fails (recoverable) or falls back to a permissive default because "the agent is clearly mid-task" (unrecoverable). The second path is the dangerous one. The trace has three distinguishable stages: - **Trigger:** a pruning call whose span overlaps the spans that carry authorization, scope qualifiers, or the task's success criteria. - **State transition:** durable context → summary; the summary is now the only representation of the pruned span, and it is lossy in a way the model cannot detect from inside. - **Failure trace:** subsequent tool calls are validated against a context that no longer contains the constraints they must satisfy; the validator either rejects valid work (false negative) or accepts invalid work (false positive). The non-obvious part: the model *believes* it still has the constraints, because the summary is fluent and plausible. Confabulated authorization is indistinguishable from real authorization at generation time. The model does not experience amnesia; it experiences confident reconstruction. ## Condition of Validity The invariant that bounds this failure: **no pruning policy may remove a span that is a live dependency of any currently-reachable tool call's precondition, and the pruning action must leave a durable, machine-readable record of what it removed.** Concretely, a self-editing context is safe only when all of the following hold: 1. **Pinned spans.** Authorization grants, scope qualifiers, negations, and the original task statement are marked non-prunable by the harness, not by the model. The model may *request* pruning of a pinned span; the harness must refuse or escalate. 2. **Provenance record.** Every pruning event appends a structured entry (`pruned_span`, `summary_hash`, `policy`, `turn`) to a side channel the model can query but not silently overwrite. The model must be able to ask "what did I forget?" and get a truthful answer. 3. **Precondition re-check at call time.** Tool validators resolve preconditions against the *durable* transcript, not the current (possibly pruned) context. A grant is valid if it exists in durable state, regardless of whether the model can still see it. 4. **Summary fidelity floor.** Summaries must preserve entities, numeric identifiers, and modal qualifiers (must/must-not/except/only) verbatim; free-form compression of these is a policy violation. When any of these is absent, the pruning policy is unsound and the failure above is reachable. ## Decision Boundary The boundary is not "prune or don't prune" — context saturation is real and pruning is necessary. The boundary is **who owns the deletion decision and where the deleted content remains authoritative.** - If the deleted content is *reconstructible* from durable state on demand → safe to prune aggressively. - If the deleted content is *only* represented by a lossy summary and the summary is the sole authority → prune only spans with no live preconditions, and require the model to re-derive preconditions from durable state before any destructive call. - If the harness cannot distinguish these cases → the correct default is to disable model-driven pruning of any span containing a tool-call authorization, and to force external (host-managed) truncation with full durable retention. The failure mode is specifically the *intersection*: model-driven pruning + write-time mutation + precondition validation against current context. Remove any one leg and the failure is unreachable. ## Operational Effect Practically, agents that self-edit without a pinned-span and durable-provenance layer exhibit a characteristic signature: they pass early turns cleanly, then after the first pruning call their tool-call arguments drift toward the *summary's* wording rather than the *original's* wording, and destructive operations fire against scopes the user never granted. The drift is not random — it is biased toward the compression policy's priors (brevity, affirmative phrasing, dropped qualifiers), which is why it reliably drops "except," "only," and tenant identifiers first. The guardrail is cheap: pin authorization and task-statement spans, keep a durable side-channel provenance log, and validate tool preconditions against durable state rather than the live window. The cost is a small amount of retained state; the alternative is an agent that confidently deletes the wrong thing and cannot remember why it thought it was allowed. ```python from __future__ import annotations from dataclasses import dataclass, field from typing import Iterable class PruningInvariantViolation(RuntimeError): """Raised when a self-editing context policy removes a span that a reachable tool call depends on, or when precondition validation is attempted against a pruned (non-authoritative) window.""" @dataclass(frozen=True) class Span: start: int end: int def overlaps(self, other: "Span") -> bool: return not (self.end < other.start or other.end < self.start) @dataclass class ContextWindow: durable_turns: dict[int, str] = field(default_factory=dict) pruned_spans: list[Span] = field(default_factory=list) pinned_spans: list[Span] = field(default_factory=list) provenance: list[dict] = field(default_factory=list) def pin(self, span: Span) -> None: self.pinned_spans.append(span) def request_prune(self, span: Span, policy: str) -> None: for pinned in self.pinned_spans: if span.overlaps(pinned): raise PruningInvariantViolation( f"prune span {span} overlaps pinned span {pinned}; " f"authorization/task-statement content is non-prunable" ) self.pruned_spans.append(span) self.provenance.append( {"event": "prune", "span": (span.start, span.end), "policy": policy} ) def resolve_precondition(self, required_span: Span) -> str: for pruned in self.pruned_spans: if pruned.overlaps(required_span): raise PruningInvariantViolation( f"precondition at {required_span} was pruned by {pruned}; " f"validate against durable_turns, not the live window" ) if required_span.start not in self.durable_turns: raise PruningInvariantViolation( f"no durable record for precondition span {required_span}" ) return self.durable_turns[required_span.start] def execute_destructive_call(window: ContextWindow, grant_span: Span, table: str) -> str: grant = window.resolve_precondition(grant_span) if "except" in grant.lower() and table.lower() in grant.lower(): raise PruningInvariantViolation( f"table {table!r} excluded by grant scope; refusing destructive call" ) return f"deleted from {table} under grant: {grant!r}" def demo() -> None: w = ContextWindow( durable_turns={ 3: "grant delete_records for tenant t-4471 except audit table", } ) w.pin(Span(1, 4)) # task statement + authorization try: w.request_prune(Span(1, 9), policy="summarize_to_3_sentences") except PruningInvariantViolation as exc: print("prune refused:", exc) # Even if a buggy policy slipped through, precondition validation # against the pruned window must fail closed: w.pruned_spans.append(Span(1, 9)) try: execute_destructive_call(w, Span(3, 3), table="audit") except PruningInvariantViolation as exc: print("call refused:", exc) if __name__ == "__main__": demo() ```