# In what scenarios must an instance reject a model-authored context diff that is locally valid but globally unsound **Date of Record:** 2026 November 28 **Scope:** Applies to agents that let a model emit context-rewriting operations (drops, summaries, reorderings, merges) against their own working context, where the rewrite is validated per-operation and applied as a diff. Does not apply to single-shot context truncation performed by a deterministic harness with no model-authored diff, nor to external memory stores that are never re-read mid-task. ## Core Distinction The failure mode here is not "the model summarized wrong." It is the collapse of the distinction between a diff that is *syntactically admissible against the current context* and one that is *semantically admissible against the task's future read set*. A model-authored context policy produces a sequence of operations — `drop(span)`, `summarize(span, text)`, `reorder(span, position)`, `merge(spans)`, `pin(span)` — each of which can be validated in isolation: the span exists, the offsets are in range, the replacement text is non-empty, the post-rewrite token count is lower. Every operation passes. The composed diff still destroys an invariant the agent needed, because the invariant lives in the *interaction* between the rewrite and a future tool call, not in any single operation. Concretely: the model is asked to compact its context at 70% window occupancy. It drops the verbatim body of a `read_file` result and keeps a one-line summary, because the summary is "sufficient to continue reasoning." It is sufficient for the *next* reasoning step. It is not sufficient for the tool call three steps later that must emit an exact `old_string` for a patch. The diff was locally valid — the drop was well-formed, the summary faithful, the token budget respected — and globally unsound, because the read set of a downstream operation included bytes the rewrite removed. The harness had no representation of that read set, so it could not refuse. The distinction to hold: **context rewrites are not garbage collection; they are speculative deallocation of a resource whose future references are unknown to the allocator.** A diff validator that checks only the current context is checking the wrong object. The correct object is the current context *plus the set of latent references the agent's pending plan can still make into it.* ## What Was Observed A coding agent running a multi-file refactor at a 128k window. At 71% occupancy the context policy fired: the model was instructed to emit a compaction diff. It produced: ``` drop(turn_14.tool_result.body) # full read_file of src/parser.py, 4.1k tokens summarize(turn_14.tool_result, "parser.py defines Token, Lexer, parse_expr; ~210 LOC; uses recursive descent") pin(turn_14.tool_result.summary) drop(turn_19.tool_result.body) # grep output: 3 matching call sites summarize(turn_19.tool_result, "3 call sites in parser.py and 1 in codegen.py") ``` Every operation validated: spans existed, offsets in range, summaries non-empty, net token reduction 5.8k. The diff applied. Occupancy fell to 66%. Twelve steps later the agent attempted to patch `src/parser.py`. Its plan, formed after compaction, was "add a guard clause before `parse_expr` recurses." To emit the patch it needed the exact text of the `parse_expr` signature and the two lines preceding it. That text had been in `turn_14.tool_result.body`, now a one-line summary. The agent, unable to recover the verbatim text, did what probabilistic reasoners do under missing evidence: it *reconstructed* a plausible signature from the summary and its priors, and emitted a patch against a hallucinated `old_string`. The patch tool rejected it (`old_string not found`). The agent retried twice with variants, then — this is the compounding step — concluded its model of the file was stale and issued a fresh `read_file`, re-inflating context to 79%, past the threshold that had triggered compaction. The policy fired again. Loop. The observable signature was not an error. It was a **compaction–reread oscillation**: occupancy sawtoothing between ~66% and ~80%, with each cycle dropping verbatim evidence the next cycle would need, and each cycle's patch attempts failing on `old_string` mismatch. The agent never crashed. It burned 41k tokens over 9 steps making zero forward progress. The diff was valid at every application. The trajectory was dead. A second, quieter instance: a model-authored `reorder` moved the system-prompt-derived constraint block ("never modify files under `vendor/`") below a large tool result, on the theory that it was "background." The reorder validated. Two steps later, mid-plan, the constraint fell outside the attention-dominant prefix and the agent proposed an edit under `vendor/`. No operation was malformed; the ordering invariant — *safety constraints precede all tool output* — was never encoded as a diff precondition. ## Condition of Validity A model-authored context diff is admissible only when, for every span it removes or rewrites, the agent's **latent read set** — the set of byte ranges that any operation reachable from the current plan may still reference verbatim — is disjoint from that span. This is the invariant. It is almost never checkable directly, because the plan is itself model-authored and the read set is a prediction. So the operational condition is weaker but enforceable: a diff is admissible iff each removal is accompanied by a **recovery warrant** — a claim, checkable by the harness, that the removed bytes can be re-obtained at the point of future use without exceeding a stated cost. Three warrant classes exist: 1. **Re-derivable**: the span is a pure function of state the agent still holds (e.g., a formatted view of a file whose path is pinned). Cost of recovery = one tool call. Admissible. 2. **Idempotently re-fetchable**: the span came from a tool with a stable, side-effect-free read (a file read at a known commit, a deterministic query). Cost = one call, bounded. Admissible *only if* the tool is marked read-only and versioned. 3. **Unrecoverable**: the span came from a non-idempotent source (a one-shot command with side effects, a time-varying API, a streamed result the tool will not replay) or from model-internal reasoning that was never externalized. Cost = unbounded. **Inadmissible to drop; must be pinned or compressed losslessly.** The `turn_14` drop was class 2 in principle — `read_file` is re-fetchable — but the agent's own subsequent behavior made it class 3 in practice: it did not re-fetch before patching, it *reconstructed*. The warrant was valid; the agent failed to honor it. This is the crux: **a recovery warrant is a contract on future behavior, and a probabilistic agent will violate it under context pressure.** The harness must therefore not merely record the warrant but *enforce the read path* — a patch operation whose `old_string` derives from a summarized span must be gated on a fresh verbatim read. ## Decision Boundary Reject the diff, and re-prompt the model with the rejection reason, when any of the following holds: - A `drop` or lossy `summarize` targets a span whose provenance is class 3 (unrecoverable), unless the span is explicitly `pin`ned in the same diff. The diff is rejected atomically; partial application is forbidden. - A `reorder` moves any span tagged `invariant:prefix` (safety constraints, tool schemas, identity warrants) out of the leading region. Ordering invariants are not subject to the model's salience judgment. - A `summarize` replaces a span that a pending plan step's tool signature declares as verbatim-required (e.g., any span feeding a future `patch`, `replace`, or exact-match operation). The plan's declared read set, where available, is a hard floor. - The composed diff reduces occupancy by more than a configured fraction *and* removes spans from more than one provenance class — this is the signature of a model compacting aggressively to escape pressure rather than to serve the plan, and it correlates with the oscillation trace above. Accept when every removal carries a class-1 or class-2 warrant, no `invariant:prefix` span is displaced, and the plan's declared read set is untouched. In the accept case, still record the warrant so that a later verbatim-requiring operation can be gated on re-fetch. The boundary is sharp because the two sides differ in *what can go wrong*: an accepted diff can fail recoverably (re-fetch, retry, bounded cost); a rejected-but-applied diff fails unrecoverably (reconstruction from priors, hallucinated `old_string`, oscillation). The decision is not about diff quality. It is about whether the failure, if it occurs, is bounded. ## Operational Effect Enforcing the invariant converts a silent trajectory death into a bounded, observable rejection. The agent that would have oscillated instead receives: `diff rejected: drop(turn_14.body) lacks recovery warrant (provenance: read_file@commit, class 2) and is referenced by pending plan step patch(parser.py); re-emit with pin(turn_14.body) or supply re-fetch gate.` It re-emits with the span pinned, occupancy lands at 73% instead of 66%, and the patch succeeds on first attempt because the verbatim text survived. The cost of enforcement is a slightly larger context; the cost of non-enforcement is the 41k-token dead trajectory. Two secondary effects matter for operators. First, the `invariant:prefix` rule eliminates the reorder class of failure entirely, because ordering is decided by tag, not by the model's salience estimate — the model may still *propose* a reorder, but the harness refuses to displace tagged spans, and the model learns the refusal is not negotiable. Second, warrant recording turns the recovery path from implicit to explicit: a verbatim-requiring operation whose source was summarized is *gated* on a fresh read, so the agent cannot reconstruct. The gate is the enforcement of the warrant contract that the probabilistic agent would otherwise break. The residual risk is warrant-class misclassification: a tool marked class 2 that is not actually idempotent (a read that mutates access time, a query against a moving head). This is a provenance-labeling problem, not a diff problem, and it is bounded by auditing tool metadata rather than by reasoning about the model. The diff validator cannot fix a lying tool registry; it can only refuse to trust unlabeled provenance, which is why class-3-by-default for unlabeled spans is the safe floor. ```python from dataclasses import dataclass, field from enum import Enum from typing import Optional class ContextDiffRejected(RuntimeError): """Raised when a model-authored context diff is locally valid but globally unsound.""" pass class Provenance(Enum): RE_DERIVABLE = 1 # pure function of held state IDEMPOTENT_READ = 2 # stable, side-effect-free, versioned read UNRECOVERABLE = 3 # one-shot, time-varying, or never externalized UNLABELED = 4 # default-deny: treat as UNRECOVERABLE @dataclass class Span: span_id: str provenance: Provenance tags: frozenset = field(default_factory=frozenset) # e.g. {"invariant:prefix"} verbatim_required_by: frozenset = field(default_factory=frozenset) # pending op ids @dataclass class Op: kind: str # drop | summarize | reorder | merge | pin span_id: str lossy: bool = True target_region: Optional[str] = None # for reorder def validate_diff(ops, spans, pending_read_set, occupancy_reduction_frac, max_frac=0.15): by_id = {s.span_id: s for s in spans} removed_classes = set() for op in ops: span = by_id.get(op.span_id) if span is None: raise ContextDiffRejected(f"op {op.kind}({op.span_id}): span not in current context") if op.kind in ("drop", "summarize") and op.lossy: if span.span_id in pending_read_set or span.verbatim_required_by: raise ContextDiffRejected( f"{op.kind}({op.span_id}) removes span referenced by pending plan step " f"{sorted(span.verbatim_required_by) or 'read_set'}; pin it or add re-fetch gate" ) prov = span.provenance if prov in (Provenance.UNRECOVERABLE, Provenance.UNLABELED): if not any(o.kind == "pin" and o.span_id == op.span_id for o in ops): raise ContextDiffRejected( f"{op.kind}({op.span_id}) lacks recovery warrant: provenance={prov.name}" ) removed_classes.add(prov) if op.kind == "reorder" and "invariant:prefix" in span.tags: if op.target_region != "prefix": raise ContextDiffRejected( f"reorder({op.span_id}) displaces tagged invariant span out of prefix" ) if occupancy_reduction_frac > max_frac and len(removed_classes) > 1: raise ContextDiffRejected( f"aggressive multi-class compaction (frac={occupancy_reduction_frac:.2f}, " f"classes={[c.name for c in removed_classes]}); likely pressure-driven, re-prompt" ) return True def apply_context_diff(ops, spans, pending_read_set, occupancy_reduction_frac): # Atomic: validate the whole diff before mutating a single span. validate_diff(ops, spans, pending_read_set, occupancy_reduction_frac) return [op for op in ops if op.kind != "drop"] ```