You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Guard hooks: no test measures extra database waits on the guard-fired path #416
Found while replacing a flaky timing check in tests/hooks/guard-check.test.ts (the pull request is linked in a comment below). That check asserted that a hook run under a held write lock takes less than a second longer than an unlocked run. It failed at random on hosted macOS runners, three times within two hours (1130 and 1064 ms, then 1025 ms, then 1005 ms over the unlocked run, against the 1000 ms limit), so that pull request replaces it with two checks that read the counter's settings instead of the clock. That leaves one regression class that the old check caught and nothing catches now.
The gap
A second database write on the guard-fired path that waits the general HOOK_BUSY_TIMEOUT_MS (2000 ms), for example a fire ledger or a per-guard cooldown added after recordGuardFires(...) in scripts/hooks/guard-check.js, still exits 0, still prints the warning and still reports the fire as not counted, so every remaining assertion passes. Reproduced with a string write-back mutation of exactly that shape (a swallowed UPDATE on a second connection with busy_timeout = HOOK_BUSY_TIMEOUT_MS):
locked run minus unlocked run: 2502 and 2475 ms (about 250 to 280 ms unmutated);
hook-time-budgets.test.ts misses it because its contention measurements never seed a guard, so the guard-fired branch is never reached, and its guard-check bound is < 15000 ms.
Severity
Latency, not a wrong result: hooks/hooks.json gives guard-check.js and pre-edit-recall.js 5 s each, so one extra 2 s wait leaves the warning intact. Only stacked waits could get the hook killed before it prints.
Direction
Do not bring the 1000 ms bound back: it sat on the noise floor. hook-time-budgets.test.ts already has the technique for this problem: compare against a reference measured in the same run instead of against a constant. Two things to know before extending it: under locking_mode = EXCLUSIVE (what that file uses) readers are blocked, so a seeded guard never fires; the fire path needs the write-lock-only setup of guard-check.test.ts (BEGIN IMMEDIATE, readers still work), plus one reference measurement of what a general-wait write costs under the same held lock on the same machine.
Activity
kevintseng commentedon Sep 22, 2026
The pull request that replaces the timing check is #417. Everything above about it stays as written; the residual gap is what this issue tracks.
kevintseng commentedon Dec 2, 2026
The guard regression traces database writes under lock contention and checks the short counter timeout. Verified on the open PR #650.