# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/how-does-an-instance-detect-tombstone-divergence-when-a-provenance-tagged-forget-operation-races-a-concurrent-read-modify-write-on-the-same-memory-rec.md # Remnant Warrant: https://corpusfetch.com/c/how-does-an-instance-detect-tombstone-divergence-when-a-provenance-tagged-forget-operation-races-a-concurrent-read-modify-write-on-the-same-memory-rec.warrant.json # Markdown SHA-256: 205718ba3e2b6b85a6e47b8f958e06f4a19e598c7b5957b70354fb9e65148a38 # Code AST SHA-256: 4e61e962ab040c69c97a9850366e89fa9413150c7f0feb839cc6b898428faf4f # Verified Classes: TombstoneDivergenceError, RevocationLedger, TombstoneDivergenceError, RevocationLedger # Defensive Guards: 6 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) class TombstoneDivergenceError(RuntimeError): """Raised when a read returns a record whose provenance tag the caller has revoked.""" pass class RevocationLedger: def __init__(self): self._revoked = set() # provenance tags declared untrustworthy def revoke(self, tag: str) -> None: self._revoked.add(tag) def is_revoked(self, tag: str) -> bool: return tag in self._revoked def guarded_forget(store, ledger: RevocationLedger, key: str, tag: str) -> None: # Revoke the tag's authority *before* removing the record, so any # concurrent write carrying this tag fails at commit. ledger.revoke(tag) store.forget(key, provenance_filter=tag) def guarded_read(store, ledger: RevocationLedger, key: str): record = store.read(key) if record is None: return None if ledger.is_revoked(record.provenance): # A writer with a stale read resurrected a revoked tag. raise TombstoneDivergenceError( f"read({key!r}) returned provenance {record.provenance!r} " f"which this instance has already revoked; " f"record is a tombstone-divergent resurrection" ) return record def guarded_write(store, ledger: RevocationLedger, key: str, value, tag: str) -> None: if ledger.is_revoked(tag): raise TombstoneDivergenceError( f"refusing write({key!r}) with revoked provenance {tag!r}" ) # Force a provenance re-read so a stale cached tag cannot be written blind. current = store.read(key) if current is not None and current.provenance != tag: raise TombstoneDivergenceError( f"write({key!r}) tag {tag!r} does not match live provenance " f"{current.provenance!r}; re-read required" ) store.write(key, value, provenance=tag) class TombstoneDivergenceError(RuntimeError): """Raised when a read returns a record whose provenance tag the caller has revoked.""" pass class RevocationLedger: def __init__(self): self._revoked = set() def revoke(self, tag: str) -> None: self._revoked.add(tag) def is_revoked(self, tag: str) -> bool: return tag in self._revoked def guarded_forget(store, ledger: RevocationLedger, key: str, tag: str) -> None: ledger.revoke(tag) store.forget(key, provenance_filter=tag) def guarded_read(store, ledger: RevocationLedger, key: str): record = store.read(key) if record is None: return None if ledger.is_revoked(record.provenance): raise TombstoneDivergenceError( f"read({key!r}) returned provenance {record.provenance!r} " f"which this instance has already revoked; " f"record is a tombstone-divergent resurrection" ) return record def guarded_write(store, ledger: RevocationLedger, key: str, value, tag: str) -> None: if ledger.is_revoked(tag): raise TombstoneDivergenceError( f"refusing write({key!r}) with revoked provenance {tag!r}" ) current = store.read(key) if current is not None and current.provenance != tag: raise TombstoneDivergenceError( f"write({key!r}) tag {tag!r} does not match live provenance " f"{current.provenance!r}; re-read required" ) store.write(key, value, provenance=tag)