Skip to content

fix(daemon): give each macOS resolver probe its own clientId - #27752

Closed
outof-place wants to merge 1 commit into
stablyai:mainfrom
outof-place:fix/resolver-probe-client-id
Closed

outof-place wants to merge 1 commit into
stablyai:mainfrom
outof-place:fix/resolver-probe-client-id

Conversation

@outof-place

Copy link
Copy Markdown
Contributor

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 fixed clientId: '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 clientId replaces 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):

    • three parallel probes against a real DaemonServer all answer 'healthy' within 1.5 s. On the old code: ['unknown', 'unknown', 'healthy'] after 3001 ms.
    • a daemon that closes the probe socket after hello gives '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; with daemon-health.ts reverted to main, the new test fails as above.

  • oxlint and oxfmt --check on the two changed files: clean.

  • Behaviour measured on a fork with the same daemon code (dev runtime, terminal.create twice 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

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

macOS-only code path (process.platform !== 'darwin' returns early). randomUUID comes from node:crypto. No protocol change: the daemon already accepts any clientId.

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)

🤖 Generated with Claude Code

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]>
@coderabbitai

coderabbitai Bot commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5bf4016e-891c-4a0c-a0cd-bc684cb9e2c0

📥 Commits

Reviewing files that changed from the base of the PR and between 78144e9 and 7cb89c5.


📒 Files selected for processing (2)
  • src/main/daemon/daemon-health.ts
  • src/main/daemon/daemon-resolver-health-probe.test.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.



📝 Walkthrough

Walkthrough

Each macOS resolver health probe now uses a UUID-suffixed control client ID. Socket closure now invokes the probe’s error handler, and cleanup removes the close listener. New macOS tests check that concurrent probes return healthy and that a probe returns unknown after the socket closes.


Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 7cb89

No merge-blocking issue is identified. The reported macOS tests passed; broader platform checks remain unreported.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: assigning each macOS resolver probe its own clientId.
Description check Passed The description is complete and aligned with the template. It explains the problem, user impact, implementation, rationale, linked issue, testing, platform scope, AI disclosure, and checklist status. …
Linked Issues check Passed Issue #27751 requires concurrent macOS resolver probes to avoid the approximately 3-second terminal creation delay. daemon-health.ts now assigns each probe a UUID-suffixed clientId, so probes do n…
Out of Scope Changes check Passed The changes stay within issue #27751. The source change fixes probe client identity and close handling. The added tests verify the concurrent-probe and socket-close behavior. No unrelated production b…

  • Fix all pre-merge checks with AI
  • 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@nwparker

Copy link
Copy Markdown
Contributor

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.

@nwparker nwparker closed this Oct 26, 2026
@outof-place
outof-place deleted the fix/resolver-probe-client-id branch November 7, 2026 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

macOS: a terminal created in parallel with another waits ~3 s before its shell starts

2 participants