Repository navigation
A prompt does not wait on run.begin, and a Stop does not wait on the namespace audit - #1695
Merged
Merged
Conversation
…ave nothing to say Claude Code's wiring held the session for three calls whose answer it does not read. SessionEnd ran its five recording scripts in the hook, so the client's exit waited for them. The first Stop waited for namespace.audit, which prints only for a namespace with a critical finding. A prompt started three node processes, one of them only to send run.begin. loom-record now hands the payload to its detached copy at every event it is wired for, SessionEnd and UserPromptSubmit included. The copy of a prompt runs loom-run and asks namespace.audit once per session, keeping the verdict in the session's state; loom-namespace-health at Stop tells that verdict once and makes no call. A Stop that comes before the audit has answered passes, and a later one tells. A wiring that starts the script at Stop only (Codex, a hand-wired client) still asks there. The two lookups a prompt does wait for, loom-prompt-pack and loom-prompt-recall, run in the launcher's own process and their context goes to the host as one answer, so a prompt starts one process. loom-run writes the pending begin to the run state before it awaits the answer: a SessionEnd that comes first asks again with the same body and closes the run, as it does after a timeout. A resumed session keeps its previous run id until the answer, as it did while the prompt waited. A hook's main returns its answer and runHookMain prints it, so one process can collect the answers of several scripts. Scripts that share a process look the checkout root up once. SessionEnd no longer declares a timeout: the hook returns after node's start, one file write and one spawn. A host torn down when the client exits ends the detached copy, and the session's close records with it. The bench harness gains --shell (a session that edits and tests through the shell alone) and each hook process's own CPU time; the end-to-end session script expects the run's close after the client has exited. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
8 of 9 tasks
…a late run.begin answer or a dead audit ask no longer strands session state SessionEnd runs its five recording scripts in the hook again, with `timeout: 10`, as on main: a host that ends with the client (a container whose entrypoint is the client) would end a detached copy before it had sent the run's close, the last turns, session memory or the brief. Only the prompt's `run.begin` and the namespace audit stay handed off. - loom-run: the prompt's begin is detached, so SessionEnd can ask again and close the run before the first answer arrives. That answer is now dropped when the run state is no longer this attempt's (same `at`); before, it marked the closed run begun again and a resumed session's next prompt opened no run. - loom-namespace-health: a Stop that finds an ask older than the request bound with no verdict asks in place. A copy killed between its ask and its answer no longer silences the audit for the session. HOOKS.md says that a session whose only Stop precedes the answer is not told. - The run-hook wiring is asserted on `RECORDERS` in hooks-json.test.mjs, not on the launcher's source text. - The bench harness and the end-to-end session script are main's again: `--shell`, the own-CPU column and `minMs` are not part of this change. - README: the `loom-run.mjs` row says the prompt does not wait for the begin's answer and that a first tool observation can precede it. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
9 of 10 tasks
… that ends first still closes its run The prompt's detached process was the first to record the pending run.begin. A SessionEnd that ran before that process had started found an empty run state and sent nothing; the process then opened the run and marked it begun, with no close to come. The same state followed when SessionEnd's own ask got no answer and the prompt's answer arrived afterwards. - loom-record writes the begin to the session's run state before it starts the detached process, sharing the checkout lookup with the prompt's lookups. The detached process asks only the begin it finds kept and writes nothing before its answer: after a SessionEnd has asked and closed the run it sends no begin, which the server would take as opening the run again. - A SessionEnd whose ask gets no answer stamps the state anew, so the prompt's late answer is dropped and a resumed session asks again. - A script loom-record runs in the hook, or one that fails to load, writes its error's first line to stderr under LOOM_HOOK_DEBUG=on, by script name. - A Stop asks the namespace audit in place only when the prompt's ask is older than twice the request bound: the detached process stamps its ask before its checkout lookup and its request. - HOOKS.md names the prompt among what a job file holds. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 520efa6. Configure here.
No conflicts. main's plugin version is unchanged at 1.2.64, so both manifests stay at 1.2.66, the lowest version above it that no other open pull request uses. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
…tays, and the run it opened is closed SessionEnd asks an unanswered begin again and waits up to 400 ms. With no answer it stamped the run state anew from the copy it read before the wait, so an answer the prompt's detached process had written meanwhile was overwritten: a begun run was left with no close, and a refusal was asked again by a later prompt. SessionEnd now stamps only a state that is still the one it read. A begun state written during the wait is read back and closed inside the same deadline. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
…r of SessionEnd's wait The prompt's begin was answered at 900 ms, 500 ms after SessionEnd's 400 ms wait could end. An answer inside that wait is now kept and its run closed, so a SessionEnd process that started late put the test in the other ordering. Answered at 1,300 ms, still inside the prompt's 1,500 ms bound, the process again has 900 ms to start. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.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.

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 plugin no longer holds a prompt for
run.beginor a Stop for the namespace audit: a prompt starts one hook process instead of three, and the audit is asked by the first prompt's detached process and told at a Stop.Why
Two measured stages of short headless coding sessions with the plugin installed, in which the model called no Loom tool, put the plugin's hooks at 3.2 to 4.5 s of wall time per session. The earlier hand-off of the tool-call and Stop recorders did not lower that. This change removes two waits on calls whose answer the session does not read:
run.begin.run.beginand the audit now go to one detached process, and the two lookups whose answer the prompt waits for (loom-prompt-pack,loom-prompt-recall) run in the launcher itself, which prints their context as one answer.namespace.audit(469 ms median over 15 first passes, 193 ms of it in the server), which printed nothing in 29 sessions. The detached process of the session's first prompt now asks and stores the verdict, and the Stop hook reads it.What this change leaves alone, and why:
timeout: 10, as onmain. A host that ends with the client (a container whose entrypoint is the client, which the documented headlessclaude -puse allows) would end a detached process before it had sent the run's close, the last turns, session memory or the brief. An earlier revision of this pull request handed SessionEnd off and lost exactly that; the review found it, and this revision restoresmain's path and its tests.run.beginwas not what the first request waited for. In all 15 measured sessions a lookup (code.search8 times,context.pack7) answered afterrun.begindid, by a median of 169 ms. Both lookups can inject, so the prompt still waits for them.Scope and risk
hooks/loom-record.mjs(hands off at a prompt and runs its two lookups; SessionEnd as onmain),hooks/hooks.json(one prompt hook),hooks/loom-namespace-health.mjsandlib/namespace-health.mjs(ask at a prompt, tell at a Stop),hooks/loom-run.mjsandlib/run-hook.mjs(the launcher writes the pending begin to the run state before it starts the detached process, which asks only the begin it finds there; an answer that arrives after another writer took the state is dropped),lib/loom-client.mjs(a hook'smainreturns its answer; scripts in one process share the checkout-root lookup; a script run beside others reports its error underLOOM_HOOK_DEBUG=on),hooks/loom-prompt-pack.mjsandhooks/loom-prompt-recall.mjs(return their answer). Codex copies regenerated; both manifests at 1.2.66 (mainis at 1.2.64 and three other open pull requests hold 1.2.65).loom-namespace-healthstill asks at their first Stop), SessionStart, SessionEnd, the test gate, the code shunt, the bench harness, the end-to-end session script.additionalContext(the code pointers, then the recall on the next line) where it received two.hooks/HOOKS.mdsays so). A Stop that finds the ask older than twice the request bound with no verdict asks in place, asmaindid at the first Stop: a detached process killed between its ask and its answer does not silence the audit for the session. Twice, because the detached process stamps its ask before its checkout lookup and its request, which alone may take the bound: a live process is not asked over.run.beginis answered. The launcher writes the begin's body to the session's run state before it starts the detached process, so the state is on disk when the prompt hook returns, as it was onmain, where the prompt waited for the answer. Three orders follow, each with a test:at).mainleaves when the server answers neither ask. A run the server opened for an unanswered begin stays open in that case, onmainand here.LOOM_HOOK_DEBUG=on: a script the launcher runs in the hook (the two prompt lookups, the five SessionEnd scripts), or one that fails to load, writes its error's first line to stderr, redacted, under its own name, as a script started on its own does.run.begin, so a first tool observation, like the SessionStart primer and the prompt's recall, can carry the derived id when the server answers another one.main(median of 8 alternating real-client pairs, longer in 7), while the time from the Stop to the client's exit did not differ (later in 4 pairs, earlier in 4). Claude Code 2.1.332 in-pmode ended the SessionEnd hook with SIGTERM 1.5 s after its start onmainand on this branch alike (1,542 and 1,509 ms; one session each with the conversation settle stretched to 4 s, the close sent before it in both), whatevertimeoutthe entry declares. With that budget, the longer hook life is the likely reason the client cancelled the hook in 3 of this branch's 20 ordinary sessions on the loaded machine and in none ofmain's 18; in 2 of the 3 the close had been sent.main's documentation says thetimeoutraises that budget; this change does not touch that text, and it needs its own check against the client.Compatibility, rollout and rollback
Tests
node --test --test-concurrency=1ontests/record-hook.test.mjs tests/hooks-json.test.mjs tests/namespace-health.test.mjs tests/run-id-stash.test.mjs(changed) andtests/run-hook.test.mjs tests/prompt-pack-hook.test.mjs tests/prompt-recall-hook.test.mjs tests/hooks-doc.test.mjs tests/hook-contract.test.mjs(unchanged, they cover the changed scripts): 127 of 127 pass, at a load average of 61 on 14 cores. At a load average of 120 to 190 two unchanged timing tests ("a later prompt receives changed evidence even at the same indexed span" and "a re-sent begin and the close fit Codex's one-second SessionEnd budget") have failed, about as often onorigin/mainas on this branch when run alone.main's three SessionEnd and hand-off cases are back unchanged: the SessionEnd hook returns withobserve.crystallizeandrun.completesent and no job file left; it does not wait on a stdin its host leaves open; a tool call's hand-off outlives the process group that ran the hook. The two cases that failed on the previous head's platform runs asserted the detached SessionEnd and are gone with it.run.beginanswered after SessionEnd closed the run leaves the state at{run_id}.run.request sent, SessionEnd sendsrun.beginandrun.complete, and the released process sends neither; the state ends at{run_id}. Without the launcher's write the hook returns with an empty run state and SessionEnd sends nothing.run.beginanswered after a SessionEnd whose own ask got no answer leaves the state an attempt, not begun. Without the new stamp it endsbegunwith norun.completesent.run.beginanswered while SessionEnd waits on its own ask, which gets no answer: onerun.completeis sent with the answered id and the state ends at{run_id}. With the stamp unguarded norun.completeis sent.LOOM_HOOK_DEBUG=onand nothing with it off. The launcher's cases run with the switch on and assert an empty stderr.run.beginandnamespace.auditare unanswered; a Stop passes while the audit is unanswered and tells the stored verdict once, with onenamespace.auditin the session; a wiring with no detached process asks at the first Stop.RECORDERS.UserPromptSubmitincludesloom-run(inhooks-json.test.mjs, in place of a match on the launcher's source text intests/unit/test_search_switch_ab.py), and the SessionEnd entry declares atimeout.claude plugin validate integrations/claude-code-plugin --profile directory --strictandclaude plugin validate .: passed.ruff format --checkandruff checkon the changed Python test, the function-length gate,check_no_secrets.py,agent_plugin_sync.py --check,docs_reference.py --check,op_reach_census.py --check, Biome and Prettier on the changed files,node --checkon every plugin script. The mypy gate reports 5 errors, all inserver/llm/vertex_auth.py, from a missinggoogle.authstub in the local environment.test_search_switch_ab.py,test_codex_plugin.py,test_session_content_senders.py,test_public_copy.py,test_agent_instructions.pyandtest_plugin_checkout_bytes.py. The reviewed source pins intests/unit/session_content_senders.jsonare renewed for the changed files and their Codex copies; no sender site changed.Measurement. Before is
origin/main, after is this branch. The machine was shared and at a load average of 47 to 95 on 14 cores throughout, so wall times are several times what an idle machine gives.What the session waits for, per session. One prompt, four tool calls (three shell, one edit), one Stop and SessionEnd, driven as
node tests/bench/hook-wall-time.mjs --plugin <plugin dir> --latency 50 --tools 4 --stops 1drives them; counted in a local copy of that script with agitfirst onPATHand a wrappedfetchthat log the calling process, over four sessions per arm in which no git call timed out (the same in all four; counted on this head):Detached processes go from 8 to 9, and processes in all from 26 to 25.
Wall time,
node tests/bench/hook-wall-time.mjs --plugin <plugin dir> --latency 150 --tools 4 --stops 1 --runs 3, four alternating blocks per arm, the range of the blocks' medians in ms:origin/mainloom-namespace-health.mjsat StopThese blocks ran before the launcher wrote the run's begin. The prompt hook without and with that write, six alternating blocks of three sessions at 50 ms and a load average near 55: block medians of 650 to 1,131 ms and 527 to 1,004 ms, no difference beyond the spread. Only the namespace-health hook's change is larger than the spread between blocks: the Stop event is as long as the test gate beside it. At this load the bench does not show a shorter prompt, Stop or session, and SessionEnd runs
main's path. The SessionEnd hook alone, 15 alternating pairs against a stub that answers at once: 975 ms onmain, 889 ms on this branch,run.completesent before the hook returned in 15 of 15 on both.A real client: Claude Code 2.1.332, one headless turn with one shell call, against a local fake that answers the model API and Loom at once (
tests/e2e/agent-session.mjswith request times and a stub that answersrun.beginwith the run's id; no model provider is called), the two revisions alternating.run.completewas sent before the client exited in 18 of 18 sessions onorigin/main(183 to 483 ms before the exit) and in 19 of 20 on this branch (163 to 454 ms before). In the one that missed, run while a second benchmark shared the machine, the client cancelled the SessionEnd hook before its first request. The client also reported the hook cancelled in 2 of the other 19 sessions on this branch, each after the close was sent, and in none onmain. On this branchnamespace.auditleft withrun.begin, 1.3 to 3.6 s before the exit; onmainit left at the Stop, 0.7 to 1.4 s before. Those sessions ran before the launcher wrote the run's begin; one session oftests/e2e/agent-session.mjs claudeon this head passed (24 requests, every hook exit 0 with nothing on stderr).Target: under 1 s of hook time per session at 150 ms. Not met, and not reachable by handing recording off: the session still waits for four round trips one after the other (SessionStart's repository lookup and index status, the prompt's lookups, the test gate) and starts 16 node processes, 9 of them around the four tool calls.
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. Checked by hand: the recorded server log and transcripts behind each claim above, each changed script traced through one stub session before and after (processes, git calls, requests), the state transitions of the run and namespace-health files, the server's handling of a begin for a closed run (
_open_runinserver/tasks/app/run.pywrites the row active again), real client sessions on both revisions, and the docs against the code.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
Note
Medium Risk
Hook orchestration and run/audit state races can affect ledger correctness and when namespace warnings appear, though behavior is heavily tested and fail-open.
Overview
Claude Code now wires a single
UserPromptSubmithook (loom-record.mjs) instead of three separate processes. The launcher runsloom-prompt-packandloom-prompt-recallin the hook process, merges theiradditionalContextinto one JSON line, then spawns a detached recorder forrun.beginand the namespace audit so the prompt does not block on those network calls.keepRunBeginwrites the pendingrun.beginbody to session run state before the detached job starts;loom-runand SessionEnd logic are updated so late answers do not reopen closed runs or race with SessionEnd’s own begin retry.loom-namespace-healthtriggersnamespace.auditfrom the first prompt’s detached path and stores the verdict; Stop hooks mostly read that cache (with in-place audit only when the detached ask is overdue), which removes the Stop-time wait that often returned nothing.Supporting changes include lookup hooks returning answers for orchestration, shared checkout/git caching in
runHooksTogether, plugin 1.2.66, mirrored Codex sources, and docs/tests for wiring, races, and merged context.Reviewed by Cursor Bugbot for commit d716ba2. Bugbot is set up for automated code reviews on this repo. Configure here.