lawrencehua/skills-log/fail-closed-guards
Claude Code and agent skill by lawrencehua/skills-log
- community
Checking that the SKILL.md file is still in the repository.
When a guard/gate/precondition depends on data that might be missing, make the missing-data fallback REFUSE the action, not allow it — and confirm every write-site actually populates the field the guard reads.
Install
npx vskill@latest install lawrencehua/skills-log/fail-closed-guardsSKILL.md
The same SKILL.md was published earlier as lawrencehua/skills-log/fail-closed-guards.
fail-closed-guards
Any guard of the shape if predicate(value): allow_action() has a hidden failure mode: what does it do when value was never set? If the chosen default makes the predicate evaluate to "allow," the guard is dead code from the moment it's written — it will never actually block anything, and nobody will notice until the exact scenario it was supposed to prevent happens in production.
When to use
- You're writing or reviewing any guard, gate, permission check, or precondition that reads a field which might be missing, unset, or not-yet-written (a race condition, an optional field, a field only some code paths populate).
- You see a pattern like
dict.get(key, DEFAULT),value or DEFAULT, orgetattr(obj, "x", DEFAULT)feeding directly into anifthat gates a sensitive action. - A guard "isn't firing" and you can't tell why — check the default first.
The rule
For any guard of the form if predicate(value): allow_action():
- Identify what `value` is when the data is missing — not stamped, not set, a race condition, never initialized, an optional field nobody filled in.
- Choose the default so `predicate(missing) == False` — never
True. - Confirm every write-site actually stamps `value`. A fail-closed default doesn't help if nothing ever writes the field in the first place — the guard will "always fire closed," which just masks the real bug of a field never being populated.
The canonical anti-pattern
The fallback 999.0 was picked to mean "the last action was a long time ago, so it's safe to proceed." But if none of the code paths that build state actually stamp "t", the guard's predicate sees 999.0 on every single call — it always evaluates true, so the guard never actually blocks anything. This is dead code wearing a guard's clothing.
Checklist for any new guard
- What's the data the guard depends on? (a variable, a dict key, a DB row, a field on an object)
- What does that data look like when it's MISSING? (
None,"",0,False, key absent, row not yet inserted) - What does the guard's predicate return on that missing value?
- If the answer to #3 is "allow" → stop and flip the default or invert the predicate.
- Who writes the field? Grep for every write-site and confirm each one actually writes it — a fail-closed default is worthless if the field is never populated at all.
- Add a log line on the "guard fired because the field was missing" path, so the next person debugging knows the safe-fail kicked in rather than a real denial.
Worked examples
Reject-if-recent guard — read your predicate carefully; the safe default depends on what it's testing, not just "pick a small/large number":
A naive state.get("t", 0.0) default would be fail-open here — now - 0.0 is huge, so the "too soon" check would never trigger on a missing timestamp. The safe default flips depending on which direction the predicate refuses in.
Permission default:
Feature-flag default:
If the flag is missing from config (new environment, partial deploy), the safe default is the old, proven path.
When NOT to apply this
- Performance-tuning defaults (
cache_size: int = 256) — no safety concern, just pick something reasonable. - Display/UI defaults (
theme: str = "light") — a UI fallback, not a guard. - Backward-compat shims for legacy data — the default IS the intended legacy behavior, by design.
This applies specifically to guards, gates, and preconditions that decide whether a sensitive action proceeds.
How to use
Install: copy this folder into ~/.claude/skills/fail-closed-guards/ for personal use, or .claude/skills/fail-closed-guards/ inside a project repo.
Invoke:
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/fail-closed-guards/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/lawrencehua/skills-log/fail-closed-guards)