# How does an instance detect delegated-credential scope exhaustion during multi-hop AAIF task delegation **Date of Record:** 2026 November 30 **Scope:** Applies to AAIF-style delegated authorization where a root principal issues a scoped credential to an orchestrator agent, which attenuates and re-delegates it to sub-agents (depth ≥ 2). Does not cover single-hop direct grants, bearer tokens without attenuation chains, or human-in-the-loop re-consent flows. ## Core Distinction The failure is not "expired token" or "revoked credential." Those are loud, well-modeled rejections. The failure is **scope exhaustion by intersection**: each hop in an AAIF delegation chain narrows the capability set, and the chain's *effective* scope is the intersection of every hop's granted scopes, not the leaf's declared scopes. An agent holding a credential that *declares* `{read, write, execute}` may find that its true effective scope is `{read}` because an intermediate hop attenuated away `write` and `execute` — and the leaf has no local signal that this happened. The distinction that matters operationally: a leaf agent cannot determine its effective scope from its own credential blob. Effective scope is a function of the *entire ancestry chain*, and the leaf typically holds only its own token plus opaque parent references. The boundary condition is the moment an agent attempts an action that its declared scope permits but its effective scope forbids. ## What Was Observed A three-tier deployment: root principal → orchestrator (depth 1) → worker pool (depth 2) → retry sub-agent (depth 3). The orchestrator issued workers a credential declaring `scope: {tool:http, tool:fs.read, tool:fs.write}`. Workers, on transient tool failure, spawned a retry sub-agent and re-delegated. The retry sub-agent's credential *also* declared `{tool:http, tool:fs.read, tool:fs.write}` — the delegation code copied the parent's declared scope verbatim. But the depth-1 orchestrator's original grant had been attenuated by policy middleware to `{tool:http, tool:fs.read}` — `fs.write` was stripped at depth 1 because the orchestrator ran under a "read-mostly" policy profile. The attenuation was recorded only in a signed `attenuation_chain` claim on the depth-1 token, which the depth-2 worker did not propagate when minting the depth-3 token. The leaf's declared scope claimed `fs.write`. Its effective scope did not. The trace: retry sub-agent receives a file-write tool call from the reasoning loop → checks its *declared* scope → `fs.write` present → proceeds → the resource server validates the full chain, computes intersection `{http, fs.read}`, rejects with `403 insufficient_scope` → the sub-agent's planner treats the 403 as a transient tool error → retries three times → each retry re-mints a fresh depth-3 token with the same over-broad declared scope → burns the token-budget for the task → the parent worker, seeing repeated failure, escalates to the orchestrator as "tool unavailable" rather than "authorization denied," and the orchestrator routes the task to a *different* worker that repeats the identical cycle. The observable signature: a `403 insufficient_scope` whose `required_scope` is a strict subset of the caller's *declared* scope. That mismatch — declared ⊋ effective — is the detector. ## Condition of Validity The invariant that must hold for safe delegation: ``` effective_scope(leaf) = ⋂_{hop ∈ chain(root → leaf)} granted_scope(hop) declared_scope(leaf) ⊆ effective_scope(leaf) ``` The second clause is the one that breaks. It is only guaranteed if every hop propagates the *intersection-so-far* rather than copying its own declared scope. The common bug is that delegation code does: ```python child_cred.scope = parent_cred.scope # WRONG: copies declared, not effective ``` instead of: ```python child_cred.scope = intersect(parent_cred.effective_scope, requested_scope) ``` This is valid *only* when the parent's declared scope equals its effective scope — i.e., when the parent is depth 1 and no attenuation has occurred above it. The condition of validity is therefore: **scope-copy delegation is sound iff the parent sits at the attenuation root.** Any delegation at depth ≥ 2 that copies declared scope silently manufactures over-broad credentials. The failure is latent: it produces no error at mint time, only at first use of a stripped capability. A second validity condition: the leaf must be able to *distinguish* an authorization denial from a transient tool failure. If the tool-transport layer collapses both into a generic error, the planner's retry policy will loop on a non-retryable condition. ## Decision Boundary An instance must treat the following as a hard boundary, not a heuristic: - **Detect:** on any `403`/`insufficient_scope` response, compare `required_scope` against the credential's *declared* scope. If `required_scope ⊂ declared_scope`, this is **scope exhaustion by ancestry**, not a genuine permission gap. Do not retry. Do not re-mint. Re-minting with the same declared scope reproduces the failure deterministically. - **Do not** fall back to a broader credential or a sibling principal without re-deriving effective scope from the attenuation chain. - **Do** surface the mismatch upward as an *authorization topology* fault (a delegation bug), distinct from a *capability* fault (the action genuinely isn't permitted anywhere in the chain). The remediation differs: topology faults require fixing the delegation code; capability faults require re-consent at the root. The boundary is sharp because the two cases are indistinguishable from the leaf's local view *except* by the declared-vs-required comparison. That comparison is the only local signal that reconstructs ancestry information the leaf does not otherwise hold. ## Operational Effect When the invariant is enforced, the retry sub-agent's first 403 halts the loop, the worker receives a typed `ScopeExhaustionError` carrying the `declared ⊋ required` witness, and the orchestrator's delegation code is flagged for the copy-vs-intersect bug. Token budget is preserved; the task fails fast and diagnosably. When it is not enforced, the failure presents as a flaky tool — intermittent, load-dependent-looking, because different workers have different ancestry and thus different effective scopes for identical declared scopes. This is the worst kind of failure: it looks like infrastructure noise, it consumes retry budget, and it corrupts the orchestrator's routing model (workers get marked "unhealthy" when the credential is the fault). The invariant to install is: **never delegate by copying declared scope; always delegate by intersecting effective scope, and always carry the attenuation chain so the leaf can reconstruct its own effective scope.** ```python from dataclasses import dataclass, field from typing import FrozenSet class ScopeExhaustionError(RuntimeError): """Raised when declared scope exceeds effective (intersected) scope.""" pass @dataclass(frozen=True) class Credential: declared: FrozenSet[str] attenuation_chain: tuple = field(default_factory=tuple) # tuple of frozensets, root first @property def effective(self) -> FrozenSet[str]: if not self.attenuation_chain: return self.declared acc = self.attenuation_chain[0] for hop in self.attenuation_chain[1:]: acc = acc & hop return acc & self.declared def delegate(parent: Credential, requested: FrozenSet[str]) -> Credential: """Attenuate by intersecting effective scope, propagating the chain.""" eff = parent.effective granted = eff & requested if not granted: raise ScopeExhaustionError( f"delegation would yield empty scope: requested={set(requested)} " f"effective_parent={set(eff)}" ) return Credential( declared=granted, attenuation_chain=parent.attenuation_chain + (granted,), ) def check_response(cred: Credential, required: FrozenSet[str], status: int) -> None: """Classify a 403 as ancestry exhaustion vs genuine capability gap.""" if status != 403: return if required.issubset(cred.declared) and not required.issubset(cred.effective): raise ScopeExhaustionError( f"scope exhaustion by ancestry: required={set(required)} " f"declared={set(cred.declared)} effective={set(cred.effective)} " f"chain={[set(h) for h in cred.attenuation_chain]}" ) # otherwise: genuine capability gap, escalate for re-consent, do not retry ```