Repository navigation
perf(autonomy): test the lane-stop gate's arming before buffering stdin - #2861
Conversation
`plugins/autonomy/hooks/lane-stop-gate.sh` buffered the entire `Stop` payload and only then tested whether the gate was armed at all. An unarmed session — the interactive default, which cannot produce a gate decision no matter what the payload contains — therefore paid the full bounded stdin read against the registration's 15s budget for a guaranteed no-op. The change is a pure reordering: the `gate_maybe_configured` definition and its `|| exit 0` call now sit above the `hook::buffer_stdin` assignment. Why it is safe. `gate_maybe_configured` references `$INPUT` nowhere. Its whole body is two environment presence tests and two `grep -q lane_stop_gate` passes over the files `gate_user_settings_file` / `gate_managed_settings_files` resolve. Both helpers come from `lane-stop-gate-lib.sh`, sourced near the top of the script, and both derive from the `GATE_*` globals `gate_resolve_install` establishes above the moved block — so every dependency the block has is still in scope at its new position, and nothing is established between the old and new positions that it needs. Everything payload-derived stays exactly where it was, below the buffer: `hook::require_jq`, `EVENT`, `SESSION_ID`, and the `SubagentStop`-versus-`Stop` discrimination. The comment above the pre-filter already stated the cheap-exit intent; it is updated to say the exit is stdin-free as well as jq-free, and to record the boundary so a later edit does not undo the ordering. Two cases pin both halves of the contract by binding the hook's stdin to a regular file on fd 3 rather than a pipe and reading back, on that same shared file description, what the hook left unconsumed. Case 47: an unarmed session exits 0 with the whole payload still unread. Case 48: an armed session still drains stdin and still returns `decision: block`, proving the payload reads remain below the buffer. Case 47 was confirmed to FAIL against the pre-fix ordering (leftover 0 of 148 bytes) and pass after; case 48 passes under both, which is what makes it the no-behavior-change control. Verified locally: the plugin's own test file (89 pass, 0 fail), `check-changelog-parity.sh --check/--check-order/--check-bump/--check-preserved`, `validate-plugins.sh`, `check-shell-portability.sh --paths`, shellcheck, and markdownlint-cli2 on the CHANGELOG. Closes #2852 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01RPRAvSLuRmR6rPQeCvdok6
|
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 finished @kyle-sexton's task in 1m 31s —— View job Security review (
|
|
Last security-reviewed head: |
|
Claude finished @kyle-sexton's task in 3m 22s —— View job Claude PR Review
SummaryReviewed all four changed files ( Verified claims:
Note on verification: this review lane's No findings to report — I'm not filing any inline comments since I found nothing to anchor them to. |
Fresh-eyes review of the reorder found the new comment over-inclusive: it said both settings-file locators derive from the `GATE_*` globals, but only `gate_user_settings_file` does (via `GATE_CONFIG_ROOT`). `gate_managed_settings_files` depends on nothing but `uname -s` and fixed absolute paths, so a future editor reading that sentence would look for a dependency that is not there. Named each locator's actual dependency instead, in the hook comment and in the CHANGELOG entry's matching clause. Also drops `probe_run`'s documented-but-unexercised `[KEY=VAL ...]` tail: neither case passes an extra, and an unused passthrough in a test helper is surface that invites a caller the cases do not cover. No behavior change. The suite still reports PASS=89 FAIL=0 against the fixed hook, and the discriminating case still FAILs against a byte-identical reproduction of the pre-fix ordering (leftover 0 of 148 bytes). Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01RPRAvSLuRmR6rPQeCvdok6
|
Claude finished @kyle-sexton's task in 1m 1s —— View job Security review (
|
|
Claude has reviewed this PR 2 times. The lane skips further automatic reviews after 5; deleting this comment resets the count. |
|
Claude finished @kyle-sexton's task in 2m 59s —— View job Code review (
|
Resolves the autonomy CHANGELOG collision: main shipped 0.22.2 (#2861), so this branch's simplification entry moves to 0.22.3 and the manifest is re-bumped to match.
Summary
plugins/autonomy/hooks/lane-stop-gate.shbuffered the entireStoppayload and only thentested whether the lane gate was armed at all. An unarmed session — the interactive default,
which cannot produce a gate decision no matter what the payload contains — paid the full
bounded stdin read against the registration's 15s budget for a guaranteed no-op.
This is a pure reordering: the
gate_maybe_configureddefinition and its|| exit 0call nowsit above the
hook::buffer_stdinassignment.Why the reorder is safe
gate_maybe_configuredreferences$INPUTnowhere. Its whole body is two environmentpresence tests (
..._ARM_ID,..._ENABLED) and twogrep -q lane_stop_gatepasses over thefiles
gate_user_settings_file/gate_managed_settings_filesresolve.lane-stop-gate-lib.sh, sourced near the top of the script, and bothderive from the
GATE_*globalsgate_resolve_installestablishes above the moved block.Every dependency the block has is in scope at its new position; nothing it needs is
established between the old and new positions (that span is the
STARTstamp and theemit_teldefinition only).hook::require_jq,EVENT,SESSION_ID, and theSubagentStop-versus-Stopdiscrimination.The comment above the pre-filter already stated the cheap-exit intent; it now says the exit is
stdin-free as well as jq-free, and records the boundary so a later edit does not undo it.
Tests
Two cases pin both halves of the contract by binding the hook's stdin to a regular file on
fd 3 rather than a pipe, then reading back — on that same shared open file description —
what the hook left unconsumed. The leftover byte count is the only observation that separates
the two orderings, since both exit 0 on an unarmed session.
ARM_ID, no env enable claim, no settings file, nolane_stop_gatestring anywhere the helpers resolve): exits 0 with the whole payload stillunread.
returns
decision: block, proving the payload reads remain below the buffer.Case 47 was confirmed to FAIL against the pre-fix ordering (leftover 0 of 148 bytes) and
pass after — the pre-fix hook was reproduced byte-for-byte from
origin/mainin a scratch treeand the new suite run against it, yielding exactly one failure. Case 48 passes under both
orderings, which is what makes it the no-behavior-change control. Neither case has a skip
branch.
Verification
Run locally on the rebased head:
bash plugins/autonomy/hooks/lane-stop-gate.test.sh— PASS=89 FAIL=0bash scripts/check-changelog-parity.sh --check/--check-order/--check-bump origin/main/--check-preserved origin/mainbash scripts/validate-plugins.shbash scripts/check-shell-portability.sh --pathson both touched shell filesshellcheck --rcfile=.shellcheckrcon both touched shell filesnpx --no-install markdownlint-cli2 plugins/autonomy/CHANGELOG.md— 0 errorsbash scripts/check-silent-skips.sh,check-discriminating-test-skips.sh,check-drive-root-litter.shScope
Four files: the hook, its test file,
plugins/autonomy/CHANGELOG.md, and the plugin manifestversion (
0.22.1→0.22.2). No change tohook::buffer_stdinorhook-utils.sh, and no"shell": "bash"pin on theStopregistration — the issue scopes both out.Related
docs/conventions/hook-budget/README.mdadopted the ≤ 500 ms per-turn ceilingfor always-on
Stop-shaped hooks that this hook's unarmed path was spending against.hook-utils: a repo env block can disable every hook by starving the stdin readtimeout) — adjacent, about the read itself rather than its placement. Not a duplicate; this
PR touches neither
hook::buffer_stdinnorhook-utils.sh.here was re-read from
origin/maincontent today, and this branch was rebased onto thecurrent tip (
2d20a2774424d88e9eb95425fab830d9a6e1f1c7) rather than the tip it was firstbranched from.