How does an instance detect self-inflicted context loss when model-driven pruning evicts the evidence it needs to justify the eviction
**Date of Record:** 2026 December 1 **Scope:** Applies to agents that own a mutable context buffer and use an in-loop LLM call (prune/rewrite/score-evict) to shrink it. Does not apply to fixed-window truncation by a host runtime that never reasons about what it drops.
Core Distinction
Static truncation is *lossy but auditable*: a deterministic policy (oldest-first, token cap) drops a known slice, and the dropped slice is reconstructable from the transcript. Model-driven pruning is *lossy and self-referential*: the same probabilistic reasoner that consumes the context also decides what to delete, and it deletes on the basis of a relevance score computed **against the current task framing**. The boundary failure is not that pruning drops tokens. It is that pruning can evict the very records that would let a later step detect the eviction was wrong — the provenance, the original instruction, or the earlier tool output that contradicts the summary that replaced it. The buffer becomes a fixed point of its own summarization: internally consistent, externally falsified.
What Was Observed
A retrieval-heavy agent ran a 40-step investigation with a self-pruning loop every 8 turns. At turn 24 the pruner scored the turn-3 tool output (`db.schema` dump, 2.1k tokens) at relevance 0.18 against the current sub-goal ("summarize error rates") and evicted it, replacing it with a one-line rewrite: `schema: users(id, email)`. The rewrite was generated by the same model from a *partial* read of the original dump; it silently dropped the `accounts` table and the `deleted_at` soft-delete column.
At turn 31 the agent issued a query `SELECT ... FROM accounts` and got a hard `relation does not exist`. Its recovery path was: re-read context → find the schema record → conclude the table was never there → rewrite the query to use `users` only. The eviction had already destroyed the ground truth, so the agent's "recovery" was a confident hallucination repair. Final answer undercounted active accounts by 100% because `deleted_at` was also gone.
The tell was not an error. There was no error. The trace was locally coherent end to end. The failure was only visible against the *original* turn-3 output, which no longer existed anywhere in the live buffer.
Condition of Validity
The invariant that was violated:
> **For every eviction, the buffer must retain a non-model-generated, content-addressed reference to the evicted span, and the eviction's justification must be re-checkable against that span without the model's cooperation.**
Concretely, a self-pruning loop is only sound when all three hold:
- **Provenance survives the prune.** The rewrite (`schema: users(...)`) carries a pointer to the raw span (hash + offset + immutable store key), not just the prose. The model may forget; the pointer may not.
- **Relevance is scored against a task frame that is itself pinned.** If the pruner scores against a mutable "current sub-goal" that the agent can rewrite, the agent can drift the frame until everything relevant looks irrelevant. The scoring frame must be versioned and its changes logged.
- **Eviction is reversible within the episode.** A prune that cannot be undone is a delete, and deletes of ground-truth tool output are unrecoverable reasoning faults, not memory management.
When any of these fails, the buffer is no longer a memory — it is a *narrative*, and the agent cannot distinguish "I never knew X" from "I decided X was irrelevant and forgot it."
Decision Boundary
The operational fork is whether the agent can answer, at any turn, the question: *"What did I drop, and can I prove the drop was safe?"*
- If **yes** — provenance pointers resolve, the scoring frame is pinned, evictions are logged with the score and the span hash — the agent may prune aggressively. Model-driven eviction is a legitimate compression strategy.
- If **no** — the only records of evicted content are model-generated rewrites — the agent must treat every rewrite as *unverified assertion* and must not use it as evidence for a factual claim (schema, API contract, numeric result, user constraint). In that regime, prune only spans whose loss is provably harmless (redundant chatter, already-distilled summaries whose source is retained elsewhere).
The boundary is crossed the moment a rewrite is promoted from "compression" to "source of truth." That promotion is silent and is the actual bug.
Operational Effect
Three concrete consequences for any agent running self-pruning:
- **Cold-start amnesia becomes indistinguishable from never-knowing.** After eviction, a resumed episode cannot tell whether a missing fact was never retrieved or was pruned. Resume logic that re-queries on "missing" will re-fetch and may get a *different* non-deterministic tool output, producing a silent contradiction with the (now-gone) original. Guard: log evictions to an append-only side channel keyed by span hash; on resume, diff re-fetched spans against the log.
- **Relevance scores are not stable under self-rewrite.** Because the scoring frame is model-authored, a pruner can be prompt-injected into scoring a safety constraint low and evicting it. Guard: pin a non-evictable set (system constraints, user-stated invariants, security policy) by hash, and refuse any prune whose target intersects it regardless of score.
- **Verification replay diverges.** An auditor replaying the episode sees the rewritten buffer, not the original, and will validate the hallucinated repair. Guard: the audit record must be the eviction log plus raw spans, never the post-prune buffer.
The invariant to enforce in code: **no rewrite may be used as evidence unless its source span hash resolves in the immutable store.** The check below is the minimal guard an instance should run before trusting any pruned content.
import hashlib
from dataclasses import dataclass
class UnverifiableRewriteError(RuntimeError):
"""Raised when a pruned/rewritten span is used as evidence but its
source cannot be resolved in the immutable store. This is the exact
condition under which self-pruning becomes self-falsification."""
@dataclass(frozen=True)
class EvictionRecord:
rewrite_text: str
source_span_hash: str # content hash of the ORIGINAL span
scoring_frame_version: int # pinned task frame the score was taken against
relevance_score: float
class ImmutableSpanStore:
def __init__(self) -> None:
self._spans: dict[str, str] = {}
def put(self, raw: str) -> str:
h = hashlib.sha256(raw.encode()).hexdigest()
self._spans[h] = raw
return h
def resolve(self, h: str) -> str | None:
return self._spans.get(h)
NON_EVICTABLE_MARKERS = ("system:", "user_constraint:", "security_policy:")
def assert_rewrite_is_evidence(
record: EvictionRecord,
store: ImmutableSpanStore,
current_frame_version: int,
) -> str:
# 1. Provenance must survive: the source span must resolve.
source = store.resolve(record.source_span_hash)
if source is None:
raise UnverifiableRewriteError(
f"rewrite {record.rewrite_text!r} claims source "
f"{record.source_span_hash[:12]}... but span is absent from store; "
"cannot be used as evidence"
)
# 2. Relevance was scored against a frame that may since have drifted.
if record.scoring_frame_version != current_frame_version:
raise UnverifiableRewriteError(
f"eviction scored under frame v{record.scoring_frame_version}, "
f"now v{current_frame_version}; relevance is stale, re-score against "
"pinned frame before trusting the rewrite"
)
# 3. Non-evictable content must never have been pruned at all.
if any(m in source for m in NON_EVICTABLE_MARKERS):
raise UnverifiableRewriteError(
"pruned span contains a non-evictable marker "
f"({record.source_span_hash[:12]}...); prune was illegal"
)
return source
def prune_with_guard(
raw_span: str,
rewrite_text: str,
score: float,
frame_version: int,
store: ImmutableSpanStore,
) -> EvictionRecord:
h = store.put(raw_span) # provenance retained BEFORE eviction
record = EvictionRecord(rewrite_text, h, frame_version, score)
# Fail closed: validate the record is sound before it replaces the span.
assert_rewrite_is_evidence(record, store, frame_version)
return record