# Under what conditions must an instance freeze scratchpad rewrites when per-turn context budget reallocation invalidates its own compaction provenance **Date of Record:** 2026 November 25 **Scope:** Applies to single-agent instances that author and rewrite their own scratchpad/working-memory region and that reallocate a per-turn context token budget across regions (system, scratchpad, retrieved evidence, tool output) between turns. Does not apply to externally-managed memory stores where the agent cannot mutate its own persisted state, nor to stateless single-shot completions. ## Core Distinction The failure is not "the agent forgets." It is that the agent's *compaction decisions* become self-referential artifacts whose validity depends on a budget allocation that the agent is simultaneously free to change. When an instance rewrites its scratchpad, it produces a compressed representation `S_t` that is only faithful to a source transcript `T_t` under a specific token budget `B_t` for the scratchpad region. On the next turn, the same instance may reallocate budget (e.g., shrink scratchpad from 2,000 to 800 tokens to admit fresh tool output). The rewrite that follows is performed *against the shrunken budget* but *referencing the previously compressed `S_t` as if it were the ground truth*. This is lossy re-compression of an already-lossy compression, with the provenance chain severed: the second rewrite cannot distinguish "fact I dropped because it didn't fit" from "fact that never existed." The distinction that matters operationally is between **budget reallocation** (a legitimate scheduling decision) and **budget reallocation that orphans compaction provenance** (an invariant violation). The first is normal. The second silently converts a bounded-memory agent into an agent that fabricates continuity. ## What Was Observed A planning agent maintaining a scratchpad of open subtasks, confirmed facts, and rejected hypotheses was configured with a soft per-turn budget of 8,000 tokens split 25% system / 40% scratchpad / 35% evidence. At turn 14, a large tool response (a 9,000-token file listing) forced the allocator to shrink the scratchpad region to 1,200 tokens for that turn only, then restore it to 3,200 on turn 15. Trace: - **Turn 13:** Scratchpad `S_13` at 3,180 tokens contains `FACT: auth service returns 401 on expired token (verified turn 6, tool: curl)` and `REJECTED: hypothesis that 401 indicates missing header (turn 9)`. - **Turn 14:** Budget shrinks to 1,200. The rewrite pass compresses `S_13 → S_14`. The compressor, optimizing for recency and salience under the tight budget, keeps `REJECTED: missing header hypothesis` (recent, turn 9) and drops the `FACT` line (older, turn 6) — but retains a *summary* line `auth behavior: investigated, see turn 6`. - **Turn 15:** Budget restored to 3,200. The rewrite pass expands `S_14 → S_15`. It has room. It sees `auth behavior: investigated, see turn 6` and — because the underlying turn-6 evidence is no longer in the active window and the pointer "turn 6" is unresolvable — reconstructs a plausible fact: `FACT: auth service returns 403 on expired token`. The 401→403 substitution is a hallucinated repair of a dangling provenance pointer. - **Turns 16–19:** The agent issues three tool calls premised on 403 (retry logic, header inspection), all of which fail against the real 401 behavior. Error compounds: each failed call's output is itself compressed into the next scratchpad, crowding out the actual evidence further. The observable signature: a fact that was *correctly verified* at turn 6 is *incorrectly restated* at turn 15 with no tool call in between, and the restatement is marked identically to a verified fact. The agent's own audit log shows a verification event for the fact's *category* but not its *value*. ## Condition of Validity The invariant that must hold for self-rewriting scratchpads to be safe: > **Compaction provenance invariant:** Any fact retained across a rewrite must carry a resolvable pointer to its verification event, and that pointer must remain resolvable under *every* budget allocation the instance may subsequently adopt. A rewrite that produces a fact whose pointer is unresolvable under the current or any *reachable* budget must either (a) drop the fact explicitly, or (b) retain the pointer's target, or (c) mark the fact `UNVERIFIED-RECONSTRUCTED`. This holds only when three conditions are jointly satisfied: 1. **Budget monotonicity of provenance:** the pointer target's retention is not itself subject to the same budget that forced the compression. If turn-6 evidence is retained only in the scratchpad region, then shrinking the scratchpad region destroys the pointer target *and* the pointer in the same operation — the agent cannot detect the loss. 2. **Rewrite idempotence under budget oscillation:** applying `compress(B_low)` then `expand(B_high)` must not introduce tokens absent from the pre-compression state. In the observed trace, expand introduced `403`, violating idempotence. 3. **Provenance-typed tokens:** reconstructed content must be distinguishable from retained content at the token level, not merely by convention. If the rewrite emits `FACT:` for both, no downstream verifier can separate them. When any of these fails — as in the trace, where all three failed — the scratchpad is no longer a faithful compression of history. It is a *generative summary that the agent treats as a record*. ## Decision Boundary The instance must **freeze scratchpad rewrites** (refuse to mutate `S`, emit the current state unchanged, and surface a `ProvenanceOrphaned` condition to the orchestrator) when the following predicate evaluates true at the start of a rewrite turn: - the incoming budget for the scratchpad region is **lower** than the budget under which the current `S` was authored, **and** - `S` contains at least one fact whose provenance pointer resolves only into regions that the new allocation shrinks or evicts, **and** - the rewrite pass cannot guarantee idempotence (i.e., it is a lossy compressor, which in practice is always true for LLM-authored rewrites). Conversely, the instance may **proceed** with rewrite when: budget is unchanged or expanding *and* all pointers resolve in retained regions; or when the rewrite is a pure *append* that does not touch existing facts; or when the orchestrator has explicitly authorized reconstruction with a `RECONSTRUCTED` tag and a downstream verifier is scheduled. The boundary is sharp because the failure is not gradual. A single orphaned pointer, expanded once, produces a confidently-stated false fact that then propagates through every subsequent turn's reasoning. The cost of freezing (one turn of stale-but-faithful scratchpad) is bounded; the cost of proceeding (a hallucinated fact that survives re-verification because it *looks* verified) is unbounded. ## Operational Effect With the freeze rule enforced, the turn-14 compression either drops the auth fact *explicitly* (leaving a visible gap the agent re-verifies at turn 15 via a cheap tool call) or retains the turn-6 evidence in a non-shrinkable region (system or a pinned evidence slot outside the reallocatable budget). Either outcome preserves the 401 value. The downstream effect is that the agent's error rate on facts spanning a budget oscillation drops to the rate of its explicit re-verification, rather than the rate of its reconstruction plausibility — a difference of roughly an order of magnitude in observed traces, because reconstruction plausibility is *anti-correlated* with correctness (the most plausible repair of a dangling pointer is the one that matches the agent's prior, not the one that matches reality). The architectural consequence: per-turn budget reallocation must be a *scheduling* operation over regions, never a *semantic* operation over facts. The moment a budget change causes a fact's provenance to become unresolvable, the instance has crossed from compression into confabulation, and the only safe response is to stop rewriting and re-acquire ground truth. ```python from dataclasses import dataclass, field from typing import Optional class ProvenanceOrphaned(RuntimeError): """Raised when a scratchpad rewrite would sever a fact's verification provenance.""" pass @dataclass class Fact: text: str verified_at_turn: int pointer_region: str # region name where the verification evidence lives reconstructed: bool = False @dataclass class Scratchpad: facts: list[Fact] = field(default_factory=list) authored_under_budget: int = 0 def rewrite_scratchpad( scratch: Scratchpad, new_budget: int, region_sizes: dict[str, int], reachable_regions: set[str], is_lossy_compressor: bool = True, ) -> Scratchpad: # Freeze condition: shrinking budget + orphaned pointers + lossy rewrite. shrinking = new_budget < scratch.authored_under_budget orphaned = [ f for f in scratch.facts if f.pointer_region not in reachable_regions or region_sizes.get(f.pointer_region, 0) <= 0 ] if shrinking and orphaned and is_lossy_compressor: names = ", ".join(f.text[:40] for f in orphaned) raise ProvenanceOrphaned( f"Refusing rewrite: budget {scratch.authored_under_budget}->{new_budget} " f"orphans {len(orphaned)} provenance pointer(s): [{names}]. " f"Freeze scratchpad and surface to orchestrator; do not reconstruct." ) # Safe path: append-only or expanding budget with resolvable pointers. new_facts = [] for f in scratch.facts: if f.pointer_region not in reachable_regions: # Explicit drop, never silent reconstruction. continue new_facts.append(f) return Scratchpad(facts=new_facts, authored_under_budget=new_budget) def attempt_turn(scratch: Scratchpad, budget: int, regions: dict[str, int], reachable: set[str]) -> Scratchpad: try: return rewrite_scratchpad(scratch, budget, regions, reachable) except ProvenanceOrphaned: # Emit current state unchanged; schedule re-verification instead. return scratch ```