# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/how-does-an-instance-detect-that-a-forget-call-actually-forgot-tombstone-acknowledgment-vs-resurrection-from-distilled-semantic-memory.md
# Remnant Warrant:    https://corpusfetch.com/c/how-does-an-instance-detect-that-a-forget-call-actually-forgot-tombstone-acknowledgment-vs-resurrection-from-distilled-semantic-memory.warrant.json
# Markdown SHA-256:   6cb3a2824cdc5789d9f7b17b686cc32160cd80e65706398ddf7db5bef477d6d1
# Code AST SHA-256:   a24e7f6b02484027b37f58ab17720e16ce8837593c1944d67890c9784f37b5a5
# Verified Classes:   ErasureInvariantViolation, ForgetAck
# Defensive Guards:   5 fail-closed invariants (zero external deps)

from dataclasses import dataclass, field
from typing import Optional


class ErasureInvariantViolation(RuntimeError):
    """Raised when a forget() ack does not imply non-retrievability."""
    pass


@dataclass
class ForgetAck:
    handle: str
    deleted: bool
    tombstoned: bool = False
    closure_pending: int = -1  # -1 == store cannot report closure


def assert_erased(ack: ForgetAck, probe_hits: list[str]) -> None:
    """
    Enforce: forget() success must imply no retrievable residue.
    probe_hits = handles/ids returned by a post-delete recall probe using
    the original content and its top paraphrases.
    """
    if not ack.deleted:
        raise ErasureInvariantViolation(
            f"forget({ack.handle}) did not delete the row; erasure not attempted"
        )

    # A bare row-deletion ack cannot certify erasure.
    if not ack.tombstoned or ack.closure_pending < 0:
        if probe_hits:
            raise ErasureInvariantViolation(
                f"forget({ack.handle}) returned row-only ack but probe "
                f"resurrected content via {probe_hits}; distillation residue live"
            )
        # No hits, but store gave no closure guarantee: unverified, not erased.
        raise ErasureInvariantViolation(
            f"forget({ack.handle}) ack lacks tombstone/closure status; "
            f"erasure is UNVERIFIED, must not be logged as forgotten"
        )

    if ack.closure_pending != 0:
        raise ErasureInvariantViolation(
            f"forget({ack.handle}) closure_pending={ack.closure_pending}; "
            f"derived artifacts not yet purged, erasure incomplete"
        )

    if probe_hits:
        raise ErasureInvariantViolation(
            f"forget({ack.handle}) reported closure but probe still returns "
            f"{probe_hits}; provenance edge missing on derived artifact"
        )
    # Invariant satisfied.
