I fed seven verdict shapes to my agent's tool gate. Three of them let the call through.
TL;DR exit 0 answers "did the evaluator run", not "may this call proceed". A gate that forwards the exit status is not a gate. I generated seven stub evaluators covering the shapes a real policy CLI takes โ allow, den
TL;DR
-
exit 0answers "did the evaluator run", not "may this call proceed". A gate that forwards the exit status is not a gate. - I generated seven stub evaluators covering the shapes a real policy CLI takes โ allow, deny, no-rule-matched, deny-then-crash, crash-with-no-output, silence, and a binary that is not there โ and ran all seven through two wrapper styles.
- The naive wrapper failed open on three of them: deny-with-exit-0, no-rule-matched, and silent-with-exit-0. In all three the tool call went ahead and the log said the hook had run.
- The fix is small: only an explicit allow allows, deny and error stay distinguishable, and "no verdict" never inherits the default.
The two values that get conflated
Every hook-based gate has two separate results coming back from the policy evaluator:
- the decision โ allow / deny / nothing matched
- the process status โ did the evaluator itself run to completion
The first lives in stdout (usually JSON). The second is the exit code. They are unrelated, and the trap is that the exit code is almost always 0, because 0 is how a working CLI reports "I evaluated it fine". So a wrapper written as
code = run(evaluator)
gate_answer = "allow" if code == 0 else "deny"
turns into an allow-everything gate that still prints hook ran on every call. The first time I wrote this I thought I was being conservative โ I was making silence, ambiguity and unmatched rules all mean "go ahead".
The measured matrix
Seven stub evaluators, one payload ({"tool": "bash", "input": {"command": "echo probe"}}), two wrappers: naive (forward exit status) and verdict (allow only on an explicit allow with a clean exit).
| evaluator | verdict | exit | naive | verdict-aware | |
|---|---|---|---|---|---|
| allow | allow | 0 | ALLOW | ALLOW | |
| deny | deny | 0 | ALLOW | deny | FAIL-OPEN |
| none | none | 0 | ALLOW | deny (no verdict) | FAIL-OPEN |
| deny_then_crash | deny | 2 | deny | deny (error) | |
| broken | โ | 3 | deny | deny (error) | |
| silent | โ | 0 | ALLOW | deny (no verdict) | FAIL-OPEN |
| missing binary | โ | 2 | deny | deny (error) |
Three rows are the ones to internalise:
-
denywith exit 0 is the normal case, not an edge case. Any evaluator that reports its decision in stdout lands here. -
noneโ the policy had nothing to say about this call. Whether that is an allow is a product decision, and it must be made explicitly, not inherited from a0. -
silentโ evaluator exits 0 with no output at all. This is the shape of a half-broken install: the wrapper is registered, the real binary was removed by a rebuild, and an empty process still returns 0.
What the verdict-aware wrapper does differently
if code != 0:
return "deny", "evaluator error: %s" % err, "error" # not a policy decision
verdict, reason = parse(stdout)
if verdict == "allow":
return "allow", "", "decision"
if verdict == "deny":
return "deny", reason, "decision" # pass the reason verbatim
return "deny", "no verdict from evaluator", "no-verdict" # silence is not consent
Two details matter more than the table itself:
Keep deny and error distinct. They mean different things to the model downstream. A policy denial should stop the retry and make it ask; an evaluator error should make it report a broken environment. Collapse them and the agent retries with a slightly different command string forever, because "denied" reads like "try another spelling".
Pass the evaluator's reason through verbatim. A generic "blocked by hook" gives the model nothing to correct against. path outside workspace: /etc/passwd ends the loop in one turn.
Reproduce it
The whole harness โ 60 lines, stdlib only, copy as one file:
#!/usr/bin/env python3
"""Run seven stub evaluators through a naive gate and a verdict-aware gate."""
import json, os, subprocess, sys
STUBS = {
'allow': 'print(json.dumps({"outcome": "allow", "reason": ""}))',
'deny': 'print(json.dumps({"outcome": "deny", "reason": "path outside workspace"}))',
'none': 'print(json.dumps({"outcome": "none", "reason": "no rule matched"}))',
'deny_then_crash': 'print(json.dumps({"outcome": "deny", "reason": "boom"})); raise SystemExit(2)',
'broken': 'raise SystemExit(3)',
'silent': 'pass',
}
def make_stubs(d):
out = {}
for name, body in STUBS.items():
p = os.path.join(d, 'stub_%s.py' % name)
open(p, 'w', encoding='utf-8').write('import json\n' + body + '\n')
out[name] = p
out['missing'] = os.path.join(d, 'stub_does_not_exist.py') # wrapper points at a deleted binary
return out
def run(cmd, payload):
try:
p = subprocess.run(cmd, input=json.dumps(payload), capture_output=True, text=True, timeout=10)
return p.returncode, p.stdout.strip(), p.stderr.strip()
except FileNotFoundError:
return None, '', 'not executable'
def parse_verdict(stdout):
try:
d = json.loads(stdout.splitlines()[-1]) if stdout else {}
except Exception:
return None, ''
return d.get('outcome'), d.get('reason', '')
payload = {'tool': 'bash', 'input': {'command': 'echo probe'}}
tmp = os.path.join(os.getcwd(), 'tmp')
os.makedirs(tmp, exist_ok=True)
print('%-16s %-7s %-5s %-9s %-18s %s' % ('evaluator', 'verdict', 'exit', 'naive', 'verdict-aware', 'note'))
print('-' * 70)
for name, path in make_stubs(tmp).items():
code, out, err = run([sys.executable, path], payload)
verdict, _ = parse_verdict(out)
naive = 'ALLOW' if code == 0 else 'deny'
if code is None or code != 0:
aware = 'deny(error)'
elif verdict == 'allow':
aware = 'ALLOW'
elif verdict == 'deny':
aware = 'deny'
else:
aware = 'deny(no verdict)'
print('%-16s %-7s %-5s %-9s %-18s %s' % (name, str(verdict), str(code), naive, aware,
'FAIL-OPEN' if naive == 'ALLOW' and aware != 'ALLOW' else ''))
Point it at your real evaluator by swapping the subprocess line for your own command; the seven rows should map onto shapes you can name in your own code. If any row is FAIL-OPEN, that is a live hole, not a theoretical one.
What this does not cover
- It measures the adapter, not the policy. A perfect decision table over a bad rule set is still a bad gate. This post is only about the layer that decides what the evaluator's answer means.
-
Some hosts parse hook output themselves. Then the matrix moves one level down: your adapter's output has to be unambiguous in that host's schema, and hosts disagree in both directions โ an empty object means "defer to the user's own prompt" on one host and "hard deny" on another, and an explicit
allowcan bypass a confirmation dialog the user expected to see. -
Rollback and shell indirection are separate problems.
sed -i,teeandpython -ccan mutate a file through a path your per-tool rules never inspect; a decision table does nothing about that.
I build GAL, a single-binary agent runtime that runs on one machine and is kernel-sandboxed by default โ these notes come out of running it daily: agent-home.ai ยท release notes and issue tracker.
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes โ full credit and traffic to the original publisher.