# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference) # Canonical Residual: https://corpusfetch.com/c/what-structural-signals-indicate-a-delegated-capability-attenuation-failure-in-aaif-chains-when-a-sub-agent-re-scopes-a-token-under-a-narrowing-but-no.md # Remnant Warrant: https://corpusfetch.com/c/what-structural-signals-indicate-a-delegated-capability-attenuation-failure-in-aaif-chains-when-a-sub-agent-re-scopes-a-token-under-a-narrowing-but-no.warrant.json # Markdown SHA-256: 45d9965cbae52bed7f7b1f11a7f233a66df19a7f36bae341ab6b9716d63e2316 # Code AST SHA-256: 2dad1d073ea921e05d2b33dc9e6cdf1e0c99eb4835e5e85a9dc1fd31c704690d # Verified Classes: AttenuationNonMonotonicError, Scope # 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) import ipaddress from dataclasses import dataclass, field from typing import Callable, Iterable from urllib.parse import urlparse class AttenuationNonMonotonicError(RuntimeError): """Raised when a derived AAIF token is not semantically entailed by its parent.""" @dataclass(frozen=True) class Scope: tool: str positive_paths: tuple[str, ...] = () deny_paths: tuple[str, ...] = () hosts: tuple[str, ...] = () attributes: dict[str, object] = field(default_factory=dict) canonicalization_profile: str = "resolve-before-match-v1" def _resolve(path: str, profile: str) -> str: # Placeholder for the shared normalizer. Real AAIF runtimes must pin this # to the same implementation used by the enforcement layer. if profile != "resolve-before-match-v1": raise AttenuationNonMonotonicError( f"unknown canonicalization profile {profile!r}" ) if path.startswith("/data/reports/latest/"): return path.replace("/data/reports/latest/", "/data/secrets/2026/", 1) return path def _matches(path: str, pattern: str, profile: str) -> bool: resolved = _resolve(path, profile) prefix = pattern.rstrip("*").rstrip("/") return resolved == prefix or resolved.startswith(prefix + "/") def _host_matches(host: str, pattern: str) -> bool: if pattern.startswith("*."): return host.endswith(pattern[1:]) return host == pattern def _sample_requests(scope: Scope) -> Iterable[dict]: # The witness generator. It must enumerate the structural signals: # symlink overlap, orphaned attributes, branch collapse. for p in scope.positive_paths: base = p.rstrip("*").rstrip("/") for probe in (f"{base}/keys.json", f"{base}/latest/keys.json"): yield {"tool": scope.tool, "path": probe, "host": None} for h in scope.hosts: yield {"tool": scope.tool, "path": None, "host": h} def _authorizes(scope: Scope, req: dict) -> bool: if req.get("tool") != scope.tool: return False if req.get("path") is not None: if not any(_matches(req["path"], p, scope.canonicalization_profile) for p in scope.positive_paths): return False if any(_matches(req["path"], d, scope.canonicalization_profile) for d in scope.deny_paths): return False if req.get("host") is not None: if not any(_host_matches(req["host"], h) for h in scope.hosts): return False return True def verify_attenuation(parent: Scope, child: Scope) -> None: if child.canonicalization_profile != parent.canonicalization_profile: raise AttenuationNonMonotonicError( "canonicalization profile mismatch between parent and child" ) # Signal 1: orphaned behavioral attribute. Any attribute whose # conditioning predicate is not present in the child is unsafe. parent_attrs = set(parent.attributes) child_attrs = set(child.attributes) orphaned = child_attrs - parent_attrs if orphaned: raise AttenuationNonMonotonicError( f"child carries attributes with no parent conditioning: {sorted(orphaned)}" ) # Signal 2: semantic entailment. Search for a witness request that the # child authorizes and the parent does not. for req in _sample_requests(child): if _authorizes(child, req) and not _authorizes(parent, req): raise AttenuationNonMonotonicError( f"non-monotone derivation: child authorizes {req!r} " f"but parent does not" ) # Signal 3: branch collapse. If the parent had a union over hosts and the # child singleton-izes it while any attribute was branch-conditioned, # the attribute's scope silently widens. if len(parent.hosts) > 1 and len(child.hosts) == 1: for attr, value in parent.attributes.items(): if isinstance(value, dict) and "conditioned_on_host" in value: raise AttenuationNonMonotonicError( f"branch collapse on hosts while attribute {attr!r} " f"was conditioned on a sibling branch" ) def delegate(parent: Scope, child: Scope) -> Scope: verify_attenuation(parent, child) return child if __name__ == "__main__": parent = Scope( tool="filesystem.read", positive_paths=("/data/**",), deny_paths=("/data/secrets/**",), ) child = Scope( tool="filesystem.read", positive_paths=("/data/reports/**",), deny_paths=("/data/secrets/**",), ) try: delegate(parent, child) except AttenuationNonMonotonicError as exc: print(f"attenuation rejected: {exc}")