Skip to content

guardrails: all guards run after a block, and the README does not document the PowerShell over-blocks #4236

Closed

Description

@kyle-sexton

Problem

Session: Windows 11, Claude Code 2.1.278, auto mode, guardrails 0.35.0, PowerShell lane.

Root cause

Traced by reading the installed source; not executed (the audit session's Bash tool was blocked by another plugin, so nothing was profiled and packet integrity is ungradable).

F5. The dispatcher runs every guard after a block.

  • run-guards.sh lines 367-393: run_from sources every remaining guard after one exits 2. The code only raises RC (lines 346-347) and never stops early.
  • On the PowerShell lane, 8 guards run, and the ps-command.sh library is sourced once per event (lines 126-131). That is 2300+ lines of bash parsed on every PowerShell call.
  • RUN_GUARDS_PROFILE=1 (lines 340-345) is the built-in way to measure. Not run.

F6. README gap.

Related: #3508, #3623 (hook performance).

Proposed fix

Cheapest first:

  1. README, block-hook-bypass section: & $var script arg1 arg2 (a call through a variable followed by two or more positionals with at least one bare word) is blocked as a file write. Rewrite it as & 'C:/literal/path.exe' script args, or put a flag first.
  2. README, PowerShell sink section: a foreach { git ... } loop is refused by the git guards regardless of verb. Unroll it into flat git -C <path> ...; statements.
  3. Profile the allow path with RUN_GUARDS_PROFILE=1 on a Windows host to confirm or refute the per-call cost.
  4. Stop after the first block. This removes duplicate denial paragraphs and saves time on the block path. Weigh it against losing all reasons in one denial.

Acceptance criteria

  • README's block-hook-bypass section documents the & $var positional rule and the literal-path rewrite.
  • README's PowerShell sink section documents the {} / () git refusal and the unrolled-statement rewrite.
  • A command blocked by two guards produces at most one full-length denial paragraph.
  • A RUN_GUARDS_PROFILE=1 measurement of the PowerShell allow path on Windows is recorded in the issue or the README.

Found by /plugin-quality:audit (run 20260919T170952Z).

Activity

  1. added
    needs-triage
    on Sep 19, 2026
  2. added
    agent-ready
    status: ready
    and removed
    needs-triage
    on Sep 23, 2026
  3. kyle-sexton commented on Sep 23, 2026

    @kyle-sexton
    MemberAuthor

    This was generated by AI during triage.

    Decision defaulted: keep run-guards.sh running the full remaining chain after a block (a multi-reason denial is worth more to the operator than the perf save on an already-failing path); ship the two README additions (owned by #4234/#4235 respectively) and a RUN_GUARDS_PROFILE=1 measurement as the uncontroversial part — veto before merge

  4. added theissue type on Sep 23, 2026
  5. kyle-sexton commented on Sep 23, 2026

    @kyle-sexton
    MemberAuthor

    This was generated by AI during triage.

    Agent Brief

    Type: Task
    Summary: The guard dispatcher keeps running every remaining guard after one has already blocked a command, and the plugin's documentation does not yet describe two known PowerShell over-block classes or their rewrites.

    Current behavior:
    Once any guard in the dispatcher's chain exits with a block, the dispatcher still runs every remaining guard in the chain before finishing, rather than stopping at the first block. On the PowerShell lane this means a blocked command can produce multiple long denial paragraphs, one per guard that also objects, and pays the parsing cost of every remaining guard's library on a call that is already refused. Separately, the plugin's documentation does not describe the call-through-a-variable positional-operand block or its literal-path rewrite, nor the read-only-git-inside-grouping block or its unrolled-statement rewrite.

    Desired behavior:
    Defaulted decision: keep the dispatcher running the full remaining guard chain after a block — a multi-reason denial is judged more valuable to the operator than the time saved on a path that is already failing, so this is not changed. Ship the two documentation additions instead: a section describing the call-through-a-variable positional-operand rule and its literal-path (or flag-first) rewrite, and a section describing the brace/parenthesis grouping git refusal and its unrolled-flat-statement rewrite. Also record one measurement of the PowerShell allow-path cost, taken with the dispatcher's existing profiling mechanism on a Windows host, in the plugin's documentation.
    Maintainer-vetoable alternative: stop the guard chain at the first block instead of running the remainder, accepting the loss of every additional reason in one denial in exchange for the time saved on an already-blocked call.

    Key interfaces:

    • The plugin's README needs a documented section, alongside the call-through-a-variable write-detection section, naming the positional-operand rule and its rewrite (owned by the sibling positional-operand issue).
    • The plugin's README needs a documented section, alongside its PowerShell sink coverage, naming the brace/parenthesis grouping git refusal and its unrolled-statement rewrite (owned by the sibling grouping issue).
    • The dispatcher's existing profiling mechanism (an environment-variable-gated per-guard timing report) is what should produce the recorded measurement; no new instrumentation is needed.

    Acceptance criteria:

    • The README's section covering the call-through-a-variable write detection documents the positional-operand rule and its rewrite.
    • The README's section covering the PowerShell sink documents the brace/parenthesis git refusal and its unrolled-statement rewrite.
    • A recorded measurement (in the issue or the README) shows the per-guard timing of the PowerShell allow path on a Windows host, produced via the dispatcher's existing profiling mechanism.
    • The dispatcher's behavior of running every remaining guard after a block is unchanged and has a passing regression test demonstrating a doubly-blocked command still produces both guards' denial text.

    Out of scope:

    • Stopping the guard chain early after the first block — considered and explicitly rejected as the defaulted decision; only pursue if the maintainer vetoes the default.
    • The underlying fixes for the two documented over-block classes themselves — tracked in the sibling positional-operand and grouping issues respectively.
  6. kyle-sexton commented on Sep 29, 2026

    @kyle-sexton
    MemberAuthor

    Posted from the 2026-09-29 audit of the Cursor run (499 PRs, 2026-09-27 to 2026-09-29). The owner authorized fixing the findings; merging is not authorized. Fix PR: #5340 (draft).

    Reopened. #4848 closed this with "Closes #4236" while its own body said the Windows RUN_GUARDS_PROFILE cost is unmeasured. Acceptance criterion 3 (a recorded per-guard timing of the PowerShell allow path on a Windows host) is not delivered. Criteria 1, 2 and 4 are met: the README notes, the dual-sink test at run-guards.test.sh:530-540, and the dispatcher unchanged.

    #5340 removes the to-do prose and the "this Linux checkout" aside from the README, so user docs no longer carry it. The measurement stays open here (the earlier audit row said "file follow-up"; reopening is the same tracking without splitting the issue). No duplicate exists: searched 2026-09-29 for RUN_GUARDS_PROFILE and "guardrails Windows measurement".

    Operator steps on a Windows host with Git Bash: from plugins/guardrails/hooks, run the Bash|PowerShell row of hooks.json (its args are pinned in run-guards.test.sh at the BASH_ROW_ARGS definition used at L1065) with RUN_GUARDS_PROFILE=1 and a PowerShell payload on stdin, for example:

    {"tool_name":"PowerShell","tool_input":{"command":"git status"},"cwd":"<repo>"}
    

    Run it 5 times. Paste the per-guard run-guards: <ms> ms rc=<n> <guard> lines and the wall time for one run, and say which host and load. Record the figure in the README's hook-budget section or on this issue. Close when recorded.

  7. added
    needs-human
    on Sep 29, 2026
  8. kyle-sexton commented on Sep 30, 2026

    @kyle-sexton
    MemberAuthor

    Owner decision (2026-09-30): Only acceptance criterion 3 is still open (criteria 1, 2 and 4 are met). An agent will take the measurement through /fleet:reach on melo-desk-001's Windows lane (windows-shell, ssh-admin), the always-on Windows host; melo-lap-001 (reachable only on AC) is the fallback or a second data point. The probe is read-only and non-elevated. Steps: (1) confirm Git Bash and a plugin checkout exist there; if none, git clone --depth 1 into a scratch dir and leave existing worktrees alone. (2) From plugins/guardrails/hooks, run the Bash|PowerShell row of hooks.json (args pinned at BASH_ROW_ARGS in run-guards.test.sh, used at L1065) with RUN_GUARDS_PROFILE=1 and stdin {"tool_name":"PowerShell","tool_input":{"command":"git status"},"cwd":"<repo>"}; profiling needs EPOCHREALTIME (run-guards.sh:603-605), which Git Bash's bash 5 provides. (3) Run it 5 times and capture the per-guard run-guards: <ms> ms rc=<n> <guard> stderr lines and each run's wall time, plus the host, load (idle or not) and bash version. (4) Record the per-guard ms and wall-time table in the README hook-budget section (plugins/guardrails/README.md, "Hook budget accounting") through a normal PR, or as a comment here, then close #4236 as completed. The dispatcher keeps running the full chain after a block (criterion 4 test at run-guards.test.sh:530-540); the measurement does not change that. No credentials, secrets, billing, elevation or deletion are involved.

    Approved by the owner with all consensus recommendations on 2026-09-30 (three read-only researchers, majority or judge).

    Next: run the probe on melo-desk-001; needs-human stays until the result is recorded here or in the README.

  9. kyle-sexton commented on Sep 30, 2026

    @kyle-sexton
    MemberAuthor

    Acceptance criterion 3 measured: per-guard timing of the PowerShell allow path on a Windows host, via the existing RUN_GUARDS_PROFILE=1 mechanism.

    Host and conditions

    • Host: melo-desk-001 (Windows, Intel Core Ultra 9 285K), reached through the WSL-to-Windows-on-this-machine route of /fleet:reach (WSL interop, console account KyleSexton; no ssh hop needed because the agent runs on this machine). Read-only and non-elevated.
    • Load: not idle. Win32_Processor.LoadPercentage was 58 before the runs and 68 after; about 10 GB free RAM.
    • Git Bash bash 5.3.15(1)-release (EPOCHREALTIME present), node v24.21.0, git 2.55.0.windows.3.
    • Code: shallow clone of origin/main at 7fceea88baa99d9e68c24837459a51a92e6d3991 into C:\Users\KyleSexton\claude-lane-sandbox\probe4236 (scratch, removed afterwards; existing worktrees untouched).

    Command (run under Git Bash from plugins/guardrails/hooks, 5 times; CLAUDE_PLUGIN_ROOT set to the clone's plugins/guardrails). Args are the Bash|PowerShell row of hooks.json verbatim:

    printf '%s' '{"tool_name":"PowerShell","tool_input":{"command":"git status"},"cwd":"<clone root>"}' | RUN_GUARDS_PROFILE=1 node "$CLAUDE_PLUGIN_ROOT/hooks/exec-bash.mjs" "$CLAUDE_PLUGIN_ROOT/hooks/run-guards.sh" --lib lib/powershell/ps-command.sh --max-substitutions 256 --max-command-len 16384 block-no-verify.sh block-dangerous-git.sh block-hook-bypass.sh flag-commit-pr-skill-bypass.sh block-noncanonical-commit.sh block-convention-violation.sh block-windows-drive-tmp.sh block-exported-msys-pathconv.sh block-root-delete-target.sh
    

    Wall time is EPOCHREALTIME around the whole pipeline (node launcher, bash start, all guards). Every run exited 0 with empty stdout (allow).

    Raw run-guards: <ms> ms rc=<n> <guard> lines, ms per run (1, 2, 3, 4, 5)

    Guard run 1 run 2 run 3 run 4 run 5 rc
    block-no-verify.sh 7 6 6 7 6 0
    block-dangerous-git.sh 7 6 7 7 7 0
    block-hook-bypass.sh 7 6 6 6 6 0
    flag-commit-pr-skill-bypass.sh 0 0 0 0 0 0
    block-noncanonical-commit.sh 7 6 6 7 6 0
    block-convention-violation.sh 7 6 6 6 6 0
    block-windows-drive-tmp.sh 4 4 4 3 4 0
    block-exported-msys-pathconv.sh 3 3 3 3 2 0
    block-root-delete-target.sh 3 3 4 3 2 0
    Sum of guard lines 45 40 42 42 39
    Wall time (ms) 269 169 177 176 160

    Run 1 wall time includes cold caches; runs 2 to 5 span 160 to 177 ms.

    What it shows against criterion 3: a recorded per-guard timing of the PowerShell allow path on a named Windows host, produced with the dispatcher's existing profiling mechanism, is now on this issue. On a busy host the guards total about 39 to 45 ms; the rest of the 160 to 270 ms wall time is the node launcher and Git Bash start-up. Criteria 1, 2 and 4 were confirmed met in the 2026-09-29 comment; the dispatcher was not touched, so the run-the-full-chain-after-a-block behavior is unchanged.

    Closing as completed. The figure can be copied into the README "Hook budget accounting" section in a later docs pass if wanted; the criterion allows "in the issue or the README".

  10. removed
    needs-human
    on Sep 30, 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

    agent-readystatus: ready

    Type

    Fields

    No fields configured for Task.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions