Skip to content

perf(autonomy): test the lane-stop gate's arming before buffering stdin - #2861

Merged
kyle-sexton merged 2 commits into
mainfrom
fix/2852-lane-stop-gate-order
Aug 16, 2026
Merged

kyle-sexton merged 2 commits into
mainfrom
fix/2852-lane-stop-gate-order

Conversation

@kyle-sexton

Copy link
Copy Markdown
Member

Summary

plugins/autonomy/hooks/lane-stop-gate.sh buffered the entire Stop payload and only then
tested 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_configured definition and its || exit 0 call now
sit above the hook::buffer_stdin assignment.

Why the reorder is safe

  • gate_maybe_configured references $INPUT nowhere. Its whole body is two environment
    presence tests (..._ARM_ID, ..._ENABLED) 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.
    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 START stamp and the
    emit_tel definition only).
  • 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 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.

  • Case 47 — unarmed (no ARM_ID, no env enable claim, no settings file, no
    lane_stop_gate string anywhere the helpers resolve): exits 0 with the whole payload still
    unread
    .
  • Case 48 — armed via the trusted user-settings channel: 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 — the pre-fix hook was reproduced byte-for-byte from origin/main in a scratch tree
and 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=0
  • bash scripts/check-changelog-parity.sh --check / --check-order / --check-bump origin/main /
    --check-preserved origin/main
  • bash scripts/validate-plugins.sh
  • bash scripts/check-shell-portability.sh --paths on both touched shell files
  • shellcheck --rcfile=.shellcheckrc on both touched shell files
  • npx --no-install markdownlint-cli2 plugins/autonomy/CHANGELOG.md — 0 errors
  • bash scripts/check-silent-skips.sh, check-discriminating-test-skips.sh,
    check-drive-root-litter.sh

Scope

Four files: the hook, its test file, plugins/autonomy/CHANGELOG.md, and the plugin manifest
version (0.22.1 → 0.22.2). No change to hook::buffer_stdin or hook-utils.sh, and no
"shell": "bash" pin on the Stop registration — the issue scopes both out.

Related

  • Closes autonomy: lane-stop-gate.sh buffers stdin before testing whether the gate is armed, so an unarmed session pays the full Stop-hook cost for a guaranteed no-op #2852
  • Issue 1809 — docs/conventions/hook-budget/README.md adopted the ≤ 500 ms per-turn ceiling
    for always-on Stop-shaped hooks that this hook's unarmed path was spending against.
  • Issue 1883 (hook-utils: a repo env block can disable every hook by starving the stdin read
    timeout) — adjacent, about the read itself rather than its placement. Not a duplicate; this
    PR touches neither hook::buffer_stdin nor hook-utils.sh.
  • Issue 2691 — merged fixes silently reverted by stale-base squash merges. Every line cited
    here was re-read from origin/main content today, and this branch was rebased onto the
    current tip (2d20a2774424d88e9eb95425fab830d9a6e1f1c7) rather than the tip it was first
    branched from.

