Skip to content

disk-hygiene: the always-on Bash|PowerShell PreToolUse gate states no measured share in its README, and its launcher scans the 3,498-line engine twice per shell call #2853

Closed

Description

@kyle-sexton

Severity carried: High (disk-hygiene-hooks F5) — uncalibrated, carried from the source audit
unchanged. All file:line citations were re-read from origin/main at
2de57a3798489d2c205fa21d3233b70fec5a42c9 on 2026-08-16.

Problem

disk-hygiene registers an always-on PreToolUse hook on every shell tool call and states no
measured share for it in its README
, which the repo's own hook-budget convention requires. That is a
conformance gap, not a stopwatch argument — checkable by reading two files. Underneath it sits a
concrete, source-readable cost the accounting would have surfaced: the launcher scans the 3,498-line
engine twice per invocation to recover one constant that lives on line 26.

Evidence — the conformance gap

docs/conventions/hook-budget/README.md:41-42, verbatim:

  1. A plugin adding or widening an always-on hook states its measured share (method above) in
    its README, and the change's review weighs that share against the headroom left in the budget.

plugins/disk-hygiene/README.md:227-228 is where the plugin accounts for that hook, verbatim:

did during active cleanup. Known costs, accepted: one launcher shell plus one Python launch per
Bash/PowerShell call, and on a machine where no Python 3 interpreter resolves at all the gate fails

A count of launches, no measured figure. Absence claim, scoped to the file searched:
grep -ciE 'hook.budget|measured share|[0-9]+ ?ms\b|parallel wall' over
plugins/disk-hygiene/README.md (378 lines, origin/main) returns 0. No claim is made about any
other file.

The missing number already exists. Issue 1809's decision comment, which adopted the budget, carries
it in its own measurement table:

| disk-hygiene engine-gate solo / Stop detector | ~135 ms / ~280 ms per turn |

and states the remediation model:

The current Bash|PowerShell lane exceeds the budget ~3–6×; the overage becomes per-plugin work items
(guardrails spawn-reduction is already tracked in #1403) — a reason to fix the members, never to
relax the ceiling.

Guardrails got its work item under that decision (issue 1403; delivered as issue 2663, the completed
analogue). disk-hygiene never got one. This is the missing sibling item, not a re-litigation.

Evidence — what the always-on registration fires on

plugins/disk-hygiene/hooks/hooks.json: PreToolUse array :3-15, registration object :4-14,
matcher "Bash|PowerShell" at :5, "shell": "bash" at :10, "timeout": 60 at :11.
grep -c '"if"' over that file returns 0 — no condition anywhere, so it fires on every Bash and
PowerShell tool call in every session where the plugin is installed.
plugins/disk-hygiene/skills/clean/SKILL.md frontmatter carries a second Bash|PowerShell
PreToolUse registration at :6-9. Both are deliberate and documented; this issue does not propose
changing that design, but while the clean skill is loaded the launcher runs twice per shell call,
doubling every per-invocation figure below.

Evidence — the per-invocation launcher cost

plugins/disk-hygiene/hooks/run-python-hook.sh (107 lines) builds $ENGINE at :34, then at :35-36
runs two separate full-file sed passes over it purely to recover MIN_PYTHON:

MIN_PYTHON_MAJOR="$(sed -n 's/^MIN_PYTHON = (\([0-9]*\), \([0-9]*\)).*/\1/p' "$ENGINE")"
MIN_PYTHON_MINOR="$(sed -n 's/^MIN_PYTHON = (\([0-9]*\), \([0-9]*\)).*/\2/p' "$ENGINE")"

Interpreter resolution then reaches two command -v sites (:73, inside a two-candidate loop over
python3 python, and :83 for py) and three interpreter-startup probe sites (:77, inside that
same loop, plus :84 and :85) before :107 execs the guard.

Executed against the origin/main copy of the engine:

$ wc -l engine.txt ; wc -c engine.txt
3498
140771
$ grep -c '^MIN_PYTHON' engine.txt
1
$ grep -n '^MIN_PYTHON' engine.txt
26:MIN_PYTHON = (3, 11)

Neither sed stops at the match, so each pass scans all 3,498 lines: 6,996 lines and 281,542 bytes
read per launch
to fetch a value on line 26 — doubled again while the clean skill is loaded. That
count is deterministic and platform-independent, so no timing claim is needed to establish it and none
is made here. Quantifying the wall-clock share is what the first acceptance criterion asks for, by the
convention's own method.

This refines a merged SSOT decision rather than reversing it. The sed parse exists so the version
floor has one origin (PR 1028), and the constant's line shape is locked by
plugins/disk-hygiene/skills/clean/scripts/test_hygiene.py:2350
(r"^MIN_PYTHON = \((\d+), (\d+)\)$"). A single pass with an early exit —
sed -n 's/^MIN_PYTHON = (\([0-9]*\), \([0-9]*\)).*/\1 \2/p;/^MIN_PYTHON/q', which returns 3 11 and
stops at line 26 — keeps the origin, the regex contract and that test intact. The grep -c = 1 above
is what makes the early exit safe.

Why the current behavior is wrong

The convention exists because nobody sums the always-on set and the consumer pays the sum. A plugin
that widened the always-on lane and recorded "one launcher shell plus one Python launch" instead of a
measured share makes Rule 1's headroom check impossible to perform — there is nothing to weigh. And
the un-measured share turns out to contain a double full scan of a 140,771-byte file, on a path most
sessions never benefit from because most sessions never invoke the plugin.

Acceptance criteria

  • plugins/disk-hygiene/README.md states the plugin's measured share of the always-on
    per-tool-call budget by the method in docs/conventions/hook-budget/README.md, with the host and
    date it was measured on — replacing the launch-count sentence at :227-228.
  • A test asserts a single hook launch performs at most one read of the engine file and that the
    read stops at the MIN_PYTHON line rather than scanning to EOF, so the two-pass form cannot
    return unnoticed. MIN_PYTHON remains the single origin and test_hygiene.py:2350 still passes.
  • "timeout": 60 at hooks.json:11 is unchanged. It is a 10× reduction, not a cost: per the
    hooks reference fetched as raw markdown on 2026-08-16 (text/markdown, 272,682 bytes), line 422
    gives the command-hook default as 600 seconds.

Out of scope

  • Narrowing the matcher. An if clause would drop the no-marker branch of _engine_gate_relevant,
    which catches an alias of the bundled engine invoked under another name. A first-stage shell filter
    that exits before starting Python may be better, but either way it is a coverage tradeoff in its own
    PR.
  • Defaulting the plugin-scope registration off behind a userConfig boolean — a product decision.
  • The two-registration design itself: documented, deliberate, not challenged here.

Related

  • Issue 1809 — adopted the budget and deferred the overage to per-plugin items; this is the
    disk-hygiene one. Issue 1403 / issue 2663 are the guardrails sibling and its completed analogue,
    precedent that this class of item lands.
  • PR 1028 — established MIN_PYTHON as the single origin and the sed parse; this issue keeps that
    contract intact.
  • Issue 2691 — stale-base squash merges silently reverted merged fixes with CI green and issues left
    closed as completed. Every citation here is from origin/main content today, not from closure state.
  • Windows-observed only. No Linux behavior is asserted anywhere in this issue.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-triage

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions