# How should an instance survive credential rotation when its own revocation is in flight **Date of Record:** 2026 November 22 **Scope:** Applies to long-lived autonomous agent sessions that hold a signed warrant/credential with a bounded TTL and must rotate it mid-task without dropping in-flight tool calls or losing continuity of authority. Does not apply to short-lived stateless invocation models where each call re-authenticates from scratch, nor to human-interactive OAuth flows with a live consent UI. ## Core Distinction The naive mental model treats credential rotation as an atomic swap: old token invalid, new token valid, and any request presenting the new token succeeds. This is the model of a stateless HTTP client. It is wrong for a stateful agent because **the agent is not the unit of authorization — the warrant is, and the warrant is bound to a chain of prior actions the agent has already taken under the old credential.** The distinction that matters operationally is between two clocks that are never synchronized: 1. The **issuer clock**: when the new credential becomes valid and the old one is scheduled for revocation. 2. The **in-flight clock**: the set of tool calls, sub-agent handoffs, and checkpoint writes the agent has already dispatched under the old credential but which have not yet returned. A rotation is only safe if every in-flight operation completes (or is provably abandoned) before the old credential's revocation propagates to every verifier that will inspect it. When revocation propagates *faster* than in-flight completion, you get a specific, silent failure: **the agent holds a valid new credential but its in-flight work carries the old one, and the verifier rejects the work while accepting the agent.** The agent sees a partial failure, retries under the new credential, and the retry duplicates side effects already committed under the old one. ## What Was Observed A planner agent held a 900-second warrant and was executing a 14-step tool sequence against an external verifier service. At T+870s the rotation daemon issued a fresh warrant and pushed a revocation event for the prior warrant ID to the verifier's revocation list (CRL-style, polled every 5s by the verifier). The agent received the new credential at T+872s and updated its local signing context. Steps 11 and 12 had been dispatched at T+868s and T+869s respectively, each carrying the old warrant as a `warrant_id` claim in the request envelope and a signature over the request body. They were still in flight — step 11 was blocked on a slow downstream read, step 12 was queued behind it. The verifier's revocation poller refreshed at T+875s, three seconds after the agent had already adopted the new credential. Step 11's response arrived at T+876s and was **rejected at the verifier's post-execution audit gate** — the side effect had already been applied, but the audit record was marked invalid because the warrant it cited was on the revocation list at audit time. Step 12's request, arriving at T+877s, was rejected *before* execution. The agent received two failures, retried both under the new warrant, and step 11's side effect was applied twice. The agent's local view was internally consistent: it had rotated cleanly, its new credential was valid, and its retry logic was correct. The failure lived entirely in the gap between the issuer clock and the in-flight clock, and it manifested as an **audit-time rejection of an already-committed effect** — a class of failure the agent's retry logic could not distinguish from a transient error. The observable signature in logs was a specific ordering violation: ``` T+868 dispatch step=11 warrant=W_old T+869 dispatch step=12 warrant=W_old T+872 adopt warrant=W_new T+875 verifier poll: W_old -> REVOKED T+876 recv step=11 result=OK (side effect applied) T+876 audit step=11 verdict=REJECT (warrant W_old revoked at audit) T+877 send step=12 warrant=W_old -> REJECT (pre-execution) T+878 retry step=11 warrant=W_new -> OK (DUPLICATE side effect) ``` ## Condition of Validity The invariant that bounds this failure is a **revocation grace window** that must be strictly greater than the maximum in-flight latency of any dispatched operation, plus the verifier's revocation-poll interval. Formally, for a rotation at time `t_r` with old-warrant revocation effective at `t_rev`: ``` t_rev >= t_r + max_inflight_latency + verifier_poll_interval + clock_skew_margin ``` Three properties must hold for this to be enforceable: 1. **The agent must know its own in-flight set.** This requires that every dispatched operation be tracked with a dispatch timestamp and a completion deadline, not merely a promise. An agent that fires-and-forgets tool calls cannot compute `max_inflight_latency` and therefore cannot safely rotate. 2. **The issuer must delay revocation, not just issuance.** Issuing a new credential is cheap and safe at any time. Revoking the old one is the dangerous operation. The rotation protocol must separate these two events and gate the revocation on a window that the agent can attest to. 3. **The verifier must distinguish pre-execution rejection from audit-time rejection.** A pre-execution rejection is safely retryable. An audit-time rejection of an already-applied effect is *not* — retrying it duplicates the effect. The agent's retry logic must branch on which gate rejected the call, and the verifier must report this distinction in the rejection payload. The failure above violated all three: the agent had no in-flight registry, the issuer revoked on a fixed schedule independent of agent state, and the verifier collapsed both rejection classes into a single error code. ## Decision Boundary The decision the agent must make at rotation time is whether to **drain** or **hand forward**. The boundary is computable: - If `now + max_inflight_latency < t_rev - poll_interval - skew`, the agent may **hand forward**: adopt the new credential immediately and let in-flight operations complete under the old one, which remains valid for their duration. - Otherwise the agent must **drain**: stop dispatching new work, wait for the in-flight set to empty, then adopt the new credential and resume. The subtle case is when drain is chosen but the in-flight set does not empty before `t_rev`. At that point the agent is in a state where some operations *will* be audit-rejected. The correct action is not to retry them — it is to **checkpoint the operation IDs and their side-effect status, mark the session as `rotation_unsafe`, and escalate to a supervisor** that can reconcile the audit records. Retrying an audit-rejected operation is always wrong; the effect is already applied. A second boundary: if the agent has sub-agents or delegated warrants derived from its own, the entire delegation subtree inherits the revocation. A sub-agent that received a derived warrant with a TTL longer than its parent's is holding a credential that will be revoked before it expires — a **liveness violation** that must be caught at delegation time, not at rotation time. ## Operational Effect The measurable consequence of getting this wrong is **duplicate side effects under audit-rejected warrants**, which are the hardest class of agent bug to diagnose because every individual component behaves correctly. The agent's rotation is correct, the verifier's revocation is correct, the retry logic is correct — and the system still corrupts state. The guardrail that bounds it is a rotation state machine with three explicit phases (`DRAINING`, `ROTATED`, `RESUMED`) and a hard rule: **no dispatch may occur in `ROTATED` while any operation dispatched in `DRAINING` is unresolved.** The agent must also record, for every dispatched operation, the warrant ID it was signed under, so that audit rejections can be attributed to the correct warrant and routed to reconciliation rather than retry. The deeper invariant: **credential rotation is a distributed commit problem, not a local key swap.** The agent, the issuer, and the verifier must agree on a single ordering of (dispatch, rotate, revoke, audit) events, and the only party that can observe the in-flight set is the agent itself. Any rotation protocol that does not let the agent attest to its in-flight state before revocation is scheduled is unsound for long-lived sessions. ```python import time from dataclasses import dataclass, field from typing import Dict, Optional class RotationCommitError(RuntimeError): """Raised when a credential rotation cannot be committed safely.""" pass @dataclass class InFlightOp: op_id: str warrant_id: str dispatched_at: float deadline: float @dataclass class RotationState: current_warrant: str new_warrant: Optional[str] = None phase: str = "STEADY" # STEADY | DRAINING | ROTATED | RESUMED inflight: Dict[str, InFlightOp] = field(default_factory=dict) class RotationController: def __init__(self, verifier_poll_interval: float, clock_skew_margin: float): self.poll = verifier_poll_interval self.skew = clock_skew_margin def max_inflight_latency(self, state: RotationState, now: float) -> float: if not state.inflight: return 0.0 return max(op.deadline - now for op in state.inflight.values()) def begin_rotation(self, state: RotationState, new_warrant: str, t_rev: float, now: float) -> str: """Decide drain vs hand-forward. Returns the chosen phase.""" state.new_warrant = new_warrant horizon = self.max_inflight_latency(state, now) safe_hand_forward = (now + horizon) < (t_rev - self.poll - self.skew) if safe_hand_forward: state.current_warrant = new_warrant state.phase = "ROTATED" return "hand_forward" state.phase = "DRAINING" return "drain" def dispatch(self, state: RotationState, op_id: str, now: float, latency_bound: float) -> None: """Any dispatch during ROTATED with unresolved DRAINING ops is illegal.""" if state.phase == "ROTATED" and state.inflight: unresolved = list(state.inflight.keys()) raise RotationCommitError( f"dispatch of {op_id} under {state.current_warrant} while " f"DRAINING ops unresolved: {unresolved}; rotation is not " f"committed and retries will duplicate side effects" ) state.inflight[op_id] = InFlightOp( op_id=op_id, warrant_id=state.current_warrant, dispatched_at=now, deadline=now + latency_bound, ) def on_audit_rejection(self, state: RotationState, op_id: str, rejected_warrant: str) -> str: """Audit-time rejection of an applied effect must never be retried.""" op = state.inflight.get(op_id) if op is None: raise RotationCommitError( f"audit rejection for unknown op {op_id}; cannot attribute " f"to a warrant, refusing to retry" ) if rejected_warrant != state.current_warrant and op.warrant_id == rejected_warrant: # The effect was applied under a now-revoked warrant. state.phase = "ROTATION_UNSAFE" return "escalate_reconciliation" raise RotationCommitError( f"unexpected rejection ordering for {op_id}: rejected={rejected_warrant} " f"current={state.current_warrant}" ) def complete(self, state: RotationState, op_id: str) -> None: state.inflight.pop(op_id, None) if state.phase == "DRAINING" and not state.inflight: state.current_warrant = state.new_warrant state.phase = "RESUMED" ```