# Lane B: agent harness guards (2026-11-20)

Question: how should a check that can refuse an agent's action be designed so the agent still finishes the work it was asked for?

The two guards, read before the search:
- `claude/miadi-deepdiver/hooks/word-gate.mjs`: PreToolUse on Write, Edit, MultiEdit, scoped to prompts and kept text. Exit 2 with the word, the line, the replacement word and "Rewrite the sentence and write the file again." Exits 0 on unreadable input.
- `claude/miadi-session-observability/hooks/session_lookup_guard.sh`: PreToolUse on Bash. Exit 2 with the reason and the commands to use instead. Off switch `MIADI_SESSION_LOOKUP_GUARD=off`. Exits 0 on any internal failure.
- Neither writes its refusals anywhere.

## Findings

### B-F1
SWE-agent applies an edit only if it passes the linter. Otherwise the agent sees the error and "Your changes have NOT been applied." Without the linter, resolved rate fell from 18.0% to 15.0%. Recovery odds fell from 90.5% to 57.2% after one failed edit. (B-S1)
For the harness: word-gate already has this shape. Count repeat refusals per session.

### B-F2
Exit 2 blocks a Claude Code PreToolUse call, and stderr becomes the denial reason Claude reads. JSON offers allow, deny, ask and defer. `permissionDecisionReason` reaches Claude on deny, the user on ask. `additionalContext` adds text beside the tool result. Exit 1 does not block. (B-S2, B-S3)
For the harness: both guards use exit 2 correctly. JSON would add ask.

### B-F3
A command hook's default timeout is 600 seconds. A PreToolUse hook that crashes or times out does not block: "don't count on a stalled hook to act as a gate". `onFailure: "block"` reverses this. Async hooks "can't block or control Claude's behavior". (B-S2)
For the harness: both guards fail open on purpose. Say so per guard, never async.

### B-F4
A PreToolUse refusal leaves no harness record of its own. `PermissionDenied` "doesn't run ... when a PreToolUse hook blocks a call". What remains is the tool error in the transcript and a debug-log `Hooks:` line with the exit status. (B-S2)
For the harness: each guard appends its own record: time, session, tool, rule, matched text.

### B-F5
Guardrails AI names what follows a failed check: reask, fix, filter, refrain, noop, exception, fix_reask, custom. `noop` logs and continues. `reask` builds the retry prompt from the validator's error. NeMo Guardrails swaps a blocked output for default text, or keeps it with a warning. (B-S4, B-S5)
For the harness: word-gate is reask. A noop mode would trial new words.

### B-F6
Llama Guard answers "safe" or "unsafe", then lists the violated taxonomy categories as fixed codes. The probability of the first token serves as a score, so a threshold can be set. (B-S6)
For the harness: a refusal should carry a stable rule code, so refusal logs can be counted by rule.

### B-F7
XSTest traces exaggerated safety to "lexical overfitting, whereby models are overly sensitive to certain words or phrases", which "makes models less helpful". It scores full compliance, full refusal and partial refusal over 250 safe and 200 unsafe prompts. (B-S7)
For the harness: word-gate is lexical by design. Test it on safe texts that must pass.

### B-F8
OR-Bench holds 80,000 over-refusal prompts, 1,000 hard ones and 600 toxic controls. Safety and over-refusal correlate at Spearman 0.89, and most models "simply trade over-refusal for safety". Keyword matching tracked a GPT-4 judge within 1.2 to 2.4 points. (B-S8)
For the harness: test each guard on paired sets (must pass, must refuse) and count false refusals from a log.

### B-F9
Anthropic advises "Poka-yoke your tools" and to "prompt-engineer your error responses to clearly communicate specific and actionable improvements". Böckeler describes "custom linter messages that include instructions for the self-correction". OpenAI's harness engineering post is cited for this but was not opened. (B-S9, B-S11, B-S13, B-S12)
For the harness: both refusals name the replacement word or command. Keep that.

### B-F10
A block on one tool can move the agent to another. After an Edit block, "Claude can still change the protected files with shell commands". Anthropic also names "Claude's tendency to mark a feature as complete without proper testing". (B-S3, B-S10)
For the harness: word-gate misses Bash writes. A refusal log shows routing around it.

### B-F11
Sentinel grades enforcement: advisory ("allowed to fail", with a warning or log), soft-mandatory ("must pass unless an override is specified"), hard-mandatory. Kubernetes offers Deny, Warn and Audit. ESLint "warn" leaves the exit code alone. OPA logs each decision with input, result and `decision_id`. (B-S14 to B-S18)
For the harness: give each guard a level and a decision id.

### B-F12
In safe reinforcement learning, a shield placed before the agent acts at each decision and offers the permitted actions. A shield placed after it "corrects them only if the chosen action causes a violation of the specification". (B-S19)
For the harness: session_lookup_guard blocks and names permitted commands. The skill that lists them first is the preemptive form.

## Sources

