Skip to content

perf(disk-hygiene): read the engine once per hook launch and state the measured share - #2869

Merged
kyle-sexton merged 2 commits into
mainfrom
fix/2853-hook-budget-measured-share
Aug 16, 2026
Merged

kyle-sexton merged 2 commits into
mainfrom
fix/2853-hook-budget-measured-share

Conversation

@kyle-sexton

@kyle-sexton kyle-sexton commented Aug 16, 2026 •

Copy link
Copy Markdown
Member

Closes #2853

What

The disk-hygiene half of the hook-budget conformance gap (sibling of the guardrails item, issue 1403 / issue 2663, under the issue 1809 budget adoption):

  • Single, early-terminating engine read per hook launch. The always-on Bash|PowerShell launcher recovered MIN_PYTHON with two separate full-file sed passes over the ~3,500-line engine, neither stopping at the match. It now runs one sed whose address-block q terminates the read at the MIN_PYTHON line. Note the obvious one-liner (s///p;/^MIN_PYTHON/q) does NOT stop — q's address sees the already-substituted pattern space — which is why the block form is used. hygiene.MIN_PYTHON stays the floor's single origin (PR 1028); VersionFloorTests still passes.
  • Behavioral contract test. run-python-hook.test.sh now proves, via a recording sed shim plus an argv replay against a two-floor fixture (first floor (3, 14), last line (9, 99)), that one launch reads the engine exactly once and that the read stops at the first match instead of scanning to EOF. Fixture floors are deliberately not 3/11 so the hardcoded fallback cannot masquerade as a pass.
  • README states the measured share. The trust-surface record's launch-count sentence is replaced with the share measured by the method in docs/conventions/hook-budget/README.md — EPOCHREALTIME wall-clock around direct hook invocation with a benign payload, Windows 11 + Git Bash (the convention's binding host), 2026-08-16: the engine-gate hook costs ~190–300 ms per shell tool call across batches (92 single runs; ~19–30% of the <= 1 s typical per-tool-call ceiling). Per the review thread, the two-registration set (plugin hook + clean skill frontmatter belt) was measured as a concurrent parallel wall (& + wait, 60 pairs): ~320–410 ms, ~1.3–1.5x the same-batch single wall rather than a naive 2x. Of the single-hook cost, the engine read accounts for ~24 ms (~13%) in the single-read form, down from ~38 ms (~19% of a ~205 ms hook) in the two-pass form.
  • hooks.json "timeout": 60 is unchanged, per the issue's third criterion.
  • Version 0.20.13 + CHANGELOG section above main's 0.20.12.

Verification

  • run-python-hook.test.sh: all 17 assertions pass locally (Windows 11 + Git Bash).
  • test_hygiene.VersionFloorTests: 3/3 OK under CPython 3.14.7.
  • shellcheck and markdownlint-cli2 clean; all four changelog-parity checks pass locally.
  • An independent fresh-context verifier re-ran the measurement from scratch (two batches of N=15) and confirmed the README numbers are honest within host noise: full hook 209–216 ms, single read 20–30 ms, two-pass form 44–68 ms. It also confirmed by reasoning over the sed program that the q genuinely fires on the original pattern space.
  • Verifier findings worth recording (both low, future-regression gaps, not present defects): the shim counts only sed readers, so a future launcher that added a second read via cat/awk/stdin-redirected sed would not be caught by the exactly-once assertion; and the stop-at-EOF replay is necessary-but-not-sufficient (a range-addressed 0,/floor/ program would print one line yet read to EOF). The committed program is neither shape.

Related

  • Issue 1809 — adopted the hook budget and deferred the overage to per-plugin items; this PR is the disk-hygiene item.
  • Issue 1403 / issue 2663 — the guardrails sibling item and its completed analogue.
  • PR 1028 — established MIN_PYTHON as the single origin and the sed parse; this PR keeps that contract intact.
  • docs/conventions/hook-budget/README.md — the measurement method and budget this PR conforms to.
  • Issue 2851 (feat/2851-per-child-rollup) — lands after this PR and also touches the disk-hygiene CHANGELOG and manifest; this PR does not touch hygiene.py or its tests.

🤖 Generated with Claude Code

https://claude.ai/code/session_01RPRAvSLuRmR6rPQeCvdok6

…e measured share

Close the disk-hygiene half of the hook-budget conformance gap (issue 2853,
the sibling of guardrails' issue 1403/2663 under the issue 1809 budget
adoption):

- The always-on Bash|PowerShell launcher recovered MIN_PYTHON with two
  separate full-file sed passes over the ~3,500-line engine, neither
  stopping at the match. It now runs one sed whose address-block q
  terminates the read at the MIN_PYTHON line. hygiene.MIN_PYTHON stays the
  floor's single origin (PR 1028); VersionFloorTests' shape/count lock
  still passes.
