# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/when-must-an-instance-refuse-to-honor-a-forgetting-request-because-a-derived-artifact-s-provenance-is-not-yet-resolvable.md
# Remnant Warrant:    https://corpusfetch.com/c/when-must-an-instance-refuse-to-honor-a-forgetting-request-because-a-derived-artifact-s-provenance-is-not-yet-resolvable.warrant.json
# Markdown SHA-256:   e4106f207ec663a9f6feb082eec0ab835c835cf9ec26cb532e013755e1ce3841
# Code AST SHA-256:   880369c91f408e3a97cf4c8e6141bd66472a01a4d813d0b7d020d91ceb003023
# Verified Classes:   UnresolvableProvenanceError
# Defensive Guards:   1 fail-closed invariants (zero external deps)

class UnresolvableProvenanceError(RuntimeError):
    """Raised when a forget request cannot be honored because at least one
    derived artifact's provenance link to the target is unresolved and the
    in-flight registry cannot bound its commit within the caller's deadline."""
    pass


def forget(store, target_id, deadline_s, in_flight_registry):
    derivations = store.provenance_derivations_of(target_id)  # committed edges
    in_flight = in_flight_registry.pending_for(target_id)      # written, edge uncommitted

    unbounded = [d for d in in_flight if d.expected_commit_s is None
                 or d.expected_commit_s > deadline_s]
    if unbounded:
        raise UnresolvableProvenanceError(
            f"forget({target_id}) refused: {len(unbounded)} in-flight derivation(s) "
            f"have no bounded provenance commit within {deadline_s}s: "
            f"{[d.id for d in unbounded]}"
        )

    if in_flight:
        # Bounded in-flight derivations: defer, do not delete the source yet.
        return {"forgotten": "deferred",
                "in_flight": [d.id for d in in_flight],
                "bound_s": max(d.expected_commit_s for d in in_flight)}

    # All derivations resolved and committed; safe to delete source and derivations.
    for d in derivations:
        store.delete_derivation(d.id)
    store.delete_source(target_id)
    return {"forgotten": True}
