Skip to content

The test gate reads a shell command of any length in time proportional to its length - #1714

Merged
zlareb1 merged 5 commits into
mainfrom
fix/test-gate-default-advises-only
Nov 28, 2026
Merged

zlareb1 merged 5 commits into
mainfrom
fix/test-gate-default-advises-only

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Related: #1696
Related: #1709

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in a release)

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

The Claude Code and Codex plugins' test gate no longer stalls at the end of a session whose transcript holds a very long single-line shell command. It reads a build tool and its argument, and an install verb and the name after it, up to 256 characters apart, so the read takes time proportional to the command's length.

Why

The default hold is unchanged. This pull request first removed the default hold at Stop. Review found that this takes a capability away by default (a session that changed code and ran no test would end unheld) and that no measured cost needs it: on main the default already holds none of the 29 recorded sessions and sends no Stop request for them. The head now keeps the hook, its tests and the documentation as they are on main, and fixes the one defect measured there: the time the default takes to read one long line.

Failing cases, measured on main (ed765e0) before the edit. CPU time of testedSince on a transcript with one single-line command, by the shape repeated in it:

Shape repeated on one line 5,000 chars 10,000 chars 20,000 chars Per doubling
x install, then make test 0.27 s 2.14 s 17.3 s 8 times
install, then make test 24 times 0.25 s 2.02 s 16.7 s 8 times
npm 44 times, rm, tests 18 times 0.59 s 4.64 s 35.5 s 8 times
gradle -x a_test_test… 0.13 s 1.01 s 7.85 s 8 times
make 7 ms 26 ms 101 ms 4 times
go 6 ms 22 ms 84 ms 4 times
install, then pytest 35 times 2 ms 6 ms 22 ms 4 times

The pattern runs in one synchronous RegExp.test, which the hook's exit timer cannot interrupt. The Stop hook itself, started as the client starts it on a dirty checkout whose transcript holds an edit and then the first line at 20,010 characters, returned after 17.1 s on main; at 200,010 characters the same line extrapolates to hours, so that Stop waits for the client's hook timeout.

Pattern. Every slow line is one simple command. The pattern's three spans from a tool word to its argument ([^\n;|&]*) each run to the end of the simple command from every tool word, and the verb lookbehind (FETCHED, the same span) runs back to its start from every test or runner name. The cost is the number of tool words, times the number of names after each, times the length the lookbehind walks, and all three grow with the line.

Hypothesis. Bound that span to 256 characters in the four places it is written. The cost per tool word then has a ceiling, so the read is linear in the line's length. Predicted before the edit, from the same pattern with the bound: no verdict changes on the commands of the existing tests or on the recorded commands; the first line reads in under a millisecond at any length; the costliest line costs ten times more at ten times the length; the replay of the recorded sessions equals main's in all three modes. All held; the numbers are under Tests.

Why 256. On 49,906 distinct shell commands recorded in local agent sessions, of which main reads 2,428 as a test run, a bound of 256 or more changes no verdict. A bound of 200 changes one and a bound of 128 two. Both are commands that run no test, which main reads as a run because a test word stands 138 characters after node in one and 239 after go in the other. The longest simple command in those sessions is 3,702 characters.

Readings this does not change. These are read as on main, and each is named in the README's Stops that pass paragraph or follows from it:

Command Read as It is Cost of the misread
npm --prefix testapp run build a test run no run the stop passes
yarn workspace testbed build a test run no run the stop passes
make testdata a test run no run the stop passes
grep -rn pytest . a test run no run the stop passes
make install test no run a test run held once, one model request
mvn clean install test no run a test run held once, one model request
./gradlew integrationTests no run a test run held once, one model request

The first four pass by the rule's design: a command that names a runner counts, since what is read is whether the session ran a test at all, and make testdata cannot be told from make testall by its text. The last three need a new rule each, and a rule added here has so far misread the next input: reading Tests as a Gradle task reads gradle build -PskipTests as a run, which the existing test asserts is none, and whether install is a package verb or a target depends on the tool before it. They are misreadings of a command's words, not of its length, so they stay out of this change.

Scope and risk

  • Files. lib/test-gate.mjs: one constant, SPAN, used in the verb pattern and in the three tool spans, and a comment. Its Codex copy. One test. One sentence in the README. Both manifests. 37 lines added and 11 deleted over 6 files.
  • What changes for a session. A tool and its argument more than 256 characters apart in one simple command are not read as a run, so that stop is held once, at one model request. A name more than 256 characters after an install verb is read as a run, so that stop passes. Neither occurs in 50,064 recorded commands.
  • Cost that is left. The read is linear with a ceiling per tool word. The costliest line found by a search over repeated shapes costs 3.8 microseconds of CPU per character: 0.08 s at 20,000 characters, 0.77 s at 200,000 and 7.6 s at 2,000,000. Such a line holds a tool word, a verb and eighteen tests in every 287 characters; a long line of JSON or base64 holds few tool words and costs far less.
  • LOOM_TEST_GATE=block is unchanged. RUNNER is read only by testedSince, which only the default path calls. The replay's block output is byte-identical to main's.
  • Hooks in a user's session. The change removes the one synchronous step of this hook whose cost grew faster than its input.
  • Not changed. The default hold, the edit-time line, LOOM_TEST_GATE=block and off, hooks.json, the hook script, the server.