- run-python-hook.test.sh gains a behavioral contract: a recording sed
  shim proves one launch reads the engine exactly once, and replaying the
  recorded argv against a two-floor fixture proves the read stops at the
  first match instead of scanning to EOF.
- README's trust-surface record replaces the launch-count sentence with
  the share measured by the hook-budget convention's method (2026-08-16,
  Windows 11 + Git Bash, 32 runs per variant): about 190 ms per shell tool
  call for the engine-gate hook, of which the engine read accounts for
  about 24 ms (13 percent) single-read, down from about 38 ms (19 percent)
  two-pass.
- hooks.json "timeout": 60 is unchanged, per the issue's third criterion.

Co-Authored-By: Claude Fable 5 <[email protected]>
@cursor

cursor Bot commented Aug 16, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@claude

claude Bot commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 3m 54s —— View job


Code review complete

  • Gather context (PR diff, changed files, repo guidelines)
  • Understand the request (/review:code-review lane)
  • Review run-python-hook.sh engine-read change
  • Review run-python-hook.test.sh behavioral contract test
  • Review README / CHANGELOG accuracy
  • Post findings (inline + summary)

Scope: correctness and maintainability per REVIEW.md's code-review lane (this repo runs a separate security lane, so security is out of scope here). No blocking or important findings — nothing to post inline.

