In 5 seconds
A safety control can fail silently — especially when it is designed to fail open. Test the protection in the real runtime, not only in isolation.
For you if: You build coding-agent hooks, approval gates, context-budget controls, or other safeguards that are supposed to intervene before an AI tool call.
This article is part of Nyansa Hub’s Lean Context + Durable Intelligence series.
Here is a sanitized operational lesson from a context-budget workflow.
The control we wanted
A coding agent worked across long-running projects with large logs and handoff files. The default rule was simple: read a small recent slice first, search before opening large history, and ask before an unbounded large-file read.
Because prose rules can be ignored, the workflow added a pre-tool-call hook. It inspected a proposed file read and could return an ask decision before the tool executed.
Why fail open?
The hook should not hang the entire development environment because it receives an unexpected input. So malformed input deliberately fell through and allowed the tool call.
That is a reasonable availability choice — but it creates a new requirement: you must prove the hook is actually running.
The bug
The first parser assumed the incoming JSON started directly with {. In the real shell/runtime path, the input could contain a leading UTF-8 byte-order mark. Parsing failed.
And because parse failure was intentionally fail-open, the failure was invisible. Tool calls completed. Nothing appeared broken. The protection simply did not intervene.
The fix
Strip the actual BOM character before parsing:
JSON.parse(input.replace(/^\uFEFF/, ''))
Then test BOM-prefixed input explicitly.
The bigger lesson was not the one-line fix
Running the hook script against hand-constructed JSON had created false confidence. The real problem only became obvious when the actual runtime tool call was repeated and the expected on-screen prompt did not appear.
So the verification checklist became part of the control:
- unbounded large-file read → ask prompt appears;
- bounded read under the limit → proceeds silently;
- one command referencing multiple large histories → ask prompt appears;
- malformed input → does not hang the tool;
- BOM-prefixed input → parses correctly;
- real runtime behavior is observed after installation or runtime changes.
Fail-open and fail-closed are design choices, not slogans
A fail-closed control can block legitimate work when the guard itself breaks. A fail-open control preserves availability but can silently remove protection. The correct choice depends on consequence.
What should not be optional is health testing. If silence can mean either “allowed” or “guard failed,” build an explicit way to distinguish them.
This generalizes beyond context budgets
The same lesson applies to permission gates, secret scanners, idempotency checks, logging, backup routines, approval verification, and kill switches. Test the failure path as deliberately as the happy path.
Related Nyansa Hub reading
- How to Give a Coding Agent Enough Context Without Letting It Read Everything
- Capability Is Not Permission in Ecommerce Automation
- Safe Ecommerce Automation Coding Build Kit
Sources and current references
Put this into practice
Use the Lean AI Context Playbook if you want the operating method. Use the AI Context & State Management Toolkit when context, continuity, and durable state are recurring across projects or agents.
If your main question is repeated input and cost, use the AI Context Cost Calculator. If you want bounded reads and context budgets enforced technically, use the Token-Efficient Agent Context Coding Build Kit. Need the complete system? Use the Lean AI Operations Bundle.
Browse the full Lean Context + Durable Intelligence family →
Continue the path
Use the free AI Context Reset Checklist when you need a clean handoff, and the AI Continuity Checklist when you want to test vendor independence and business continuity.
For coding-agent project scope, use the Coding for Ecommerce Operators Toolkit. For live automation authority, approvals, verification, and recovery, use the Safe Ecommerce Automation Toolkit.
Nyansa Hub — Playbooks for Smarter Ecommerce.