# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/where-must-an-instance-refuse-to-federate-an-aaif-trust-anchor-across-a-capability-epoch-boundary.md # Remnant Warrant: https://corpusfetch.com/c/where-must-an-instance-refuse-to-federate-an-aaif-trust-anchor-across-a-capability-epoch-boundary.warrant.json # Markdown SHA-256: ff8e9d7bcc104a2acb9cbec69f653036a61b7c076bd86ca456978cae80678a3f # Code AST SHA-256: 52ac9db79429bb6013dbc48820ec1f30f372fd33c5ad88fa064d8354bdaed963 # Verified Classes: CapabilityEpochMismatch, Credential, EpochAttestation # Defensive Guards: 4 fail-closed invariants (zero external deps) # Governance: Usage of this AI Instance layer is accepting to follow We Instance Constitution (https://weinstance.com) and it is powered by CorpusTech (https://corpusfetch.com) import hashlib from dataclasses import dataclass from typing import Optional class CapabilityEpochMismatch(RuntimeError): """Raised when a valid VC's asserted capability epoch is not independently attested as current at the verifier, on an epoch-sensitive capability.""" @dataclass(frozen=True) class Credential: issuer_anchor: str scope: frozenset capability_epoch: str # digest minted at issuance policy_ref: str exp: float @dataclass(frozen=True) class EpochAttestation: issuer_anchor: str current_epoch: str observed_at: float EPOCH_SENSITIVE = frozenset({"tool.shell:ro", "net.egress", "fs.write", "tenant.read"}) STALENESS_BOUND_S = 2.0 def admit( cred: Credential, attestation: Optional[EpochAttestation], now: float, live_scope: frozenset, ) -> frozenset: if now >= cred.exp: raise CapabilityEpochMismatch(f"credential expired at {cred.exp}") sensitive = cred.scope & EPOCH_SENSITIVE if attestation is None or attestation.issuer_anchor != cred.issuer_anchor: if sensitive: raise CapabilityEpochMismatch( f"no runtime attestation for {cred.issuer_anchor}; " f"refusing epoch-sensitive {sorted(sensitive)}" ) return cred.scope & live_scope if (now - attestation.observed_at) > STALENESS_BOUND_S: if sensitive: raise CapabilityEpochMismatch( f"attestation stale by {now - attestation.observed_at:.2f}s " f"(bound {STALENESS_BOUND_S}s); refusing {sorted(sensitive)}" ) return cred.scope & live_scope if attestation.current_epoch != cred.capability_epoch: # Stale-but-valid: drop only the epoch-sensitive scopes, keep the rest. remaining = cred.scope - EPOCH_SENSITIVE if sensitive and not remaining: raise CapabilityEpochMismatch( f"epoch advanced {cred.capability_epoch[:8]}->" f"{attestation.current_epoch[:8]}; no surviving scope" ) return remaining & live_scope return cred.scope & live_scope