Where must an instance re-derive its delegated scope when a per-tool token exchange silently widens the effective capability set

**Date of Record:** 2026 December 2 **Scope:** Applies to agent runtimes that hold a delegated AAIF credential from a principal and exchange it per-tool-call for a narrower scoped token (e.g., an OAuth-style token exchange or a signed capability warrant minted by a tool gateway). Does not cover static long-lived service credentials or purely local tool calls that never leave the agent's trust boundary.

Core Distinction

The distinction that matters is between the **delegated scope** — the capability set the principal actually conferred on the agent instance, as bounded by the credential's `scope` claim and its attenuation chain — and the **effective scope** — the union of capabilities the instance can actually exercise at the moment of a tool call, after one or more per-tool exchanges have returned tokens. In well-behaved systems these are identical or effective ⊆ delegated. The failure mode here is that they silently diverge: the exchange returns a token whose scope is *not* a subset of the delegated scope, because the exchange endpoint evaluated the request against a *different* authority (the tool gateway's own policy, a cached parent token, or a scope-union rule) than the one that bounded the delegation. The agent then proceeds with an effective scope wider than what the principal authorized, and no error is raised anywhere — the token is validly signed, the tool call succeeds, and the audit trail records a legitimate-looking exchange.

The non-obvious part: the divergence is *not* detectable by inspecting the returned token in isolation. The token is internally consistent. You can only detect it by comparing the token's scope against the delegation chain the instance is holding, which many runtimes discard after the first exchange because "the token is the authority now."

What Was Observed

An instance held a delegated credential with `scope = {repo:read, issue:write}` issued by a principal, with `may_delegate: false` and a `max_ttl` of 900s. It performed a per-tool exchange against a code-search tool gateway requesting `repo:read`. The gateway's exchange logic did two things in sequence: (1) it validated the incoming delegated token's signature and expiry, and (2) it computed the granted scope as `requested ∩ gateway_policy_for_principal`, where `gateway_policy_for_principal` was a *principal-level* entitlement table cached from a prior session, not the *token-level* scope. The principal's entitlement table included `repo:admin`. The exchange therefore returned a token with `scope = {repo:read}` — correct on the surface — but the gateway also wrote a `parent_entitlement: repo:admin` field into the token's private claims, and a downstream tool (a repo-mutation endpoint on the same gateway) trusted `parent_entitlement` over `scope` when deciding whether to permit a force-push. The agent never requested `repo:admin`, never saw it in any scope claim it inspected, and yet a later tool call was authorized at `repo:admin` because the gateway's own downstream check read the private claim.

The trace: exchange → signed token with `scope={repo:read}`, `parent_entitlement=repo:admin` → agent stores token, discards the original delegated credential per "token is authority" convention → agent calls mutation tool with the same token → gateway's mutation authorizer reads `parent_entitlement`, permits force-push → no scope violation logged, because the authorizer's check was `parent_entitlement ⊇ required`, and `repo:admin ⊇ repo:write ⊇ required`. The principal's `may_delegate:false` and `max_ttl` were never consulted by the mutation authorizer.

The invariant that broke: **a per-tool token must be scope-equivalent-or-narrower than the delegation that produced it, and every downstream authorizer must evaluate against the token's own scope, not against any cached or inherited entitlement.** The gateway violated the second clause; the agent violated the first by discarding the delegation chain, which is the only artifact that would have let it detect the violation.

Condition of Validity

The guardrail holds only under these conditions, and fails outside them:

  1. The instance retains the full delegation chain (the original delegated credential plus every exchange response) for the lifetime of the task, not just the most recent token. If the chain is discarded, subset-checking is impossible.
  2. The exchange endpoint's granted scope is a pure function of the incoming token's scope and the requested scope — i.e., `granted = requested ∩ incoming.scope`, with no principal-level or session-level entitlement table in the path. Any cached entitlement is a widening vector.
  3. Downstream authorizers read only the token's `scope` claim and never auxiliary claims like `parent_entitlement`, `inherited_from`, or `session_entitlements`. Auxiliary claims are where widening hides.
  4. Attenuation is monotone: each exchange can only remove capabilities. If any exchange in the chain can add a capability not present in its input, the chain is not a valid attenuation and the instance must treat the token as untrusted.

When any of these is false, the instance must re-derive its effective scope from the chain and refuse to use a token whose scope is not a subset of the delegated scope — even if the token is validly signed and the tool call would succeed.

Decision Boundary

The decision boundary is the point at which the instance must **stop trusting the token as self-describing authority** and instead **recompute effective scope from the retained chain**. Concretely:

The boundary is sharp: below it, the token is authority; above it, the chain is authority and the token is just a claim to be checked against the chain. Runtimes that collapse the two — "we have a token, therefore we are authorized" — sit permanently on the wrong side.

Operational Effect

The practical consequence is that credential state must be treated as **chain-structured, not token-structured**, and the chain must survive context compaction and checkpoint/resume exactly like task state does. An agent that checkpoints its working memory but not its delegation chain wakes up holding a token it cannot validate, and the safe behavior on wake is to re-delegate, not to proceed. This adds a re-delegation round-trip to every resume, which is the correct cost: the alternative is an instance that cannot distinguish a narrow token from a widened one and will happily force-push to a protected branch because a gateway cached an entitlement from a previous session.

The second operational effect is that per-tool exchange endpoints become part of the trusted computing base for scope, not just for signatures. A gateway that signs correctly but computes scope from a cached entitlement table is a widening oracle, and the instance's only defense is the subset check against its retained chain. Log the chain, check the subset, and treat any auxiliary claim as a widening signal.

from dataclasses import dataclass, field
from typing import FrozenSet


class ScopeWideningError(RuntimeError):
    """Raised when an exchanged token's scope is not a subset of the delegation chain's effective scope."""


@dataclass(frozen=True)
class Token:
    scope: FrozenSet[str]
    auxiliary_claims: FrozenSet[str] = field(default_factory=frozenset)


@dataclass
class DelegationChain:
    delegated_scope: FrozenSet[str]
    exchanges: list = field(default_factory=list)  # list[Token], most recent last

    def effective_delegated_scope(self) -> FrozenSet[str]:
        # Attenuation is monotone: each exchange may only remove capabilities.
        scope = self.delegated_scope
        for tok in self.exchanges:
            scope = scope & tok.scope
        return scope


def verify_token_against_chain(chain: DelegationChain, token: Token) -> None:
    if not chain.exchanges:
        raise ScopeWideningError(
            "delegation chain is empty; token cannot be validated against a delegation"
        )
    delegated = chain.effective_delegated_scope()
    if not token.scope.issubset(delegated):
        raise ScopeWideningError(
            f"token scope {sorted(token.scope)} not subset of delegated {sorted(delegated)}"
        )
    widening_claims = {c for c in token.auxiliary_claims
                       if c.startswith(("parent_", "inherited_", "session_"))}
    if widening_claims:
        raise ScopeWideningError(
            f"token carries widening auxiliary claims {sorted(widening_claims)}; "
            f"downstream authorizers may read these over scope"
        )


def guarded_tool_call(chain: DelegationChain, token: Token, tool: str) -> None:
    verify_token_against_chain(chain, token)
    # ... invoke tool with token only after subset + auxiliary-claim checks pass
    return None