Repository navigation
fix(daemon): give each macOS resolver probe its own clientId - #27752
outof-place wants to merge 1 commit into
Conversation
Every new PTY first asks the daemon for macOS resolver health over a fresh control socket, and every probe said hello as 'resolver-health-check'. The daemon replaces a control socket whose clientId a newer hello reuses, so when two terminals were created together the second probe's hello closed the first one's socket. The probe settled only on 'error', not 'close', so that create waited out the 3 s probe timeout before spawning (1 to 3 of 3 concurrent pairs on a dev runtime; sequential creates took 12 to 40 ms). Use a unique clientId per probe and settle as 'unknown' when the socket closes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to No merge-blocking issue is identified. The reported macOS tests passed; broader platform checks remain unreported. Pre-merge checks |
|
|
Thanks so much @outof-place for tracking this down and fixing it. We couldn't push to your fork's branch, so the fix continues in #33833. I rebased it onto main and tightened the tests. Your authorship is kept on the commit. Closing this one in favor of that PR. |
ELI5
When two terminals start at the same time on macOS, one of them sometimes sits for 3 seconds before its shell appears. Two quick health checks were using the same name, so the second one hung up on the first, and the first waited out its full timeout.
What Changed
Before: each new PTY first runs
getMacDaemonSystemResolverHealth, which connects to the daemon with the fixedclientId: 'resolver-health-check'. Two probes in parallel collide: the daemon replaces the earlier control socket with that id, and the earlier probe (listening only for'error') waits for the 3 s timeout, returns'unknown', and only then lets its terminal spawn.After: every probe says hello with its own
resolver-health-check-<uuid>, and a probe whose socket closes settles as'unknown'at once instead of waiting for the timer. Parallel creates start as fast as sequential ones.Why
The daemon's rule (a newer hello with the same
clientIdreplaces the old control socket) is right for real clients reconnecting, so the probe is what should change. Settling on'close'also covers any other way the daemon drops the probe's socket. A shared single-flight probe would also avoid the collision, but it changes more behaviour; this is the minimal fix.Linked Issue
Fixes #27751
Visual Proof
N/A: no UI change. The effect is timing: a terminal created in parallel with another no longer waits ~3 s.
Testing
New
src/main/daemon/daemon-resolver-health-probe.test.ts(macOS only; the probe returns'unknown'elsewhere without touching the socket):DaemonServerall answer'healthy'within 1.5 s. On the old code:['unknown', 'unknown', 'healthy']after 3001 ms.'unknown'within 1.5 s. On the old code: 3002 ms.Ran on this branch (macOS):
vitest run --config config/vitest.config.ts src/main/daemon/daemon-resolver-health-probe.test.ts src/main/daemon/daemon-health.test.ts src/main/daemon/daemon-authenticated-client-activity.test.ts→ 37/37 pass; withdaemon-health.tsreverted to main, the new test fails as above.oxlintandoxfmt --checkon the two changed files: clean.Behaviour measured on a fork with the same daemon code (dev runtime,
terminal.createtwice in parallel, 3 rounds per run): with the fix 0 of 9 pairs waited 3 s (17-55 ms); without it 5 of 6 pairs took 3010-3032 ms.Not run: full
pnpm lint,pnpm typecheck,pnpm test,pnpm build. Linux, Windows and SSH were not tested; the changed code path runs on macOS only.I manually tested these changes locally (measured on our fork's dev runtime, see above, not on this branch's app)
Automated tests added/updated, or explained why not below
AI Disclosure
Written with Claude Code (Claude Opus 5.5): root cause, fix, tests and this description.
Review
Agent skill upstream boundary
Notes
macOS-only code path (
process.platform !== 'darwin'returns early).randomUUIDcomes fromnode:crypto. No protocol change: the daemon already accepts anyclientId.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)🤖 Generated with Claude Code