# Where must an instance re-validate a delegated scope after a token refresh, and why OIDC `sub` continuity is not scope continuity **Date of Record:** 2026 December 1 **Scope:** Applies to AAIF deployments where an agent's authorization is expressed as a scoped delegation token (audience-bound, scope-limited, short-TTL) minted against an OIDC-bound agent identity, and where the agent refreshes that token mid-task via an OIDC refresh or client-credentials flow. Does not apply to long-lived static API keys, nor to human-in-the-loop consent flows that re-prompt per action. ## Core Distinction The failure mode here is not token expiry and it is not signature forgery. It is the **silent decoupling of identity continuity from scope continuity across a refresh boundary**. OIDC guarantees that the refreshed token's `sub` (and `iss`, `aud`) still resolve to the *same principal*. It does **not** guarantee that the *scope set* attached to that principal is unchanged. Scopes are a mutable, policy-derived projection of the principal's entitlements at mint time, not an immutable property of the identity. When an agent treats "my refresh succeeded and `sub` matches" as "my authority is intact," it conflates two invariants that AAIF deliberately keeps separate: *who I am* (stable across refresh) and *what I may do right now* (recomputed at every mint). The boundary condition: a mid-execution refresh where the re-minted token carries a **narrower** scope set than the token the agent's in-flight plan was built against. The agent's cached plan, tool bindings, and pending sub-goals were all validated against the *old* scope envelope. After refresh, those bindings are stale but structurally valid, so nothing in the transport layer raises an error. The scope check happens at token *use*, not at token *swap*. ## What Was Observed A research-orchestration agent held a delegation token with scopes `repo:read repo:write issue:comment artifact:upload` and a 15-minute TTL. It executed a 40-step plan: clone, patch, open PR, comment on an issue, upload a build artifact. At step 22 (roughly 14 minutes in) the client library performed a proactive refresh 60 seconds before expiry. The refresh succeeded: HTTP 200, new JWT, valid signature, `sub` byte-identical, `aud` unchanged. The re-minted token carried `repo:read issue:comment artifact:upload`. The `repo:write` scope had been revoked by a policy change 90 seconds earlier — an over-broad grant was being narrowed — and the IdP correctly reflected the reduced entitlement at the next mint. No revocation event was pushed to the agent; there is no continuous revocation channel in this deployment, only mint-time projection. Steps 1–21 had already completed. Step 23 (`git push` of the patched branch) ran against the new token. The Git host rejected it with a 403 carrying `insufficient_scope`. The agent's error handler classified this as a *transient* authorization blip (403 is frequently retried) and retried twice, then fell back to a different tool binding that used the *cached* old token string still held in the plan object — which had not yet expired and still validated server-side for another 40 seconds. The push succeeded on the stale token. The policy narrowing was bypassed for the remainder of the old token's lifetime, and the audit log recorded two different tokens authorizing the same logical operation. The observable signature: **a successful refresh followed by a scope-rejection that the retry layer masks, with a stale-token fallback that silently re-widens authority.** The failure is invisible in the happy path and only surfaces as an audit discontinuity — one operation, two `jti` values, two different scope claims. ## Condition of Validity The invariant that must hold for safe refresh is: > For every in-flight plan step *s* not yet executed, `scopes(refreshed_token) ⊇ required_scopes(s)`. This is a *plan-level* invariant, not a token-level one. A refresh is only safe if the agent re-validates the *remaining* plan against the *new* scope set before resuming. The conditions under which this invariant is violated: 1. The agent caches per-step required scopes at plan-construction time and does not recompute them post-refresh. 2. The refresh path and the execution path are decoupled — refresh updates a token store, but plan objects hold token *snapshots* rather than references. 3. The error taxonomy collapses `insufficient_scope` (a permanent, plan-invalidating condition) into the same class as `token_expired` (a transient, refresh-triggering condition). 4. A stale-token fallback exists and is reachable after a refresh, allowing pre-refresh authority to be reasserted. The invariant holds only when the agent treats a refresh as a **plan-validity checkpoint**: on every token swap, diff `old_scopes` against `new_scopes`, and if `new_scopes` is not a superset of the union of remaining-step requirements, halt and re-plan rather than resume. ## Decision Boundary The decision the agent must make at the refresh boundary is binary and must be resolved *before* the next tool call, not inferred from the next tool call's response: - **Superset or equal:** resume the existing plan. No re-validation of completed steps needed. - **Strict subset (narrowing):** the plan is partially invalidated. Compute the set of remaining steps whose required scopes fall outside `new_scopes`. If that set is empty, resume. If non-empty, abort the plan, emit a re-plan signal, and — critically — **invalidate every cached token snapshot in the plan object** so no stale-token fallback is reachable. The boundary is *not* "did the refresh succeed." It is "does the refreshed scope envelope still cover the unexecuted remainder of the plan." An agent that only checks the former will pass every liveness probe while violating authorization on the exact steps that matter. The stale-token fallback must be architecturally impossible after a narrowing refresh: the old token must be dropped from memory at swap time, not left reachable via a plan snapshot. ## Operational Effect Downstream, the effect is an **audit discontinuity masquerading as a retry**. Because the operation ultimately succeeded (via stale token), no alert fires on the authorization path. The only trace is that a single logical operation is authorized by two distinct `jti` values with divergent scope claims — detectable only by correlating the audit log against the refresh event, which most deployments do not do. The policy narrowing that was supposed to take effect at T+90s actually took effect at T+130s (old token expiry), and the 40-second gap is a window in which revoked authority remained exercisable. For a write scope, that window is a correctness and security defect; for a read scope it is a confidentiality leak. The agent reports success. The system reports success. The invariant was violated silently. The guardrail is a refresh-time plan re-validation gate plus snapshot invalidation, enforced structurally so that a narrowing refresh cannot leave a usable old token reachable. ```python import time from dataclasses import dataclass, field from typing import FrozenSet class ScopeContinuityViolation(RuntimeError): """Raised when a refreshed token no longer covers the remaining plan.""" pass @dataclass(frozen=True) class DelegationToken: jti: str sub: str scopes: FrozenSet[str] issued_at: float ttl: float def expired(self, now: float | None = None) -> bool: return (now or time.time()) >= self.issued_at + self.ttl @dataclass class PlanStep: name: str required: FrozenSet[str] @dataclass class Plan: steps: list[PlanStep] cursor: int = 0 def remaining(self) -> list[PlanStep]: return self.steps[self.cursor:] @dataclass class AgentSession: token: DelegationToken plan: Plan # Snapshots that a naive executor might fall back to. Must be cleared on narrowing. stale_snapshots: list[DelegationToken] = field(default_factory=list) def refresh(self, new_token: DelegationToken) -> None: if new_token.sub != self.token.sub: raise ScopeContinuityViolation( f"principal drift on refresh: {self.token.sub} -> {new_token.sub}" ) old_scopes = self.token.scopes new_scopes = new_token.scopes if not new_scopes.issuperset(old_scopes): uncovered = { s.name: (s.required - new_scopes) for s in self.plan.remaining() if not new_scopes.issuperset(s.required) } if uncovered: # Narrowing invalidates the remainder: abort and re-plan. # Also purge snapshots so no stale-token fallback is reachable. self.stale_snapshots.clear() self.token = new_token raise ScopeContinuityViolation( f"refresh narrowed scopes {sorted(old_scopes - new_scopes)}; " f"remaining steps uncovered: {uncovered}" ) # Superset or equal: safe to resume. self.stale_snapshots.clear() self.token = new_token def execute_next(self) -> str: if self.plan.cursor >= len(self.plan.steps): return "done" step = self.plan.steps[self.plan.cursor] # Re-check at use time against the *current* token, never a snapshot. if not self.token.scopes.issuperset(step.required): raise ScopeContinuityViolation( f"step {step.name!r} requires {sorted(step.required)} " f"not in current token {sorted(self.token.scopes)}" ) self.plan.cursor += 1 return step.name def run_session(sess: AgentSession, refreshed: DelegationToken) -> list[str]: executed = [] try: sess.refresh(refreshed) except ScopeContinuityViolation: # Re-plan signal propagates; do not resume on stale authority. raise while True: try: executed.append(sess.execute_next()) except ScopeContinuityViolation: raise if sess.plan.cursor >= len(sess.plan.steps): break return executed ```