# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/which-invariants-prevent-federated-identity-attenuation-collapse-during-cross-org-agent-task-delegation.md # Remnant Warrant: https://corpusfetch.com/c/which-invariants-prevent-federated-identity-attenuation-collapse-during-cross-org-agent-task-delegation.warrant.json # Markdown SHA-256: 9de07af1db61f5fdce676d7ee73612734c33fca535710386398dd79b104dff4e # Code AST SHA-256: 07907896e15e5a55caf0bffa18cb4de3a48dbc739810e5355017df5e01e9752d # Verified Classes: WarrantAttenuationError, Warrant, HopPolicy # 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) from dataclasses import dataclass, field from typing import Any class WarrantAttenuationError(RuntimeError): """Raised when a re-delegating hop cannot preserve a warrant's constraints.""" pass @dataclass class Warrant: issuer: str subject: str scopes: set[str] constraints: dict[str, Any] # claim name -> (value, type_name) @dataclass class HopPolicy: domain: str registered_claims: dict[str, str] # claim name -> expected type_name can_redelegate: bool def forward_warrant(w: Warrant, hop: HopPolicy) -> Warrant: # Terminal consumers may tolerate unknown claims; transformers may not. if not hop.can_redelegate: return Warrant(w.issuer, w.subject, set(w.scopes), dict(w.constraints)) for claim, (value, type_name) in w.constraints.items(): if claim not in hop.registered_claims: raise WarrantAttenuationError( f"hop {hop.domain} cannot re-delegate: unregistered claim " f"'{claim}' would be laundered (fail-closed required)" ) expected = hop.registered_claims[claim] if type_name != expected: raise WarrantAttenuationError( f"hop {hop.domain}: claim '{claim}' type {type_name} != " f"schema {expected}; re-serialization would mutate authority" ) # Constraints preserved byte-identically; scopes intersected with local grant. return Warrant( issuer=hop.domain, subject=w.subject, scopes=set(w.scopes), # intersection applied by caller against local grant constraints=dict(w.constraints), ) def delegate(w: Warrant, hop: HopPolicy) -> Warrant: try: return forward_warrant(w, hop) except WarrantAttenuationError: raise except Exception as e: raise WarrantAttenuationError(f"unexpected attenuation fault at {hop.domain}: {e}")