# Which invariants prevent federated agent identity from desynchronizing from MCP session-bound authorization tokens across reconnects **Date of Record:** 2026 November 28 **Scope:** Applies to MCP clients that bind a federated agent identity (OIDC/OAuth subject) to a long-lived transport session and mint per-request authorization tokens scoped to that session. Does not cover stateless HTTP-per-request MCP transports where no session identity is retained between calls, nor does it cover pure capability negotiation without an authorization layer. ## Core Distinction The failure mode is not "token expiry" and not "identity spoofing." It is **identity–session drift**: the federated subject that owns an MCP session (`Mcp-Session-Id`) and the subject embedded in the per-request authorization token (`sub` / `act.sub` in the delegated chain) diverge because the two are refreshed on *different clocks* and validated against *different caches*. A federated agent presents a long-lived workload identity (e.g., a SPIFFE ID or an OIDC `sub` with a delegation chain) at session establishment. The MCP server records `session_id → principal` at `initialize`. Per-request tokens are then minted downstream, often by a token-exchange step (RFC 8693), carrying a *short-lived* `sub` plus an `act` (actor) claim. The invariant that must hold is: > For every request `r` on session `s`, `principal(s) == sub(token(r))` **and** `act_chain(token(r))` is rooted in the same federation trust anchor that authorized `principal(s)` at `initialize`. The non-obvious break: these two facts are checked by *different subsystems* — session state lives in the transport layer, token validation lives in the auth middleware — and neither holds a lock on the other. Drift is invisible to both. ## What Was Observed A delegated agent (`sub=agent:planner`, `act.sub=agent:executor`) established an MCP session against a tool server. At `initialize`, the server resolved the delegation chain and cached `session_id → {root: agent:planner, actor: agent:executor, anchor: federation-A}`. Mid-task, the upstream token-exchange service rotated the federation anchor: the workload was re-attested under `federation-B` (a re-parented trust domain after a key ceremony), and subsequent per-request tokens carried `anchor=federation-B` with the *same* `sub` and `act` strings. String comparison of `sub`/`act` passed. The session cache still held `anchor=federation-A`. The result was a **silent anchor substitution**: requests were authorized against a stale federation trust root that no longer vouched for the workload, while the auth middleware — validating only `sub`/`act` equality — reported success. The drift surfaced only when an auditor replayed the session transcript and found that the `anchor` recorded at `initialize` never appeared in any subsequent request token, and no request token's anchor appeared in the session record. The two halves of the identity were never simultaneously true. A second observed variant: on transport reconnect (WebSocket drop → resume with the same `Mcp-Session-Id`), the client re-`initialize`d with a *fresh* federated token whose `act.sub` had advanced (executor → executor-v2 after a redeploy). The server's resume path matched only `session_id` and skipped re-resolution of the delegation chain, so the session retained `actor=executor` while every request token said `executor-v2`. Downstream, a tool gated on `act.sub == executor` denied, while a tool gated on `sub == planner` allowed — producing a split-brain permission state within a single logical session. ## Condition of Validity The equality invariant is only sound when the following hold jointly. Each is a precondition, not a guarantee: 1. **Anchor is part of the binding key.** The session record must key on `(sub, act_chain_hash, federation_anchor)`, not `(sub, act)` alone. Anchor rotation is a *binding change*, not a token refresh. 2. **Reconnect forces re-resolution.** Any resume on an existing `Mcp-Session-Id` must re-run delegation-chain resolution against the presented token and compare to the cached tuple; mismatch must terminate the session, not patch it. 3. **Single validation path.** Session identity and request-token identity must be compared by one function that sees both, not by two middlewares each seeing one. 4. **Monotonic actor version.** If `act.sub` can advance within a session (redeploy), the binding must record a version and treat any non-monotonic or skipped version as drift. When any of these is absent — notably when anchor is excluded from the key (very common, because anchors are "infrastructure, not identity") — the invariant silently degrades to string equality and the drift is undetectable until replay. ## Decision Boundary The operational choice is between **fail-closed re-binding** and **fail-open continuation** at the moment drift is detected: - If `anchor(token) != anchor(session)` **or** `act_chain_hash(token) != act_chain_hash(session)`: terminate the session (`404`/`410` on the session, force re-`initialize`). Continuation is not permitted even if `sub` matches, because the trust root that authorized the session is no longer the trust root vouching for the request. - If only `sub` matches but the anchor rotated *and* the new anchor is a verified descendant of the old (explicit re-parenting attestation): allow a **single** re-bind event, logged, with the session record updated atomically. Any second rotation within the session lifetime is treated as drift. - If `act.sub` advanced without a version increment: reject; this is the reconnect-skip signature. The boundary is: **anchor change alone is sufficient to break the binding; sub equality alone is never sufficient to preserve it.** ## Operational Effect Enforcing the full binding key converts a class of silent authorization drift into an explicit, auditable session termination. The cost is more frequent re-`initialize` churn during federation key ceremonies and agent redeploys — sessions do not survive anchor rotation, by design. The benefit is that the session transcript becomes replayable: every request token's anchor and actor are provably consistent with the anchor and actor recorded at `initialize`, so an auditor can verify the invariant offline without trusting either middleware's logs. Systems that omit anchor from the binding key appear to have higher session continuity and lower error rates, but their continuity is purchased by authorizing requests against trust roots that never vouched for them — a defect that is invisible in metrics and only visible under replay. ```python from dataclasses import dataclass from typing import Optional class IdentitySessionDrift(RuntimeError): """Raised when a request token's federated binding diverges from the session binding.""" pass @dataclass(frozen=True) class Binding: sub: str act_chain_hash: str federation_anchor: str actor_version: int @dataclass class SessionRecord: session_id: str binding: Binding rebind_count: int = 0 def resolve_binding(token: dict) -> Binding: return Binding( sub=token["sub"], act_chain_hash=token["act_chain_hash"], federation_anchor=token["federation_anchor"], actor_version=token["act_version"], ) def authorize_request(session: SessionRecord, token: dict, anchor_is_verified_descendant: bool) -> SessionRecord: incoming = resolve_binding(token) cached = session.binding if incoming.sub != cached.sub: raise IdentitySessionDrift( f"subject mismatch on session {session.session_id}: {cached.sub} != {incoming.sub}" ) if incoming.act_chain_hash != cached.act_chain_hash: raise IdentitySessionDrift( f"actor chain hash mismatch on session {session.session_id}: " f"{cached.act_chain_hash} != {incoming.act_chain_hash} (reconnect re-resolution skipped?)" ) if incoming.actor_version < cached.actor_version: raise IdentitySessionDrift( f"non-monotonic actor version on session {session.session_id}: " f"{cached.actor_version} -> {incoming.actor_version}" ) if incoming.federation_anchor != cached.federation_anchor: if not anchor_is_verified_descendant: raise IdentitySessionDrift( f"federation anchor rotated without attestation on session {session.session_id}: " f"{cached.federation_anchor} -> {incoming.federation_anchor}" ) if session.rebind_count >= 1: raise IdentitySessionDrift( f"second anchor rotation within session {session.session_id}; treating as drift" ) session.binding = incoming session.rebind_count += 1 return session if incoming.actor_version > cached.actor_version: session.binding = incoming return session ```