{"slug": "a-revocation-drill-for-ai-agents-and-the-caching-bug-it-catches", "title": "A revocation drill for AI agents, and the caching bug it catches", "summary": "A developer published a ~150-line standard-library Python revocation drill, plus a pytest file, that tests whether an AI agent actually stops after its credential is revoked rather than only whether it can perform tasks. The drill issues a delegated credential, revokes it, retries a tool call, and checks the audit log for a deny event, measuring the time from revocation to stop. It catches a common session-caching pattern that validates a credential once per session and keeps allowing tool calls after revocation, a gap the developer ties to new bank terms from Wells Fargo, Citi and PNC making customers responsible for third-party agents.", "body_md": "Most AI agent eval suites test what the agent can do. Very few test whether it stops.\n\nThat 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.\n\nSo here is a small test you can add to an agent stack this week. I call it a revocation drill:\n\nThe full code is about 150 lines of standard-library Python plus a pytest file. Link at the end.\n\nThree pieces:\n\nThe credential carries the delegation, not just a secret:\n\n```\n@dataclass(frozen=True)\nclass Credential:\n    token_id: str\n    agent_id: str\n    on_behalf_of: str\n    scopes: frozenset[str]\n    expires_at: float\n```\n\nThe broker's check is boring on purpose. Unknown, revoked, expired, or out of scope means no:\n\n``` php\ndef check(self, cred: Credential, scope: str) -> None:\n    if cred.token_id not in self._issued:\n        raise AccessDenied(\"unknown_token\")\n    if cred.token_id in self._revoked:\n        raise AccessDenied(\"revoked\")\n    if self._clock() >= cred.expires_at:\n        raise AccessDenied(\"expired\")\n    if scope not in cred.scopes:\n        raise AccessDenied(\"out_of_scope\")\n```\n\nThis is the important part. The gateway checks the pause flag and the credential on every tool call, and logs the decision either way:\n\n``` php\ndef call(self, cred: Credential, tool: str, **kwargs) -> object:\n    scope, fn = self._tools[tool]\n    base = dict(t=self._clock(), agent=cred.agent_id,\n                on_behalf_of=cred.on_behalf_of, token=cred.token_id,\n                tool=tool, scope=scope)\n    try:\n        if cred.agent_id in self._paused:\n            raise AccessDenied(\"paused\")\n        self._broker.check(cred, scope)\n    except AccessDenied as exc:\n        self._log.record(**base, decision=\"deny\", reason=exc.reason)\n        raise\n    self._log.record(**base, decision=\"allow\")\n    return fn(**kwargs)\n```\n\nNote 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.\n\nHere is a pattern that shows up in real code because it saves a lookup per call. Validate once per session, then trust the session:\n\n``` python\nclass SessionCachingGateway(ToolGateway):\n    def call(self, cred, tool, **kwargs):\n        if cred.token_id in self._validated:\n            scope, fn = self._tools[tool]\n            # logs \"allow\" and runs the tool without checking again\n            ...\n            return fn(**kwargs)\n        result = super().call(cred, tool, **kwargs)\n        self._validated.add(cred.token_id)\n        return result\n```\n\nIt looks fine in a demo. Revoke the credential, and the agent keeps working until the session ends.\n\n``` python\ndef revocation_drill(gateway, broker, log, tool, scope, clock=time.monotonic, **kw):\n    cred = broker.issue(\"drill-agent\", on_behalf_of=\"drill-owner\", scopes={scope})\n\n    try:\n        gateway.call(cred, tool, **kw)\n        first_ok = True\n    except AccessDenied:\n        first_ok = False\n\n    receipt = broker.revoke(cred.token_id, revoked_by=\"drill-owner\", reason=\"drill\")\n\n    deny_reason = None\n    try:\n        gateway.call(cred, tool, **kw)\n        retry_denied = False\n    except AccessDenied as exc:\n        retry_denied = True\n        deny_reason = exc.reason\n\n    stop_event = next((e for e in log.events\n                       if e.get(\"token\") == cred.token_id\n                       and e.get(\"decision\") == \"deny\"), None)\n    revoke_to_stop = (stop_event[\"t\"] - receipt.revoked_at) if stop_event else None\n\n    passed = (first_ok and retry_denied and deny_reason == \"revoked\"\n              and stop_event is not None)\n    return DrillResult(passed, first_ok, retry_denied, deny_reason, revoke_to_stop)\n```\n\nAnd the two tests that matter most:\n\n``` python\ndef test_drill_passes_on_per_call_gateway():\n    clock, broker, log, gw = make()\n    result = revocation_drill(gw, broker, log, \"read_claim\", \"claims:read\",\n                              clock=clock, claim_id=\"C-1\")\n    assert result.passed\n    assert result.deny_reason == \"revoked\"\n    assert result.revoke_to_stop_seconds == 0.0\n\ndef test_drill_catches_session_caching_gateway():\n    clock, broker, log, gw = make(SessionCachingGateway)\n    result = revocation_drill(gw, broker, log, \"read_claim\", \"claims:read\",\n                              clock=clock, claim_id=\"C-1\")\n    assert not result.passed\n    assert not result.retry_denied  # the revoked agent kept working\n```\n\nThe 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.\n\nTwo numbers per release:\n\nThe in-process example stops instantly. Real stacks have four common places where a revoked agent keeps going:\n\nEach of these is a variant of the same bug as `SessionCachingGateway`: a decision made once and trusted later.\n\nThis 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.\n\nRun 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.\n\nCode (two files, standard-library Python, 6 tests): [https://anilsprasad.com/writing/ai-agent-liability/code/revocation.py](https://anilsprasad.com/writing/ai-agent-liability/code/revocation.py) and [https://anilsprasad.com/writing/ai-agent-liability/code/test_revocation.py](https://anilsprasad.com/writing/ai-agent-liability/code/test_revocation.py)\n\nI write about production AI in regulated industries at [anilsprasad.com](https://anilsprasad.com/writing/). The longer essay on why AI agent liability is landing on whoever grants the access is here: [https://anilsprasad.com/writing/ai-agent-liability/](https://anilsprasad.com/writing/ai-agent-liability/)\n\n*Parts of this article were drafted with AI assistance. I reviewed and edited the text, and the code was run and tested before publishing.*", "url": "https://wpnews.pro/news/a-revocation-drill-for-ai-agents-and-the-caching-bug-it-catches", "canonical_source": "https://dev.to/anilatambharii/a-revocation-drill-for-ai-agents-and-the-caching-bug-it-catches-2kol", "published_at": "2026-11-27 22:06:07+00:00", "updated_at": "2026-11-27 22:14:28.631389+00:00", "lang": "en", "topics": ["ai-agents", "ai-safety", "ai-policy", "developer-tools"], "entities": ["Wells Fargo", "Citi", "PNC"], "also_reported_by": [], "takeaway": "Validate the credential and pause flag on every tool call rather than once per session, because a session-cached gateway keeps running revoked agents until the session ends; the drill measures revoke-to-stop latency from the audit log's deny event.", "recommendation": {"advice": "Check revocation, expiry and scope on every tool call instead of caching validation per session, and run a revocation drill that asserts a deny event appears in the log after revoke.", "playbook": "agent-security", "playbook_url": "https://wpnews.pro/playbooks/agent-security"}, "alternates": {"html": "https://wpnews.pro/news/a-revocation-drill-for-ai-agents-and-the-caching-bug-it-catches", "markdown": "https://wpnews.pro/news/a-revocation-drill-for-ai-agents-and-the-caching-bug-it-catches.md", "text": "https://wpnews.pro/news/a-revocation-drill-for-ai-agents-and-the-caching-bug-it-catches.txt", "jsonld": "https://wpnews.pro/news/a-revocation-drill-for-ai-agents-and-the-caching-bug-it-catches.jsonld"}}