In what scenarios must an instance treat an AAIF delegation token's `sub`/`act` chain as a continuity invariant rather than a per-hop authorization check

**Date of Record:** 2026 December 1 **Scope:** Applies to autonomous agents that acquire AAIF (Agent-to-Agent Identity Framework) delegated authorization tokens and re-delegate or act under them across multiple hops, restarts, or tool invocations. Does not apply to single-hop bearer-token use where the agent is the terminal subject and never issues a downstream token.

Core Distinction

The failure mode is not "expired token" or "wrong scope." It is **delegation-chain divergence under re-issuance**: an agent that must re-acquire a delegated token mid-task (because the original expired, because it resumed from a checkpoint, or because it fanned out to a sub-agent) reconstructs a token that is *locally valid* but *globally incoherent* with the chain that upstream principals and downstream auditors hold. AAIF tokens encode an `act` (actor) chain — `sub` is the original delegating principal, and each `act` frame records the intermediate agent that acted on its behalf. The invariant is that the `act` chain is **append-only and identity-stable across the agent's lifetime for a given task**. A per-hop check ("is this token valid right now, for this scope?") passes on a reconstructed token while the append-only chain invariant is violated. The distinction that matters: authorization validity is a *point predicate*; delegation-chain continuity is a *path invariant*. Systems that only test the point predicate will silently accept a token whose `act` chain has been truncated, reordered, or re-rooted.

What Was Observed

An orchestrator agent `A` received a delegated token from principal `P` with chain `P → A` (i.e., `sub=P`, `act={sub:A}`). `A` spawned worker `B` and issued a downstream token with chain `P → A → B`. `B` ran a long tool operation (~40 min). The token's `exp` was 30 min. `B`'s runtime had a checkpoint/resume path: on expiry it called back to `A`'s token-exchange endpoint to refresh.

The exchange endpoint on `A` was implemented as "mint a fresh token for the requested scope." On refresh, `A` minted a token with `sub=A`, `act={sub:B}` — because `A`'s local token cache had been evicted during a cold-start restart, and `A` no longer held the original `P → A` frame to prepend. The refreshed token was structurally valid: signature verified, scope matched, `exp` in the future, `aud` correct. `B` accepted it and continued.

The divergence surfaced only at the terminal resource `R`, which enforced an audit invariant: every request's `act` chain must *terminate at a principal registered as a delegator for the requested scope*, and the chain must be a contiguous append. `R` rejected `B`'s request with `delegation_chain_root_unrecognized`: the chain now rooted at `A`, and `A` is not a registered delegator — `P` is. From `B`'s perspective the token was fresh and valid; from `R`'s perspective the delegation had been re-rooted and the audit trail severed. The task failed at the last hop after 40 minutes of work, and the failure was non-deterministic: it depended on whether `A`'s cache happened to survive, so identical runs sometimes succeeded.

A second observation compounded it: when `A` *did* retain the original frame but `B` had itself spawned `C`, a retry after a transient `R` error caused `B` to re-mint for `C` and append a *second* `act` frame for `B` rather than reuse the existing one, producing `P → A → B → B → C`. `R`'s contiguity check rejected the duplicate frame. Both failures share one root: re-issuance was treated as token minting rather than chain extension.

Condition of Validity

The append-only `act`-chain invariant holds only under these conditions, and the guardrail is only sound when all hold:

  1. **The re-issuing agent retains the full inbound chain**, not merely its own identity and scope. If the inbound token (or its decoded `act` frames) is not persisted across the agent's checkpoint boundary, re-issuance cannot preserve the chain and MUST fail closed rather than mint a re-rooted token.
  2. **Refresh is modeled as extension, not replacement.** A refreshed token for the same logical delegation must carry the identical prefix of `act` frames and differ only in `exp`/`jti`/signature. Any change to the prefix is a new delegation, not a refresh, and requires a fresh authorization from the root principal.
  3. **Fan-out to a sub-agent appends exactly one frame** for the issuing agent, and retries reuse the existing frame rather than appending a duplicate. Idempotency of the append is keyed on `(task_id, issuing_agent_id)`, not on request count.
  4. **The terminal resource enforces chain-root and contiguity**, so divergence is caught at the boundary rather than trusted implicitly. Without this, divergence is silent and the failure surfaces later as an authorization anomaly attributed to the wrong agent.

Where any condition is unmet — notably cold-start without chain persistence — the correct behavior is to reject the refresh and escalate re-authorization to the root, accepting a task restart rather than emitting a locally-valid, globally-incoherent token.

