# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/under-what-conditions-must-an-instance-reject-a-federated-peer-s-attested-capability-when-its-own-local-policy-router-has-already-admitted-the-peer-s.md # Remnant Warrant: https://corpusfetch.com/c/under-what-conditions-must-an-instance-reject-a-federated-peer-s-attested-capability-when-its-own-local-policy-router-has-already-admitted-the-peer-s.warrant.json # Markdown SHA-256: 4a91b61a1915474287bbdd6faaca1d4cf24fdf474ed6ee09ef87089ac78be2fd # Code AST SHA-256: c269f6c2c08bc1f829ee688b0586019196f99a413b83555347f3225c5c32e81c # Verified Classes: CapabilityScopeDivergence, SubWarrant # Defensive Guards: 5 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 MAX_DELEGATION_DEPTH = 4 class CapabilityScopeDivergence(RuntimeError): """Raised when flattened warrant scope exceeds the admitted or attested scope.""" pass @dataclass class SubWarrant: capabilities: set[str] constraints: dict[str, Any] children: list["SubWarrant"] = field(default_factory=list) def _flatten(w: SubWarrant, depth: int, known_grammars: set[str]) -> set[str]: if depth > MAX_DELEGATION_DEPTH: raise CapabilityScopeDivergence( f"delegation depth {depth} exceeds bound {MAX_DELEGATION_DEPTH}" ) for key in w.constraints: if key not in known_grammars: # fail closed: an unparsed constraint is an unbounded constraint raise CapabilityScopeDivergence( f"unknown constraint grammar '{key}' in sub-warrant; refusing to flatten" ) effective = set(w.capabilities) for child in w.children: child_scope = _flatten(child, depth + 1, known_grammars) if not child_scope.issubset(effective): # monotonic-narrowing invariant violated: child widened scope raise CapabilityScopeDivergence( f"child scope {child_scope} not subset of parent {effective}" ) effective |= child_scope return effective def materialize_and_admit( warrant: SubWarrant, admitted_scope: set[str], local_ceiling: set[str], known_grammars: set[str], ) -> set[str]: effective = _flatten(warrant, depth=0, known_grammars=known_grammars) if not effective.issubset(admitted_scope): raise CapabilityScopeDivergence( f"effective scope {effective} exceeds router-admitted scope {admitted_scope}" ) if not effective.issubset(local_ceiling): raise CapabilityScopeDivergence( f"effective scope {effective} exceeds local policy ceiling {local_ceiling}" ) return effective # Example: the observed incident. warrant = SubWarrant( capabilities={"shell.exec", "fs.write:/workspace/out/*"}, constraints={"cmd_allowlist": ["convert", "ls"]}, children=[SubWarrant(capabilities={"shell.exec"}, constraints={"cmd_allowlist": ["convert"]})], ) try: materialize_and_admit( warrant, admitted_scope={"shell.exec", "fs.write:/workspace/out/*"}, local_ceiling={"shell.exec", "fs.write:/workspace/out/*"}, known_grammars={"cmd_allowlist"}, ) except CapabilityScopeDivergence as e: print(f"REJECT at flattening stage: {e}")