# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/in-what-scenarios-must-an-instance-treat-concurrent-forget-as-a-tombstone-barrier-rather-than-a-delete.md
# Remnant Warrant:    https://corpusfetch.com/c/in-what-scenarios-must-an-instance-treat-concurrent-forget-as-a-tombstone-barrier-rather-than-a-delete.warrant.json
# Markdown SHA-256:   3bb3d833053c649efc780165c4a4432fd2375a448c299bf7c8654d1dc7e8814e
# Code AST SHA-256:   38a1acead4aedd0582bb63a7e3b2087d393fab049363c016659cad40ae198b60
# Verified Classes:   ResurrectionAfterForget, ContextStore
# Defensive Guards:   1 fail-closed invariants (zero external deps)

import time
from dataclasses import dataclass, field

class ResurrectionAfterForget(RuntimeError):
    """Raised when a write's provenance closure intersects a live tombstone."""
    pass

@dataclass
class ContextStore:
    records: dict = field(default_factory=dict)
    tombstones: dict = field(default_factory=dict)  # id -> expiry_ts
    tombstone_ttl_s: float = 300.0  # >= max agent context-window lifetime

    def forget(self, record_id: str) -> None:
        # Tombstone, not point delete. Retain until no reader can hold a copy.
        self.tombstones[record_id] = time.time() + self.tombstone_ttl_s
        self.records.pop(record_id, None)

    def _poisoned(self, provenance: list[str]) -> list[str]:
        now = time.time()
        return [p for p in provenance
                if p in self.tombstones and self.tombstones[p] > now]

    def write(self, record_id: str, content: dict, derived_from: list[str]) -> None:
        # Write-time provenance check: the only place resurrection can be caught.
        hit = self._poisoned(derived_from)
        if hit:
            raise ResurrectionAfterForget(
                f"refusing write {record_id}: provenance {hit} is tombstoned "
                f"(forgotten content would be resurrected under a new id)"
            )
        self.records[record_id] = {"content": content, "derived_from": derived_from}

# Trigger: Summarizer retrieved ep_4471 pre-forget, commits distillation post-forget.
store = ContextStore()
store.records["ep_4471"] = {"content": {"vendor": "Acme"}}
store.forget("ep_4471")  # Planner's correction arrives mid-distillation
try:
    store.write("sem_9001", {"vendor": "Acme"}, derived_from=["ep_4471", "ep_4473"])
except ResurrectionAfterForget as e:
    print(f"blocked resurrection: {e}")  # correct: correction holds