Compatibility, rollout and rollback

Tests

  • Time of the read. The table under Why, and this one for the head, from the script below run in integrations/claude-code-plugin with a shape and a length:

    Shape repeated on one line 20,000 chars 200,000 chars 2,000,000 chars Read as
    x install, then make test 0.3 ms 0.4 ms 0.4 ms a run
    install, then make test 24 times 33 ms 301 ms 2.91 s no run
    npm 44 times, rm, tests 18 times 78 ms 770 ms 7.63 s no run
    gradle -x a_test_test… 8 ms 75 ms 730 ms no run
    make 5 ms 44 ms 451 ms no run
    go 4 ms 40 ms 352 ms no run
    install, then pytest 35 times 2 ms 18 ms 158 ms no run

    Every row costs ten times more at ten times the length. The first line is now read as a run: its verb is more than 256 characters before all but the first 25 of its make test. The third row is the costliest of 11,697 lines tried at 20,000 characters: 4,000 random mixes of 27 words, and 7,697 of a grid over a tool, a verb and a test word, each repeated a varying number of times.

    import { testedSince } from "./lib/test-gate.mjs";
    const units = {
      cubic: ["x install ", "make test "],
      verbs: ["x", " install" + " make test".repeat(24)],
      costly: ["", " npm".repeat(44) + " rm" + " tests".repeat(18)],
      skipped: ["x", " gradle -x a" + "_test".repeat(14)],
      make: ["", "make "],
      go: ["", "go "],
      names: ["x", " install" + " pytest".repeat(35)],
    };
    const [head, unit] = units[process.argv[2]];
    const command = head + unit.repeat(Math.round((Number(process.argv[3]) - head.length) / unit.length));
    const rows = [{ type: "assistant", message: { content: [{ type: "tool_use", id: "t", name: "Bash", input: { command } }] } }];
    const before = process.cpuUsage();
    const ran = testedSince(rows, 0);
    console.log(command.length, "chars", (process.cpuUsage(before).user / 1e3).toFixed(1), "ms", ran);
  • The Stop hook on those lines, started as a process on a dirty checkout whose transcript holds an edit and then the long command, server unreachable:

    Stop hook, wall time main This head
    Default, x install then make test, 10,010 chars 2.38 s not run
    Default, the same, 20,010 chars 17.1 s 0.18 s
    Default, the same, 200,010 chars not run 0.17 s
    Default, the costliest line, 200,039 chars not run 0.97 s
    LOOM_TEST_GATE=block, 20,010 chars 0.22 s 0.17 s
    LOOM_TEST_GATE=block, 200,010 chars not run 0.18 s
  • Verdicts on recorded commands. testedSince of main's library and of this head's on each distinct shell command of the recorded sessions:

    Commands Count Read as a test run on main Verdicts that differ
    The two recorded benchmark runs 158 69 0
    Local agent sessions 49,906 2,428 0
  • Replay of the 29 recorded sessions (two recorded benchmark runs of one coding task, the sessions with the plugin installed), with the driver and method of The test gate names an edited file's tests when it is edited, and holds the end of a session only when the session ran no test since its last code change #1696 and A package install, a prose-looking test fixture or a Codex shell call under another name does not let a session end untested #1709: each recorded tool call's file changes applied to a fresh checkout, one call after another, with the recorded times; the plugin's own hook scripts started as the client starts them; a local stub for code.test_gate; the Stop gate on the transcript as it stood at the first Stop. main is ed765e0, the head's plugin files are those of this push.

    At the first Stop main This head
    Default: sessions held 0 of 29 0 of 29
    Default: code.test_gate requests at Stop 0 0
    Default, every test run taken out: sessions held 29 of 29 29 of 29
    Default, every test run taken out: requests at Stop 58 (two trials a session) 58
    LOOM_TEST_GATE=block: sessions held 6 of 29 6 of 29, the same six
    LOOM_TEST_GATE=block: requests at Stop 58 58

    The Stop output and the edit-time lines are byte-identical per session between main and the head in all three replays. The replayed source file equals the file the run kept in all 29 sessions, no session was replayed twice and no Stop needed a third trial.

  • node --test integrations/claude-code-plugin/tests/test-gate.test.mjs: 49 tests, 48 pass, 1 skipped (Windows only), 0 fail. The new test asserts the bound on both sides for a tool and for a verb, and that two lines of 20,000 characters (the first and the third of the tables) are read within 2 s of CPU; they take 0.08 s.

  • The same test on main's library fails at its first bound assertion. Its two lines cost 17 s and 35 s of CPU there.

  • Gates. ruff format --check ., ruff check, the function-length gate, check_no_secrets.py and every generator's --check (agent_plugin_sync included) pass. Biome's format check passes on integrations/ and Prettier's on the README. node --check passes on the library, its Codex copy and the test file. claude plugin validate integrations/claude-code-plugin --profile directory --strict passes. The mypy gate reports 5 errors, all in server/llm/vertex_auth.py, from type stubs missing in the local environment; this change holds no Python.

  • Not run locally. No pytest suite. I called the 32 argument-free test functions of tests/unit/test_codex_plugin.py, test_public_copy.py, test_published_links.py and test_agent_instructions.py directly; none failed. Of the plugin's test files only the changed one was run, so the others, which start this hook, are left to CI. Nothing was run under a live Claude Code or Codex session, and nothing on Windows. The replay's stub answers code.test_gate as the recorded messages show the index did, not as a server would today. The search for the costliest line covers repeated shapes only, so a costlier line of another shape may exist; the bound still caps the cost per tool word.

