# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/what-structural-signals-indicate-a-retention-policy-forget-is-not-yet-durable-across-a-memory-tool-s-read-write-forget-api.md
# Remnant Warrant:    https://corpusfetch.com/c/what-structural-signals-indicate-a-retention-policy-forget-is-not-yet-durable-across-a-memory-tool-s-read-write-forget-api.warrant.json
# Markdown SHA-256:   0b7dafd2bd45bdcd8d4fbffe5148f5fc908f7fefc71609098516df37928473c7
# Code AST SHA-256:   bb787c1736ea9b3e240d89bca2cf2e3c52443a8fff7a0f6f4d5ee6f951851702
# Verified Classes:   ForgetDurabilityError, ForgetReceipt
# Defensive Guards:   3 fail-closed invariants (zero external deps)

from dataclasses import dataclass
from datetime import datetime


class ForgetDurabilityError(RuntimeError):
    """Raised when a forget returned success but the erasure is not yet durable."""


@dataclass
class ForgetReceipt:
    record_id: str
    deleted_at: datetime
    audit_id: str


def assert_durable_forget(
    receipt: ForgetReceipt,
    lineage_descendants: list[str],
    index_watermark: datetime,
    pending_write_buffer: list[str],
) -> None:
    # A forget is only auditable if no live surface can reconstruct the record.
    if lineage_descendants:
        raise ForgetDurabilityError(
            f"record {receipt.record_id} has live lineage descendants "
            f"{lineage_descendants}; cascade forget required before asserting erasure"
        )
    if index_watermark < receipt.deleted_at:
        raise ForgetDurabilityError(
            f"vector index watermark {index_watermark.isoformat()} predates "
            f"tombstone {receipt.deleted_at.isoformat()}; search can still surface record"
        )
    if receipt.record_id in pending_write_buffer:
        raise ForgetDurabilityError(
            f"record {receipt.record_id} still in write-behind buffer; "
            f"retention scheduler may re-materialize it"
        )
    # Durable: safe to assert the erasure guarantee downstream.
