Repository navigation
perf(guardrails): cut the Write/Edit PreToolUse row's spawns from 14 to 7 - #11064
Conversation
…to 7 hardcoded-path-check decides clean content with a builtin prefilter (hpp::prefilter, extracted from hpp::scan_text) before either git probe when no telemetry envelope can be written, runs rev-parse as $(exec git ...), and skips the scan capture on clean content. secret-pattern-detection decides clean content in the parent shell with secrets::any_match and opens the capture subshell only on a hit. Lower the guardrails-pretooluse-write-edit-spawns ceiling to 7 with ratchet.py propose-tighten --write. Refs: #10208 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
claude-security-review reviewed Incremental security review of The change adds two test cases for the clean-content early exit:
Why nothing is reportable:
Skip gate 2 applies: the change has no security-relevant surface. No cost or spend implications. critical-findings: 0 |
|
claude-review reviewed Incremental review of The change adds two cases that pin the telemetry condition on the clean-content early exit. The exit is at
I read Not tested: the No cost or security hold applies. |
…rly exit With telemetry on, clean content must still emit exactly one ok envelope; with telemetry off, it must exit before any git probe. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes #10208
Summary
A clean Write, Edit or NotebookEdit cost the guardrails PreToolUse row 14 processes on Linux. It now costs 7. No guard verdict changes. The
guardrails-pretooluse-write-edit-spawnsceiling drops from 14 to 7 throughratchet.py propose-tighten --write.Spawns per guard, from
scripts/hook-census.shon the counter's payload, attributed per pid withstrace -ffand bash xtrace:exec-bash.mjs→run-guards.sh)<(printf …)process substitution, one path-resolving subshell (only because the census target sits under a temp root)What was removed:
git rev-parseandgit check-ignore) are now skipped on clean content, and so is theVIOLATIONS=$(…)capture. Every branch after the project-dir check ends inexit 0when the content is clean. The only difference between those branches is that the clean scan emits anoktelemetry envelope. So when no envelope can be written (the default, telemetry off), the guard decides clean content first, with the builtin prefilter thathpp::scan_textalready had. That prefilter now lives inhpp::prefilterand both callers use it. It runs with the project dir as the root. Acleanverdict with a root is alsocleanwithout one, so the verdict holds whichever scan root git would have chosen. On the dirty path, the rev-parse runs as$(exec git …), which saves the extra fork bash adds for a redirected command in a command substitution. Its exit status (127 when git is missing) and its output are unchanged.secrets::any_match(the combined grep thatsecrets::scan_textalready opened with) decides clean content in the parent shell. Thescan_out=$(…)capture subshell now runs only on a hit.secrets::scan_textkeeps its stdout contract forgit-hooks/pre-commit-content.sh.Left in place on purpose:
<(printf …)process substitution in the secret oracle. A here-string deadlocks at the pipe-size boundary (documented inlib/path-detection/hardcoded-path-patterns.sh), andprintf | grep -qunder pipefail turns a hit into a miss.grep -E. Replacing it with a builtin was not attempted.Fix
plugins/guardrails/lib/path-detection/hardcoded-path-patterns.sh: moved the builtin gate out ofhpp::scan_textintohpp::prefilter. The code moved; it was not copied.plugins/guardrails/hooks/hardcoded-path-check.sh: extracts the content earlier, exits early on a clean prefilter when telemetry is off, runsexec gitin the rev-parse captures, and wraps the scan capture in a prefilter check.plugins/guardrails/lib/secret-detection/secret-patterns.sh: addssecrets::any_match, whichsecrets::scan_textnow calls.plugins/guardrails/hooks/secret-pattern-detection.sh:secret_scancallssecrets::any_matchbefore the capture..performance/ratchets.json: ceiling 14 → 7 viapython3 plugins/performance/scripts/ratchet.py propose-tighten --write. The counter's goal text now names the 3 remaining execs. The same run also proposedjs-complexity-share2.54 → 2.04 from this host's lizard. That change is unrelated and was not kept.plugins/guardrails/reference/edit-write-guards/PLAN.md: the table row and the claim paragraph now give the new count..changes/guardrails/fragment, patch.Verification
scripts/hook-census.shon the counter's payload:spawns=14 creations=9 execs=5before,spawns=7 creations=4 execs=3after. The Edit form of the payload also measures 7.ratchet.py check:spawns=7 = ceiling. Host versions: bash 5.3.9, dash as sh, git 2.53.0, strace 6.19..claude/hookspathscripts/check-affected.sh --testson the committed head: 13 passed, 3 skipped.hooks/hooks.jsonis untouched and nothing isasync.Related
🤖 Generated with Claude Code