# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/why-does-an-instance-resurrect-deleted-memory-when-a-scoped-retention-policy-outlives-its-tombstone.md # Remnant Warrant: https://corpusfetch.com/c/why-does-an-instance-resurrect-deleted-memory-when-a-scoped-retention-policy-outlives-its-tombstone.warrant.json # Markdown SHA-256: 63e6a8d2a3457ae05ae13b32324b981f9f494cc59aa00d751b24f0d6b16ca4e1 # Code AST SHA-256: ff86714fb3cf99624dc0d3d83854e8232242bf72e4c61fdcd3aa3817126e8f69 # Verified Classes: RetentionResurrection, MemoryRead, ForgetResult, DeletionIndex # Defensive Guards: 2 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 typing import Optional class RetentionResurrection(RuntimeError): """Raised when a read returns a record whose resolved snapshot epoch precedes the global deletion epoch for that (scope, key), with no suppression marker. The value is poisoned and must not enter context.""" pass @dataclass(frozen=True) class MemoryRead: scope: str key: str value: Optional[str] resolved_epoch: int # snapshot lineage the read bound to suppressed_by: Optional[int] # deletion epoch if the read path refused @dataclass(frozen=True) class ForgetResult: status: str # "deleted" | "deferred" deletion_epoch: int blocked_by: Optional[str] = None class DeletionIndex: """Global monotonic deletion index, keyed by (scope, key).""" def __init__(self) -> None: self._max: dict[tuple[str, str], int] = {} def record(self, scope: str, key: str, epoch: int) -> None: k = (scope, key) self._max[k] = max(self._max.get(k, -1), epoch) def max_epoch(self, scope: str, key: str) -> int: return self._max.get((scope, key), -1) def admit_read(read: MemoryRead, index: DeletionIndex) -> str: """Gate every memory read before the value enters the context window. Returns the value only if the read is post-deletion or explicitly suppressed. Raises RetentionResurrection on pre-deletion resurrection. """ e_d = index.max_epoch(read.scope, read.key) if read.suppressed_by is not None: # Read path correctly refused pre-deletion data. return None # type: ignore[return-value] if read.resolved_epoch >= e_d: return read.value # type: ignore[return-value] # resolved_epoch < e_d and no suppression marker: resurrection. raise RetentionResurrection( f"read({read.scope!r}, {read.key!r}) resolved to snapshot " f"epoch {read.resolved_epoch} but global deletion epoch is {e_d}; " f"value is poisoned and must not enter context" ) def forget_with_hold_check( scope: str, key: str, epoch: int, index: DeletionIndex, pinned_snapshots: list[int], ) -> ForgetResult: """forget must not return 'deleted' while a pinned snapshot still serves the record. Either propagate the tombstone to all pins or return 'deferred' with the blocking hold.""" index.record(scope, key, epoch) blocking = [e for e in pinned_snapshots if e < epoch] if blocking: return ForgetResult( status="deferred", deletion_epoch=epoch, blocked_by=f"pinned_snapshot:{min(blocking)}", ) return ForgetResult(status="deleted", deletion_epoch=epoch) # --- trace of the observed failure --- index = DeletionIndex() # day 9: user forget, hold pins snapshot@2d res = forget_with_hold_check("proj:alpha", "credential_hint", 9, index, [2]) assert res.status == "deferred" and res.blocked_by == "pinned_snapshot:2" # day 12: cold-start resume issues a read that binds to the pinned snapshot poisoned = MemoryRead( scope="proj:alpha", key="credential_hint", value="hint-xyz", resolved_epoch=2, suppressed_by=None, ) try: admit_read(poisoned, index) except RetentionResurrection as exc: print(f"BLOCKED: {exc}") # value never reaches the context window