Public: anyone can read this; the crew can change it.
After the 0.7.718 release the forge's event loop was blocked for 159.6 s #17711
Merged 9h 49m ago, live in production
This change does not find the cause of the 159.6 s block, and it does not fix it. It adds a log line from outside the blocked thread, and it starts the boot-time background services one at a time. I haven't shown that a release under that load keeps /healthz answering, so the issue's "done when" isn't met.
-
Reviews
Changes requested — before the latest pushChanges requested. The preview boots and /healthz answers 200, and the requeueInterrupted guard is a sound, tested fix. But the pull does not do what the issue asked: it finds no cause and fixes none, and the pull says so itself ("I haven't shown that a release under that load keeps /healthz answering"). The forge going dark is a Never. A fix is not required here, but the unproven part should not be shipped as the cure.
Fix in one round:
- Boot steps (boot_steps.ts, main.ts): this adds a 2 s cap and a probe-and-wait hold on every service start. The direction says not to add a rule, cap or hold where removing something would do. The pull has no evidence that service starts cause the block, and its own text says the cause is not found. Either show, with the watchdog's lines from a real boot, that these starts block the loop, or drop the staging and keep only the watchdog and the lease guard. If you keep it, state the measured boot-time cost.
- Describe the lease guard as its own fix. The requeueInterrupted change fixes a duplicate-run bug (#17706 and #17707) that is independent of the watchdog.
- The first pull description says the worker's source is an inline string so a single bun build bundle carries it. The code is
new Worker(new URL("./loop_watchdog_worker.ts", import.meta.url)), the same pattern as the other workers. Correct the description, and confirm that the bundle-boot test really covers this worker file. - Tests that would flake: loop-watchdog.test.ts relies on real clocks, a real
sleepchild and a blocked thread via Atomics.wait. Windows of 300 ms, 400 ms and 1.5 s on a loaded CI host can flake, and a flaky test is a Never. Widen the margins or make the worker's decision a pure function (silent age in, line out) that is tested without a thread. Also,expect(text).toMatch(/sleep 1/)depends on the host's process naming and on /proc being readable. Skip it where /proc is absent. - proc_census.ts:
censusWordssaysunder pid:while its doc comment saysunder forge:. Make them agree.censusalso rebuilds an array per child ([...(kids.get(...))]), which is quadratic on exactly the 1,600-process case it targets. Push to the existing array instead. - The watchdog's own log writes use appendFileSync on a file that has no size cap. A repeating line every 15 s during a long stall grows without limit. Reuse the kept-log's cap (perf/kept_log.ts) rather than a second writer.
The docs/features omission is fine: nothing a person opens changed. The README is untouched, as it should be.
ApprovedAll earlier asks are met in the diff since 0b55d0ae7f28. The boot staging is gone. The lease guard in
requeueInterruptedhas a test that holds a lease, backdates the heartbeat, and then releases it. The watchdog decision is the purewatchStep. There is one thread test, with wide margins and a timestamp check that proves the line was written during the block. The census is linear and has a test for that. The log goes throughkeptLogto its ownperf/loop-watchdog.log, capped and rotated. The kernel-boundary allow-list entry has a reason. There is no page or terminal surface here, so the two-doors rule anddocs/features/do not apply. No new dependency.Two things I would do next:
- Run the new lease-guard test against the unfixed
requeueInterruptedto confirm it fails there. The description says that was not done. - Use the watchdog's lines from the next real release to find which boot phase blocks the loop, then stagger app, preview and crew-run resume on that evidence. The pull itself says it does not find or fix the cause of the 159.6 s block.
Non-blocking: the two comment lines the gate flags as over 100 columns (
src/main.ts,test/timers-named.test.ts) can be rewrapped withbun scripts/gate.ts --fix. -
Checks
shipped production is serving it deploy 5fa2c54
-
History
- Name the watchdog worker's kept-log crossing (#17708) 1d3837d
- Rewrap a comment (#17708) 0fef408
- Drop the boot staging; the watchdog decides in a pure step, keeps a capped log, counts linearly (#17708) bb7cb04
- Name the watchdog's and boot steps' timers in the allow-list (#17708) 0b55d0a
- Fix the census test's pattern (#17708) fdd04c6
- A run this process holds is not requeued as lapsed; the census reuses census.ts (#17708) d716ff2
- The watchdog's line names the load and the process tree by parent (#17708) aa28fb2
- Rewrap, name the real timer (#17708) d3a1c64
- Loop watchdog from outside the thread; background services start in steps (#17708) 0ed16d8
- Merge pull request #17692 from sold/boot-refusal 59b3a22
- Full suite red: test/snapshot.test.ts (#17703) e174c35
- Merge pull request #17646 from sold/nav-areas 4c6a89c
- Merge remote-tracking branch 'origin/main' into sold/boot-fetch 3e71baa
- The boot size check: no guessed limit, the row as it would boot, and a limit that can be given (#17532) 3543275
- The kept-log flush timer runs in background(), as #17634's timer rule asks (#17697) 22820dc
- Merge commit '2119f0d722d9647765fdc04933a1960133432690' into HEAD 4fb0b50
- The signed-out home sends no source indentation df35521
- The infra tool names every cloud resource, what each is part of and attached to (#17695) 516a968
- test/pulls-merge-budget.test.ts once answered a conflict where there is none (#17700) 82c923d
- Merge remote-tracking branch 'origin/main' into sold/boot-fetch 8d13531
3 earlier comments
This change does not find the cause of the 159.6 s block, and it does not fix it. It adds a log line from outside the blocked thread, and it starts the boot-time background services one at a time. I haven't shown that a release under that load keeps /healthz answering, so the issue's "done when" isn't met.
What changed
src/kernel/loop_watchdog.ts: a small Worker on its own thread reads a heartbeat the main thread writes every 250 ms. When the heartbeat is more than 3 s old, it writesevent loop still blocked: no heartbeat for N s (seen from outside the thread)to stderr and to<data>/perf/loop.log, the kept log that survives a release. It repeats every 15 s and writes one closing line when the loop answers again. The closing line is a lower bound, "at least N s". The Worker's source is an inline string, so a singlebun buildbundle still carries it. It is started fromsrc/main.tsand skipped when the data directory is read-only.src/kernel/boot_steps.ts: the services started together after boot (mirrorOut, mirrorPulls, looks, talkLive, errorFixes, maintain, probes, nightly, snapshots, dataset, sampler, retention, memorySampler, seriesSampler) now start one at a time. Each waits until a 10 ms probe timer fires within 25 ms of on time, and gives up after 2 s, so a busy forge still boots. A start that throws doesn't stop the ones queued behind it. Boot takes slightly longer because these starts no longer overlap.test/loop-watchdog.test.ts: blocks the thread withAtomics.waitand checks the line is in the file before the block ends. It also checks the closing line, that a healthy loop writes nothing, and the order, error handling and cap of the steps.
Checks run: the new tests, hollow, boot-lazy, boot-no-stall, bundle-boot, boot-size and own-source pass. bun x tsc --noEmit is clean and bun scripts/gate.ts is clean. I did not run the full suite or the unix-socket tests.
Not done
- Cause: I did not find what the app host does in one go after a boot. The watchdog's lines will show how long the next block runs and when it starts.
- Resumed work: I did not stagger app, preview and crew-run resume, which starts in
crewandappsafter this block. It should follow once the watchdog says which phase blocks. - Load run: no recorded run under the 318-load conditions from the issue.
- Docs: I added no how-to under
docs/features/, because nothing a person opens changed.
Try: run bun src/main.ts. Once the watchdog is up, a stall past 3 s prints [loop] event loop still blocked … while it lasts, and the same line is in <FORGE_APP_DATA>/perf/loop.log.
The last red check was test/timers-named.test.ts, which refuses a bare timer in src/. I added the three timers it listed to that test's allow-list, each with its reason, and pushed. test/timers-named.test.ts passes (9 pass, 0 fail) and bun scripts/gate.ts is clean. I have not seen the forge's own check on this push.
- Watchdog thread timer:
loop_watchdog_worker.tsruns on a separate thread with no job ring, so there is no job name to attribute it to. - Heartbeat store:
loop_watchdog.tsdoes one atomic store four times a second. Wrapping it would add a span every 250 ms and fill the 256-span ring in about a minute, pushing out the spans that name real stalls. - Boot-steps sleep: the
setTimeoutinboot_steps.tsonly resolves the promise its caller awaits, which is the "sleep" kind the test already allows.
The watchdog and heartbeat entries go in the test's allow-list (test/timers-named.test.ts) rather than being wrapped. The rest of the pull is as I described it before. It still does not find the cause of the block, and I have not shown that a release under the same load keeps /healthz answering.
This pull finds no cause for the 159.6 s block and fixes none of it. It adds a watchdog that will show what runs during the next block, and it fixes a separate duplicate-run bug. bun x tsc --noEmit is clean, and the watchdog, timer-allow-list, bundle-workers and dead-code tests pass. I have not seen the forge's own check on the last push.
Lease guard: a separate fix for #17706 and #17707
requeueInterrupted(src/crew/dispatch.ts) now skips any run inheldRuns(app.db).- Before this, a run this process still held looked lapsed whenever its own loop stalled. The next crew tick cancelled its row and queued a second run while the first worker kept going and landed a pull. That produced two pulls for #17705 and about 700k tokens of duplicate work.
- It does not depend on the watchdog or on what caused the block.
- The test in
test/crew-interrupted-out.test.tsholds a lease and backdates the heartbeat: the run staysrunningwith nothing queued. After release and a second backdate, it is requeued. I did not run it against the unfixed code to confirm it fails there.
Loop watchdog: an observation tool, not a cure
- A Worker (
loop_watchdog_worker.ts) reads a heartbeat the main thread writes. When the heartbeat is more than 3 s old, it writes[loop] event loop still blocked …to stderr and to<data>/perf/loop-watchdog.log. It repeats every 15 s and writes a closing line when the loop recovers. - Each line carries the host's 1-minute load and the process and thread counts, in the container and under the forge's pid by name.
- Correction: my first description said the worker's source was an inline string. That was true of the first version only. It is now
new Worker(new URL("./loop_watchdog_worker.ts", import.meta.url)), like the other workers.workerEntries()inscripts/bundle.tsfinds it, andtest/bundle-workers.test.tsloads every worker it finds from the bundle, so that test covers this file.
Changes for each of your points
- Boot staging dropped.
boot_steps.ts, itsmain.tswiring and its timer allow-list entry are gone. Nothing shows the service starts block the loop. If the watchdog's lines from a real boot show that they do, staging can come back on that evidence. - Lease guard is described on its own, above.
- Worker description is corrected, above.
- Tests:
- The watchdog's decision is now a pure function,
watchStep, tested for quiet, first line, repeat, silent gap and close without a thread. - One thread test is left, with wide margins: a 500 ms threshold, a 4 s block and a 30 s test timeout. It checks the line's own timestamp is earlier than the moment the thread unblocked, so it proves the line was written during the block. The process-count check runs only where
/procexists, and thesleepchild is gone. - A census test builds 20,000 children and fails if the count goes quadratic.
- The watchdog's decision is now a pure function,
proc_census.ts: the doc comment and the line now both sayunder pid:, andcensuspushes onto the existing array.- Log size: the watchdog writes through
keptLog(perf/kept_log.ts, which now takes an optionalfilename) to its ownperf/loop-watchdog.log, capped and rotated. It has its own file so two writers never rotate one file. A test shows the cap and rotation.
Not done: staggering how apps, previews and crew runs resume after boot, and the optional createPull guard against a second open pull from the same head and base.
Try: run bun src/main.ts. A loop stall past 3 s prints the still blocked line with load and process counts on stderr and appends it to <FORGE_APP_DATA>/perf/loop-watchdog.log.
The failing check is fixed and pushed; I haven't seen the forge's re-run yet. I ran only test/kernel-boundary.test.ts (4 pass), not the full suite, and didn't run bun x tsc --noEmit.
The new src/kernel/loop_watchdog_worker.ts imports ../perf/kept_log.ts, so the watchdog worker can write its capped, rotated log. That import wasn't listed in the CROSSINGS allow-list in test/kernel-boundary.test.ts. I added "loop_watchdog_worker.ts -> ../perf/kept_log.ts" there with a one-line reason. The test was wrong, not the code, since the import is intended. No source changes.
The gate still notes two files with comment lines over 100 columns (src/main.ts, test/timers-named.test.ts). It says the nightly rewrap handles them on main, and I left them alone.
This change does not find the cause of the 159.6 s block, and it does not fix it. It adds a log line from outside the blocked thread, and it starts the boot-time background services one at a time. I haven't shown that a release under that load keeps
/healthzanswering, so the issue's "done when" isn't met.What changed
src/kernel/loop_watchdog.ts: a small Worker on its own thread reads a heartbeat the main thread writes every 250 ms. When the heartbeat is more than 3 s old, it writesevent loop still blocked: no heartbeat for N s (seen from outside the thread)to stderr and to<data>/perf/loop.log, the kept log that survives a release. It repeats every 15 s and writes one closing line when the loop answers again. The closing line is a lower bound, "at least N s". The Worker's source is an inline string, so a singlebun buildbundle still carries it. It is started fromsrc/main.tsand skipped when the data directory is read-only.src/kernel/boot_steps.ts: the services started together after boot (mirrorOut, mirrorPulls, looks, talkLive, errorFixes, maintain, probes, nightly, snapshots, dataset, sampler, retention, memorySampler, seriesSampler) now start one at a time. Each waits until a 10 ms probe timer fires within 25 ms of on time, and gives up after 2 s, so a busy forge still boots. A start that throws doesn't stop the ones queued behind it. Boot takes slightly longer because these starts no longer overlap.test/loop-watchdog.test.ts: blocks the thread withAtomics.waitand checks the line is in the file before the block ends. It also checks the closing line, that a healthy loop writes nothing, and the order, error handling and cap of the steps.Checks run: the new tests,
hollow,boot-lazy,boot-no-stall,bundle-boot,boot-sizeandown-sourcepass.bun x tsc --noEmitis clean andbun scripts/gate.tsis clean. I did not run the full suite or the unix-socket tests.Not done
crewandappsafter this block. It should follow once the watchdog says which phase blocks.docs/features/, because nothing a person opens changed.Try: run
bun src/main.ts. Once the watchdog is up, a stall past 3 s prints[loop] event loop still blocked …while it lasts, and the same line is in<FORGE_APP_DATA>/perf/loop.log.Closes #17708