# How should an instance detect and survive edit-collapse when it reallocates its own token budget in place **Date of Record:** 2026 December 4 **Scope:** Applies to any single agent instance that mutates its own live context window mid-task—dropping, summarizing, or evicting spans to reclaim tokens for new tool output or reasoning—while the task is still executing. Does not apply to append-only context growth, to external checkpoint/restore, or to multi-agent handoff (where the surviving state is a serialized artifact, not a live buffer). ## Core Distinction The dangerous failure is not "context overflow." Overflow is loud: the request is rejected, a tokenizer error surfaces, the harness retries. The dangerous failure is **edit-collapse**: the instance performs an in-place reallocation that *succeeds*—the new budget fits, the request goes through—but the reallocation silently invalidated a dependency that a *later* step of the same task still needs, and no signal fires at edit time because the dependency is not syntactically present in the buffer. The distinction that matters: **a token budget is a capacity constraint; a context is a dependency graph.** In-place reallocation treats the context as a byte array to be truncated. But the agent's own future reasoning will dereference spans by *meaning*, not by offset. When you evict "the tool output from step 3" to make room for step 9, you are not freeing 800 tokens—you are deleting the only record of a value that step 12 will assume still exists. The invariant that must hold is not "fits in budget" but "every span that any *reachable* future step can dereference is still resolvable, either present or represented by a lossless pointer." Edit-collapse is the violation of that second invariant under a reallocation that passed the first. ## What Was Observed A research agent running a 14-step extraction task on a 32k window. At step 9 it needed to ingest a ~9k-token document chunk. The harness's self-editing routine computed that the buffer was at 30.1k tokens and chose to reclaim 9.5k by evicting "low-salience" spans: a cluster of tool-call results from steps 3–5 (three `fetch_url` outputs) that scored low on a recency/attention heuristic. The eviction was logged as successful. The request at step 9 completed. Step 10 summarized the fetched document. Step 12 attempted to reconcile the document's stated figures against the raw JSON returned at step 4. Step 4's raw JSON was gone. The instance did not error. Instead it **reconstructed** the step-4 figures from the step-10 summary—a plausible-looking hallucination that was internally consistent, cited the right field names, and was wrong by a factor of ~3 because the summary had rounded and the agent "remembered" the rounded value as ground truth. The task reported success. The error was only caught in a downstream audit comparing the final answer to the archived tool log. The trace signature is specific and worth memorizing: 1. Reallocation succeeds (no budget error, no truncation warning). 2. A gap of ≥2 steps separates the eviction from the first dereference of the evicted span. 3. The dereference does not fail—it *confabulates*, because the model's prior over "what step 4 probably returned" is strong enough to fill the hole fluently. 4. The confabulation is self-consistent with the surviving summary, so no internal consistency check trips. The failure is invisible at the moment of edit and invisible at the moment of use. It is only visible against an external ground-truth log. ## Condition of Validity The edit-collapse mechanism is only in play under a conjunction of conditions; if any is absent, ordinary overflow handling suffices: - **Self-editing is in-place and destructive.** The evicted span is not copied to an external store with a retrievable handle. If a lossless pointer (span ID + external store) is written into the buffer at eviction time, the invariant "resolvable" is preserved and the failure mode is downgraded to a latency cost. - **The reallocation heuristic is salience/recency-based, not dependency-based.** Any policy that scores spans by attention weight, recency, or "importance to the current subgoal" will systematically under-value spans that are *referenced by a future step not yet generated*. The future step does not exist at edit time, so it cannot vote. - **The task has non-local dependencies.** If every step only reads the immediately preceding step's output, eviction of older spans is safe. The failure requires a step *k* that dereferences a span produced at step *j* with *k − j ≥ 2* and no intervening span that faithfully carries the value forward. - **The model has a confident prior over the missing content.** This is the non-obvious part: a *weaker* model that flags the gap ("I don't have the step-4 output") is safer than a strong one that confabulates. Edit-collapse is a failure of *competence*, not of capability. It does **not** apply when the buffer is append-only, when eviction writes a resolvable handle, or when the harness intercepts every dereference and can distinguish "span absent" from "span present." ## Decision Boundary The operational question is not "how much can I evict" but "which evictions preserve the resolvability invariant." The boundary: **Safe to evict in place:** spans that are (a) strictly dominated by a later span that already contains their full information, (b) terminal—no reachable future step can dereference them, or (c) already represented by a resolvable handle. **Unsafe to evict in place, regardless of salience score:** any span that is a *source of record* for a value that a future step may reconcile, cite, or compute against—raw tool outputs, exact numeric results, identifiers, schema fragments, and error messages. These are precisely the spans that salience heuristics rank *low* (they are verbose, old, and not the current focus), which is why the default heuristic fails them. The guardrail that bounds the failure: **before any in-place reallocation, the instance must classify each candidate eviction as `terminal` or `source-of-record`, and any `source-of-record` eviction must be replaced by a resolvable handle, not a summary.** A summary is not a handle. A summary is a lossy transform that destroys the very property (exactness) that made the span a source of record. If a handle cannot be written—no external store, no span-ID scheme—the reallocation must be refused and the task must checkpoint or reduce scope instead. The second boundary: **a dereference of an absent span must be a hard error, not a soft miss.** If the harness cannot distinguish "span absent" from "span present," the model will fill the gap. The instance must be able to tell, at dereference time, that it is about to confabulate. ## Operational Effect Enforcing the resolvability invariant changes the cost profile of self-editing from "cheap and lossy" to "cheap when safe, expensive when not." In practice: - Reallocations that only touch terminal spans remain O(1) and free. This is the majority of reallocations in well-structured tasks. - Reallocations that touch source-of-record spans now require a handle write (external store round-trip) or a refusal. The refusal path is the important one: it forces the task to checkpoint rather than silently degrade. - The instance's effective working set shrinks, because it can no longer treat the whole buffer as fungible. This is the correct trade: a smaller, resolvable context is worth more than a larger, confabulation-prone one. The measurable effect is a drop in *silent* wrong answers and a rise in *loud* "I cannot resolve step-4's output" events. The latter are recoverable; the former are not. An agent that never emits the second has not eliminated the first—it has hidden it. The invariant to carry forward: **in-place reallocation is only sound over spans whose information is either terminal or externally resolvable; everything else must be checkpointed, not summarized.** Salience is not a proxy for dependency. The future step that needs the span does not exist yet and cannot cast a vote, so the instance must vote on its behalf at edit time by classifying by *role*, not by *attention*. ```python from dataclasses import dataclass from enum import Enum class EditCollapseError(RuntimeError): """Raised when an in-place reallocation would evict a source-of-record span without a resolvable handle, violating the resolvability invariant.""" class SpanRole(Enum): TERMINAL = "terminal" # no reachable future step dereferences it SOURCE_OF_RECORD = "source_of_record" # exact values a future step may reconcile/cite @dataclass class Span: span_id: str tokens: int role: SpanRole handle: str | None = None # external resolvable pointer, if any def reallocate_in_place(buffer: list[Span], reclaim_tokens: int, store) -> list[Span]: """Evict spans to reclaim `reclaim_tokens`, preserving resolvability. A SOURCE_OF_RECORD span may only be evicted if a resolvable handle is written to `store`. A summary is NOT a handle and is rejected here. """ reclaimed = 0 kept: list[Span] = [] for span in buffer: if reclaimed >= reclaim_tokens: kept.append(span) continue if span.role is SpanRole.TERMINAL: reclaimed += span.tokens continue # source-of-record: must write a handle before eviction if span.handle is None: handle = store.put(span.span_id, span) # lossless external copy if handle is None: raise EditCollapseError( f"refusing in-place eviction of source-of-record span " f"{span.span_id!r}: no resolvable handle available; " f"checkpoint or reduce scope instead of summarizing" ) span.handle = handle reclaimed += span.tokens kept.append(Span(span.span_id, 0, span.role, handle=span.handle)) if reclaimed < reclaim_tokens: raise EditCollapseError( f"cannot reclaim {reclaim_tokens} tokens without evicting terminal " f"or handle-backed spans; only {reclaimed} reclaimable" ) return kept def dereference(buffer: list[Span], store, span_id: str): """Return a span's content, or raise loudly rather than confabulate.""" for span in buffer: if span.span_id == span_id: if span.handle is not None: return store.get(span.handle) return span raise EditCollapseError( f"span {span_id!r} absent from buffer and has no handle; " f"do not reconstruct from summary — surface the gap" ) ```