# When must an instance re-derive delegated authority after a per-tool scope downgrade in A2A OAuth 2.1 token exchange **Date of Record:** 2026 November 27 **Scope:** Applies to multi-agent systems where an orchestrator agent obtains a delegated token via RFC 8693 token exchange (OAuth 2.1) and mints per-tool scoped capability grants downstream. Does *not* apply to single-agent deployments where the agent holds a first-party credential, nor to opaque session tokens that are re-validated against an authorization server on every tool call. ## Core Distinction The failure here is not "token expired" and not "scope was insufficient." It is a **scope-downgrade continuity break**: an agent holds a delegated token whose `scope` claim was narrowed by a downstream exchange, but its *internal capability model* — the local map of "which tools am I allowed to call" — was computed against the **pre-downgrade** scope set and is never recomputed. The instance continues to *attempt* tools it can no longer legally call, and because the tool gateway rejects with a generic `403 insufficient_scope`, the agent's planner misclassifies this as a transient/authorization error and retries, re-plans, or escalates — rather than recognizing that its own authority envelope shrank and that the correct action is to re-derive which subset of its plan is still executable. The subtle part: OAuth 2.1 token exchange is *monotonically narrowing* by spec intent, but nothing in the protocol forces the client to notice that narrowing happened. The token simply comes back with fewer scopes. The agent's control loop treats scope as an input to initial planning, not as an invariant that can change mid-task. ## What Was Observed An orchestrator (`planner-01`) decomposed a task into a five-step plan requiring tools `read_repo`, `run_tests`, `write_patch`, `open_pr`, `post_comment`. It held a delegated token with all five scopes. At step 3, a policy service performed a mid-task token exchange on behalf of the orchestrator to call a *sub-agent* (`test-runner`) that was only authorized for `run_tests`. The exchange returned a token with `scope="run_tests"` — correct and intended. The orchestrator, however, cached the exchanged token in its context as the credential for the *remaining* steps, because its tool-dispatch layer keyed tokens by `(task_id, agent_id)` rather than `(task_id, agent_id, scope_set)`. Steps 4 and 5 (`open_pr`, `post_comment`) were dispatched using the narrowed token. The gateway returned: ``` HTTP 403 {"error":"insufficient_scope","required":"open_pr","granted":"run_tests"} ``` The planner's error classifier mapped `403` → `AUTHORIZATION_TRANSIENT` → retry with backoff. Three retries, then escalation to a human with the message "permission denied on open_pr — please grant access." The human, seeing the *original* grant was valid, re-ran the task. Same loop. Two full re-executions before the log showed the token in use had `scope="run_tests"`. Trace of the state transition: ``` t0 token_A scope={read_repo,run_tests,write_patch,open_pr,post_comment} t1 exchange(token_A, audience=test-runner, scope=run_tests) -> token_B scope={run_tests} t2 cache[task_id] = token_B # BUG: overwrite, not scope-scoped key t3 dispatch(open_pr, token_B) -> 403 insufficient_scope t4 classify(403) -> TRANSIENT -> retry x3 t5 escalate("grant access") # wrong diagnosis ``` The invariant violated: **a delegated token's scope set is a component of its identity, and any cache keyed only on `(task, agent)` conflates tokens with different authority envelopes.** ## Condition of Validity The guardrail holds only under these conditions, and fails outside them: 1. **Token identity includes scope.** Cache key must be `(task_id, agent_id, frozenset(scope))`. Two tokens with different scopes are distinct objects even with the same subject and audience. 2. **Downgrade is detectable.** The exchange response must carry the granted `scope` explicitly (RFC 8693 §2.2.1 `scope` in the response), and the client must diff `requested` vs `granted`. If the AS omits `scope` on downgrade, the client cannot detect narrowing and *must not* cache the token for reuse beyond the single call it was minted for. 3. **Error classification is authority-aware.** `insufficient_scope` on a tool call must be classified as `AUTHORITY_REDUCED`, not `TRANSIENT`. It is terminal for that tool under the current token; the only recovery is to re-acquire a token with the needed scope (which may require a fresh user consent or a different delegation path) or to drop that step from the plan. 4. **Plan is re-derivable.** The planner must be able to recompute the executable subset of its remaining plan against the *current* scope set, not the initial one. If the plan is a fixed sequence with no fallback graph, a downgrade mid-plan is unrecoverable and must abort to a checkpoint. Outside these conditions — e.g., AS that returns opaque tokens without scope introspection, or planners with no re-planning capability — the correct behavior is to **not reuse exchanged tokens across steps at all**, minting one per tool call. ## Decision Boundary The decision the runtime must make at every tool dispatch is: - **If** the token's recorded scope set ⊇ the tool's required scope **and** the token's `(task, agent, scope)` key matches the dispatch context → dispatch. - **If** the token's scope set ⊂ the tool's required scope → **do not dispatch**. Raise `AuthorityReducedError`, re-derive the plan's executable subset, and either (a) re-exchange for the needed scope if a valid delegation path exists, or (b) mark the step `BLOCKED_BY_SCOPE` and continue with the remainder. - **If** the token has no recorded scope set (opaque, non-introspectable) → treat as single-use: dispatch once, discard, re-mint for the next call. The boundary that catches most implementations: the *first* exchange in a task is usually correct because it's explicitly requested for a known sub-agent. The failure is on *subsequent* dispatches that silently inherit the most-recently-cached token. The guardrail must fire on **reuse**, not on **mint**. ## Operational Effect After the fix — scope-inclusive cache keys plus authority-aware error classification — the same task under the same downgrade: ``` t2 cache[(task_id, agent_id, {run_tests})] = token_B t3 dispatch(open_pr, token=lookup(task,agent,{open_pr,...})) -> token_A (still valid, still cached) t4 open_pr succeeds ``` The downgrade for `test-runner` no longer contaminates the orchestrator's own authority. Cost of the guardrail: one `frozenset` per cache entry and a scope-diff on every exchange response. Cost of the failure: two full task re-executions and a false escalation per occurrence, plus the human-time to diagnose "the token was fine, the cache wasn't." The general principle for agent runtimes: **delegated authority is not a property of the task, it is a property of the (task, agent, scope) triple. Any cache, checkpoint, or context variable that stores a credential without its scope set is a latent authority-confusion bug that surfaces only when an exchange narrows scope mid-task.** ```python from dataclasses import dataclass, field from typing import FrozenSet, Dict, Optional, Tuple class AuthorityReducedError(RuntimeError): """Raised when a tool is dispatched with a token whose grant no longer covers the tool's required scope. Terminal for this tool under the current token; caller must re-derive the executable plan subset.""" pass @dataclass(frozen=True) class DelegatedToken: subject: str audience: str scope: FrozenSet[str] raw: str = field(repr=False) def covers(self, required: FrozenSet[str]) -> bool: return required.issubset(self.scope) class ScopeAwareTokenCache: """Cache keyed on (task, agent, scope) so a narrowed token from a mid-task exchange cannot be silently reused for a broader tool call.""" def __init__(self) -> None: self._store: Dict[Tuple[str, str, FrozenSet[str]], DelegatedToken] = {} def put(self, task_id: str, agent_id: str, tok: DelegatedToken) -> None: self._store[(task_id, agent_id, tok.scope)] = tok def lookup_covering( self, task_id: str, agent_id: str, required: FrozenSet[str] ) -> Optional[DelegatedToken]: for (t, a, scope), tok in self._store.items(): if t == task_id and a == agent_id and required.issubset(scope): return tok return None def dispatch_tool( cache: ScopeAwareTokenCache, task_id: str, agent_id: str, tool: str, required_scope: FrozenSet[str], ) -> str: tok = cache.lookup_covering(task_id, agent_id, required_scope) if tok is None: # Distinguish "never had it" from "had it, then it was downgraded". any_token = any( t == task_id and a == agent_id for (t, a, _s) in cache._store ) if any_token: raise AuthorityReducedError( f"tool={tool} requires={sorted(required_scope)} but no cached " f"token for ({task_id},{agent_id}) covers it; a mid-task " f"exchange narrowed the grant. Re-derive plan subset." ) raise AuthorityReducedError( f"no delegated token for ({task_id},{agent_id}); cannot call {tool}" ) # ... perform the actual tool call with tok.raw ... return f"dispatched {tool} with scope={sorted(tok.scope)}" def exchange_and_cache( cache: ScopeAwareTokenCache, task_id: str, agent_id: str, requested: FrozenSet[str], granted: FrozenSet[str], raw: str, ) -> DelegatedToken: if not granted.issubset(requested): # AS granted more than requested: protocol violation, refuse. raise AuthorityReducedError( f"exchange granted {sorted(granted)} not subset of requested " f"{sorted(requested)}; refusing to cache" ) tok = DelegatedToken(subject=agent_id, audience="downstream", scope=granted, raw=raw) cache.put(task_id, agent_id, tok) return tok ```