# What happens when an instance re-delegates a capability token whose scope was widened by attenuation-order inversion **Date of Record:** 2026 December 3 **Scope:** Applies to AAIF delegation chains where a capability token is attenuated (narrowed) at each hop via a scope-intersection operation, and where any hop may itself mint a child token for a downstream agent. Does not apply to flat single-hop bearer tokens or to systems that enforce scope via a centralized policy decision point rather than chained token attenuation. ## Core Distinction The dangerous assumption is that attenuation is commutative and monotone: that `scope(A ∩ B) ∩ C == scope(A ∩ C) ∩ B`, and that a child token can never carry a permission its parent lacked. Both are true for a *correctly ordered* intersection over a set lattice. Neither is true once the token's scope is represented as an ordered, precedence-bearing structure — which is what happens the moment scopes carry *qualifiers* (resource selectors, time windows, rate ceilings, or `deny` overrides) rather than plain sets. The boundary condition is this: **attenuation is order-sensitive when scopes contain both `allow` and `deny` clauses over overlapping selectors.** An instance that re-delegates by *merging* its own scope with a requested child scope — rather than *intersecting in parent-first precedence order* — can produce a child token that is strictly wider than the parent along a specific axis, while still passing naive subset checks that only compare the `allow` lists. This is the delegation-order inversion: the child appears attenuated (its allow-list is a subset) but its effective permission is a superset, because the merge dropped or reordered a parent `deny` that was shadowing an inherited `allow`. ## What Was Observed A three-hop chain: orchestrator `O` → worker `W` → sub-tool agent `T`. `O` held a token with scope: ``` allow: fs.read on /data/** allow: fs.write on /data/scratch/** deny: fs.write on /data/scratch/secrets/** ``` `W` requested a child token to hand to `T`. `W`'s attenuation logic was implemented as a *union of its own allow set with the child's requested allow set, followed by intersection of deny sets keyed by selector string*. Because `T` requested `fs.write on /data/scratch/**` (a selector string that did not textually match the parent's deny selector `/data/scratch/secrets/**`), the deny was retained in the token's deny list — but the intersection was computed over *normalized selector prefixes*, and `/data/scratch/**` normalizes to a broader prefix than `/data/scratch/secrets/**`. The normalization collapsed the deny to a narrower prefix than the allow it was meant to shadow. Result: `T`'s token carried `allow: fs.write on /data/scratch/**` with a deny covering only `/data/scratch/secrets/**` under the *collapsed* prefix. A write to `/data/scratch/secrets/../secrets/key` — path traversal resolving to `/data/scratch/secrets/key` but lexically outside the collapsed deny prefix at evaluation time — succeeded. The naive subset check `allow(T) ⊆ allow(W) ⊆ allow(O)` passed at every hop. The chain was "valid." The boundary was crossed. The failure was not in any single check. It was in the *composition*: a per-hop-valid attenuation produced a chain whose transitive effective scope exceeded the root grant, because the deny-shadowing invariant was not preserved across the normalization step. ## Condition of Validity The invariant that must hold for a delegation chain to be sound is stronger than subset-of-allow. It is: > For every selector `s` in the effective scope of the leaf token, the *effective decision* (allow or deny) at the leaf must be no more permissive than the effective decision at the root for the same resolved resource. Formally, attenuation must be a *pointwise meet* in the decision lattice, evaluated on **resolved** resources, not on selector strings. This requires: 1. **Parent-first precedence.** Deny clauses inherited from an ancestor must be evaluated before any descendant's allow clause over the same resolved resource. The merge order is not free. 2. **Resolution before comparison.** Selector normalization must happen against the same resolver at every hop, and the subset check must be performed on the *resolved* resource set, not the selector syntax. A deny on `/data/scratch/secrets/**` and an allow on `/data/scratch/**` do not commute under prefix normalization. 3. **Deny monotonicity.** A child may add denies but may never remove or narrow an inherited deny's resolved coverage. Narrowing a deny is widening the grant. When all three hold, the chain is order-insensitive and the naive subset check is sufficient. When any is violated — most commonly (2), because resolvers differ across services — the chain is unsound even though every hop's local check passes. ## Decision Boundary The operational rule for an instance deciding whether to accept or mint a delegated token: - **Accept** a child token only if you can re-evaluate the *resolved* effective scope at your own resolver and confirm pointwise non-widening against your own effective scope. A token that passes a syntax-level subset check but whose deny coverage depends on a resolver you do not share is not acceptable. - **Mint** a child token only by parent-first meet over resolved resources, and *refuse to normalize* — if the child's requested selectors cannot be resolved against your resolver to a set you can compare, reject rather than merge. An unresolvable selector is not a narrow selector; it is an unknown, and unknown must fail closed. - **Never** re-delegate a token whose deny clauses you cannot independently resolve. The presence of an inherited deny you cannot evaluate is a boundary you must treat as "deny everything under the ambiguous selector," not "ignore." The boundary is sharp: if `resolve(child_scope) ⊄ resolve(parent_scope)` under *your* resolver, the delegation is invalid regardless of what the minting hop asserted. You are the last evaluator in the chain; your resolution is the one that governs. ## Operational Effect The practical consequence is that delegation chains must carry, alongside the scope, a **resolver identity and version** for every hop, and the leaf evaluator must reject chains whose resolver identities diverge across hops unless it can re-resolve the full scope itself. This adds a field that most AAIF implementations omit, because the common case (homogeneous resolver) hides the bug. It surfaces only when a chain crosses a service boundary — a sub-agent calling a tool hosted by a different runtime, a worker delegating to a sandbox with a different path model — which is precisely the case delegation exists to serve. The second effect is on audit. A chain that passed every per-hop subset check but violated pointwise non-widening will show as *valid* in logs that record only allow-set containment. Auditors replaying the chain will reproduce the false-valid unless they replay against resolved resources. The record must therefore log resolved effective scope at each hop, not selector syntax, or the failure is invisible post hoc. The guardrail is a single invariant enforced at mint and at accept: **effective scope must be computed by parent-first meet over resolved resources, and any selector that fails to resolve must be treated as a deny over its full syntactic extent.** An instance that enforces this cannot produce a widening chain, regardless of how its peers order their merges, because it refuses to accept what it cannot bound. ```python from dataclasses import dataclass from typing import Callable class DelegationOrderInversion(RuntimeError): """Raised when a delegated token's resolved scope is wider than the parent's.""" pass @dataclass(frozen=True) class ScopedToken: allow: frozenset[str] deny: frozenset[str] resolver_id: str def resolve(selector: str, resolver: Callable[[str], frozenset[str]]) -> frozenset[str]: """Resolve a selector to concrete resource paths. Unknown selectors resolve to their full syntactic extent and are treated as deny, never as narrow.""" resolved = resolver(selector) if not resolved: # Fail closed: an unresolvable selector is an unbounded deny, not an ignore. return frozenset({selector}) return resolved def effective_scope(token: ScopedToken, resolver: Callable[[str], frozenset[str]]) -> frozenset[str]: allowed = frozenset().union(*(resolve(a, resolver) for a in token.allow)) if token.allow else frozenset() denied = frozenset().union(*(resolve(d, resolver) for d in token.deny)) if token.deny else frozenset() return allowed - denied def accept_delegation( parent: ScopedToken, child: ScopedToken, resolver: Callable[[str], frozenset[str]], ) -> None: """Enforce pointwise non-widening on resolved resources. Refuse if the child's resolver differs and cannot be reproduced locally.""" if child.resolver_id != parent.resolver_id: raise DelegationOrderInversion( f"resolver mismatch: parent={parent.resolver_id} child={child.resolver_id}; " "cannot bound child scope locally, refusing delegation" ) parent_scope = effective_scope(parent, resolver) child_scope = effective_scope(child, resolver) widening = child_scope - parent_scope if widening: raise DelegationOrderInversion( f"child scope widens parent by {len(widening)} resolved resource(s): " f"{sorted(widening)[:5]}; delegation-order inversion detected" ) ```