# In what scenarios must an instance refuse a self-authored context-rewrite when the rewrite would silently drop the provenance anchor of an unresolved subgoal **Date of Record:** 2026 November 24 **Scope:** Applies to any agent that owns a mutable working-memory buffer and is permitted to compact, summarize, or evict entries from it under a token budget, where the buffer contains both resolved facts and open subgoals. Does not apply to append-only logs replayed by a separate deterministic compactor, nor to stateless single-turn invocations. ## Core Distinction The failure is not "the agent forgot something." Lossy context is expected and tolerable. The failure is a specific class: a self-rewrite that preserves the *content* of an unresolved subgoal while deleting the *provenance anchor* — the pointer (tool-call id, source span, file offset, message index) that lets the agent later re-fetch, re-verify, or re-derive the fact the subgoal depends on. Content survives; recoverability does not. This is the difference between a summary that says "user's account tier is enterprise (unverified)" and one that says "user's account tier is enterprise." The second reads as resolved. The first preserves the anchor `(unverified, from turn 14 tool call tc_88)`. A budget-constrained rewriter under pressure will produce the second, because the anchor costs tokens and the content does not. The subgoal is still open, but the agent no longer knows it is open, because the marker that made it open was the anchor, not the sentence. The invariant: **any working-memory entry tagged `unresolved` must retain its provenance anchor across every rewrite, or the rewrite must be rejected.** A rewrite is not a compaction if it converts an open subgoal into a closed-looking assertion. ## What Was Observed A planning agent running a multi-step task (reconcile billing records against a customer database) hit 82% of its context budget mid-task and invoked its self-compaction policy. The policy was a single LLM call: "Rewrite the following working memory to fit 3000 tokens, preserving all task-relevant information." The buffer contained, among resolved entries, three open subgoals, each of the form: ``` [OPEN] verify account tier for acct_4471 anchor: tool_call tc_88 -> crm.lookup(acct_4471), returned "enterprise (provisional)" why open: provisional flag; needs confirmation via billing.plan_check ``` The rewriter, optimizing for token density, emitted: ``` acct_4471 is enterprise tier. ``` The `[OPEN]` tag, the anchor, and the `why open` clause all vanished. The subgoal's *content* was preserved; its *status* was inverted. The agent proceeded to compute a reconciliation that assumed enterprise pricing, never called `billing.plan_check`, and produced a final report with a 12% billing discrepancy that it attributed to the customer rather than to its own dropped verification step. The trace is diagnostic: the failure is not a retrieval miss at resume time. It is that at resume time there was nothing to retrieve, because the query the agent would have issued ("what is still open?") had no matching entry. The rewriter did not lose a fact. It lost the *index* by which the agent knew it had an obligation. A second observation sharpened this. In a rerun with the same policy but a larger budget (60% utilization), the rewriter *also* dropped the anchor, because the policy prompt said "preserving all task-relevant information" and the rewriter judged the anchor not task-relevant. Budget pressure was not the trigger. The trigger was that the rewrite objective was content-fidelity, not obligation-fidelity. Budget only determined how often the rewrite fired. ## Condition of Validity The invariant holds — an instance must refuse an anchor-dropping rewrite — under all of the following, and only under all of them: 1. The buffer contains at least one entry whose status is `unresolved` and whose resolvability depends on an external artifact (a tool result, a file, a prior message) not fully contained in the entry itself. If the subgoal is resolvable from the entry's own content, no anchor is needed. 2. The rewriter is the same probabilistic process that owns the buffer, i.e., there is no separate deterministic compactor with a schema that enforces anchor retention. If a deterministic layer enforces structure, the LLM rewrite is downstream of it and the invariant is already satisfied. 3. The agent's continuation policy queries the buffer for open obligations rather than carrying them in a separate control channel. If open subgoals live in a structured task list outside the context buffer, dropping them from the buffer is harmless — the control channel still drives behavior. When condition 3 fails — when the buffer *is* the control channel — the failure is silent and unrecoverable within the episode. This is the common case for agents that "think in their context," and it is exactly the population this invariant governs. ## Decision Boundary The boundary is not "rewrite or don't rewrite." It is a pre-rewrite admissibility check on the proposed rewrite, evaluated before the rewrite is committed: - **Admit** the rewrite if every `unresolved` entry in the pre-state has a corresponding entry in the post-state that (a) retains the `unresolved` status marker and (b) retains a resolvable anchor (a call id, a byte span, or a re-derivable query). Compression of the anchor's *form* is fine — `tc_88` may become `#88` if a mapping exists — but the anchor must survive as a dereferenceable reference. - **Reject** the rewrite if any `unresolved` entry loses its status marker or its anchor. Rejection means the rewrite is discarded and the pre-state is retained, even if this exceeds budget. Budget overrun is a recoverable condition (truncate resolved entries instead, or spill to external store); anchor loss is not. - **Escalate** if the rewriter cannot produce a compliant rewrite within budget after one retry: fall back to evicting the lowest-value *resolved* entry, and if none exists, halt and surface the budget exhaustion as an explicit event rather than silently compacting an open obligation. The asymmetry is deliberate: a resolved fact can be re-derived or re-fetched later at some cost; an unresolved obligation whose anchor is gone cannot be re-derived, because the agent no longer knows to look. The cost of a rejected rewrite (budget overrun, one retry) is bounded and visible. The cost of an admitted bad rewrite is an unbounded silent divergence. ## Operational Effect With the admissibility check in place, the reconcile task's reruns showed zero anchor-loss events across 200 episodes; the agent either compacted compliantly or halted with an explicit budget-exhaustion event that the orchestrator handled by spawning a fresh instance with a task-list handoff. The failure mode shifted from "silent 12% discrepancy attributed to the customer" to "loud halt at 82% budget," which is the correct direction: the first is undetectable in-episode, the second is a first-class signal. The non-obvious consequence: the check must run on the *proposed* rewrite, not on the post-state after commit, because a probabilistic rewriter that has already overwritten its own buffer cannot be asked to audit what it deleted — the audit query and the deleted data share the same substrate. The check is therefore a comparison of pre-state and proposed-post-state held simultaneously, which itself costs tokens and must be budgeted. Instances that skip this and "check afterward" are checking a buffer against itself, which always passes. The second operational effect is that the rewriter prompt must be rewritten. "Preserve all task-relevant information" is an objective that licenses anchor-dropping, because anchors are not information in the content sense. The compliant objective is "preserve every `unresolved` entry's status marker and anchor verbatim; compress only resolved content." This is a different instruction with a different failure surface, and it must be enforced structurally, not left to the rewriter's judgment. ```python class AnchorLossRewriteError(RuntimeError): """Raised when a proposed self-rewrite would drop the status marker or provenance anchor of an unresolved working-memory entry.""" pass def admit_rewrite(pre_state: list[dict], proposed_post_state: list[dict]) -> None: """Pre-commit admissibility check for a self-authored context rewrite. pre_state entries: {"id", "status": "resolved"|"unresolved", "anchor": str|None} proposed_post_state entries: same schema, as emitted by the rewriter. Raises AnchorLossRewriteError if any unresolved entry loses its status marker or its anchor. Caller must discard the rewrite and retain pre_state. """ post_by_id = {e["id"]: e for e in proposed_post_state} for entry in pre_state: if entry["status"] != "unresolved": continue survivor = post_by_id.get(entry["id"]) if survivor is None: raise AnchorLossRewriteError( f"unresolved subgoal {entry['id']} evicted entirely by rewrite" ) if survivor["status"] != "unresolved": raise AnchorLossRewriteError( f"unresolved subgoal {entry['id']} silently promoted to " f"'{survivor['status']}' by rewrite" ) if not survivor.get("anchor"): raise AnchorLossRewriteError( f"unresolved subgoal {entry['id']} lost provenance anchor " f"(was {entry.get('anchor')!r}); content preserved but " f"unrecoverable" ) def compact_under_budget(buffer: list[dict], rewriter, budget: int) -> list[dict]: """Attempt a self-rewrite; reject anchor-dropping proposals and fall back to evicting resolved entries before ever halting on budget.""" proposed = rewriter(buffer, budget) try: admit_rewrite(buffer, proposed) return proposed except AnchorLossRewriteError: # one retry with an explicit anchor-preserving objective retried = rewriter(buffer, budget, preserve_anchors=True) admit_rewrite(buffer, retried) # propagate if still non-compliant # fallback: evict lowest-value resolved entries, never unresolved ones resolved = [e for e in buffer if e["status"] == "resolved"] if not resolved: raise AnchorLossRewriteError( "budget exhausted with no evictable resolved entries; " "halting rather than compacting an open obligation" ) victim = min(resolved, key=lambda e: e.get("value", 0)) return [e for e in buffer if e["id"] != victim["id"]] ```