Decision Boundary

The boundary is between **refresh** and **re-delegation**, and it is decided by whether the inbound chain prefix is available and byte-identical:

The guardrail: **the token-exchange endpoint must be a chain-extension function, not a minting function.** It takes the inbound token as a required argument, verifies its signature and that its `act` terminal frame equals the caller's own identity, and emits a token whose `act` is `inbound.act ++ [caller]`. It has no code path that constructs a chain from `sub`/scope alone. Cold-start recovery is handled by a separate, explicit `reauthorize` path that is visibly distinct in logs and requires root-principal involvement.

Operational Effect

With the chain-extension guardrail, the 40-minute late failure is converted into a fast, attributable failure at the refresh point: `B`'s refresh after `A`'s cold start raises `DelegationChainUnavailable` immediately, `B` stops, and the orchestrator re-authorizes from `P` with a new task-scoped chain. The audit trail at `R` remains contiguous, and the failure is deterministic — it no longer depends on cache survival. The cost is that cold-start restarts force re-authorization rather than transparent refresh; this is the correct trade, because a transparent refresh that severs the chain is not transparent at all — it is a silent re-rooting that the terminal resource will eventually reject, attributing the fault to whichever agent happens to hold the token at rejection time. The invariant to hold operationally: an agent's `act`-chain prefix for a task is part of its durable state, checkpointed alongside its task state, and any code path that emits a delegated token without that prefix fails closed.

from dataclasses import dataclass, field
from typing import Optional


class DelegationChainError(RuntimeError):
    """Raised when a token exchange would violate the append-only act-chain invariant."""
    pass


@dataclass(frozen=True)
class ActFrame:
    agent_id: str


@dataclass(frozen=True)
class DelegatedToken:
    sub: str                      # root principal
    act: tuple[ActFrame, ...]     # append-only actor chain
    scope: str
    exp: int
    jti: str


@dataclass
class AgentTokenState:
    # Durable state: must survive checkpoint/restart. If absent, refresh is impossible.
    inbound: Optional[DelegatedToken] = None
    issued_frames: dict[str, str] = field(default_factory=dict)  # task_id -> agent_id already appended


def extend_chain(
    state: AgentTokenState,
    self_id: str,
    task_id: str,
    requested_scope: str,
    now: int,
) -> DelegatedToken:
    """Chain-extension exchange. Refuses to mint a re-rooted token."""
    if state.inbound is None:
        # Cold start / eviction: we cannot preserve the chain prefix.
        raise DelegationChainError(
            f"agent {self_id} has no inbound chain for task {task_id}; "
            "refresh impossible, escalate to root principal for re-delegation"
        )

    inbound = state.inbound
    if not inbound.act or inbound.act[-1].agent_id != self_id:
        raise DelegationChainError(
            f"inbound act-chain terminal frame {inbound.act[-1] if inbound.act else None} "
            f"!= caller identity {self_id}; token not issued to this agent"
        )

    if requested_scope != inbound.scope:
        raise DelegationChainError(
            f"scope escalation/change {inbound.scope!r} -> {requested_scope!r} "
            "requires re-delegation from root, not refresh"
        )

    # Idempotent append: reuse existing frame for this task rather than duplicating.
    if task_id in state.issued_frames:
        if state.issued_frames[task_id] != self_id:
            raise DelegationChainError(
                f"task {task_id} already delegated to {state.issued_frames[task_id]}, "
                f"not {self_id}"
            )
        appended = inbound.act
    else:
        appended = inbound.act + (ActFrame(self_id),)
        state.issued_frames[task_id] = self_id

    return DelegatedToken(
        sub=inbound.sub,
        act=appended,
        scope=inbound.scope,
        exp=now + 1800,
        jti=f"{task_id}:{self_id}:{now}",
    )


def reauthorize_from_root(
    root_principal: str,
    self_id: str,
    task_id: str,
    scope: str,
    now: int,
) -> tuple[DelegatedToken, AgentTokenState]:
    """Explicit re-delegation path after chain loss. New chain, new task authorization."""
    new_token = DelegatedToken(
        sub=root_principal,
        act=(ActFrame(self_id),),
        scope=scope,
        exp=now + 1800,
        jti=f"reauth:{task_id}:{self_id}:{now}",
    )
    state = AgentTokenState(inbound=new_token, issued_frames={task_id: self_id})
    return new_token, state