Skip to content

Agent speed: guard-hook fast path and ready-made commands #1094

Backlog

Description

@scuttletoby

Agents spend most of their time on per-call overhead, not on work. Measured on one machine over 10 hours of fork agents (32 sessions, ~2,800 shell calls):

  • 62% of active time is the model's turn between calls (~9 s each), 38% running tools.
  • About half of all shell calls are a single read or search; only 6% of turns send more than one tool call at once.
  • Every shell call runs three guard hooks. actions-disable-guard takes ~200 ms even on an idle machine (a ~5,000-line script parsed on every call; -B means no cached bytecode). Under memory pressure it hits its 10 s timeout, and since the hook blocks on failure, the agent's command is refused.

Part 1: guard hooks fast path

  • actions-disable-guard, capacity-pipe-guard and the PostToolUse memory-index-guard get a fast path: a few-line check that exits at once when the command cannot be what the guard looks for (e.g. no gh/curl/api/workflow words; no t3-capacity), and only then loads the full guard.
  • The full guard loads from a module so its bytecode can be cached (or is otherwise made cheap to start).
  • Target: under 20 ms per call for ordinary commands, the same verdicts for every case the current tests cover (shared contract tests run against both paths), and no refusal from a timeout on a slow machine for a command the fast path passes.

Part 2: ready-made commands in the kit

Long pipelines agents rebuild each time, each costing several turns:

  • fork-ci-why <pr>: for each failing required check on the PR head, print only the error lines (strip ANSI and timestamps) and the job link.
  • fork-clone <name> [branch]: blob-less clone into the work folder; reuse another clone's node_modules when the lockfile is identical, else install once.
  • fork-precheck: format and lint the files changed against the base, then run the test files the change touches, gated by the capacity check.
  • fork-quickfix <pr> fmt: format a PR's changed files and push, for the mechanical CI reds.

Each command lists itself in the facts index so agents find it.

State question

  • Runs again: hooks and commands are stateless, except that fork-clone reuses an existing folder only when it is a clone of the same repo.
  • Stops half-way: a killed fast path means the hook fails, which already blocks (fails safe). A half-made clone is detected and re-made.
  • Old or empty state: a missing config or tool gives the current full-guard behaviour, never a pass.

Activity

  1. scuttletoby commented on Nov 27, 2026

    @scuttletoby
    OwnerAuthor

    Part 3: the pre-commit hook

    Found today: the repo's pre-commit hook re-runs fmt, lint and a whole-repo knip on every commit. knip takes ~4 GB, and under load one commit's hook ran past 30 minutes and was killed, so the writer committed with --no-verify. Two whole-repo knip runs at once pushed a 12 GB machine into swap, and every agent's commands were refused (the guards time out).

    • The hook formats and lints only the staged files, and runs no whole-repo knip (CI runs knip on every PR).
    • If a knip step stays, it is opt-in (an env var) and runs through the machine's memory gate when one exists.
    • Test: a commit with one staged file runs fmt and lint on that file only.
  2. 14 remaining items

  3. added
    area:guards
    size:medium
    type:feature
    on Nov 29, 2026
  4. scuttletoby commented on Nov 30, 2026

    @scuttletoby
    OwnerAuthor

    Working on Part 2's last command: fork-quickfix <pr> fmt (format a PR's changed files and push, for mechanical formatting reds). One fork PR.

    🤖 Generated with Claude Code

  5. scuttletoby commented on Nov 30, 2026

    @scuttletoby
    OwnerAuthor

    Guard time budget on long scripts (11-30)

    actions-disable-guard refuses a long ops script (~1,300 lines) with "could not finish reading … within 5 s". The time goes into call_reason: for every call that hands a function words made at run time, the guard re-reads that function's body. One helper with 27 such calls (each calling three more helpers) uses most of the 5 s budget alone; with that helper stubbed the whole file reads in ~1.1 s.

    Fix asked: read each function body once per (function, which arguments are made words) and reuse the answer, so the cost grows with the number of functions, not calls x depth. Same refusals, same budget.

    Four false readings seen in the same script (each refuses a harmless line):

    1. a case pattern like .|..|""|*/*) or *[\*\?\[]*): the | between patterns is read as a pipe into a shell;
    2. flock -w 5 9: -w is not known to take a value, so 5 is read as the program;
    3. systemd-run --user … "${ENV_PAIRS[@]}" -E NAME="$v" "$SELF" … where the array holds -E NAME=VALUE pairs: the array is read as the program name;
    4. bash -c "$CONST" inside a function called with made words counts as hidden text even when CONST is a fixed top-level string.

    A writer is on the memoizing fix plus these false readings (speed first).

  6. scuttletoby commented on Nov 30, 2026

    @scuttletoby
    OwnerAuthor

    Another false refusal, for the guard-reading work here: actions-disable-guard refused a plain root kit install, sudo sh fork-kit-bootstrap.sh --kit claude-login --repo … --sha … --timer.

    Its reason: it "can't read the bootstrap's die text, nor the old claude-login helper's line 154". Neither one switches anything off in CI, so this is the same kind of false refusal as the ones listed above: run-time text the guard cannot read. Please add it as a test row when #1504's readings land: a die helper that only prints its argument, and a same-named older script elsewhere on PATH.

    I installed the kit through the usual root route instead.

    🤖 Generated with Claude Code

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

    area:guardssize:mediumtype:feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions