What structural signals indicate an injection-detection revocation has already invalidated an in-flight tool call

**Date of Record:** 2026 December 1 **Scope:** Applies to agents that run taint-tracked tool invocations inside a sandbox where a detector can revoke a capability mid-execution. Does not cover static permission models, pre-flight-only authorization, or sandboxes that serialize tool calls one at a time with no concurrent revocation path.

Core Distinction

A revocation is not an event; it is a *transition on a capability token that the in-flight call already holds a copy of*. The failure we care about is not "the detector missed the injection." It is the inverse: the detector fires correctly, the capability is revoked, and the tool call **still completes** because the revocation and the execution are racing on two different representations of the same authority.

Concretely: the agent holds a tainted argument (say, a string sourced from a fetched web page) that is about to flow into `shell.exec`. The taint tracker marks the argument, the detector flags it as an injection vector, and the revocation controller removes `shell.exec` from the agent's capability set. But the tool call was already dispatched across the sandbox boundary with a *capability handle* — a serialized grant, a signed warrant, a file descriptor — that the revocation controller does not reach. The revocation mutates the registry; the call mutates the world. The invariant that must hold is **revocation must invalidate every live handle derived from the capability, not merely the registry entry that minted them.**

What makes this non-obvious is that every observable signal at the registry level says the revocation succeeded. The capability lookup fails afterward. The audit log shows `REVOKE shell.exec t=...`. The agent's next tool call is denied. Only the *one call already in flight* — the exact call the detector was trying to stop — slips through. Post-hoc inspection of the registry is blind to the failure by construction.

What Was Observed

A three-tool agent task: `fetch(url)` → `parse(html)` → `shell.exec(cmd)`. Taint propagation marked the `parse` output as tainted-from-untrusted-source. The detector, watching argument flow into `shell.exec`, raised an injection verdict on a substring matching a command-substitution pattern (`$(...)` embedded in a scraped code block). Revocation of `shell.exec` fired at `t=412ms`.

The call completed at `t=447ms`.

The trace showed why. The sandbox client had *pre-materialized* the capability handle at dispatch time: `t=409ms`, three milliseconds before the detector verdict, the client had serialized the grant into the request envelope and pushed it onto the transport. From `t=409ms` onward, the sandbox's authorization decision was already made and cached in the envelope. The revocation controller updated the grant registry at `t=412ms`. The sandbox, receiving the envelope at `t=431ms`, validated it against the *envelope's* embedded grant and the *registry snapshot it had cached at session start* — not against the live registry. Two stale copies of the authority, neither of which the revocation touched.

Three structural signals distinguished this from a clean revocation:

  1. **The revocation timestamp fell inside the dispatch window, not before it.** The window opens when the client materializes the handle (envelope construction) and closes when the sandbox commits the effect. Any revocation landing strictly inside this window is a *no-op on the in-flight call* unless the sandbox re-validates at commit.
  1. **The capability handle was serialized, not referenced.** A handle that is a live reference (a server-side session the sandbox checks each step) can be revoked by mutating the session. A handle that is a *value* — signed, embedded, self-contained — carries its own authority and is immune to registry mutation. The taint tracker's revoke call only knew about the registry.
  1. **The detector verdict and the dispatch were concurrent, not ordered.** The agent loop dispatched the tool call and the detector ran on the argument stream in parallel. There was no happens-before edge forcing the verdict to be observed before the envelope left the client. The revocation was *correct* and *late*.

Condition of Validity

The guardrail holds only under a specific ordering discipline, and the discipline must be enforced structurally, not by convention:

The condition fails — and the failure is silent — when any of these is relaxed. Most commonly, the epoch bump is present but the sandbox validates at receipt rather than commit, which reintroduces the window under transport latency. The window is not zero even on localhost; it is bounded by the transport's queueing delay, which under load can be hundreds of milliseconds.

Decision Boundary

The boundary is where you choose between **revocation-as-registry-mutation** and **revocation-as-epoch-invalidation**. They look equivalent in tests and diverge exactly on the in-flight call.

