Repository navigation
The test gate reads a shell command of any length in time proportional to its length - #1714
Merged
Merged
Conversation
…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>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related: #1696
Related: #1709
Changelog category (leave one):
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
mainthe 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 onmain, 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 oftestedSinceon a transcript with one single-line command, by the shape repeated in it:x install, thenmake testinstall, thenmake test24 timesnpm44 times,rm,tests18 timesgradle -x a_test_test…makegoinstall, thenpytest35 timesThe 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 onmain; 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 everytestor 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
mainreads 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, whichmainreads as a run because atestword stands 138 characters afternodein one and 239 aftergoin 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:npm --prefix testapp run buildyarn workspace testbed buildmake testdatagrep -rn pytest .make install testmvn clean install test./gradlew integrationTestsThe 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 testdatacannot be told frommake testallby its text. The last three need a new rule each, and a rule added here has so far misread the next input: readingTestsas a Gradle task readsgradle build -PskipTestsas a run, which the existing test asserts is none, and whetherinstallis 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
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.testsin every 287 characters; a long line of JSON or base64 holds few tool words and costs far less.LOOM_TEST_GATE=blockis unchanged.RUNNERis read only bytestedSince, which only the default path calls. The replay's block output is byte-identical tomain's.LOOM_TEST_GATE=blockandoff,hooks.json, the hook script, the server.Compatibility, rollout and rollback
mainholds 1.2.74. At this push the other open pull requests that touch a plugin manifest hold 1.2.75 (The test gate touches only the edited definitions and labels every test with its evidence #1707), 1.2.69 (The format, unit and statement-shape regression checks pass #1706), 1.2.55 (Loom traces record invocation origin, outcome and benchmark context #1112), 1.2.47 (Automatic hooks retain bound session privacy #948) and 1.2.46 (Claude Code plugin hooks use the configured complete MCP endpoint #770).main, and one README wording fix. The repository builds a squash message from the commit bodies, and the first two describe a change this head does not hold, and a version (1.2.74) it does not hold either. The squash merge should take this title and a body written for the final diff.i18n/are not edited by hand; the translation workflow picks the changed page up after the merge.Tests
Time of the read. The table under Why, and this one for the head, from the script below run in
integrations/claude-code-pluginwith a shape and a length:x install, thenmake testinstall, thenmake test24 timesnpm44 times,rm,tests18 timesgradle -x a_test_test…makegoinstall, thenpytest35 timesEvery 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 atestword, each repeated a varying number of times.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:
mainx installthenmake test, 10,010 charsLOOM_TEST_GATE=block, 20,010 charsLOOM_TEST_GATE=block, 200,010 charsVerdicts on recorded commands.
testedSinceofmain's library and of this head's on each distinct shell command of the recorded sessions:mainReplay 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.mainis ed765e0, the head's plugin files are those of this push.maincode.test_gaterequests at StopLOOM_TEST_GATE=block: sessions heldLOOM_TEST_GATE=block: requests at StopThe Stop output and the edit-time lines are byte-identical per session between
mainand 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.pyand every generator's--check(agent_plugin_syncincluded) pass. Biome's format check passes onintegrations/and Prettier's on the README.node --checkpasses on the library, its Codex copy and the test file.claude plugin validate integrations/claude-code-plugin --profile directory --strictpasses. The mypy gate reports 5 errors, all inserver/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.pyandtest_agent_instructions.pydirectly; 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 answerscode.test_gateas 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
mainfor seven shapes before editing, compared the verdicts ofmainand the head on 50,064 recorded commands, searched for the costliest line under the bound, ran the changed test file on this head and onmain's library, replayed the recorded sessions in three modes againstmain, and ran the gates listed above.I can explain every line of this diff and how it interacts with the rest of Loom.
Checklist
make test-unitand applicable integration results are reported by CI; a full local run is not required before pushing.docs/reference/configuration.mdand thedocs/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).main; no merged migration is edited.hooks/,lib/,bin/,skills/,.mcp.json, the Codexplugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.npm --prefix frontend run build) and its tests pass, iffrontend/changed.docs/describe the system as it now is, and this description names any operator steps and wire changes.tests/unit/test_public_copy.py).git commit -s), as CONTRIBUTING.md asks.🤖 Generated with Claude Code