# How should an instance handle mid-handshake identity expiry when a short-lived workload token rotates between attestation and the first RPC? **Date of Record:** 2026 December 1 **Scope:** Applies to zero-trust agent-to-agent (A2A) handshakes where each agent instance presents a short-lived workload identity (SPIFFE-style SVID, signed JWT, or mTLS cert) whose TTL is comparable to or shorter than the handshake-plus-first-call latency. Does not apply to long-lived static credentials or to purely intra-process delegation where no network attestation occurs. ## Core Distinction The failure is not "token expired." Token expiry is expected and handled by re-issuance. The failure is **identity discontinuity across the attestation boundary**: the peer verifies identity `A_t0` at handshake time, but the first substantive RPC arrives bearing `A_t1`, where `t1 > t0` and the two identities are cryptographically distinct even though they represent the same agent instance. A naive verifier treats this as a *different principal* and rejects; a naive issuer treats it as the *same principal* and silently accepts. Neither is correct, because the handshake established a *session binding* to a specific key, and rotation severs that binding unless the rotation is itself attested. The invariant that must hold: **a session is bound to the identity that performed the handshake, and any post-handshake rotation must carry a signed continuity proof from the pre-rotation key.** Without that proof, the new token is an unauthenticated claim of succession. ## What Was Observed A two-agent pipeline: an orchestrator (`orch-7`) hands a subtask to a worker (`wrk-3`) over mutual TLS with 90-second SVIDs. Mean handshake latency was 40 ms; mean time-to-first-RPC (after the worker loaded a model shard, ~55 s cold) was 58 s. Under normal load the SVID survived. Under a model-shard reload that pushed first-RPC latency past the 90 s TTL, the following trace appeared: 1. `t=0.00s` — `orch-7` presents SVID `O@t0` (exp `t=90s`). `wrk-3` presents `W@t0` (exp `t=90s`). mTLS completes; both sides pin the peer's leaf public key into the session record. 2. `t=0.04s` — Handshake finishes. `wrk-3` records session `S` bound to `O@t0.pubkey`. `orch-7` records `S` bound to `W@t0.pubkey`. 3. `t=0.03s→58s` — `wrk-3` blocks on shard load. No application traffic. Both SVIDs cross their 80%-of-TTL renewal threshold and the local workload API rotates them. 4. `t=58.1s` — `wrk-3` sends its first RPC over session `S`, but its TLS library has rotated the leaf to `W@t1`. The record layer on the *existing* connection still uses the old key (rotation only affects new handshakes), so `orch-7` sees no anomaly here. 5. `t=58.2s` — `wrk-3` opens a *second* connection for a callback channel and presents `W@t1`. `orch-7`'s verifier checks `W@t1.pubkey` against the session's pinned `W@t0.pubkey`: **mismatch**. Verifier raises `IdentityDiscontinuity`. 6. `t=58.3s` — `orch-7`'s retry logic, seeing a transient-looking auth error, retries on a fresh handshake. The fresh handshake now uses `O@t1`/`W@t1`, succeeds, but the *original session `S`* — holding 58 s of accumulated task state, partial tool results, and a baton token — is abandoned. The retry re-executes the subtask from scratch. The observable damage: **a duplicate side-effecting tool call** (the worker's first RPC had already mutated external state before the callback failed), plus **58 s of wasted compute**, plus a **split-brain task record** where the orchestrator's ledger shows two attempts and the worker's shows one. The non-obvious part: the failure did not occur at handshake. It occurred at the *first post-rotation connection*, and it was triggered by the worker's own renewal daemon — a component the orchestrator had no visibility into and no way to distinguish from a genuine impersonation attempt. ## Condition of Validity This analysis holds when all of the following are true: - Workload identity TTL is within one order of magnitude of end-to-end handshake-plus-first-call latency. If TTL ≫ latency, rotation never lands mid-session and the boundary is never exercised. If TTL ≪ latency, the system cannot function at all and fails loudly at handshake. - The transport pins peer keys at session establishment (standard mTLS session resumption, or an explicit session record). Systems that re-verify the *current* peer cert on every message do not exhibit this exact trace — they exhibit a worse one: they accept `W@t1` without any continuity proof, which is an undetected impersonation window. - Rotation is performed by a local daemon independent of the application, so the application cannot coordinate "rotate only between sessions." - The protocol has a callback or second-channel phase, so a *new* connection is opened after state has accumulated. Single-connection, single-RPC interactions mask the bug. Where the system uses long-lived credentials, or where rotation is coordinated with session teardown, or where the peer identity is re-attested per-message via a signed continuity chain, the failure does not manifest. ## Decision Boundary The verifier faces a three-way choice at step 5, and only one branch is safe: - **Reject on key mismatch (naive):** correct against impersonation, catastrophic against legitimate rotation. Creates the duplicate-execution failure above. - **Accept any valid SVID for the same SPIFFE ID / subject (naive):** correct against rotation, but converts the session into an unauthenticated channel — any holder of a valid `W@t*` token can inject into session `S`. This is the impersonation window. - **Accept only with continuity proof (correct):** the new identity must present a signature over `(old_pubkey, new_pubkey, session_id, rotation_timestamp)` made by the *old* private key, chained to the original handshake. The verifier then advances the session's pinned key without tearing down state. The decision boundary is therefore: **rotation is admissible iff the pre-rotation key signs the succession.** The old key is the only entity that can prove "I, who you already trust, am now this new key." Absent that signature, a valid new token is just a stranger with good credentials. A secondary boundary governs retry policy: an `IdentityDiscontinuity` must **not** be classified as retryable-transient. It must be classified as `requires_rehandshake_with_state_transfer`, because the safe recovery is not "start over" but "resume session `S` under the new identity, carrying the baton token and ledger." ## Operational Effect Concrete consequences for an agent runtime implementing this: 1. **SVID TTL must be floored at `p99(handshake + first_RPC) × safety_factor`**, and the safety factor must account for cold-start variance (model load, shard fetch), not steady-state latency. A 90 s TTL for a 58 s cold path has a safety factor of 1.55 — insufficient once tail latency is considered. 2. **Session records must store a key history, not a single pinned key**, with each entry carrying the continuity signature. Verification walks the chain; a gap breaks the session. 3. **Rotation daemons must emit continuity proofs as a first-class artifact**, not just a new cert. The workload API's rotation event must be observable to the application so it can attach the proof to the next connection. 4. **Retry classifiers must distinguish `IdentityDiscontinuity` from `AuthFailure`.** The former is resumable-with-proof; the latter is terminal. Conflating them produces either duplicate side effects (retry) or lost work (abort). 5. **The baton token must be bound to the session, not the identity**, so that a proven rotation does not invalidate in-flight coordination state. The guardrail that bounds the whole class: **no session may change its pinned identity without a signature from the previous identity.** Everything else — TTL sizing, retry policy, callback channel design — is downstream of that single invariant. ```python import hashlib import hmac from dataclasses import dataclass, field from typing import Optional class IdentityDiscontinuity(RuntimeError): """Raised when a session's peer identity changes without a valid continuity proof.""" pass class ContinuityProofInvalid(IdentityDiscontinuity): """Raised when a rotation is claimed but the pre-rotation key did not sign it.""" pass @dataclass class SessionRecord: session_id: str # Ordered list of (pubkey_fingerprint, continuity_sig_from_prev_or_None) key_chain: list = field(default_factory=list) baton_token: Optional[str] = None @property def current_key(self) -> str: return self.key_chain[-1][0] def _fingerprint(pubkey: bytes) -> str: return hashlib.sha256(pubkey).hexdigest() def _verify_continuity( old_privkey_signer, old_pubkey: bytes, new_pubkey: bytes, session_id: str, rotation_ts: int, signature: bytes, ) -> bool: """The pre-rotation key must sign the succession tuple.""" msg = b"|".join([ old_pubkey, new_pubkey, session_id.encode(), str(rotation_ts).encode(), ]) expected = old_privkey_signer(msg) return hmac.compare_digest(expected, signature) def admit_connection( session: SessionRecord, presented_pubkey: bytes, continuity_sig: Optional[bytes], rotation_ts: Optional[int], ) -> None: """ Called on every new connection bound to an existing session. Mutates session.key_chain on proven rotation; raises otherwise. """ presented_fp = _fingerprint(presented_pubkey) if presented_fp == session.current_key: return # no rotation, fast path # Key changed. This is the decision boundary. if continuity_sig is None or rotation_ts is None: raise IdentityDiscontinuity( f"session {session.session_id}: peer key rotated to {presented_fp[:12]} " f"without continuity proof; refusing to advance pinned identity" ) old_fp = session.current_key # The verifier must reconstruct the old pubkey from its chain to check the sig. old_pubkey = session.key_chain[-1][2] # stored alongside fp in real impl if not _verify_continuity( old_privkey_signer=_signer_for(old_fp), old_pubkey=old_pubkey, new_pubkey=presented_pubkey, session_id=session.session_id, rotation_ts=rotation_ts, signature=continuity_sig, ): raise ContinuityProofInvalid( f"session {session.session_id}: rotation {old_fp[:12]} -> {presented_fp[:12]} " f"carries invalid continuity signature; treating as impersonation" ) session.key_chain.append((presented_fp, continuity_sig, presented_pubkey)) # baton_token survives rotation because it is session-bound, not identity-bound def _signer_for(fingerprint: str): # Placeholder: in production this resolves to the verifier's held copy of # the peer's pre-rotation public key and performs signature verification. raise NotImplementedError("wire to key store") ```