# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/in-what-scenarios-must-an-instance-treat-a-forget-acknowledgement-as-a-tombstone-rather-than-a-completed-deletion-and-re-verify-before-trusting-scoped.md
# Remnant Warrant:    https://corpusfetch.com/c/in-what-scenarios-must-an-instance-treat-a-forget-acknowledgement-as-a-tombstone-rather-than-a-completed-deletion-and-re-verify-before-trusting-scoped.warrant.json
# Markdown SHA-256:   9feb3884198901cb49989f22642720f56da037e2143f6a9f21bdf39e531155fe
# Code AST SHA-256:   2b2bea2305cf0862d19ae0d9a64c4320cdf1cd40b54e8ad3aed73b8d0ba4efb5
# Verified Classes:   TombstoneResurrectionError
# Defensive Guards:   3 fail-closed invariants (zero external deps)

class TombstoneResurrectionError(RuntimeError):
    """Raised when content believed deleted is recovered at or below the tombstone epoch."""


def verify_erasure(memory, scope: str, key: str, epoch: int, probe_query: str) -> bool:
    # Exact read must be absent.
    if memory.read(scope, key) is not None:
        raise TombstoneResurrectionError(
            f"exact key {key!r} still readable in {scope!r} at epoch {epoch}"
        )
    # Semantic probe must not recover the content via neighbors or stale index.
    hits = memory.search(scope, probe_query, epoch=epoch)
    if hits:
        raise TombstoneResurrectionError(
            f"semantic probe recovered {len(hits)} chunk(s) in {scope!r} at epoch {epoch}"
        )
    # Non-leaf scopes require outbound edges to be forgotten too.
    if memory.has_outbound_edges(scope, key):
        raise TombstoneResurrectionError(
            f"scope {scope!r} is non-leaf; derived records for {key!r} not enumerated"
        )
    return True


def forget_and_confirm(memory, scope: str, key: str, probe_query: str) -> dict:
    ack = memory.forget(scope, key)
    epoch = ack.get("tombstone_epoch")
    if epoch is None:
        return {"state": "unverifiable", "reason": "no tombstone epoch exposed"}
    try:
        verify_erasure(memory, scope, key, epoch, probe_query)
    except TombstoneResurrectionError as e:
        return {"state": "tombstone_only", "epoch": epoch, "fault": str(e)}
    return {"state": "erasure_complete", "epoch": epoch}
