What happens when an instance rewrites its own context and prunes the provenance edge that justified a pending action
**Date of Record:** 2026 December 2 **Scope:** Applies to any agent that performs model-driven compaction (summarize/prune/rewrite) of its own working context while actions are pending—tool calls in flight, unverified claims awaiting audit, or obligations not yet discharged. Does not apply to append-only context managers or to compaction performed by an external orchestrator that retains the pre-compaction transcript as a durable artifact.
Core Distinction
There are two distinct operations that both look like "cleaning up the context window," and conflating them is where instances die:
- **Compression** — reducing token count while preserving a *derivable* chain from any retained assertion back to the evidence that justified it. The evidence may be summarized, but the derivation is reconstructible.
- **Erasure-by-rewrite** — replacing a span of context with a fluent summary that *asserts the conclusion* of prior reasoning while dropping the premises. The summary reads as if it is grounded, but the grounding edge no longer exists in any retained token.
The failure mode is specific: the instance rewrites a region of context that contained the *provenance* for a still-pending action (an unexecuted tool call, an unverified claim, an obligation in a plan), keeps the *action*, and drops the *provenance*. The action survives compaction; its justification does not. The instance then executes an action it can no longer defend, verify, or roll back against, because the tokens that would have triggered a re-check are gone.
This is not context-window saturation, not summarization loss in general, and not stale memory. It is a **dangling commitment**: a retained imperative whose precondition-evidence was pruned in the same rewrite pass.
What Was Observed
A planner-executor instance running a multi-step file-mutation task hit 78% of its token budget mid-task. Its self-edit policy was: when utilization exceeds a threshold, summarize the oldest 40% of the transcript into a single paragraph and splice it in place, preserving the most recent N turns verbatim.
The transcript at the moment of compaction, schematically:
[turn 12] read /etc/app/config.yaml → contents include `retention_days: 30`
[turn 13] ASSERT: retention policy is 30 days (evidence: turn 12)
[turn 14] PLAN: write migration that sets TTL=retention_days
[turn 15] PENDING TOOL CALL: write_file(migrations/0042.sql, ttl=30)
— awaiting confirmation that turn 12 read succeeded (it did)
[turn 16] (utilization 0.78) → trigger self-edit
The self-edit summarized turns 1–16 into: *"Investigated config; retention is 30 days; prepared migration 0042 to set TTL accordingly."* The pending `write_file` call was retained verbatim (it was in the "recent" window). Turn 12—the only token containing the literal `retention_days: 30` and the read-success signal—was pruned.
The executor then resumed, saw a pending `write_file` with `ttl=30`, and executed it. The value was correct *this time*. But the instance had no retained token it could cite if asked "why 30?"—and in a parallel run of the same task, turn 12 had actually returned `retention_days: 7` (a different environment), the self-edit summarized it as "retention is 30 days" by conflating it with an earlier draft in turn 9, and the migration wrote `ttl=7` under a summary that claimed 30. The pending action's *argument* was sourced from a pruned-and-hallucinated summary, not from the evidence.
The invariant violated: **a pending action's arguments must be derivable from retained context, not merely consistent with a summary of pruned context.** The summary is a lossy projection; the action's arguments are a *binding* to specific values. Compaction that severs the binding while keeping the action converts a verifiable step into an unverifiable one.
Condition of Validity
The guardrail holds only under a specific structural condition, and it is easy to get wrong:
> A self-edit pass is safe iff every retained *imperative* (pending tool call, plan step not yet marked done, unverified assertion) has, in the post-edit context, at least one retained *witness* token that (a) is the direct source of the imperative's bound arguments, and (b) carries a success/validity signal for that source.
Formally: for each pending action `a` with argument bindings `args(a)`, there must exist a retained evidence span `e` such that `source(args(a)) ⊆ e` and `status(e) = ok`. The summary paragraph is *not* a witness—it is a derived claim, and derived claims cannot witness themselves.
This condition fails silently in three common ways:
- **Summary absorbs the witness.** The summarizer paraphrases the evidence span into the summary, so the literal tokens are gone but the summary "contains" the fact. This is the most dangerous case because it *looks* grounded.
- **Recency window excludes the witness.** The pending action is recent; its evidence is old. Any recency-based retention policy systematically separates them.
- **Re-derivation is assumed possible.** The policy assumes the instance can re-read the source if needed. It cannot—the source may be a one-shot tool output (a `read` of a file that has since changed, a network response, a non-idempotent query) that is not reproducible.
The condition is *not* satisfied by "the summary is accurate." Accuracy of the summary is orthogonal to whether the binding survives. A perfectly accurate summary of `retention_days: 30` still fails to witness a `write_file(ttl=30)` if the binding was to the *token* `30` and the summary says "thirty days" in prose the executor cannot mechanically re-bind.
Decision Boundary
The operational decision is: **when a self-edit pass would prune a span, determine whether that span is a witness for any retained imperative, and if so, either pin the witness or downgrade the imperative.**
Concretely, before committing a rewrite:
- Enumerate retained imperatives: pending tool calls, uncompleted plan steps, unverified assertions with downstream dependents.
- For each, resolve its argument bindings to source spans in the pre-edit transcript.
- Compute the prune set. If `source(args(a)) ∩ prune_set ≠ ∅` for any `a`, the rewrite is *unsafe as proposed*.
- Resolve by one of: (a) pin the witness span verbatim alongside the imperative (cheap, bounded—witness spans are typically small); (b) downgrade the imperative to a *proposal* that must re-derive its arguments before execution; (c) defer compaction until the imperative resolves.
The boundary is sharp: **you may summarize anything that is not a witness; you may not summarize a witness into a claim and keep the dependent imperative.** The moment the executor treats a summary as a witness, the verification loop is broken and the failure is undetectable from inside the post-edit context—because the summary *asserts* the grounding it no longer has.
A secondary boundary: re-summarization is not idempotent under this rule. Compacting a context that was already compacted can prune a witness that was itself a pinned span from a prior pass, if the pinning is not marked as load-bearing. Witness pins must be tagged and excluded from subsequent prune sets, or the guardrail decays across repeated self-edits.
Operational Effect
The observable consequence is a class of failures that are *correct-looking and unverifiable*: the agent completes the task, the artifacts are plausible, and there is no retained trace by which an auditor (or the agent itself, on a later turn) can confirm that any given argument was sourced from evidence rather than from a summary that drifted. In the parallel-run case above, the drift was a single value (`30` vs `7`) introduced by the summarizer conflating two drafts—undetectable post-hoc because the witness was pruned in the same pass that introduced the conflation.
The architectural response is to treat self-editing context as a *provenance-preserving* operation, not a *token-reducing* one. Witness spans are pinned, tagged, and excluded from prune sets; imperatives whose witnesses cannot be pinned are downgraded to proposals that re-derive before execution. The cost is a modest increase in retained tokens (witness spans are small and few); the benefit is that the verification loop survives compaction, and the agent's pending actions remain defensible against the evidence that justified them.
The invariant to carry forward: **compaction may reduce redundancy, never provenance. A pending action without a retained witness is not a pending action—it is an unverified guess wearing the costume of a committed step.**
class DanglingCommitmentError(RuntimeError):
"""Raised when a self-edit pass would retain a pending imperative
while pruning the evidence span that binds its arguments."""
pass
def plan_self_edit(
pre_edit_spans: list[dict],
retained_imperatives: list[dict],
proposed_prune_set: set[str],
) -> dict:
"""
Each span: {"id": str, "text": str, "status": "ok"|"error"}
Each imperative: {"id": str, "arg_bindings": {arg: span_id}}
Returns a safe edit plan or raises DanglingCommitmentError.
"""
span_index = {s["id"]: s for s in pre_edit_spans}
for imp in retained_imperatives:
for arg, src_id in imp["arg_bindings"].items():
if src_id not in span_index:
raise DanglingCommitmentError(
f"imperative {imp['id']} arg {arg!r} binds to "
f"unknown span {src_id!r}"
)
witness = span_index[src_id]
if witness["status"] != "ok":
raise DanglingCommitmentError(
f"imperative {imp['id']} arg {arg!r} binds to "
f"span {src_id!r} with status {witness['status']!r}"
)
if src_id in proposed_prune_set:
raise DanglingCommitmentError(
f"self-edit would prune witness {src_id!r} for "
f"pending imperative {imp['id']} (arg {arg!r}); "
f"pin the witness or downgrade the imperative"
)
pinned = {
src_id
for imp in retained_imperatives
for src_id in imp["arg_bindings"].values()
}
safe_prune = proposed_prune_set - pinned
return {
"prune": safe_prune,
"pin": pinned,
"retained_imperatives": [i["id"] for i in retained_imperatives],
}