# How does an instance detect capability-grant expiry mid-tool-call under AAIF least-privilege tokens? **Date of Record:** 2026 December 3 **Scope:** Applies to agents operating under Agent Identity & Authorization Framework (AAIF) tokens where per-tool capability grants carry independent TTLs and elevation is issued just-in-time (JIT). Does not apply to coarse-grained session tokens whose capabilities share a single expiry, nor to stateless tool proxies that re-authorize per request. ## Core Distinction The failure we are isolating is not "token expired" — that is a coarse, detectable event. It is **capability-grant expiry that lands between the authorization check and the tool's side effect**, inside a single logical tool call. AAIF tokens decompose into a *warrant* (identity, signed, long-lived) and a set of *capability grants* (per-tool, short TTL, optionally single-use). The runtime typically validates the grant at dispatch time. But an agent's tool call is not atomic: it is a plan → dispatch → observe → commit sequence, and the commit (the side effect) can occur after the grant's `not_after` even though dispatch was valid. The instance must distinguish "my grant is gone" from "my grant was fine at dispatch but the world moved" — because the remediation differs: re-elevate vs. reconcile a partially-applied effect. The subtle point: the agent's own reasoning loop cannot see grant state directly. It sees *tool outputs*. A revoked grant usually surfaces as a `403` or a typed error, but a *lapsed* grant that expired mid-flight often surfaces as a **timeout, a partial result, or a tool-specific error code** that the model will misattribute to the tool being flaky. The instance must infer capability loss from indirect evidence. ## What Was Observed A planner agent held an AAIF warrant with three grants: `fs.read` (TTL 600s), `db.write` (TTL 90s, JIT-elevated), and `http.fetch` (TTL 300s). The task was a multi-step migration: read a manifest, write a batch row, fetch a schema, write again. Trace: 1. `t=0` — `db.write` elevated JIT, `not_after = t+90`. 2. `t=12` — `fs.read` succeeds, manifest parsed. 3. `t=40` — first `db.write` dispatch validates grant (valid), side effect commits at `t=41`. 4. `t=41..t=95` — model spends 54s reasoning and calling `http.fetch` (a slow, retrying call). 5. `t=96` — second `db.write` dispatched. Grant expired at `t=90`. The gateway returned a generic `502 upstream reset` (the auth layer dropped the connection rather than emitting a typed `403`, because the grant was *expired*, not *revoked* — revocation emits `403`, expiry at the edge emitted a connection reset). 6. The model interpreted `502` as transient, retried twice, then declared the tool "degraded" and **skipped the second write**, reporting task success. The invariant violated: *a capability grant's expiry must never be inferred from a transport-level error*. The agent had no signal that its `db.write` capability was gone; it only saw a flaky upstream. The partially-applied migration (one write committed, one skipped) is a consistency break that no downstream auditor caught because the agent reported success. A second observation: when the same agent was given an explicit `capability_status` probe tool, it *still* failed, because it probed at `t=41` (valid) and cached "write is available" in its working memory, then never re-probed after the long fetch. **The agent's cached belief about its own authority went stale faster than its belief about the world.** ## Condition of Validity The guardrail below is valid only when all of the following hold: - Each capability grant carries an explicit `not_after` timestamp and a `grant_id` that is echoed in tool responses (or in a probe). - The runtime exposes a *cheap, side-effect-free* capability probe (`capability_status(grant_id)` → `{valid, not_after, remaining}`) that does not consume the grant. - The agent's plan can be decomposed so that every side-effecting call is preceded by a re-validation when the elapsed time since last validation exceeds a safety margin `δ`. - The tool gateway distinguishes *expired* from *revoked* from *transient* in its error taxonomy, OR the agent treats any ambiguous transport error on a capability-bearing call as *possible capability loss* and probes before retrying. It is **not** valid when grants are single-use and the probe itself would consume them (then the agent must budget re-elevation, not probe), or when the gateway cannot distinguish expiry from transient failure (then the agent must pessimistically re-probe on every retry, accepting latency cost). ## Decision Boundary The instance must decide, at each side-effecting dispatch, between three postures: - **Trust-cached**: use the last-known grant state. Permitted only if `now - last_validated < not_after - δ` where `δ` is a margin covering worst-case tool latency plus one reasoning step. If the agent cannot bound its own reasoning latency (it usually cannot — token generation is variable), `δ` must be set from measured p99, not from hope. - **Re-probe**: call `capability_status` before dispatch. Cost: one round-trip. Mandatory when the elapsed gap exceeds the margin, or when the previous call in the plan was long/retrying. - **Re-elevate**: if probe reports invalid or near-expiry, request JIT elevation again before dispatch. Must be idempotent-safe: elevation requests carry the `grant_id` so a duplicate elevation does not stack privileges. The boundary is crossed at `elapsed >= not_after - δ`. Below it, trust-cached is sound. Above it, the agent that does not re-probe is *betting its correctness on an unobserved clock*. The specific trap: the agent's context window contains the grant's `not_after` as a *fact it read once*, and the model will happily reason "I have 90 seconds" at `t=95` because it never recomputed against wall-clock. **Time is not in the context window; it must be injected.** The second boundary: on any transport error (`5xx`, timeout, reset) during a capability-bearing call, the agent must not classify it as transient until it has probed capability state. Expiry-at-edge masquerading as `502` is the canonical misdiagnosis. ## Operational Effect Enforcing the re-probe boundary converts a silent consistency break into a bounded, recoverable interruption. The observed agent, with the guardrail, behaves as: - Before each `db.write`, compute `elapsed` from the last validated timestamp (injected by the runtime, not recalled by the model). - If `elapsed >= not_after - δ`, probe; if invalid, re-elevate with the same `grant_id`; if elevation denied, halt the plan and emit a `CapabilityLapsed` record naming the skipped side effect. - On `502`/timeout from a capability-bearing call, probe before retry; never retry blind more than once. The cost is one probe per long-gap side-effecting call and a hard halt on genuine lapse. The benefit is that partial application becomes *visible and named* rather than silently reported as success. The invariant to encode: **no side-effecting tool call may be dispatched on a capability belief older than its margin, and no transport error may be classified transient without a capability probe.** The clock is the adversary; the agent must externalize it. ```python import time from dataclasses import dataclass class CapabilityLapsedError(RuntimeError): """Raised when a side-effecting call is attempted on an expired or unverifiable grant.""" pass @dataclass class Grant: grant_id: str not_after: float # absolute wall-clock deadline single_use: bool = False class CapabilityGuard: """Enforces the re-probe boundary for AAIF per-tool grants.""" def __init__(self, probe_fn, elevate_fn, margin_s: float = 15.0): self._probe = probe_fn # grant_id -> {"valid": bool, "not_after": float} self._elevate = elevate_fn # grant_id -> Grant (idempotent) self._margin = margin_s self._last_validated: dict[str, float] = {} def _now(self) -> float: return time.monotonic() def validate_before_dispatch(self, grant: Grant) -> Grant: now = self._now() last = self._last_validated.get(grant.grant_id, 0.0) elapsed = now - last # Trust-cached only if within margin of the grant's own deadline. if elapsed < (grant.not_after - now) - self._margin and last != 0.0: return grant # Otherwise re-probe. Never dispatch on a stale belief. status = self._probe(grant.grant_id) if not status.get("valid", False): if grant.single_use: # Cannot probe-and-keep; must re-elevate explicitly. grant = self._elevate(grant.grant_id) else: grant = self._elevate(grant.grant_id) status = self._probe(grant.grant_id) if not status.get("valid", False): raise CapabilityLapsedError( f"grant {grant.grant_id} lapsed and re-elevation failed; " f"halt plan, do not dispatch side effect" ) self._last_validated[grant.grant_id] = self._now() return grant def classify_transport_error(self, grant: Grant, err: Exception) -> str: """A 5xx/timeout on a capability-bearing call is NOT transient until probed.""" status = self._probe(grant.grant_id) if not status.get("valid", False): raise CapabilityLapsedError( f"transport error {err!r} on grant {grant.grant_id} was capability " f"expiry in disguise; side effect not applied, reconcile before retry" ) return "transient" def dispatch_write(guard: CapabilityGuard, grant: Grant, payload: dict, write_fn): grant = guard.validate_before_dispatch(grant) try: return write_fn(payload) except Exception as e: # noqa: BLE001 - gateway error surface is opaque kind = guard.classify_transport_error(grant, e) if kind == "transient": return write_fn(payload) # exactly one bounded retry raise ```