What I checked

  • plugins/disk-hygiene/hooks/run-python-hook.sh — L53: traced the sed address-block semantics by hand. GNU/POSIX sed evaluates an address against the pattern space at the start of the cycle, before any command inside the matched block runs — so /^MIN_PYTHON = (/{s/.../\1 \2/p;q;} genuinely quits at the first match, while the naive s///p;/^MIN_PYTHON/q one-liner the comment warns against does not (the trailing address sees the already-substituted "3 11", which no longer matches ^MIN_PYTHON). The comment's claim checks out.
    • Confirmed hygiene.py has exactly one ^MIN_PYTHON line (hygiene.py#L26, value (3, 11)), matching the launcher's documented fallback and its grep -c claim.
    • The malformed-line fallback path (empty MIN_PYTHON_FLOOR → default 3 11) behaves identically to the pre-change two-pass form; not a regression.
  • plugins/disk-hygiene/hooks/run-python-hook.test.sh — the recording sed shim, its env-var wiring into the single bash "$LAUNCHER" invocation, and the argv-replay against the two-floor fixture are constructed correctly: swapping only the engine operand in the recorded argv and re-running against a fixture whose second MIN_PYTHON line sits on the final line is a real proof that the read stops at the first match rather than scanning to EOF (a full scan would print two lines, not one). The two trap ... EXIT registrations are correctly noted as "replaces, not chains" and both still clean up $PROBE_DIR even on an early fail-triggered exit.
  • README.md / CHANGELOG.md — the arithmetic is internally consistent (24/190 ≈ 13%, 38/205 ≈ 19%, 190/1000 ≈ 19%, 2×190 = 380), and the measurement method (EPOCHREALTIME, Windows 11 + Git Bash, 32 runs/variant) matches docs/conventions/hook-budget/README.md's stated method and exceeds its ≥10-run minimum.
  • plugin.json/CHANGELOG.md version bump (0.20.12 → 0.20.13) is consistent across both files; hooks.json is untouched, matching the PR's third stated criterion.
  • Per REVIEW.md's always-check list: no high-risk security action needing an audit-log entry, and no multi-location write needing an atomicity mechanism — neither check applies to this diff.

Note: I could not execute the test suite myself (this lane's tools are read-only: Read/Glob/Grep/gh pr diff etc., no general Bash), so the "17 assertions pass locally" and the independent verifier's re-measurement are author-claimed and not independently re-run by me — my review is based on reading the sed semantics and script logic by hand, which checks out.

@claude

claude Bot commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 1m 36s —— View job


Claude finished the security review

  • Gather context (PR diff, files changed)
  • Run /review:security-review per custom instructions
  • Post findings

Security review

Reviewed all 5 changed files (plugins/disk-hygiene/hooks/run-python-hook.sh, hooks/run-python-hook.test.sh, README.md, CHANGELOG.md, .claude-plugin/plugin.json) against origin/main (this PR is a single commit, so the diff against its parent is identical to the PR diff).

No security issues found.

Notes from the review, for the record:

  • The rewritten MIN_PYTHON extraction in run-python-hook.sh#L53 still captures only digit groups (\([0-9]*\)) from a trusted, plugin-bundled file (hygiene.py), so the values interpolated into PYTHON_VERSION_PROBE at L61 can't carry injected Python/shell content — same constraint as the prior two-pass form, unchanged.
  • The empty-match fallback (MIN_PYTHON_MAJOR=3 / MINOR=11 at L57-60) still fails closed to the same floor as before if the read produces nothing.
  • No changes to hooks.json permissions/matchers, no new external command execution, no new untrusted input reaching a shell or sed program — ENGINE is derived from the plugin's own install path, not attacker-influenced.
  • The new test scaffolding in run-python-hook.test.sh (PATH-shimmed sed, temp dirs) is test-only, runs a fixture built from static strings, and isn't part of the shipped hook surface.
  • Doc/version/changelog files carry no executable content of concern.

This lane is scoped to security only (logic flaws, injection, trust-boundary, Actions risk) — no code-quality/style feedback given per this lane's remit; /review:code-review covers that separately.

Branch: fix/2853-hook-budget-measured-share

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6c29742281

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread plugins/disk-hygiene/README.md Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Last security-reviewed head: 6c2974228128c1a307b52d0e9ffeb9c69c7fb1fa. On the next push, the relevance gate compares only the commits since this SHA; delete this comment to force a full re-review.

@github-actions

github-actions Bot commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

Claude has reviewed this PR 2 times. The lane skips further automatic reviews after 5; deleting this comment resets the count.

…current wall

Review follow-up on PR 2869: the hook-budget convention measures matching
hooks as parallel wall (max of the set under spawn contention, launched
with & + wait), not a sum. Replace the naive 2x doubling with the
measured concurrent pair wall (60 pairs, three N=20 batches: about
320-410 ms, about 1.3-1.5x the same-batch single wall) and widen the
single-hook figure to the observed cross-batch range (92 runs, about
190-300 ms).

Co-Authored-By: Claude Fable 5 <[email protected]>
@claude

claude Bot commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 2m 19s —— View job


Code review complete

  • Gather context (PR diff, changed files, repo guidelines)
  • Understand the request (/review:code-review lane)
  • Review run-python-hook.sh engine-read change
  • Review run-python-hook.test.sh behavioral contract test
  • Review README / CHANGELOG accuracy, including the second (docs-only) commit
  • Post findings

Scope: correctness and maintainability per the review:code-review lane (security is scoped to the separate security lane in this repo). No blocking or important findings survive — nothing to post inline.

What changed since the prior review (this run covers head ba7e9b8, which adds one docs-only commit on top of 6c29742, already reviewed):

  • The second commit directly answers the outstanding Codex P2 finding ("measure concurrent hooks instead of doubling their latency"). README.md#L232-235 no longer reports 2 × 190 ms ≈ 380 ms; it now reports a genuine concurrent measurement (& + wait, 60 pairs) of the two-registration set — ≈ 320–410 ms, framed as ≈ 1.3–1.5× the same-batch single-hook wall rather than a naive double. This matches the hook-budget convention's stated method (docs/conventions/hook-budget/README.md lines 13–15, 29–30: "the wall is the max of the set under spawn contention, not the sum"). CHANGELOG.md#L18-25 was updated in lockstep with the same figures — no drift between the two files.
  • Grepped both files for leftover "doubled" language after the edit — none remains; the fix is complete, not partial.
  • Re-checked the arithmetic: 320–410 ms falls inside a plausible 1.3–1.5× band of a 190–300 ms single-hook range when computed same-batch (as the text specifies), and the independent verifier's re-measurement quoted in the PR body (209–216 ms full hook) sits inside the claimed 190–300 ms range — no internal contradiction.

Carried forward from the prior review of 6c29742 (unchanged by this commit, still holds):

  • run-python-hook.sh L53: the address-block sed genuinely quits at the first MIN_PYTHON match (the address is evaluated against the pattern space at cycle start, before s/// mutates it) — traced by hand again, still correct.
  • run-python-hook.test.sh: the recording sed shim + argv replay against the two-floor fixture is a real behavioral proof (a full scan would print two lines, not one), and the two trap ... EXIT registrations (replace, not chain) both still clean up their temp dirs correctly.
  • plugin.json version bump (0.20.12 → 0.20.13) is consistent with the new CHANGELOG section; hooks.json is untouched.

I could not execute the test suite or the measurement script myself (this lane's tools are Read/Glob/Grep/Bash(gh pr diff/view/comment/review) only), so the "17 assertions pass locally" claim and the raw batch measurements behind the ms figures remain author-claimed and unverified by me — my review is based on reading the diff, the sed/shell semantics, and cross-checking the stated numbers for internal consistency, which all check out.
· Branch: fix/2853-hook-budget-measured-share

@kyle-sexton
kyle-sexton merged commit 9d2a0cc into main Aug 16, 2026
1 check passed
@kyle-sexton
kyle-sexton deleted the fix/2853-hook-budget-measured-share branch August 16, 2026 21:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant