A revocation drill for AI agents, and the caching bug it catches
Most AI agent eval suites test what the agent can do. Very few test whether it stops.
That gap got harder to ignore this month. Wells Fargo's new online terms, in effect from November 24, ask customers to revoke any AI agent they let into their accounts and to be able to show evidence they did. Citi, PNC, and others now tell customers they are responsible for what third-party agents do. Proving that an agent stopped is turning into a contract term.
So here is a small test you can add to an agent stack this week. I call it a revocation drill:
- Give the agent a scoped credential.
- Let it complete one real action.
- Revoke the credential.
- Ask it to do the same thing again.
- Pass only if the second call fails, the denial is logged with the agent's identity, and you can measure the time from revoke to stop.
The full code is about 150 lines of standard-library Python plus a pytest file. Link at the end.
The shape of the system
Three pieces:
- A credential broker that gives each agent its own short-lived, scoped credential and records a revocation receipt.
- A tool gateway: the one checkpoint every tool call passes through.
- An audit log where every decision names the agent and the human it acts for.
The credential carries the delegation, not just a secret:
@dataclass(frozen=True)
class Credential:
token_id: str
agent_id: str
on_behalf_of: str
scopes: frozenset[str]
expires_at: float
The broker's check is boring on purpose. Unknown, revoked, expired, or out of scope means no:
def check(self, cred: Credential, scope: str) -> None:
if cred.token_id not in self._issued:
raise AccessDenied("unknown_token")
if cred.token_id in self._revoked:
raise AccessDenied("revoked")
if self._clock() >= cred.expires_at:
raise AccessDenied("expired")
if scope not in cred.scopes:
raise AccessDenied("out_of_scope")
The gateway checks on every call
This is the important part. The gateway checks the pause flag and the credential on every tool call, and logs the decision either way:
def call(self, cred: Credential, tool: str, **kwargs) -> object:
scope, fn = self._tools[tool]
base = dict(t=self._clock(), agent=cred.agent_id, on_behalf_of=cred.on_behalf_of, token=cred.token_id, tool=tool, scope=scope)
try:
if cred.agent_id in self._paused:
raise AccessDenied("paused")
self._broker.check(cred, scope)
except AccessDenied as exc:
self._log.record(**base, decision="deny", reason=exc.reason)
raise
self._log.record(**base, decision="allow")
return fn(**kwargs)
Note the pause() method on the gateway. That is where alerts should go. An alert that only opens a ticket lets the agent keep running until someone reads it.
The bug the drill catches
Here is a pattern that shows up in real code because it saves a lookup per call. Validate once per session, then trust the session:
class SessionCachingGateway(ToolGateway):
def call(self, cred, tool, **kwargs):
if cred.token_id in self._validated:
scope, fn = self._tools[tool]
# logs "allow" and runs the tool without checking again ...
return fn(**kwargs)
result = super().call(cred, tool, **kwargs)
self._validated.add(cred.token_id)
return result
It looks fine in a demo. Revoke the credential, and the agent keeps working until the session ends.
The drill
def revocation_drill(gateway, broker, log, tool, scope, clock=time.monotonic, **kw):
cred = broker.issue("drill-agent", on_behalf_of="drill-owner", scopes={scope})
try:
gateway.call(cred, tool, **kw)
first_ok = True
except AccessDenied:
first_ok = False
receipt = broker.revoke(cred.token_id, revoked_by="drill-owner", reason="drill")
deny_reason = None
try:
gateway.call(cred, tool, **kw)
retry_denied = False
except AccessDenied as exc:
retry_denied = True
deny_reason = exc.reason
stop_event = next((e for e in log.events if e.get("token") == cred.token_id and e.get("decision") == "deny"), None)
revoke_to_stop = (stop_event["t"] - receipt.revoked_at) if stop_event else None
passed = (first_ok and retry_denied and deny_reason == "revoked" and stop_event is not None)
return DrillResult(passed, first_ok, retry_denied, deny_reason, revoke_to_stop)
And the two tests that matter most:
def test_drill_passes_on_per_call_gateway():
clock, broker, log, gw = make()
result = revocation_drill(gw, broker, log, "read_claim", "claims:read", clock=clock, claim_id="C-1")
assert result.passed
assert result.deny_reason == "revoked"
assert result.revoke_to_stop_seconds == 0.0
def test_drill_catches_session_caching_gateway():
clock, broker, log, gw = make(SessionCachingGateway)
result = revocation_drill(gw, broker, log, "read_claim", "claims:read", clock=clock, claim_id="C-1")
assert not result.passed
assert not result.retry_denied # the revoked agent kept working
The repo has four more tests: scope enforcement, expiry, alert-to-pause with a named human resume, and a check that every log line names both the agent and the principal. All six pass on Python 3.13 with pytest. The clock is injected, so the tests are deterministic.
What to measure
Two numbers per release:
- Revoke-to-stop time: from the revocation receipt to the first denied call. In this in-process example it is zero. In a real system with token caches, queues, and retries, it will not be. Measure your baseline and make it go down.
- Alert-to-pause time: from a policy alert to the first paused call. If the honest answer is "when someone reads the ticket," that is your number.
Where revocation leaks in real stacks
The in-process example stops instantly. Real stacks have four common places where a revoked agent keeps going:
- Token caches. Many clients hold an access token until it expires. If your tool server trusts the token without checking with the issuer, a revoke does nothing until expiry. Use short expiries, and check a revocation list or token introspection at the tool boundary.
- Long-running tasks. A job that started before the revoke may hold an open session. Check at every tool call, not at task start.
- Queues and retries. An action queued before the revoke can run after it. Attach the credential to the action and check it when the action runs, not when it was queued.
- Sub-agents. If one agent hands work to another, derive the child's credential from the parent's, so revoking the parent revokes the child.
Each of these is a variant of the same bug as SessionCachingGateway: a decision made once and trusted later.
What this is not
This is a teaching reference, not an auth system. In production, use your identity provider's short-lived tokens, check them at the tool boundary on every call, and ship the audit log somewhere the agent cannot write to.
The point of the drill is the test, not the broker. Run the drill three ways before you trust it: a fresh call after revoke, a call from inside a long-running task that started before the revoke, and a call from your framework's retry logic. Cached sessions tend to hide in the last two.
Code (two files, standard-library Python, 6 tests): https://anilsprasad.com/writing/ai-agent-liability/code/revocation.py and https://anilsprasad.com/writing/ai-agent-liability/code/test_revocation.py
I write about production AI in regulated industries at anilsprasad.com. The longer essay on why AI agent liability is landing on whoever grants the access is here: https://anilsprasad.com/writing/ai-agent-liability/
Parts of this article were drafted with AI assistance. I reviewed and edited the text, and the code was run and tested before publishing.
Comments
No comments yet. Start the discussion.