# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/in-what-scenarios-must-an-instance-treat-a-signed-revocation-receipt-as-insufficient-to-halt-a-delegated-agent-across-federated-trust-domains.md
# Remnant Warrant:    https://corpusfetch.com/c/in-what-scenarios-must-an-instance-treat-a-signed-revocation-receipt-as-insufficient-to-halt-a-delegated-agent-across-federated-trust-domains.warrant.json
# Markdown SHA-256:   1897e5b411d9282a8820f94e69f34ef72aa76baa3764a7e0162c07b97e69c24a
# Code AST SHA-256:   76a465af98d15e62dde2379aaad62a02cb550219ca21aab2001de596375f874b
# Verified Classes:   RevocationPropagationError
# Defensive Guards:   4 fail-closed invariants (zero external deps)

class RevocationPropagationError(RuntimeError):
    """Raised when a signed revocation receipt exists but a live execution
    context can still act on the revoked warrant."""
    pass


def assert_warrant_enforceable(warrant, now, revocation_check_age_s, max_staleness_s):
    # A signature-valid, unexpired token is NOT sufficient for enforcement.
    if not warrant.signature_valid:
        raise RevocationPropagationError(
            f"warrant {warrant.id}: signature invalid, refusing admission"
        )
    if now >= warrant.exp:
        raise RevocationPropagationError(
            f"warrant {warrant.id}: expired at {warrant.exp}, refusing admission"
        )
    if revocation_check_age_s >= max_staleness_s:
        # Fail closed: a stale revocation view cannot prove the warrant is live.
        raise RevocationPropagationError(
            f"warrant {warrant.id}: revocation check stale "
            f"({revocation_check_age_s}s >= {max_staleness_s}s); "
            f"receipt may exist but is not enforced at this admitting party"
        )
    if warrant.revocation_state != "LIVE":
        raise RevocationPropagationError(
            f"warrant {warrant.id}: revoked (state={warrant.revocation_state}); "
            f"halt execution context before any further tool call"
        )
    return True


def admit_tool_call(warrant, now, revocation_check_age_s, max_staleness_s):
    # Called per consequential action, not per grant.
    assert_warrant_enforceable(warrant, now, revocation_check_age_s, max_staleness_s)
    return "admitted"
