You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(daemon): wake every macOS pool worker each minute so none ages past psynch's half-range - #36373
On macOS, Node's file worker threads can fall asleep for good after a long run. Terminals then stop taking typing and new terminals time out, but the daemon still answers health checks. This PR wakes every worker once a minute so none of them gets old enough to hit the bug.
What Changed
threadpool-waiter-refresh.ts runs only on macOS in the terminal daemon. Every 60 seconds it posts one blocking read per libuv pool worker on a private FIFO and releases them together 20 ms later. The pool size is read from UV_THREADPOOL_SIZE the way libuv reads it. A worker holding one read cannot take another, so the reads occupy distinct workers. Every parked worker wakes up and parks again at the current psynch generation. If the previous round has not finished, the daemon skips the round. A stuck or saturated pool gets no extra work.
daemon-entry.ts starts it after ready. docs/bug-reproductions/daemon-async-io-stall.md now names the trigger and records the evidence below.
Why
The trigger is the Darwin psynch defect in libuv#5280. A pool worker can stay parked while its siblings finish 2^23 waits. Each wait moves the condvar sequence by 0x100, so that worker ends up exactly 0x80000000 behind. After that the kernel turns every signal into a prepost, U catches L, and pthread_cond_signal returns without a syscall. The pool keeps its queue and its idle workers forever. Timers and sockets don't use the pool, so the daemon still answers RPCs.
I read a wedged production daemon (Node 24.21.0, libuv 1.52.1, macOS, 77 sessions, 2 days up) with an lldb attach that only read memory:
The pool queue held 15 uv__fs_work items with idle_threads == 4. The loop's completion queue was empty, its EVFILT_USER wakeup knote was registered, and wq_async.pending was 0. So queued work was never picked up. Completion delivery was fine.
On the pool condvar, L = U = 0xfd79d800 and S = 0xfd79d402. Three workers waited at 0xfd79d6..d8. The fourth waited at 0x7d79d800, exactly 0x80000000 behind.
Restarting the daemon on a stall ends every terminal. Detect stalled terminal daemon I/O and offer restart review #29087's detection and restart review already cover that, and they still apply to daemons that are already wedged. Once L == U signals no longer reach the kernel, so this refresh cannot recover them.
uv_cond_broadcast hits the same L == U early return.
Cost: one 20 ms pause of pool work per minute on macOS, which can delay terminal input or file work by up to 20 ms. Reaching the boundary inside one 60-second interval would take about 140,000 pool operations per second.
Linked Issue
Addresses #11178, the daemon that wedges while every liveness signal stays healthy. This removes the macOS cause for new daemons. It doesn't change readoption, and daemons that are already wedged still need the existing restart review.
N/A. This changes daemon scheduling only and adds no UI.
Testing
macOS 26.2 arm64:
Unit tests: a round really holds the whole pool (a stat posted during it waits for the release; fails with an immediate release), one round per interval, no new round while one is unfinished, no-op off macOS, and pool sizing that matches libuv. Existing daemon-entry, daemon-health, daemon-tcc-attribution, plain-node-entry-guard and daemon-async-io-probe tests pass (93 tests). tsc for node passes. The changed-code quality gate passes.
Natural trigger: serial fs.promises.stat on stock Node 24.22.1 with four workers stalled after 40,262,072 operations (21 minutes). The trigger is intermittent. 20M serial stats on two workers and 31M cycles of the libuv#5280 pthread repro completed.
Generation witness: lldb read the four idle workers of a Node 24.22.1 process before and after one refresh round. All four wait generations moved to the current value.
Red/green pthread model of the pool, aged with 1 ns timed waits on the pool mutex (the method in libuv PR 5351). Without refresh it stalled with 0/4 jobs done after 2^23 + 4,096 steps. With one 1 ms job per worker every 1M steps, all four jobs completed.
Not tested: Intel Macs, older macOS, a live daemon running this build for days.
AI Disclosure
Claude Opus 5.5 (Claude Code) did the investigation, the lldb reads, the code and this description.
Review
Agent skill upstream boundary
Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.
Notes
Cross-platform: Linux and Windows skip it. Their condvars don't use psynch.
Remote/SSH: only the local daemon starts it. A relay running on a remote macOS host is not covered.
The Electron main process has its own libuv pool and the same exposure. It is not covered here.
Mixed versions: no protocol or wire change. Old daemons keep running as they are until they restart.
Checklist
This PR is small and focused
I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
Before/after screenshots or videos attached for UI changes, or N/A with reason
Self-reviewed for correctness, security, and performance
Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)
…st psynch's half-range
A libuv worker that stays parked while its siblings finish 2^23 waits ends
up exactly 0x80000000 behind on Darwin's psynch condvar. From then on every
uv_cond_signal is a userspace no-op (libuv#5280). The pool keeps its queue
and its four idle workers forever. The daemon still answers RPCs, but
terminal input and new terminals stop.
On macOS the daemon now posts one ~1 ms pbkdf2 job per worker every 60
seconds. Each job needs its own worker, so every parked worker wakes and
parks again at the current generation. A round is skipped while the
previous one is still running, so a stuck pool gets no extra work.
The daemon now starts a Darwin-only threadpool waiter refresh after it reports readiness. The refresh creates blocking FIFO reads for the pool workers and releases them after 20 ms. It skips a round while the previous round remains unfinished. Tests cover scheduling, platform behavior, cleanup, and pool-size parsing. The reproduction document describes the proposed stall mechanism, the refresh procedure, and automated, manual, and natural reproduction observations.
Merge Risk: Moderate · up to 4c348
On macOS, a temporary-directory setup failure can terminate the daemon instead of merely disabling the refresh. Handle that failure before merging.
Pre-merge checks: 4 · 1
Failed checks: 1 warning
Check name
Status
Explanation
Resolution
Docstring Coverage
Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta…
Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed checks: 4 passed
Check name
Status
Explanation
Title check
The title clearly and concisely describes the primary change: periodically waking macOS daemon threadpool workers to avoid the psynch half-range defect.
Description check
The description is complete and relevant. It includes the required explanation, changes, rationale, linked issue, visual-proof statement, testing details, AI disclosure, cross-platform notes, and chec…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Description check
Explanation
The description is complete and relevant. It includes the required explanation, changes, rationale, linked issue, visual-proof statement, testing details, AI disclosure, cross-platform notes, and checklist. It also clearly records known testing limits and uncovered components.
Full details: Docstring Coverage
Explanation
Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 4 functions across 3 files. (1 skipped: 1 unsupported.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: ba6651cd-369b-46f6-b088-0127c3dbaf5f
Commits
Reviewing files that changed from the base of the PR and between 437c47f and 1efae95.
Files selected for processing: 4
docs/bug-reproductions/daemon-async-io-stall.md
src/main/daemon/daemon-entry.ts
src/main/daemon/threadpool-waiter-refresh.test.ts
src/main/daemon/threadpool-waiter-refresh.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Longer natural-workload comparison on macOS 26.2 arm64, stock Node 24.22.1 / libuv 1.52.1. Both isolated processes ran serial fs.promises.stat('/tmp') on the default four-worker pool, side by side:
Variant
Result
No refresh
Stalled after 63,621,610 operations (26 min). No completion for the next 3 minutes.
startThreadpoolWaiterRefresh() at its default 60 s interval
Completed 90,000,000 operations (31 min), exit 0
This is one run per side and the trigger is intermittent, so it supports the change but doesn't prove it.
… racing short jobs
Four short pbkdf2 jobs only wake every worker if all four are posted
before the first one finishes. A preempted main thread could let one worker
take two jobs and leave a parked worker untouched.
Each round now posts one blocking read per worker on a private FIFO and
releases them together 20 ms later. A worker holding one read cannot take
another, so the reads occupy distinct workers. A test checks that pool work
posted during a round waits for the release, and it fails when the release
is immediate.
The reason will be displayed to describe this comment to others. Learn more.
Follow-up Comments
Handle refresh-factory rejection without an unhandled rejection.
67-110: Minor · Stability & Availability · Quick win
Handle refresh-factory rejection without an unhandled rejection.
If temporary-directory setup fails, createFifoHoldRound() rejects before its try. The detached refresh promise has no rejection handler, so the rejection can remain unhandled after the daemon reports readiness and can terminate the daemon. Handle the rejection and disable this optional mitigation.
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 5fb5b0f4-082c-4a76-b6a0-c6669f3a6943
Commits
Reviewing files that changed from the base of the PR and between 1efae95 and 4c34810.
Files selected for processing: 3
docs/bug-reproductions/daemon-async-io-stall.md
src/main/daemon/threadpool-waiter-refresh.test.ts
src/main/daemon/threadpool-waiter-refresh.ts
Files skipped from review as they are similar to previous changes: 3
docs/bug-reproductions/daemon-async-io-stall.md
src/main/daemon/threadpool-waiter-refresh.test.ts
src/main/daemon/threadpool-waiter-refresh.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Field data from a daemon running this change (daily build, Node 24.21.0 / libuv 1.52.1, macOS 26.2 arm64, about 57 hours up under normal use). A read-only lldb snapshot:
L has advanced 0xc089ad (12.6M) waits since start, which is past the 2^23 half-range point. No worker is more than 3 waits behind, and L != U, so signals still reach the kernel. The private FIFO is open in the daemon, and its offset shows the rounds running.
On the 20 ms hold: if a worker isn't scheduled within 20 ms, that round can miss it. The next round comes 60 s later. At this daemon's rate (about 61 waits/s, 3.7k per round), a worker would have to miss about 2,300 consecutive rounds, roughly 38 hours, to reach the boundary. So I kept the fixed hold instead of adding release coordination.
This branch has not been deployed
No deployments
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
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.
ELI5
On macOS, Node's file worker threads can fall asleep for good after a long run. Terminals then stop taking typing and new terminals time out, but the daemon still answers health checks. This PR wakes every worker once a minute so none of them gets old enough to hit the bug.
What Changed
threadpool-waiter-refresh.tsruns only on macOS in the terminal daemon. Every 60 seconds it posts one blocking read per libuv pool worker on a private FIFO and releases them together 20 ms later. The pool size is read fromUV_THREADPOOL_SIZEthe way libuv reads it. A worker holding one read cannot take another, so the reads occupy distinct workers. Every parked worker wakes up and parks again at the current psynch generation. If the previous round has not finished, the daemon skips the round. A stuck or saturated pool gets no extra work.daemon-entry.tsstarts it afterready.docs/bug-reproductions/daemon-async-io-stall.mdnow names the trigger and records the evidence below.Why
The trigger is the Darwin psynch defect in libuv#5280. A pool worker can stay parked while its siblings finish 2^23 waits. Each wait moves the condvar sequence by 0x100, so that worker ends up exactly 0x80000000 behind. After that the kernel turns every signal into a prepost,
UcatchesL, andpthread_cond_signalreturns without a syscall. The pool keeps its queue and its idle workers forever. Timers and sockets don't use the pool, so the daemon still answers RPCs.I read a wedged production daemon (Node 24.21.0, libuv 1.52.1, macOS, 77 sessions, 2 days up) with an
lldbattach that only read memory:uv__fs_workitems withidle_threads == 4. The loop's completion queue was empty, itsEVFILT_USERwakeup knote was registered, andwq_async.pendingwas 0. So queued work was never picked up. Completion delivery was fine.L = U = 0xfd79d800andS = 0xfd79d402. Three workers waited at0xfd79d6..d8. The fourth waited at0x7d79d800, exactly0x80000000behind.Alternatives considered:
L == Usignals no longer reach the kernel, so this refresh cannot recover them.uv_cond_broadcasthits the sameL == Uearly return.Cost: one 20 ms pause of pool work per minute on macOS, which can delay terminal input or file work by up to 20 ms. Reaching the boundary inside one 60-second interval would take about 140,000 pool operations per second.
Linked Issue
Addresses #11178, the daemon that wedges while every liveness signal stays healthy. This removes the macOS cause for new daemons. It doesn't change readoption, and daemons that are already wedged still need the existing restart review.
Related: #31926, #32220.
Visual Proof
N/A. This changes daemon scheduling only and adds no UI.
Testing
macOS 26.2 arm64:
statposted during it waits for the release; fails with an immediate release), one round per interval, no new round while one is unfinished, no-op off macOS, and pool sizing that matches libuv. Existingdaemon-entry,daemon-health,daemon-tcc-attribution,plain-node-entry-guardanddaemon-async-io-probetests pass (93 tests).tscfor node passes. The changed-code quality gate passes.fs.promises.staton stock Node 24.22.1 with four workers stalled after 40,262,072 operations (21 minutes). The trigger is intermittent. 20M serial stats on two workers and 31M cycles of the libuv#5280 pthread repro completed.lldbread the four idle workers of a Node 24.22.1 process before and after one refresh round. All four wait generations moved to the current value.AI Disclosure
Claude Opus 5.5 (Claude Code) did the investigation, the
lldbreads, the code and this description.Review
Agent skill upstream boundary
Notes
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)