AI assistance in the code (leave one; writing this description with AI is fine):

  • AI-generated (an agent wrote most of the diff): Claude Code. I measured the time of the read on main for seven shapes before editing, compared the verdicts of main and the head on 50,064 recorded commands, searched for the costliest line under the bound, ran the changed test file on this head and on main's library, replayed the recorded sessions in three modes against main, and ran the gates listed above.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • Local format, lint, type checks and focused tests pass. The full make test-unit and applicable integration results are reported by CI; a full local run is not required before pushing.
  • Generated files are regenerated in this PR, not by hand: the SDK op tables, docs/reference/configuration.md and the docs/reference/ tables (python scripts/codegen/docs_reference.py), the reach manifest, schemas/schema.sql (make schema-dump) and the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py).
  • A new migration is additive and numbered after the latest on main; no merged migration is edited.
  • A behaviour change to any file a plugin ships (hooks/, lib/, bin/, skills/, .mcp.json, the Codex plugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.
  • The frontend builds (npm --prefix frontend run build) and its tests pass, if frontend/ changed.
  • Docs under docs/ describe the system as it now is, and this description names any operator steps and wire changes.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers; the history goes in this description (tests/unit/test_public_copy.py).
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.
  • I signed the Contributor License Agreement (CLA) if CLA assistant requested a signature.

🤖 Generated with Claude Code

…y when a team turns blocking on

By default the Stop test gate held a session whose transcript showed no
test run since its last code change. It decided that by matching shell
command text against a list of runners, package verbs and prose file
names. Each review of the rule found commands it reads wrongly in both
directions: `npm --prefix testapp run build`, `make testdata` and `grep
-rn pytest .` count as a test run, and `make install test` and `gradlew
integrationTests` count as none. A wrong hold costs the session one model
request; a wrong pass skips the check without a word.

The pattern that rejects install verbs is also cubic on one long line. `x
install ` followed by `make test ` 2,000 times takes 16 s in the rule and
4,000 times takes 141 s, inside a synchronous regular expression that the
hook's exit timer cannot interrupt, so that Stop waits for the client's
hook timeout.

The default Stop entry now exits before it reads its input. The line that
names an edited file's tests on the tool call that edits it is unchanged,
and so is LOOM_TEST_GATE=block, which holds the stop until the named tests
ran. `testedSince`, `lastCodeChange`, `isProse` and its three patterns,
`RUNNER`, `FETCHED`, `LEFT_OUT`, `startsRunner` and `rolloutCommand` are
deleted with their tests and their documentation: block mode reaches none
of them.

Both plugin manifests move to 1.2.74.

Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
loom-docs Ready Ready Preview Nov 28, 2026 3:02pm UTC
loom-telemetry Ready Ready Preview Nov 28, 2026 3:02pm UTC

Request Review

zlareb1 and others added 4 commits November 28, 2026 19:54
…st uses

Two other open pull requests moved to 1.2.74 and 1.2.75 while this one
was being opened, and two pull requests with one version ship only the
first.

Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…d in linear time

The two commits before this one removed the default hold. A session that
changed code and ran no test would then end unheld, and no measured cost
needed that: the default already held none of the recorded sessions. This
commit puts the hook, the library, their tests and the documentation back
as they were, so by default a session that ran no test since its last
code change is held once, as before.

What was wrong is the read of one long line. Each span of the runner
pattern ran to the end of the simple command from every tool word, and
the verb lookbehind ran back from every `test`, so `x install` followed
by `make test` 2,000 times cost 17 s of CPU in one synchronous match, and
eight times more at each doubling. Each span now ends after 256
characters: a tool and its argument, and a verb and the name after it,
are read no further apart than that. That line now costs under a
millisecond. The costliest line found costs 0.08 s at 20,000 characters,
0.77 s at 200,000 and 7.3 s at 2,000,000.

No verdict changes on the commands of the existing tests or on 50,064
recorded shell commands.

Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
main moved to 1.2.74 with the file memory change. The two manifests
conflicted on the version line only and keep 1.2.76, which no other open
pull request holds.

Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
"Time that grows with its length" was also true of the read it replaces.

Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@zlareb1 zlareb1 changed the title The test gate advises at edit time and holds the end of a session only when a team turns blocking on The test gate reads a shell command of any length in time proportional to its length Nov 28, 2026
@zlareb1
zlareb1 merged commit 976a864 into main Nov 28, 2026
73 of 79 checks passed
@zlareb1
zlareb1 deleted the fix/test-gate-default-advises-only branch November 28, 2026 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant