Skip to content

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

Closed

Description

@kyle-sexton

Severity carried: High (fleet-stop-hooks S-5) — uncalibrated. Carried through from the
source audit unchanged; this issue re-grades nothing.

All file:line citations below were re-read from origin/main at
2de57a3798489d2c205fa21d3233b70fec5a42c9 on 2026-08-16.

Problem

plugins/autonomy/hooks/lane-stop-gate.sh reads and buffers the entire Stop payload before it
tests whether the lane gate is armed at all. The arm test needs no payload — it is two environment
reads and two grep passes over settings files. So a session with no gate footprint (the interactive
default) pays the full buffered-stdin cost for a guaranteed no-op.

The fix is a pure reordering, and the author already stated the intent it fails to implement.

Evidence

The read, the arm test, and the first payload consumer, in file order:

:107   INPUT=$(hook::buffer_stdin) || exit 0
:116   gate_maybe_configured() {            <- definition ...
:128   }
:129   gate_maybe_configured || exit 0      <- ... and call, both belong ABOVE :107
:134   hook::require_jq "Stop" "autonomy-lane-stop-gate" "$INPUT"   <- first payload consumer

The cheap-exit intent is already stated in the source. The comment at :109-115, verbatim:

jq-free pre-filter: is the gate plausibly configured anywhere this host could
honor — or at least CLAIMED, which must produce the visible notice below
rather than silence? Sessions with no gate footprint at all (the interactive
default) exit here, before the jq gate, so a jq-less machine never sees a
lane-stop-gate notice for a session that never opted in. The env presence
tests grant no authority: a hit only routes into evaluation, where the
trusted sources decide.

Only the placement contradicts it: the pre-filter is jq-free, but it is not stdin-free, because the
buffer already ran two lines above.

The reorder is provably safe from the callee's own body. gate_maybe_configured (:116-128)
references $INPUT nowhere. Its whole body is:

  • [[ -n "${CLAUDE_PLUGIN_OPTION_LANE_STOP_GATE_ARM_ID:-}" ]] (:117)
  • [[ -n "${CLAUDE_PLUGIN_OPTION_LANE_STOP_GATE_ENABLED:-}" ]] (:118)
  • grep -q lane_stop_gate over gate_user_settings_file (:120-122)
  • grep -q lane_stop_gate over each gate_managed_settings_files entry (:123-126)

Both helpers are defined in plugins/autonomy/hooks/lane-stop-gate-lib.sh (:138 and :155), which
lane-stop-gate.sh sources at :82 — already in scope above :107. Nothing the moved block needs is
established between :107 and :116; lines :108-115 are comment only.

The boundary, so nobody moves too much. $INPUT is first consumed at :134 and then at :140,
:143, :297, :305, :331, :435, :458, :466. Everything from :134 down stays below the
buffer. In particular the SubagentStop-versus-Stop discrimination at :140-141 is payload-derived
and must not move.

The budget it spends. plugins/autonomy/hooks/hooks.json:9 declares "timeout": 15 on the Stop
registration.

Why the current behavior is wrong

The ordering makes the maximum-cost path the one taken by the sessions that get zero function from it.
An unarmed session cannot produce a gate decision no matter what the payload contains, so reading the
payload buys nothing — and the read is charged against a 15 s Stop budget on every turn.

Exhausting that budget is not merely slow. Per the Claude Code hooks reference, raw markdown fetched
with curl from https://code.claude.com/docs/en/hooks.md on 2026-08-16 (HTTP/1.1 200,
Content-Type: text/markdown, 272,682 bytes, 3,436 lines), line 817:

A command, http, or mcp_tool hook that reaches its timeout is canceled:
Claude Code discards the hook's output, and the hook renders no decision.

So the cost is paid on the no-op path, and when the budget runs out the armed path loses its decision
too.

Non-gating observation, carried and not re-derived today. Audit packet
fleet-stop-hooks/20260814T180441Z recorded 8 autonomy Stop completions with 0 successful,
all cancelled at 16.4–21.2 s against the 15 s budget. That figure is corpus-wide across six sessions
on one Windows 11 + Git Bash host, taken while other Claude Code sessions were concurrently mutating
the same filesystem, so wall-clock may reflect contention rather than this hook's cost. It is stated
as motivation only — it is not the basis of any criterion below, and it should not be quoted as a
benchmark. The structural defect is readable from source without it.

Acceptance criteria

  • In plugins/autonomy/hooks/lane-stop-gate.sh, the gate_maybe_configured definition and its
    || exit 0 call both sit above the hook::buffer_stdin assignment, and the
    hook::require_jq / EVENT / SESSION_ID reads all remain below it.
  • A test asserts that with no arming path set — CLAUDE_PLUGIN_OPTION_LANE_STOP_GATE_ARM_ID and
    ..._ENABLED unset, and no lane_stop_gate string in the user or managed settings files the
    helpers resolve — the hook exits 0 without consuming stdin.
  • A test asserts an armed session still reaches the payload reads, so the reorder is proven not to
    have changed armed-lane behavior.

Out of scope

  • Any change to hook::buffer_stdin itself or to the shared hook-utils.sh. This PR touches one file.
  • Pinning "shell": "bash" on the autonomy Stop registration — a separate latent
    Windows-without-Git-Bash defect, separate unit.
  • No timing threshold is proposed as a gate. Durations on the observed host are confounded by
    concurrent sessions and by Windows process-spawn cost; the criteria above are mechanism-scoped for
    that reason.

Related

  • docs/conventions/hook-budget/README.md — the budget table at :20 sets a ≤ 500 ms per-turn
    ceiling for always-on Stop-shaped hooks. This hook's registered budget is 15 s and its unarmed
    path spends part of it for nothing. Budget adopted in issue 1809.
  • Issue 2691 — merged fixes silently reverted by stale-base squash merges, CI green, issues left
    closed as completed. The citations in this issue were re-read from origin/main content today
    rather than trusted from any issue's closure state, and the defect is live at the tip above
    whatever prior work was filed against this file.
  • Issue 1883 (hook-utils: a repo env block can disable every hook by starving the stdin read
    timeout) — adjacent, and about the read itself rather than its placement. Not a duplicate.
  • Windows-observed only. No Linux behavior is asserted anywhere in this issue.

Activity

  1. added
    needs-triage
    on Aug 16, 2026
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