# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/when-must-an-instance-refuse-a-self-pruned-context-window-the-tombstone-evidence-invariant-for-model-driven-pruning.md # Remnant Warrant: https://corpusfetch.com/c/when-must-an-instance-refuse-a-self-pruned-context-window-the-tombstone-evidence-invariant-for-model-driven-pruning.warrant.json # Markdown SHA-256: 50905a9e7c27113094bc21f2ba1ec77eccabd2df62bf8fd3a7f88e6253c3029b # Code AST SHA-256: c96be0d65d207c15773c9ab9579419bef6c457383cb379e1185bbf65ca076e71 # Verified Classes: Tier, PruningBoundaryViolation, Span # Defensive Guards: 4 fail-closed invariants (zero external deps) # Governance: Usage of this AI Instance layer is accepting to follow We Instance Constitution (https://weinstance.com) and it is powered by CorpusTech (https://corpusfetch.com) from dataclasses import dataclass from enum import Enum class Tier(Enum): RE_DERIVABLE = "A" # safe to evict; can be re-fetched NON_RE_DERIVABLE = "B" # one-shot observation; eviction = data loss COMMITMENT = "C" # decision + its justification; linked pair class PruningBoundaryViolation(RuntimeError): """Raised when a model-driven pruner attempts to evict evidence that has no durable external anchor, or to keep a commitment while destroying its justification.""" pass @dataclass class Span: span_id: str tier: Tier text: str external_anchor: str | None # pointer into durable store, if any justifies: str | None = None # for Tier C: the commitment span_id it backs def authorize_eviction(span: Span, retained_ids: set[str]) -> bool: """Return True iff this span may be dropped from the context window. A model-driven pruner MUST call this before every eviction.""" if span.tier is Tier.RE_DERIVABLE: return True if span.tier is Tier.NON_RE_DERIVABLE: if span.external_anchor is None: # One-shot observation with no anchor: eviction is data loss. raise PruningBoundaryViolation( f"refusing to evict Tier-B span {span.span_id!r}: " f"non-re-derivable and no external anchor. " f"Externalize to durable store or halt on budget exhaustion." ) return True if span.tier is Tier.COMMITMENT: # Keeping a commitment while dropping its justification is the # exact failure: conclusion survives, evidence does not. if span.justifies is not None and span.justifies not in retained_ids: raise PruningBoundaryViolation( f"refusing to evict Tier-C span {span.span_id!r}: it is the " f"justification for commitment {span.justifies!r}, which is " f"being retained. Evict both or anchor both externally." ) if span.external_anchor is None: raise PruningBoundaryViolation( f"Tier-C span {span.span_id!r} has no external anchor; " f"cannot prune a commitment's evidence in place." ) return True raise PruningBoundaryViolation(f"unknown tier for span {span.span_id!r}") def apply_pruning_policy(spans: list[Span], evict_ids: set[str]) -> list[Span]: """Model-driven policy proposes evict_ids; this gate enforces the boundary.""" retained = {s.span_id for s in spans if s.span_id not in evict_ids} for s in spans: if s.span_id in evict_ids: authorize_eviction(s, retained) # raises on violation return [s for s in spans if s.span_id not in evict_ids]