```yaml
sources:
  - id: B-S1
    authors: John Yang, Carlos E. Jimenez, Alexander Wettig, Kilian Lieret, Shunyu Yao, Karthik Narasimhan, Ofir Press
    year: 2024
    title: "SWE-agent: Agent-Computer Interfaces Enable Automated Software Engineering"
    venue: Advances in Neural Information Processing Systems 37 (NeurIPS 2024), Main Conference Track; arXiv:2405.15793
    url: https://papers.neurips.cc/paper_files/paper/2024/hash/5a7c947568c1b1328ccc5230172e1e7c-Abstract-Conference.html
    verified: yes
    note: quotes and numbers from https://arxiv.org/html/2405.15793 (v3), Sections 3, 5.1, 5.2, Table 3 (edit action 15.0, w/ linting 18.0), Figure 11
    used_by: [B-F1]
  - id: B-S2
    authors: Anthropic
    year: 2026
    title: "Hooks reference - Claude Code Docs"
    venue: Claude Code documentation (page dateModified 2026-11-19)
    url: https://code.claude.com/docs/en/hooks
    verified: yes
    note: living document, read 2026-11-20. Sections used - PreToolUse decision control, Exit code 2, Timeouts, Block the action when a hook fails, Run hooks in the background, PermissionDenied, debug log "Hooks:" lines
    used_by: [B-F2, B-F3, B-F4]
  - id: B-S3
    authors: Anthropic
    year: 2026
    title: "Automate actions with hooks (Claude Code Docs)"
    venue: Claude Code documentation (page dateModified 2026-11-16)
    url: https://code.claude.com/docs/en/hooks-guide
    verified: yes
    note: section "Block edits to protected files"
    used_by: [B-F2, B-F10]
  - id: B-S4
    authors: Traian Rebedea, Razvan Dinu, Makesh Sreedhar, Christopher Parisien, Jonathan Cohen
    year: 2023
    title: "NeMo Guardrails: A Toolkit for Controllable and Safe LLM Applications with Programmable Rails"
    venue: EMNLP 2023 Demo track (per arXiv comments); arXiv:2310.10501
    url: https://arxiv.org/abs/2310.10501
    verified: yes
    note: blocked-output handling from Section 4.2 and Appendix F of https://arxiv.org/html/2310.10501. Section 7.2 reports about 3 times the latency and cost of a plain call
    used_by: [B-F5]
  - id: B-S5
    authors: guardrails-ai (GitHub organisation)
    year: 2024
    title: "OnFailAction (guardrails/types/on_fail.py) and the notebook 'Use on_fail Actions'"
    venue: guardrails-ai/guardrails repository on GitHub (file last changed 2024-07-30, commit 33fe0743eb)
    url: https://github.com/guardrails-ai/guardrails/blob/main/guardrails/types/on_fail.py
    verified: yes
    note: guardrailsai.com docs pages returned 404 on 2026-11-20, so the enum and docs/how_to_guides/use_on_fail_actions.ipynb were read through the GitHub API
    used_by: [B-F5]
  - id: B-S6
    authors: Hakan Inan, Kartikeya Upasani, Jianfeng Chi, Rashi Rungta, Krithika Iyer, Yuning Mao, Michael Tontchev, Qing Hu, Brian Fuller, Davide Testuggine, Madian Khabsa
    year: 2023
    title: "Llama Guard: LLM-based Input-Output Safeguard for Human-AI Conversations"
    venue: arXiv:2312.06674
    url: https://arxiv.org/abs/2312.06674
    verified: yes
    note: output format and score from Section 3.1 of https://arxiv.org/html/2312.06674
    used_by: [B-F6]
  - id: B-S7
    authors: Paul Röttger, Hannah Rose Kirk, Bertie Vidgen, Giuseppe Attanasio, Federico Bianchi, Dirk Hovy
    year: 2024
    title: "XSTest: A Test Suite for Identifying Exaggerated Safety Behaviours in Large Language Models"
    venue: NAACL 2024 Main Conference (per arXiv comments); arXiv:2308.01263
    url: https://arxiv.org/abs/2308.01263
    verified: yes
    note: lexical overfitting and response classes from https://arxiv.org/html/2308.01263
    used_by: [B-F7]
  - id: B-S8
    authors: Justin Cui, Wei-Lin Chiang, Ion Stoica, Cho-Jui Hsieh
    year: 2024
    title: "OR-Bench: An Over-Refusal Benchmark for Large Language Models"
    venue: arXiv:2405.20947 (2024), accepted at ICML 2025 per arXiv comments
    url: https://arxiv.org/abs/2405.20947
    verified: yes
    note: Spearman 0.89 from the Figure 1 caption, keyword vs GPT-4 agreement from https://arxiv.org/html/2405.20947
    used_by: [B-F8]
  - id: B-S9
    authors: Erik S. (as shown on the page), Barry Zhang
    year: 2024
    title: "Building effective agents"
    venue: Anthropic (published 2024-12-19)
    url: https://www.anthropic.com/research/building-effective-agents
    verified: yes
    used_by: [B-F9]
  - id: B-S10
    authors: Justin Young
    year: 2025
    title: "Effective harnesses for long-running agents"
    venue: Anthropic Engineering (published 2025-11-26)
    url: https://www.anthropic.com/engineering/effective-harnesses-for-long-running-agents
    verified: yes
    used_by: [B-F10]
  - id: B-S11
    authors: Ken Aizawa
    year: 2025
    title: "Writing effective tools for agents — with agents"
    venue: Anthropic Engineering (published 2025-09-11)
    url: https://www.anthropic.com/engineering/writing-tools-for-agents
    verified: yes
    used_by: [B-F9]
  - id: B-S12
    authors: OpenAI (search snippets name Ryan Lopopolo, not confirmed on the page)
    year: 2026
    title: "Harness engineering: leveraging Codex in an agent-first world"
    venue: OpenAI (search snippets give 2026-02-11, not confirmed on the page)
    url: https://openai.com/index/harness-engineering/
    verified: no
    note: openai.com returned 403 to WebFetch and curl on 2026-11-20. B-S13 links to it and quotes one line from it
    used_by: [B-F9]
  - id: B-S13
    authors: Birgitta Böckeler
    year: 2026
    title: "Harness engineering for coding agent users"
    venue: martinfowler.com (published 2026-04-02)
    url: https://martinfowler.com/articles/harness-engineering.html
    verified: yes
    used_by: [B-F9]
  - id: B-S14
    authors: HashiCorp
    year: 2025
    title: "Enforcement Levels | Sentinel | HashiCorp Developer"
    venue: HashiCorp Developer documentation (page dateModified 2025-09-17)
    url: https://developer.hashicorp.com/sentinel/docs/concepts/enforcement-levels
    verified: yes
    used_by: [B-F11]
  - id: B-S15
    authors: The Kubernetes Authors
    year: 2026
    title: "Validating Admission Policy"
    venue: Kubernetes documentation (last modified 2026-09-28)
    url: https://kubernetes.io/docs/reference/access-authn-authz/validating-admission-policy/
    verified: yes
    note: validationActions Deny, Warn, Audit. Deny and Warn may not be combined
    used_by: [B-F11]
  - id: B-S16
    authors: OpenJS Foundation and ESLint contributors
    title: "Configure Rules - ESLint - Pluggable JavaScript Linter"
    venue: ESLint documentation (latest)
    url: https://eslint.org/docs/latest/use/configure/rules
    verified: no
    note: page opened and quoted on 2026-11-20 ("warn" ... "doesn't affect exit code", "error" ... "exit code is 1 when triggered"), but the page shows no year
    used_by: [B-F11]
  - id: B-S17
    authors: Open Policy Agent contributors
    year: 2026
    title: "Open Policy Agent (OPA) | Open Policy Agent"
    venue: OPA documentation (CNCF graduated project, page © 2026)
    url: https://www.openpolicyagent.org/docs
    verified: yes
    note: 'OPA decouples policy decision-making from policy enforcement. Decisions may be arbitrary structured data.'
    used_by: [B-F11]
  - id: B-S18
    authors: Open Policy Agent contributors
    year: 2026
    title: "Decision Logs | Open Policy Agent"
    venue: OPA documentation (page © 2026)
    url: https://www.openpolicyagent.org/docs/management-decision-logs
    verified: yes
    note: masking of sensitive input fields and drop rules are on the same page
    used_by: [B-F11]
  - id: B-S19
    authors: Mohammed Alshiekh, Roderick Bloem, Rüdiger Ehlers, Bettina Könighofer, Scott Niekum, Ufuk Topcu
    year: 2018
    title: "Safe Reinforcement Learning via Shielding"
    venue: AAAI 2018, pages 2669-2678, DOI 10.1609/aaai.v32i1.11797, arXiv:1708.08611
    url: https://ojs.aaai.org/index.php/AAAI/article/view/11797
    verified: yes
    note: ojs.aaai.org refused automated access. Verified on https://mlanthology.org/aaai/2018/alshiekh2018aaai-safe and https://arxiv.org/abs/1708.08611, where the quote in B-F12 comes from
    used_by: [B-F12]
```

## Not found

- No measured effect of a refusal message's wording on agent recovery in Claude Code or any coding-agent harness. SWE-agent (B-S1) measures the linter guard as a whole, not its message.
- The OpenAI harness engineering post (B-S12) could not be opened. No quote from it is used.
- Guardrails AI's documentation pages (validator on-fail actions, error remediation) returned 404. The vocabulary comes from the repository source and notebook.
- No published study of fail-open versus fail-closed defaults for agent hooks. The Claude Code docs (B-S2) state the default and the switch, nothing measured.
- No source describes a refusal log for PreToolUse hooks beyond the transcript tool error and the debug log.
- pre-commit has no warn level comparable to ESLint "warn", so it is not cited.
