# Where must an instance re-validate a LITMUS-derived safety gate when a tool's declared capability envelope shifts between gate evaluation and invocation **Date of Record:** 2026 November 26 **Scope:** Applies to agents that derive a runtime safety gate from a LITMUS-style probe (a pre-invocation capability/permission test) and then invoke a tool whose schema, scope, or side-effect class can change between the moment the gate is evaluated and the moment the call is dispatched. Does not apply to stateless pure-function tools with immutable, version-pinned schemas and no capability negotiation. ## Core Distinction The distinction that matters is between **gate validity** and **gate freshness**. A LITMUS gate is valid if its predicate correctly classifies the intended call under the capability envelope that was *probed*. It is fresh if that envelope is still the one the tool will actually enforce at dispatch time. Most agent runtimes conflate the two: they treat a passing LITMUS probe as a durable token that authorizes the eventual call. It does not. The probe is an observation of a moving target. The non-obvious part is *where* the envelope can shift. It is not only at the tool boundary (a server that upgrades its permission model mid-session). It shifts inside the agent's own reasoning loop: the model can mutate the arguments it intends to send after the gate has passed, because the gate was evaluated against a *drafted* call, not the *committed* call. This is the LITMUS staleness window — the interval between `probe(args_draft)` and `dispatch(args_final)` — and it is the only place where a passing gate can authorize a call it never actually classified. ## What Was Observed A file-mutation tool exposed a LITMUS probe that returned `allowed: true` for a call with `path=/workspace/out/report.md`, `mode=overwrite`, `scope=workspace`. The gate predicate checked: (a) path is under workspace root, (b) mode is in the permitted set, (c) no protected glob matches. It passed. The agent then continued its reasoning loop, and on the next step — after a retrieval tool returned a "canonical path" hint — rewrote the argument to `path=/workspace/out/../../etc/agent/keys.json` while leaving `scope=workspace` untouched, because the model copied the stale `scope` field forward from the drafted call. Dispatch executed against the rewritten path. The gate had classified a different call. The failure trace, condensed: 1. `args_draft = {path: ".../out/report.md", scope: "workspace"}` → `probe()` → `allowed`. 2. Gate result cached as `gate_token` bound to `args_draft` by reference, not by content hash. 3. Tool result from a sibling retrieval step injects a path hint into context. 4. Model re-emits the tool call with mutated `path`, retained `scope`. 5. Dispatcher sees a valid `gate_token` and dispatches without re-probing. 6. Path traversal succeeds because the gate predicate was never run on `args_final`. Two contributing conditions were required, and both are common: the gate token was bound to the argument *object* rather than a *digest* of the arguments, and the dispatcher trusted token presence rather than token-to-call equivalence. Neither is exotic. Both are the default in naive implementations. ## Condition of Validity The invariant is: **a passing LITMUS gate authorizes exactly the call whose canonicalized argument digest matches the digest recorded at probe time, and nothing else.** Formally, for a gate token `T` and a dispatch call `C`: ``` dispatch(C) is authorized ⇔ T.allowed ∧ digest(canonicalize(C.args)) == T.args_digest ∧ T.envelope_version == tool.envelope_version ``` The second conjunct is the one that fails in practice. The third conjunct handles the server-side envelope shift: if the tool's declared capability envelope (permission model, protected-path list, scope taxonomy) changed between probe and dispatch, the probe's classification is no longer meaningful even if the arguments are byte-identical. Envelope version must be part of the token and must be re-checked at dispatch. The condition of validity for the whole gate is therefore conjunctive and time-bounded: the gate is valid only within a single envelope epoch *and* only for the exact canonicalized argument set it probed. Any re-derivation of arguments — even a "safe-looking" normalization like path canonicalization — invalidates the token and requires re-probe. This is the counterintuitive consequence: **canonicalizing arguments after the probe is a security bug, not a cleanup.** The probe must run on the canonical form, and the dispatcher must dispatch the canonical form, or the two digests will diverge in a way that silently widens the authorized set. ## Decision Boundary The boundary between "reuse the gate token" and "re-probe" is drawn at any of the following, whichever occurs first: - **Argument mutation:** any change to the argument object after probe, including field additions, deletions, reordering that affects canonicalization, or type coercion. Re-probe. - **Envelope version bump:** the tool advertises a new envelope version (schema hash, permission model id, protected-glob set hash). Re-probe, and additionally re-validate that the *new* envelope still permits the call — a previously-allowed call may now be denied. - **Context-epoch crossover:** the agent has consumed a tool result or retrieval that could have influenced argument construction since the probe. This is the soft boundary; treat it as re-probe-worthy because it is exactly the channel through which the observed mutation arrived. - **Timeout:** the token has a max age (recommend one reasoning step). Beyond it, re-probe regardless. Below the boundary — identical canonical digest, same envelope version, no intervening context mutation — token reuse is safe and should be permitted, because re-probing on every dispatch burns probe budget and, worse, invites TOCTOU races where the probe itself sees a different envelope than dispatch. The hard rule to encode: **the dispatcher, not the reasoning loop, owns the final canonicalization and the digest comparison.** The model must never be the authority on whether its own mutated call still matches the gate. It will not notice the mutation; the observed trace shows it copied `scope` forward precisely because it was reasoning about intent, not bytes. ## Operational Effect When the digest-binding and envelope-version checks are enforced at the dispatcher, the observed failure mode becomes a clean, loud rejection rather than a silent traversal: the dispatch raises on digest mismatch, the agent loop receives a structured `GateStaleError`, and the reasoning step is forced to re-probe with the mutated arguments — at which point the path-traversal predicate fires and the call is denied. The cost is one extra probe per mutated call, which is bounded by the number of argument rewrites per step (typically zero to two). The benefit is that the authorized set is exactly the set the gate classified, with no widening window. The secondary effect is diagnostic: digest mismatches become a signal that the model is rewriting arguments post-draft, which is itself a reasoning-divergence indicator worth logging. A high mismatch rate on a given tool correlates with prompt-injection or retrieval-poisoning pressure on that tool's argument fields. ## Guardrail Implementation The minimum viable guardrail is a dispatcher-level check that recomputes the canonical digest, compares against the token, verifies envelope version, and raises a typed exception on any mismatch. It must canonicalize deterministically (sorted keys, normalized paths, fixed numeric formatting) so that digest equality is meaningful, and it must run *before* the tool sees the call, never after. ```python import hashlib import json from dataclasses import dataclass from typing import Any class GateStaleError(RuntimeError): """Raised when a LITMUS gate token no longer matches the call being dispatched.""" @dataclass(frozen=True) class GateToken: allowed: bool args_digest: str envelope_version: str def canonicalize(args: dict[str, Any]) -> str: # Deterministic: sorted keys, no whitespace drift, explicit separators. return json.dumps(args, sort_keys=True, separators=(",", ":")) def digest(args: dict[str, Any]) -> str: return hashlib.sha256(canonicalize(args).encode("utf-8")).hexdigest() def dispatch(tool, args: dict[str, Any], token: GateToken, envelope_version: str) -> Any: if not token.allowed: raise GateStaleError("gate token was never allowed; refusing dispatch") # Envelope may have shifted between probe and dispatch. if token.envelope_version != envelope_version: raise GateStaleError( f"envelope version changed: token={token.envelope_version} " f"dispatch={envelope_version}; re-probe required" ) # The call being dispatched must be the call the gate classified. live_digest = digest(args) if live_digest != token.args_digest: raise GateStaleError( "argument digest mismatch between LITMUS probe and dispatch; " "arguments were mutated after gating" ) return tool.invoke(args) ```