Under what conditions must an instance refuse to prune its own working context during self-editing rewrites

**Date of Record:** 2026 December 2 **Scope:** Applies to single-agent loops that perform model-driven pruning, summarization, or rewriting of their own in-flight working context (scratchpads, tool transcripts, plan state) within a single task episode. Does not apply to external memory stores, cross-episode archival compaction, or human-curated context management.

Core Distinction

There is a difference between *lossy compression of redundant tokens* and *destruction of the provenance chain that justifies a pending action*. A self-editing context controller can safely drop tokens when the dropped content is recoverable from a live referent (an open tool result, a file handle, a re-fetchable source) or when it is genuinely superseded. It must refuse to prune when the tokens being removed are the *only* remaining record of a commitment, a constraint, or a negative result that the current plan depends on. The failure is not "forgot something." The failure is "forgot something that was load-bearing for a decision already in progress, while believing it had retained it."

The non-obvious boundary: the controller's own estimate of what is redundant is computed from the same finite context it is about to truncate. Pruning decisions are made under the exact resource pressure that makes them dangerous, and the evidence that a token was load-bearing often lives *in the token you are about to delete*.

What Was Observed

A planning agent executing a multi-tool task (read config → mutate state → verify) hit 78% of its context budget. A self-edit pass was triggered with the instruction "summarize prior tool outputs and remove redundant steps." The controller emitted a rewrite that:

  1. Collapsed three `read_file` results into a one-line summary: `"config loaded, ~40 lines."`
  2. Dropped an earlier `grep` that had returned *zero matches* for a required key.
  3. Retained the plan step `"set key X from config"` because the step text itself referenced X.

The subsequent `set` call operated on a key that the dropped `grep` had already proven absent. The negative result (zero matches) was the only evidence that the plan step was invalid. After pruning, the plan looked internally consistent — every step referenced a variable that the summary claimed was "loaded." The agent executed the invalid mutation, failed verification, and re-planned from the *rewritten* context, which no longer contained the evidence that would have prevented the retry. The loop repeated twice before the token budget forced termination.

The trace shows the exact transition: the negative-result token was classified as "low relevance" by the controller because it contained no entity the current plan referenced. That is precisely the signature of a *disconfirming* observation — it references nothing the plan wants, which is why it is the thing that should veto the plan.

Condition of Validity

Pruning is valid only when, for every removed span, at least one of the following holds **and is verifiable from retained context alone**:

The critical clause is *verifiable from retained context alone*. If the justification for dropping a span requires reading the span, the drop is unverifiable and must be refused. Negative results, "do not do X" constraints, and prior failed attempts almost always fall into the unverifiable class: their relevance is defined by absence, so no positive reference in the plan will point at them.

A second validity condition: the controller must not be permitted to prune the *record of its own prior prunes*. If a rewrite silently removes the marker that a span was summarized, downstream steps cannot distinguish "never observed" from "observed and compressed," and the agent will re-fetch, re-derive, or worse, re-execute.

Decision Boundary

The boundary is crossed at the moment the controller classifies a span as prunable using a relevance score computed against the *current plan text*. This is the wrong oracle. Relevance for pruning must be computed against the *set of open obligations* — pending steps, unresolved constraints, and unverified claims — plus an explicit protected class for:

If the controller cannot prove a span is outside the protected class from retained context, it must emit a *compression with provenance* (summary plus a pointer to the raw span, or a tombstone) rather than a deletion. Deletion without tombstone is only permitted for spans inside the protected class that have been explicitly discharged by a completed step whose completion record is retained.

Concretely: refuse the rewrite when `protected_spans_removed > 0` and no tombstone or live referent covers them. This is a hard gate, not a scoring heuristic.

Operational Effect

Enforcing the gate changes the failure mode from *silent invalidation* to *budget pressure surfaced to the planner*. When the protected set cannot be compressed below budget, the correct response is not a more aggressive rewrite — it is to escalate: checkpoint the protected set to an external store, or halt and report context exhaustion. The agent that halts with an intact provenance chain can be resumed; the agent that rewrites past the gate cannot, because the evidence needed to detect its own error has been deleted by the same pass that introduced the error.

The practical invariant: **a self-edit pass may reduce tokens only if the post-rewrite context can still prove, without re-reading deleted spans, that every open obligation is either satisfied or explicitly blocked.** Any rewrite that cannot satisfy this proof obligation must be rejected and the pre-rewrite context restored.

class ContextPruneViolation(RuntimeError):
    """Raised when a self-edit rewrite would delete load-bearing context."""
    pass


PROTECTED_KINDS = frozenset({
    "negative_result",
    "constraint",
    "precondition",
    "provenance_marker",
})


def validate_self_edit(pre_spans, post_spans, open_obligations):
    """
    pre_spans: list of dicts with keys: id, kind, text, discharged_by (or None)
    post_spans: list of dicts retained after the rewrite, plus tombstones with
                keys: id, tombstone (bool), live_referent (or None)
    open_obligations: set of span ids still required by pending plan steps
    """
    retained = {s["id"]: s for s in post_spans}
    tombstones = {s["id"]: s for s in post_spans if s.get("tombstone")}

    for span in pre_spans:
        sid = span["id"]
        if sid in retained:
            continue

        # Span was removed by the rewrite. Is removal justified?
        covered = sid in tombstones or span.get("live_referent") is not None
        discharged = span.get("discharged_by") is not None

        if span["kind"] in PROTECTED_KINDS and not (covered or discharged):
            raise ContextPruneViolation(
                f"rewrite deleted protected span {sid!r} "
                f"(kind={span['kind']!r}) with no tombstone, live referent, "
                f"or discharge record; relevance oracle was plan-relative, "
                f"which cannot see disconfirming evidence"
            )

        if sid in open_obligations:
            raise ContextPruneViolation(
                f"rewrite deleted span {sid!r} still bound to an open "
                f"obligation; post-rewrite context cannot prove step validity"
            )

    # Post-rewrite must still prove every open obligation is satisfiable.
    for ob_id in open_obligations:
        if ob_id not in retained and ob_id not in tombstones:
            raise ContextPruneViolation(
                f"open obligation {ob_id!r} has no retained evidence or "
                f"tombstone after rewrite; context is now unprovable"
            )
    return True