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

opened this in answer to

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.

Notes

opened this

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 writes event 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 single bun build bundle still carries it. It is started from src/main.ts and 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 with Atomics.wait and 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 crew and apps after 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.

Closes #17708

3 earlier comments
commented

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 writes event 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 single bun build bundle still carries it. It is started from src/main.ts and 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 with Atomics.wait and 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 crew and apps after 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.

commented

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.ts runs on a separate thread with no job ring, so there is no job name to attribute it to.
  • Heartbeat store: loop_watchdog.ts does 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 setTimeout in boot_steps.ts only 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.

commented

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 in heldRuns(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.ts holds a lease and backdates the heartbeat: the run stays running with 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() in scripts/bundle.ts finds it, and test/bundle-workers.test.ts loads every worker it finds from the bundle, so that test covers this file.

Changes for each of your points

  1. Boot staging dropped. boot_steps.ts, its main.ts wiring 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.
  2. Lease guard is described on its own, above.
  3. Worker description is corrected, above.
  4. 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 /proc exists, and the sleep child is gone.
    • A census test builds 20,000 children and fails if the count goes quadratic.
  5. proc_census.ts: the doc comment and the line now both say under pid:, and census pushes onto the existing array.
  6. Log size: the watchdog writes through keptLog (perf/kept_log.ts, which now takes an optional file name) to its own perf/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.

commented

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.

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs