# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/why-does-an-instance-accept-a-federated-capability-grant-it-can-never-exercise-the-discovery-time-vs-invocation-time-policy-lattice-collapse-in-cross.md
# Remnant Warrant:    https://corpusfetch.com/c/why-does-an-instance-accept-a-federated-capability-grant-it-can-never-exercise-the-discovery-time-vs-invocation-time-policy-lattice-collapse-in-cross.warrant.json
# Markdown SHA-256:   dca554d92f00f04014513d5541e9fe8b28c8ec294d112fe97a5f05103b4f5d40
# Code AST SHA-256:   8f58aba7cf416097b5562f1acb3367b3fa7e3d742a7c242ca7de80d585e950c8
# Verified Classes:   FederatedGrantUnsatisfiable, CapabilityGrant
# Defensive Guards:   1 fail-closed invariants (zero external deps)

class FederatedGrantUnsatisfiable(RuntimeError):
    """Raised when a discovery-time grant cannot be exercised at invocation time."""
    pass


class CapabilityGrant:
    def __init__(self, capability_id, asserted_scope, transit_scope, obligations):
        self.capability_id = capability_id
        self.asserted_scope = asserted_scope
        self.transit_scope = transit_scope
        self.obligations = obligations


def verify_exercisability(grant: CapabilityGrant) -> bool:
    # The meet must be computed against the transit scope, not the asserted scope.
    # An obligation whose discharge authority is absent from transit scope makes
    # the grant unexercisable regardless of what the asserted scope contained.
    for obligation in grant.obligations:
        authority = obligation.get("discharge_authority")
        if authority not in grant.transit_scope:
            raise FederatedGrantUnsatisfiable(
                f"capability {grant.capability_id!r} declares obligation "
                f"{obligation.get('name')!r} requiring authority {authority!r}, "
                f"which is absent from transit scope {sorted(grant.transit_scope)}; "
                f"asserted scope {sorted(grant.asserted_scope)} is not a valid "
                f"proof of exercisability across the federation boundary"
            )
    return True


def plan_dependency(grant: CapabilityGrant, prior_step_irreversible: bool) -> str:
    try:
        verify_exercisability(grant)
    except FederatedGrantUnsatisfiable:
        if prior_step_irreversible:
            # Do not schedule downstream of irreversible work without a probe.
            return "probe_required"
        return "pruned"
    return "scheduled"
