Public: anyone can read this; the crew can change it.
A `[loop]` stall line names what the serving thread was doing: the route or duty in flight #17982
Merged 16h 54m ago, live in production
The [loop] stall line now says what the serving thread was running when it stopped answering. Example: ... (seen from outside the thread) in: route GET /:owner/:repo/info/refs; load 1m 4.0.
-
Reviews
Changes requested — before the latest pushNo secret or user text reaches the line: the name comes from a route pattern or a job name, and it is limited to printable ASCII. The shared-memory table bounds are correct. Three things need fixing before this lands.
- The server wiring is untested. The tests cover
Router.step,inStepandduring, but nothing checks thatanswer()clears the cell when it ends, that a request is named after the auth await, or that the watchdog worker prints the step. Delete theenterStepcalls in server.ts and every test still passes, which breaks the rule that each behaviour has a test that fails without it. Add a test that drives a request throughansweror the server and asserts the cell is""afterwards. Add one that blocks the loop inside a step with the real watchdog and asserts the log line endsin: .... - The step is misattributed when requests overlap.
inSteprestores the cell as soon as the handler's synchronous part returns its promise. Most handlers are async, so a stall in their continuation is unnamed, or it is blamed on whichever request last calledenterStep.answer'sfinally { enterStep(0) }also wipes the name of any other request still in flight. A diagnostic that names the wrong route is worse than one that names none. Either name only what is reliably known, or re-enter the step where the handler resumes. At minimum, say in the module doc and the PR that async continuations are not covered, and makefinallyuseleaveStep(matched.step), a compare-exchange, instead of an unconditional clear. during()now builds and hashes the stringduty ${name}on every call, and the table is a fixed 4,095 names that silently returns 0 when full. Intern the duty id once per name, for example in the existing job-watch record, so the hot path only does the exchange. Truncation at 95 characters also makes two long names with the same prefix collide. Compare the full name, or make the slot wider.
Checks: no door is needed (log line only). I did not run the suite.
ApprovedAll three earlier asks are met in the diff since d75bba82. (1) A step is held only for the synchronous stretch, by
inStep, which restores the previous value by compare-exchange. The unconditional clear and the re-entry after an await are gone. A stall after an await reads with noin:and is never blamed on another request, and the new server test and the async test show it. (2) Duty ids are interned once per name throughJobWatch.stepOf. (3) Long names are no longer cut: a name past the slot gets no step, and the test shows two long names with one prefix stay distinct. The line carries only a route pattern or a duty name, printable ASCII, with no path, query or token.Router.addinterns each pattern at registration, so a request costs one atomic exchange. Non-blocking:inStepallocates a closure per request and per duty call, which is fine at this size. - The server wiring is untested. The tests cover
-
Checks
shipped production is serving it deploy a338207
-
History
- Rewrap loop_step comments (gate --fix) 3750069
- Direction: a [loop] stall step names only a synchronous stretch, duties interned once (#17974) c39f13b
- Rewrap loop_step comments (gate --fix) d75bba8
- Direction: a [loop] stall line names the route or duty in flight (#17974) d812471
- Sentinel: The lane has stopped: nothing has merged and nothing said so (#17973) 010904c
- Full suite red: test/traffic-truth.test.ts (#17972) 13460d3
- Infrastructure: a game box container opens on its live log, with Restart, Stop and Start (#17946) db96b4c
- Full suite red: test/api-security-floor.test.ts (#17965) 091b8a0
- Public /privacy and /support pages (needed for the App Store listing) (#17948) 638aa4f
- A container in the cloud tree has a Logs tab with its recent lines (#17958) 07d8c64
- A join that freezes a lent job is recorded with how long the freeze took (#17956) 80543a4
- A lent job on a game box keeps the server's tps and mspt from before it and during it (#17957) a357207
- The /infra first page shows the costliest resources as a sortable table (#17955) e08c778
- Push to Apple devices (APNs): device registration and a sender (#17928) 19eaf78
- A machine's containers in the cloud tree read as a table: name, state, CPU, memory, started (#17954) ccd2925
- API shapes: no silent type changes (approvedAt became an object); contract-test responses against openapi.json (#17945) 1b196c6
- GET the models Talk offers me, and `model` on POST /api/v1/conversations and /conversation/messages (#17916) 2623a5e
- Traces: every conversation and run kept as a trace, imported from outside agents, and explored in the forge (#17943) ce8ccb6
- A cloud account can be a sealed, expiring, read-only view for a client (#17942) 046cfff
- Pages help a reader sift: icons, a type scale, settings in groups (#17940) 3000b02
The [loop] stall line now says what the serving thread was running when it stopped answering. Example: ... (seen from outside the thread) in: route GET /:owner/:repo/info/refs; load 1m 4.0. Nothing else is added to the line: no path, query, token or user text.
How it works. A new module, src/kernel/loop_step.ts, keeps one cell in shared memory that the watchdog thread reads without touching the serving thread.
- Names are stored once. Each step name (
route METHOD patternorduty <name>) is written once into a fixed-size hash table in that same shared memory and gets a number. Route names are written whenRouter.addregisters a route; duty names the first timeduring()runs them. Names are printable ASCII only and cut at 95 characters. The table holds 4,095 names; the app has about 1,571 routes. If it ever fills, new steps show no name. - The per-request cost is one write. A request stores its step number with a single
Atomics.exchange: no Map and no allocation on the hot path.Matchnow carriesstep. - Requests (
src/http/server.ts). The step is set right after the route matches and set again after the auth await. The handler's synchronous part also runs insideinStep. The cell is cleared whenanswerfinishes. Clearing it outright (instead of restoring the previous value) is safe: when a request resumes after an await, nothing else can be mid-step on the thread. - Duties (
src/perf/jobs.ts).during()wraps the job ininStep(duty <name>)and restores the previous value afterwards. The step uses only the job's name, never the hosted child's name. - The line. The watchdog worker gets the shared memory in
WatchdogStart.stepsand putsstepWords(readStep(steps))at the front ofblockedLine'sextra.
Tests (added to test/loop-watchdog.test.ts):
- With a step set, the line names it; with none, the line is unchanged.
- A matched URL with a token-like segment and a query string reads back as its pattern only.
- A
duringduty is named while it runs and cleared when it ends. - Non-ASCII names are written with
?and long names are cut.
These tests, the router, module-state, unused-exports, route-timing, job-slices, kernel-boundary, security-floor and server-timing suites, tsc --noEmit and the gate all pass. scripts/fast.ts returned "too broad", so I chose those suites myself; the full suite was not run here.
Not done:
- Work that resumes after an await outside a request's marked points is not named. For async duties, only the synchronous part is named.
- The closing ("answered again") line is unchanged.
- No governor.
No door: this is a log line, not a page, action, API route or MCP tool.
Try: on the preview every page answers as before. When the loop blocks for 3 s, perf/loop-watchdog.log gets a line ending in: route <METHOD> <pattern> or in: duty <name>.
🤖 Generated with Claude Code
When the event loop stalls, the [loop] warning now ends with what the serving thread was running: in: route GET /:owner/:repo/info/refs for a request, or in: duty maintain for a background job (#17974). The name is always a route pattern or a job name, never a path, query or token, and only printable ASCII. The watchdog reads it from shared memory on its own thread.
This round fixes the three points from review:
- Only names what is known for sure. A step is named only while its synchronous code runs, through
inStepinsrc/kernel/loop_step.ts. The cell is set back by compare-exchange the moment that code returns or throws. The server wraps the synchronous part of the auth read and of the handler. The unconditionalenterStep(0)inanswer()is gone, and so are the calls that re-entered a step after an await. The cost is that a stall in an async handler's or duty's code after anawaitshows noin:at all. That is now stated in the module doc. It is never blamed on another request. - Duty ids are interned once. Each duty's id is worked out once per name and kept on the job watch (
JobWatch.stepOf), soduring()no longer builds and hashes a string on every call. It still creates one small function per call. - Long names are no longer cut. A slot now holds 127 bytes, and a longer name gets no step rather than a shortened one, so two names with the same prefix can't collide. The longest of the 1,571 route names is 82 bytes, so every route is named today. The table holds 4,095 names and still returns 0 (no name) when full. That is documented rather than changed, because it is well above what exists.
Tests:
test/loop-step-server.test.ts(new): sends a request with a session cookie throughforgeHttp. It checks that the auth read and the handler seeroute GET /:owner, that the query's token never shows up, and that the cell is empty afterwards. It fails when the server passes step 0 instead of the route's step.- Real watchdog: the existing test now blocks the thread inside
during("watchdog-block", …)and expectsin: duty watchdog-block;in the line the worker writes. - Unit tests check that the code after an
awaitreads as unnamed and not as the other request that ran in between, that duty ids are interned, and that long names are kept whole or refused.
bun x tsc --noEmit and bun scripts/gate.ts pass. These test files pass: loop-step-server, loop-watchdog, perf-loop-jobs, perf-loop-lag-attribution, stall-witness, router, keys-capacity, module-state and unused-exports. The full suite was not run here; the forge's check runs it on push.
No door: this is a log line, and no page or terminal screen shows it.
🤖 Generated with Claude Code
The
[loop]stall line now says what the serving thread was running when it stopped answering. Example:... (seen from outside the thread) in: route GET /:owner/:repo/info/refs; load 1m 4.0. Nothing else is added to the line: no path, query, token or user text.How it works. A new module,
src/kernel/loop_step.ts, keeps one cell in shared memory that the watchdog thread reads without touching the serving thread.route METHOD patternorduty <name>) is written once into a fixed-size hash table in that same shared memory and gets a number. Route names are written whenRouter.addregisters a route; duty names the first timeduring()runs them. Names are printable ASCII only and cut at 95 characters. The table holds 4,095 names; the app has about 1,571 routes. If it ever fills, new steps show no name.Atomics.exchange: no Map and no allocation on the hot path.Matchnow carriesstep.src/http/server.ts). The step is set right after the route matches and set again after the auth await. The handler's synchronous part also runs insideinStep. The cell is cleared whenanswerfinishes. Clearing it outright (instead of restoring the previous value) is safe: when a request resumes after an await, nothing else can be mid-step on the thread.src/perf/jobs.ts).during()wraps the job ininStep(duty <name>)and restores the previous value afterwards. The step uses only the job's name, never the hosted child's name.WatchdogStart.stepsand putsstepWords(readStep(steps))at the front ofblockedLine'sextra.Tests (added to
test/loop-watchdog.test.ts):duringduty is named while it runs and cleared when it ends.?and long names are cut.These tests, the router, module-state, unused-exports, route-timing, job-slices, kernel-boundary, security-floor and server-timing suites,
tsc --noEmitand the gate all pass.scripts/fast.tsreturned "too broad", so I chose those suites myself; the full suite was not run here.Not done:
No door: this is a log line, not a page, action, API route or MCP tool.
Try: on the preview every page answers as before. When the loop blocks for 3 s,
perf/loop-watchdog.loggets a line endingin: route <METHOD> <pattern>orin: duty <name>.🤖 Generated with Claude Code
Closes #17974