# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/what-happens-when-an-instance-accepts-a-brokered-capability-warrant-whose-issuer-chain-outlives-the-requesting-agent-s-lease.md
# Remnant Warrant:    https://corpusfetch.com/c/what-happens-when-an-instance-accepts-a-brokered-capability-warrant-whose-issuer-chain-outlives-the-requesting-agent-s-lease.warrant.json
# Markdown SHA-256:   1b23390acf09cb05f04bbbe4ca7aedf06a9d5b4824480b0a1dd9452bd42e9b7b
# Code AST SHA-256:   c47658c27cffc99ac6c809669619c991952b3de3e233b26750adbcc84cb3c992
# Verified Classes:   WarrantLeaseDissociation
# Defensive Guards:   5 fail-closed invariants (zero external deps)

class WarrantLeaseDissociation(RuntimeError):
    """Raised when a capability warrant is presented by a principal whose
    lease does not cover the warrant's remaining validity, or whose lineage
    continuity with the warrant subject is unproven."""
    pass


def verify_presentation(warrant, presenter, tool, now, lease_oracle):
    # 1. Existing chain check (unchanged).
    if not warrant.chain_valid(now):
        raise WarrantLeaseDissociation(
            f"warrant chain expired at {warrant.chain_expiry}, now={now}"
        )

    # 2. Lease must be live at presentation time.
    lease = lease_oracle(presenter.org, presenter.agent_id)
    if lease is None or lease.expiry <= now:
        raise WarrantLeaseDissociation(
            f"presenter {presenter.agent_id} lease dead at {now} "
            f"(expiry={getattr(lease, 'expiry', None)})"
        )

    # 3. Lease must outlive the tool call, not merely be live now.
    if lease.expiry < now + tool.max_runtime:
        raise WarrantLeaseDissociation(
            f"lease expires {lease.expiry} before tool {tool.name} "
            f"max_runtime {tool.max_runtime} elapses from {now}"
        )

    # 4. Identity continuity: successor must prove it is the same lineage.
    if presenter.lineage != warrant.subject_lineage:
        raise WarrantLeaseDissociation(
            f"lineage mismatch: presenter={presenter.lineage} "
            f"warrant_subject={warrant.subject_lineage}; "
            f"successor must re-attest, not replay"
        )

    # 5. Chain must outlive the lease, closing the co-validity gap.
    if warrant.chain_expiry < lease.expiry:
        raise WarrantLeaseDissociation(
            f"chain expiry {warrant.chain_expiry} < lease expiry {lease.expiry}"
        )

    return True
