# Why does an instance of a delegated agent silently exceed its capability scope when a token exchange refreshes mid-task? **Date of Record:** 2026 November 30 **Scope:** Applies to agents that obtain tool-authorization tokens via on-behalf-of / token-exchange (RFC 8693) flows where a short-lived capability-scoped token is minted from a broader parent credential, and where the token is refreshed transparently during a multi-step task. Does not apply to statically provisioned long-lived API keys or to tokens minted once per task with no mid-task refresh. ## Core Distinction The failure is not "the agent was granted the wrong scope." It is a **scope-substitution at the refresh boundary**: the exchange that mints a *narrowed* child token (the capability-scoped one the planner reasoned about) and the exchange that *refreshes* it are not guaranteed to be the same operation. When the refresh path re-derives the child from the parent credential rather than re-narrowing from the prior child's recorded scope, the refreshed token inherits the **parent's** scope envelope. The agent's authorization silently widens at the moment of refresh, and because the widening is invisible to the reasoning loop—which still believes it holds the token it was issued at step 0—subsequent tool calls succeed that should have been rejected. Least privilege is violated not by escalation but by **forgetting to re-apply the narrowing**. ## What Was Observed A three-step task: `search_docs` → `read_issue` → `post_comment`. The planner was issued a capability token `T0` scoped to `{docs:read, issues:read}` (comment posting was deliberately excluded; the agent was expected to request a second exchange for `comments:write` at step 3). `T0` had a 90-second TTL. Step 1 and step 2 completed in ~40s. Step 3's reasoning stalled on a tool-output summarization pass (a large issue body triggered a second context compaction), consuming ~70s. At t≈95s the transport layer's background refresher observed `T0` expired and called the exchange endpoint. The refresher sent the **parent** subject token (the workload identity) with the original requested scope set `{docs:read, issues:read}`—but the exchange service, configured to "re-derive on refresh," resolved the parent's full grant, which included `comments:write`, and minted `T1` with `{docs:read, issues:read, comments:write}`. The refresher cached `T1` under the same logical capability handle the agent used for `T0`. The agent then called `post_comment`, which succeeded. No error, no warning, no audit anomaly—the call was *authorized*, just not by the scope the planner had reasoned about. The trace signature is distinctive: a gap between the token's `issued_at` and the task's `step_index` (refresh occurred mid-task), a `scope` delta between `T0` and `T1` where `T1 ⊋ T0`, and a tool call whose required scope is in `T1 \ T0`. In replay against a fixed-scope mint, that same call returns `403 insufficient_scope`. ## Condition of Validity The invariant that must hold is **refresh idempotence under narrowing**: for any capability handle `h`, `scope(refresh(h)) == scope(mint(h))`. This holds only if the refresh path re-narrows from the *last issued child's recorded scope set*, not from the parent credential's grant. It fails whenever: 1. The refresher is stateless w.r.t. the prior child scope (common when refresh is handled by a transport sidecar that only knows the parent token). 2. The exchange service treats the `scope` request parameter as advisory and intersects with the parent grant rather than the prior child grant. 3. Scope narrowing is expressed as a *subtractive* filter applied at mint time but re-applied against a different base at refresh time. The condition of validity is therefore: **the child scope must be persisted as the authoritative base for refresh, and refresh must be a pure function of (prior child scope, parent validity)—never of the parent grant alone.** ## Decision Boundary The agent (or its supervisor) must treat a scope *widening* across a refresh as a hard fault, not a benign event. The boundary is: - If `scope(T_new) ⊆ scope(T_old)`: accept silently (narrowing refresh is always safe). - If `scope(T_new) ⊋ scope(T_old)`: **abort the current reasoning step**, because the planner's authorization model no longer matches the credential in hand. The agent cannot safely continue reasoning about "what am I allowed to do" when the answer changed underneath it without a corresponding plan revision. - If `scope(T_new) ⊄ scope(T_old)` and `scope(T_old) ⊄ scope(T_new)` (incomparable): treat as full re-authorization and force a planner checkpoint. The guardrail is to attach the expected scope set to the capability handle at mint time and assert set-inclusion on every refresh, failing closed. ## Operational Effect Without the guardrail, least-privilege is a property that holds at `t=0` and decays silently with every TTL expiry. The blast radius is proportional to the number of refreshes in a task and the breadth of the parent grant—long-running tasks with narrow child scopes and broad parent identities are maximally exposed. The fix is architectural, not detective: persist child scope on the handle, make refresh re-narrow from it, and have the agent assert `⊆` on receipt. Audit logs alone will not catch it because every widened call is legitimately authorized by the widened token. ```python from dataclasses import dataclass, field from typing import FrozenSet class ScopeWideningOnRefresh(RuntimeError): """Raised when a refreshed capability token exceeds the scope it was minted with.""" pass @dataclass class CapabilityHandle: name: str granted_scope: FrozenSet[str] # authoritative base for refresh token: str = "" issued_at: float = 0.0 def accept_refresh(self, new_token: str, new_scope: FrozenSet[str], now: float) -> None: # Invariant: refresh must never widen the capability envelope. if not new_scope.issubset(self.granted_scope): extra = new_scope - self.granted_scope raise ScopeWideningOnRefresh( f"capability {self.name!r} refreshed with scope {sorted(new_scope)} " f"which exceeds minted scope {sorted(self.granted_scope)}; " f"unexpected privileges: {sorted(extra)}. " f"Aborting step: planner authorization model is stale." ) self.token = new_token self.issued_at = now def guarded_tool_call(handle: CapabilityHandle, required: FrozenSet[str], call) -> object: # Pre-flight: the agent may only invoke tools inside its *minted* scope, # regardless of what the live token happens to permit. if not required.issubset(handle.granted_scope): raise ScopeWideningOnRefresh( f"tool requires {sorted(required)} but capability {handle.name!r} " f"was minted for {sorted(handle.granted_scope)}" ) return call(handle.token) ```