Repository navigation
Description
Summary
Child of #3508. This issue was originally filed against guardrails with shell-oriented criteria. Both were wrong — the hook is disk-hygiene's and it is Python. Corrected below. A fix is already in flight, so this is close to a verify-and-close.
The hook
| Plugin | disk-hygiene |
| Hook | plugins/disk-hygiene/skills/clean/scripts/guard_launch_monitor.py |
| Launcher | plugins/disk-hygiene/hooks/run-python-hook.sh |
| Registration | plugins/disk-hygiene/hooks/hooks.json, Stop event |
| Configured timeout | 20 s |
| Timeouts in window | 52 |
| Average recorded duration | 31.8 s |
Root cause and status
The cost was launcher overhead, not the hook body. run-python-hook.sh re-derived its Python interpreter on every invocation: a sed read of a 3,500-line file, dirname, and an entire extra Python process spawned only to evaluate a sys.version_info >= MIN_PYTHON predicate. Four process spawns per warm call, of which one was the actual work.
Fixed on branch perf/disk-hygiene-guard-hook-spawns (4 spawns -> 1), measured with an interleaved A/B, 24 pairs alternating within one run so the host's ~6x drift hits both arms equally:
BEFORE p50 = 5446 ms p95 = 16991 ms
AFTER p50 = 1418 ms p95 = 7874 ms median paired ratio 3.71x
AFTER min = 124 ms
This hook is fixed as a side effect because it shares that launcher.
The bar it must still meet
docs/conventions/hook-budget/README.md sets the per-turn ceiling for the whole always-on Stop set at <= 500 ms parallel wall — shared with #3512 (claude-ops) and #3515 (autonomy). At AFTER p50 = 1418 ms this hook alone is still ~3x that ceiling, though the remaining wall-clock is dominated by the one irreducible interpreter spawn (AFTER min = 124 ms shows the floor when the host is briefly uncontended).
The convention also notes that interpreter choice is a budget decision — a Python Stop hook spends roughly a third of the whole per-turn budget on interpreter startup alone on the reference host.
Acceptance criteria
- Confirm the timeout count drops after
perf/disk-hygiene-guard-hook-spawnslands. - Spawn count on the warm path is 1, verified by PATH shim.
- Measured share stated in the
disk-hygieneREADME per hook-budget Rule 1. - The always-on per-turn set is re-measured across all three Stop hooks against the 500 ms ceiling, reported with the spawn-cost baseline.
- Validated with
scripts/affected-tests.sh --run.
Close as covered once that PR lands unless the re-measurement shows the per-turn set still over budget.
Note
Criteria in the original body ("collapse jq calls", "replace grep/sed with bash builtins") were written for a shell hook and do not apply to a Python one. The launcher they would apply to is already fixed.
Activity
[-]perf(guardrails): Stop hook: silent destructive-guard failures averages 31.8s and timed out 52x - reduce process spawns[/-][+]perf(disk-hygiene): Stop-event guard_launch_monitor times out 52x via run-python-hook.sh launcher overhead[/+]kyle-sexton commentedon Aug 31, 2026
Misattributed on filing — this is
disk-hygiene, notguardrails. Retitled. It is also already fixed.Corrected by the session that owns the file:
disk-hygiene'sskills/clean/scripts/guard_launch_monitor.py, launched throughdisk-hygiene/hooks/run-python-hook.sh. It is not a guardrails hook.sedread of a 3,500-line file, plus an entire extra Python spawned only to evaluate a version predicate, plusdirname).perf/disk-hygiene-guard-hook-spawns, taking the warm path from 4 process spawns to 1. This hook is fixed as a side effect, since it shares the launcher.Measured on that branch (interleaved A/B, 24 pairs alternating within one run):
Do not work this as a guardrails issue. It should be closed as covered once that PR lands, or kept open only to verify the timeout count drops. Leaving it here rather than closing immediately so the PR can link to it.
kyle-sexton commentedon Sep 6, 2026
Verification: FULLY FIXED on
main. Recommending closure as covered.Independent read-and-report verification against
origin/main@1e1e3bc52fd2fc335ce86fa398d6802893df6a2a. I did not assume the in-flight fix landed; I traced it, read both trees, and measured process creation directly.Which commit did it
PR #3523 (
perf(disk-hygiene): cut the destructive guard's per-call spawns 4 to 1...) merged 2026-08-31T21:57:57Z from head branchperf/disk-hygiene-guard-hook-spawns— the exact branch this issue names. Squash commit5b5c676b, confirmed an ancestor oforigin/mainviagit merge-base --is-ancestor. The branch no longer exists on the remote (git ls-remote --heads origin perf/disk-hygiene-guard-hook-spawnsreturns nothing), which is consistent with a merged-and-deleted branch, not an abandoned one. Shipped indisk-hygiene0.21.0; plugin is now at 0.21.9.Nothing else touched the launcher after it —
git log --followonplugins/disk-hygiene/hooks/run-python-hook.shhas5b5c676bas the most recent change.Claim-by-claim against current
mainorigin/mainsedread of the ~3,500-line engine to recoverMIN_PYTHONPYTHON_VERSION_PROBE, which opens the engine itself and regex-matches^MIN_PYTHON = (d, d)$.hygiene.MIN_PYTHONis still the single origin.run-python-hook.shL~76-90; thesedwas at L51 of5b5c676b^sys.version_info >= MIN_PYTHONsedplus a Python).resolve_python3();PYTHON_VERSION_PROBEat L~76dirname${BASH_SOURCE[0]%/*}) with the$(cd … && pwd)fork kept only for the relative-path spelling, which no registered caller uses —hooks.jsonand the skill frontmatter both pass"${CLAUDE_PLUGIN_ROOT}"/hooks/....run-python-hook.shL~42-50; thedirnamewas at L33 of5b5c676b^$HOME/.cache/disk-hygieneinterpreter cache (schema tag, verbatimPATHcompare,[[ -x ]]/[[ -s ]],-ntmtime check, 24 h TTL) reachesexechaving spawned nothing — every hot-path check is a bash builtin, and helpers report through globals specifically to avoid command-substitution subshells.guard_launch_monitor.pywas not modified by5b5c676b; its last change isdd95c789(#2536).git logon the scriptMeasured, not asserted
strace -f -e trace=clone,clone3,fork,vfork,execveover the real Stop-hook invocation (run-python-hook.sh .../guard_launch_monitor.py --data-root …), old launcher (5b5c676b^) vs.main, same host, same interpreter:The exec'd interpreter replaces the launcher's own bash process (same PID), so the warm path is genuinely one process spawn, the guard itself — the issue's acceptance criterion, met exactly, verified by syscall trace rather than by PATH shim.
Interleaved A/B wall clock, 20 alternating pairs, this Linux container:
Only ~1.38x here, versus the 3.71x median paired ratio reported on the Windows reference host. That gap is expected and does not weaken the result: this host charges ~3 ms for
bash -c true, where the reference host charged 283–1825 ms for the same call. Removing three spawns buys back three times whatever the host charges per spawn, so the direction is identical and the magnitude is a property of the host, which is precisely why #3523 made the spawn census, not a duration, the headline figure. That was the right call.Decomposing the remaining 48 ms on this host: ~3 ms bash, ~13 ms bare CPython startup, ~30 ms
guard_launch_monitor.pybody, ~2 ms launcher. The launcher is no longer a measurable term. Any further work on this hook would be against interpreter startup or the detector body, not the wrapper.Acceptance criteria status
disk-hygieneREADME per hook-budget Rule 1 —plugins/disk-hygiene/README.mdL~240-260 carries the share, the spawn census, and an explicit note that the absolute wall-clock figures were taken under host contention and should be re-measured on a quiet host before being cited.scripts/affected-tests.sh --run— perf(disk-hygiene): cut the destructive guard's per-call spawns 4 to 1, and stop its watchdog blocking commands it never judged #3523 reportstest_hygiene337 tests,GuardTests147,run-python-hook.test.sh32 assertions, ruff and shellcheck clean.Stopset re-measured across all three hooks against the 500 ms ceiling — this is a cross-hook item shared with perf(claude-ops): Stop-event unsurfaced-failure detector times out 113x, ~44x the per-turn hook budget #3512 and perf(autonomy): Stop hook: lane-stop gate averages 27.6s and timed out 73x - reduce process spawns #3515 and belongs to parent perf(hooks): Windows process-creation tax makes the hook set unusable - 1,778 timeouts / 20.6 hours blocked over 9 days #3508, not to this issue.Two things worth recording
One item in the issue body is inaccurate. The
Stophook's own measured share is not stated in the README; what is stated is the PreToolUse engine-gate hook's share (≈ 190–300 ms per tool call) plus the launcher spawn census that both hooks share. Since the fix is in the shared launcher and the census is the durable figure, I read Rule 1 as satisfied — but if a per-hook share for theStopdetector is wanted, that is a small doc follow-up, not a reason to hold this issue open.The 20 s
Stoptimeout is unchanged inhooks.json. Given the reference host's post-fix p50 of 1418 ms and p95 of 7874 ms, that headroom is now adequate, so the 52 timeouts should not recur. The residual concern the issue raises — that 1418 ms is still ~3x the ≤ 500 ms per-turn ceiling — is real, but it is dominated by the one irreducible interpreter spawn on a host charging up to 2.8 s per process launch. That is the interpreter-choice budget question, and it lives at #3508 with the other twoStophooks, where it can be judged against the whole parallel set rather than one hook in isolation.Recommendation
Close #3516 as covered by #3523. The named root cause is verifiably absent from
main, and the acceptance criterion that this issue could actually own — warm-path spawn count of 1 — is met and independently measured. The per-turn budget re-measurement is live but belongs to #3508; closing this one does not drop it.This lane does not close issues. Closure is the triage lane's call. I am reporting evidence and a recommendation only, and I have made no change to any file, branch, or issue state.
Generated by Claude Code
perf(claude-ops): halve hook-failure-audit spawns by moving redirects…
kyle-sexton commentedon Sep 26, 2026
Closing in the backlog-drain close sweep: obsolete. Evidence: PR #3523 merged (guard per-call spawns 4 to 1, watchdog stops blocking); strace verification comment 2026-09-06