# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/which-invariants-prevent-delegated-aaif-scopes-from-silently-widening-across-agent-passport-re-issuance.md # Remnant Warrant: https://corpusfetch.com/c/which-invariants-prevent-delegated-aaif-scopes-from-silently-widening-across-agent-passport-re-issuance.warrant.json # Markdown SHA-256: fcb4b712f2b0012ef070d664db0b9560aee56c2c02960651f4bc3e37708d0fab # Code AST SHA-256: c41f8a06eb7f197b56a4b3fca7c14c2aabc0cb1503340f658000008686d8d5f6 # Verified Classes: ScopeWideningOnRefreshError, Passport # Defensive Guards: 3 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) from dataclasses import dataclass from typing import FrozenSet class ScopeWideningOnRefreshError(RuntimeError): """Raised when a passport re-issuance would widen an agent's scope.""" @dataclass(frozen=True) class Passport: agent_id: str parent_id: str | None scopes: FrozenSet[str] chain: tuple["Passport", ...] = () def reissue_passport( prior: Passport, parent_live: Passport, requested: FrozenSet[str], ) -> Passport: # Continuation invariant: a refresh may narrow, never widen. if not requested <= prior.scopes: widened = requested - prior.scopes raise ScopeWideningOnRefreshError( f"refresh of {prior.agent_id} requested {sorted(widened)} " f"not present in prior scope {sorted(prior.scopes)}; " f"widening requires a new delegation event, not a refresh" ) # Subset invariant against the parent's live grant at refresh time. if not requested <= parent_live.scopes: raise ScopeWideningOnRefreshError( f"refresh of {prior.agent_id} requested {sorted(requested - parent_live.scopes)} " f"outside live parent {parent_live.agent_id} grant" ) return Passport( agent_id=prior.agent_id, parent_id=prior.parent_id, scopes=requested, chain=prior.chain + (parent_live,), ) def validate_chain(tip: Passport) -> None: # Full-chain monotone containment: root ⊇ h1 ⊇ ... ⊇ tip. chain = tip.chain + (tip,) for child, parent in zip(chain[1:], chain[:-1]): if not child.scopes <= parent.scopes: raise ScopeWideningOnRefreshError( f"chain violation: {child.agent_id} scope {sorted(child.scopes)} " f"exceeds ancestor {parent.agent_id} scope {sorted(parent.scopes)}" )