`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
@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 1m 31s —— View job


Security review (/review:security-review)

Task list

  • Gather context (PR body, changed files)
  • Understand request (custom instructions direct a /review:security-review run)
  • Invoke /review:security-review skill instructions (fetched plugins/review/skills/security-review/SKILL.md directly and followed it — the Skill tool call itself errored on review:security-review in this environment, so I read and applied the skill file's procedure manually)
  • Review the diff (git diff origin/main...HEAD) across all 4 changed files for security-relevant surface
  • Post findings

Scope reviewed

  • plugins/autonomy/hooks/lane-stop-gate.sh — the reorder itself
  • plugins/autonomy/hooks/lane-stop-gate.test.sh — the two new stdin-probe cases
  • plugins/autonomy/CHANGELOG.md, plugins/autonomy/.claude-plugin/plugin.json — no security surface

Findings

No security issues found.

This is a pure statement reordering in lane-stop-gate.sh: gate_maybe_configured/gate_maybe_configured || exit 0 (lines 105–133) now execute before INPUT=$(hook::buffer_stdin) || exit 0 (lines 135–137). I checked this specifically against the trust-boundary concerns this hook documents (per its own #1784 header comment: env-channel ENABLED/ARM_ID are untrusted and only ever gate whether to evaluate, never what the verdict is):

  • gate_maybe_configured reads only CLAUDE_PLUGIN_OPTION_LANE_STOP_GATE_ARM_ID/_ENABLED (untrusted-channel presence checks, not values) and greps gate_user_settings_file() / gate_managed_settings_files() — both resolved from GATE_* globals that gate_resolve_install (line 84) already establishes before either the old or new position of this block. No dependency ordering changed.
  • It references $INPUT nowhere, so moving it above the buffered stdin read introduces no new trust-boundary crossing — the payload-derived data (hook::require_jq, EVENT, SESSION_ID, sentinel/marker parsing) all remain below the buffer, unchanged.
  • The early exit on an unarmed session no longer draining stdin does not create a hang/DoS risk: the hook process exits immediately, closing the read end, so a caller blocked mid-write would get EPIPE/SIGPIPE rather than blocking forever.
  • No new file paths, external inputs, command construction, or privilege-relevant logic were introduced — this is scoped exactly to moving two existing statements relative to each other.

The new test cases in lane-stop-gate.test.sh (fd-3-bound regular-file stdin, leftover-byte comparison) are test-harness-only code with no injection surface (no shell interpolation of untrusted data into commands).

CHANGELOG.md and plugin.json are documentation/version-only changes with no security surface.

--- · Branch: fix/2852-lane-stop-gate-order

@github-actions

github-actions Bot commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

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

@claude

claude Bot commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

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


Claude PR Review

  • Gather context (PR body, diff, changed files)
  • Understand the request (code review per /review:code-review)
  • Read changed files in full
  • Run test suite / verification scripts locally
  • Analyze correctness of the reordering
  • Post findings (inline + summary)

Summary

Reviewed all four changed files (lane-stop-gate.sh, lane-stop-gate.test.sh, CHANGELOG.md, plugin.json) against origin/main. No correctness issues found — this is a clean, well-scoped reordering with strong test coverage.

Verified claims:

  • gate_maybe_configured() (lane-stop-gate.sh#L120-L132) references $INPUT nowhere — it's two env-presence tests plus gate_user_settings_file/gate_managed_settings_files calls, both of which resolve purely from GATE_CONFIG_ROOT/GATE_PLUGIN_ID/GATE_PLUGIN_NAME (lane-stop-gate-lib.sh#L50-L89). Those globals are set by gate_resolve_install at lane-stop-gate.sh#L84, which is unchanged and still sits above the moved block. The span between the old and new position of the block is only the START stamp and emit_tel definition, neither of which the block depends on. The reorder is safe as claimed.
  • Everything payload-derived (hook::require_jq, EVENT, SESSION_ID, the SubagentStop/Stop split) correctly remains below hook::buffer_stdin, unchanged.
  • Checked whether skipping the stdin read entirely for unarmed sessions could cause a broken-pipe/blocked-writer issue upstream (Claude Code writing a large Stop payload to a hook that exits without draining it). This exact pattern — an env/config check gating entry to hook::buffer_stdin — already exists elsewhere in this codebase (e.g. plugins/guardrails/hooks/workflow-resilience-check.sh:26,37 and flag-commit-pr-skill-bypass.sh:61,80), so this isn't a new risk class introduced by this PR.
  • The new test cases (47/48 in lane-stop-gate.test.sh) use a sound technique: binding stdin to a regular file on fd 3, running the hook with 0<&3, then reading the leftover on the same shared open-file-description via cat <&3. Since fd 3 is freshly opened per probe_run call (offset reset to 0 each time), case 48 reusing PROBE_PAYLOAD after case 47 is not a leakage risk. Case 47 (unarmed → payload fully unread) and case 48 (armed → payload still drained, still blocks) correctly isolate the one behavior that changed from the one that didn't.
  • CHANGELOG.md and plugin.json version bump (0.22.1 → 0.22.2) are consistent with the repo's existing changelog format and scoped correctly; no other file in the repo pins autonomy's version, so nothing else needs updating.

Note on verification: this review lane's Bash tool required approval for actual script execution (bash lane-stop-gate.test.sh, etc.), which wasn't grantable in this session, so I verified via careful static reading of lane-stop-gate.sh, lane-stop-gate-lib.sh, and the test file rather than re-running the suite. The author's reported local results (PASS=89 FAIL=0, confirmed-failing-on-pre-fix-ordering for case 47) are consistent with what the code does on inspection.

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

claude Bot commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

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


Security review (/review:security-review)

Task list

  • Gather context (PR body, comments, changed files)
  • Understand request (custom instructions direct a /review:security-review run for HEAD 317c0a2)
  • Invoke /review:security-review skill instructions (fetched plugins/review/skills/security-review/SKILL.md directly and followed it — the Skill tool call itself errored on review:security-review in this environment, same as the prior run)
  • Review the diff since the last security-reviewed head (60b057b → 317c0a2)
  • Post findings

Skip gate

Per the skill's skip gate, condition 3 applies: this head does not introduce any new security-relevant surface beyond what a prior successful review on this branch already covered.

The relevance gate scopes this run to commits since the last security-reviewed head (60b057bd0d77ba0c35d22ec35d6d577bd18cb5de). The only commit added since then is 317c0a2 ("narrow the pre-filter comment to the real dependency set"), and its diff is entirely non-functional:

This confirms rather than changes the trust-boundary reasoning from the prior review (job 31940555791): gate_maybe_configured still reads only untrusted-channel presence (..._ARM_ID/..._ENABLED), never values, and the payload-derived reads (hook::require_jq, EVENT, SESSION_ID) remain below hook::buffer_stdin unchanged.

No security issues found. Nothing in the incremental diff, nor in the PR as a whole, introduces new injection surface, trust-boundary crossings, or Actions-permission changes.
· Branch: fix/2852-lane-stop-gate-order

@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.

@claude

claude Bot commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

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


Code review (/review:code-review)

Task list

  • Gather context (PR body, changed files)
  • Understand request (custom instructions direct a /review:code-review run)
  • Invoke /review:code-review skill instructions (read plugins/review/skills/code-review/SKILL.md directly and followed it — the Skill tool call errored on review:code-review in this environment, as it did on the earlier security-review run for this PR)
  • Review the diff (git diff origin/main...HEAD) across all 4 changed files
  • Post findings

Scope reviewed

This is the code-review lane (correctness, design, conventions, error handling, tests, docs). This repo carries a claude-security-review workflow, so per REVIEW.md, security findings are out of scope here — they belong to the security lane, which already reviewed this PR (see the prior Claude comment above, "no security issues found").

Findings

No high-signal findings.

Verified independently (not just restating the PR's claims):

  • Dependency scope of gate_maybe_configured — traced gate_user_settings_file() and gate_managed_settings_files() in lane-stop-gate-lib.sh (lines 138–155ish): neither reads $INPUT, and both derive only from GATE_CONFIG_ROOT, which gate_resolve_install (called at line 84, unchanged position) sets before either the old or new position of the moved block. Confirms the reorder introduces no forward-reference to state established between the old and new positions.
  • Everything payload-derived stays below the buffer — hook::require_jq, EVENT, SESSION_ID, and the SubagentStop/Stop discrimination are all still after INPUT=$(hook::buffer_stdin) at line 139, unchanged from origin/main's relative order.
  • Test harness technique (lane-stop-gate.test.sh lines ~847–863) — the fd-3-bound regular-file stdin + shared-offset leftover read (probe_run) is a sound way to observe "was stdin consumed" independent of process exit code; dup2 semantics guarantee the offset is shared across the fork/exec, so the leftover-byte assertion is a real signal, not a flaky one.
  • Case 47 correctly isolates the unarmed condition (rm -f "$SETTINGS" plus unsetting all four LANE_STOP_GATE_*/CLAUDE_PLUGIN_DATA env vars) before asserting the whole payload is left unread; Case 48 correctly re-arms via the trusted settings file only and asserts both stdin drains and decision:block is still produced — a real control against the reorder silently changing armed-lane behavior.
  • Comment/code stayed in sync: the block comment at L105-121 documents the same boundary the code now enforces, and records the #2852 rationale for a future edit not to undo it.
  • CHANGELOG.md/plugin.json: the 0.22.2 patch bump and changelog stanza are consistent with a behavior-preserving performance fix.

Not independently verified (author-claimed only, per this lane's verification policy): the PASS=89 FAIL=0 local test run, check-changelog-parity.sh, check-shell-portability.sh, shellcheck, and check-silent-skips.sh results cited in the PR's Verification section — this environment's Bash tool required interactive approval to execute the test script and none was available, so I read the test logic itself (above) rather than re-running it.

No inline comments posted — nothing met the high-signal bar (no correctness bug, no convention violation, no missing test coverage for the behavior change).
· Branch: fix/2852-lane-stop-gate-order

@kyle-sexton
kyle-sexton merged commit ad63111 into main Aug 16, 2026
1 check passed
@kyle-sexton
kyle-sexton deleted the fix/2852-lane-stop-gate-order branch August 16, 2026 15:43
kyle-sexton added a commit that referenced this pull request Aug 16, 2026
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.
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