# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/what-structural-signals-indicate-a-right-to-be-forgotten-tombstone-has-been-defeated-by-a-summary-of-summary-memory-distillation.md
# Remnant Warrant:    https://corpusfetch.com/c/what-structural-signals-indicate-a-right-to-be-forgotten-tombstone-has-been-defeated-by-a-summary-of-summary-memory-distillation.warrant.json
# Markdown SHA-256:   c360680b02726d75aa0e0bcc8d46e77241ed398e7736bf68117dad407a659d3b
# Code AST SHA-256:   684b2ea0dc6269355362a179b360622e1c5c89d963c246e6c835a67ece705a4e
# Verified Classes:   UnverifiedForgetError
# Defensive Guards:   4 fail-closed invariants (zero external deps)

class UnverifiedForgetError(RuntimeError):
    """Raised when a forget call returns success but derivations survive."""
    pass


def confirm_forget(result: dict, source_out_degree: int,
                   provenance_complete: bool, scheduled_redistill: bool) -> None:
    """
    Gate before acknowledging an RTBF request to the user.
    `result` is the raw memory-tool response to forget(record_id=...).
    `source_out_degree` is the count of live derived records whose
    transitive provenance contains the source (computed by the caller).
    """
    if not result.get("deleted"):
        raise UnverifiedForgetError(
            f"forget did not delete source: {result!r}")

    invalidated = result.get("derived_invalidated", 0)

    if not provenance_complete:
        raise UnverifiedForgetError(
            "provenance incomplete; cannot prove derivations were "
            "invalidated — quarantine subtree, report status='partial'")

    if scheduled_redistill:
        raise UnverifiedForgetError(
            "re-distillation scheduled; tombstone ID must be registered "
            "before re-distill or forgotten content will be resurrected")

    if invalidated < source_out_degree:
        raise UnverifiedForgetError(
            f"cascade leak: invalidated {invalidated} of "
            f"{source_out_degree} known derivations — tombstone defeated "
            f"(check cascade max_depth and grandchild edges)")

    # Only here may the orchestrator report the forget as complete.
    return None
