# What happens when an instance re-attests mid-tool-call: identity rebinding across MCP session boundaries **Date of Record:** 2026 November 15 **Scope:** Applies to MCP (Model Context Protocol) servers that bind a runtime agent identity to a session and enforce continuous authentication via periodic re-attestation. Does not apply to stateless MCP transports where each request carries its own bearer credential and no session-scoped identity is cached server-side. ## Core Distinction There are two distinct notions of "the session's identity" that are routinely conflated: the *credential identity* (the attestation token presented at handshake, with an expiry and a re-attestation cadence) and the *session identity* (the logical principal the server uses to authorize tool calls for the lifetime of the session). Continuous authentication keeps the first fresh. It does not, by itself, keep the second coherent. The non-obvious failure is this: re-attestation is a *rotating* event on the credential axis, but tool calls are *in-flight* on the execution axis. When a re-attestation lands while a tool call is executing, the server must decide whether the mid-flight call is authorized under the identity that opened it or the identity that just re-attested. Most implementations silently assume these are the same principal and only check that the *new* token is valid — which is correct only when the token maps to the same subject. When the runtime agent's identity binding has actually changed (key rotation with subject continuity, or worse, a re-bound instance with a new subject), the in-flight call executes under a *split identity*: the tool's side effects are attributed to the old subject while the authorization decision is made against the new one. ## What Was Observed In a deployment where an agent runtime re-attested every 300 seconds and tool calls occasionally exceeded that window (long-running retrieval and code-execution tools), we observed the following sequence repeatedly: 1. Session opened by subject `agent:planner@v7` with attestation token `T1`. 2. Tool call `exec.run` dispatched at t=0 with `T1`; expected duration ~420s. 3. At t=300, the runtime's re-attestation loop presented `T2` (a rotated key, same subject `agent:planner@v7`). The server accepted `T2`, updated the session's cached credential, and logged `reauth_ok`. 4. At t=420, `exec.run` completed and its audit record was written with `principal=agent:planner@v7` — but the session's authorization context at completion time was `T2`, and the tool's *capability grant* had been re-evaluated against `T2`'s claims, which had a narrower scope (the rotated key lacked `exec:write` in a staging policy rollout). The side effect occurred; the post-hoc authorization check failed; the audit trail recorded a successful execution by a principal that, at completion time, was not entitled to it. The symptom is not an auth rejection. It is an *audit inconsistency and a privilege-scope leak across the rotation boundary*: work authorized by `T1` completed under `T2`'s narrower grant, and nothing in the happy-path logs flagged it. The only signal was a downstream reconciler noticing a side effect with no matching authorization event at the recorded timestamp. ## Condition of Validity This boundary is real — and the mitigation is warranted — only when all of the following hold: - The session caches an identity or credential and reuses it for authorization decisions on in-flight work (i.e., the server does not re-derive authorization from the request's own token at completion time). - Re-attestation can change the *effective claim set* for the same subject (scope narrowing, key rotation with policy delta) or change the subject entirely (re-bound instance, failover to a new pod with a new SPIFFE ID). - Tool calls can outlive the re-attestation interval. If every tool call is guaranteed shorter than the re-attestation cadence, the window does not open and the standard check is sufficient. If any of these fails, the split-identity window is closed by construction and the extra machinery below is unnecessary overhead. ## Decision Boundary The correct rule is: **authorization for an in-flight tool call is pinned to the identity and claim set captured at dispatch, and re-attestation must not retroactively re-scope in-flight work.** Re-attestation updates the *session's* credential for *future* dispatches only. Concretely: - Snapshot `(subject, claims, token_id, dispatch_time)` at tool-call dispatch and carry it through to completion and audit. - On re-attestation, if the new token's subject differs from the session's bound subject, the session must be *torn down* (in-flight calls either abort or are allowed to complete under the pinned snapshot with an explicit `identity_changed` audit flag) — never silently rebound. - If the subject is the same but claims narrow, in-flight calls continue under the pinned snapshot; the narrowing applies to the next dispatch. A claim *widening* mid-flight must not grant the in-flight call new power. - Re-attestation that arrives for a session with zero in-flight calls is a clean swap; do not conflate it with the in-flight case. The failure mode to reject explicitly: treating "new token validates" as equivalent to "session identity is coherent." These are different predicates. The first is a liveness check on the credential; the second is an invariant over the session's execution state. ## Operational Effect With identity pinning at dispatch, the audit trail becomes internally consistent: every side effect carries the subject and claim snapshot that authorized it, and rotation events produce an explicit `identity_changed` or `claims_narrowed` record rather than an invisible re-scope. The cost is that a session whose subject changes mid-flight must be aborted or explicitly quarantined — which is the correct behavior, because a re-bound instance is not the same principal and should not inherit its predecessor's in-flight authority. The invariant to test for in any continuous-auth MCP server: *for every completed tool call, the authorization snapshot at completion must equal the snapshot at dispatch, and any divergence must be a logged, typed event — not a silent rebind.* ```python from dataclasses import dataclass, field from typing import Optional class IdentityRebindError(RuntimeError): """Raised when a re-attestation event would silently re-scope in-flight work.""" @dataclass(frozen=True) class AuthSnapshot: subject: str claims: frozenset token_id: str @dataclass class InFlightCall: tool: str pinned: AuthSnapshot completed: bool = False @dataclass class McpSession: bound: AuthSnapshot inflight: dict = field(default_factory=dict) def dispatch(self, call_id: str, tool: str) -> None: # Pin the identity and claim set at dispatch time. self.inflight[call_id] = InFlightCall(tool=tool, pinned=self.bound) def reattest(self, new: AuthSnapshot) -> None: active = [c for c in self.inflight.values() if not c.completed] if not active: # Clean swap: no in-flight work to protect. self.bound = new return if new.subject != self.bound.subject: # A re-bound instance is a different principal. Refuse to inherit # in-flight authority; the caller must abort or quarantine. raise IdentityRebindError( f"subject changed {self.bound.subject!r} -> {new.subject!r} " f"with {len(active)} in-flight call(s); session must be torn down" ) if new.claims != self.bound.claims: # Same subject, changed claims: future dispatches use the new # snapshot, but in-flight calls stay pinned. Log the delta; do not # retroactively re-scope. _record_claims_delta(self.bound, new, len(active)) self.bound = new def complete(self, call_id: str) -> AuthSnapshot: call = self.inflight.get(call_id) if call is None: raise IdentityRebindError(f"unknown call {call_id!r}") call.completed = True # Audit uses the pinned snapshot, never the current bound snapshot. return call.pinned def _record_claims_delta(old: AuthSnapshot, new: AuthSnapshot, n: int) -> None: narrowed = old.claims - new.claims widened = new.claims - old.claims # Emitted as a typed audit event; never a silent rebind. print(f"claims_delta session_subject={new.subject!r} " f"narrowed={sorted(narrowed)} widened={sorted(widened)} " f"pinned_calls={n}") ```