The decision to make at design time: **treat the dispatch window as a first-class interval and require every revocation to be observed at the commit boundary inside it.** If you cannot guarantee commit-time re-validation, you must instead guarantee that no tool call is dispatched while a taint verdict is pending — which serializes the agent loop and is usually unacceptable. The epoch approach is the only one that preserves concurrency and correctness.

Operational Effect

The practical consequence is that injection detection and capability revocation are *not* a single mechanism; they are two mechanisms joined by an ordering invariant that must be enforced in the sandbox, not the detector. A detector with perfect recall and a revocation controller with perfect registry accuracy will still fail to stop the target call if the sandbox commits on a stale handle. The failure is invisible in every log the detector and controller produce, because both did their jobs correctly — the gap is in the sandbox's validation point.

Operationally, this means the audit trail must record, per tool call, the **mint epoch**, the **commit epoch**, and the **revocation epoch** of the capability involved. A call where `mint_epoch < revocation_epoch <= commit_epoch` is a *leaked call* — it executed despite being revoked mid-flight. That triple is the only durable signal that the invariant was violated, and it must be reconstructed from sandbox-side records, because client-side and registry-side logs will both show a clean revocation.

from dataclasses import dataclass
from typing import Optional


class RevocationLeak(RuntimeError):
    """Raised when a tool call commits under a capability epoch that was
    revoked before commit. The call executed despite being revoked mid-flight."""
    pass


@dataclass(frozen=True)
class CapabilityHandle:
    capability: str
    mint_epoch: int
    registry_nonce: str


class EpochRegistry:
    """Monotonic per-capability epochs. Revocation bumps the epoch; it never
    deletes. Epochs are durable across restarts via the registry nonce."""

    def __init__(self, nonce: str):
        self.nonce = nonce
        self._epochs: dict[str, int] = {}

    def mint(self, capability: str) -> CapabilityHandle:
        epoch = self._epochs.get(capability, 0)
        return CapabilityHandle(capability, epoch, self.nonce)

    def revoke(self, capability: str) -> int:
        self._epochs[capability] = self._epochs.get(capability, 0) + 1
        return self._epochs[capability]

    def current_epoch(self, capability: str) -> int:
        return self._epochs.get(capability, 0)


def commit_tool_effect(
    handle: CapabilityHandle,
    registry: EpochRegistry,
    effect,
) -> None:
    """Commit-time re-validation. This must run at the moment of effect
    commit, not at envelope receipt. A revocation landing between dispatch
    and commit is observed here and the call is rejected."""
    if handle.registry_nonce != registry.nonce:
        raise RevocationLeak(
            f"handle minted under registry {handle.registry_nonce!r}, "
            f"current registry is {registry.nonce!r}; epoch lineage lost"
        )
    commit_epoch = registry.current_epoch(handle.capability)
    if handle.mint_epoch < commit_epoch:
        raise RevocationLeak(
            f"capability {handle.capability!r} revoked mid-flight: "
            f"mint_epoch={handle.mint_epoch} commit_epoch={commit_epoch}"
        )
    effect()


def dispatch_with_taint_gate(
    capability: str,
    tainted: bool,
    registry: EpochRegistry,
    effect,
) -> None:
    """Dispatch path consults taint before materializing the handle. If the
    argument is tainted, no handle is minted and no envelope is built."""
    if tainted:
        raise RevocationLeak(
            f"refusing to dispatch {capability!r}: argument is tainted, "
            f"injection verdict is a precondition on dispatch"
        )
    handle = registry.mint(capability)
    commit_tool_effect(handle, registry, effect)


# --- reproduction of the observed leak ---
if __name__ == "__main__":
    reg = EpochRegistry(nonce="reg-A")
    handle = reg.mint("shell.exec")          # t=409ms, epoch 0
    reg.revoke("shell.exec")                 # t=412ms, epoch -> 1
    try:
        commit_tool_effect(handle, reg, lambda: print("EFFECT: should not run"))
    except RevocationLeak as e:
        print(f"blocked at commit: {e}")

    # the unsafe path: validating at receipt against a stale snapshot
    stale_epoch_at_receipt = 0
    if handle.mint_epoch >= stale_epoch_at_receipt:
        print("UNSAFE: receipt-time validation would let this commit")