fix(daemon-client): report a newer daemon that won a startup race as daemon-incompatible
Summary
ensureDaemon reports a daemon newer than the client with details.reason: 'daemon-incompatible' and details.mismatch: 'newer', so callers can branch on the reason. When it lost a startup race to that newer daemon, it reported the same condition with no typed reason: start catches only daemon-contended, and the refusal that reached the caller had none, so an SDK caller branched wrong.
readReusableLocalDaemon threw newerDaemonRefusedError before consulting settings.retireIncompatibleContender, so a client that may not retire contenders got that untyped refusal from observeContendingDaemon. The fix moves that check above the refuseNewer throw: such a client reports the race, ensureDaemon judges the winner again, and the canonical daemon-incompatible error answers. Two files, no new wire reason literal.
What each caller of readReusableLocalDaemon sees:
observeContendingDaemon→ensureDaemon.start(retireIncompatibleContender: false, the only route where it is false): a newer winner now reaches the existingdaemon-contendedbranch, so the nextensureOncejudges it and throwsdaemon-incompatible/mismatch: 'newer'. Every other non-reusewinner behaved this way already.ensureLocalDaemon(retireIncompatibleContender: true; CLI, MCP, proxy upstream, SDK managed client): unchanged — keepsnewerDaemonRefusedErrorand its wording, so the existing newer-daemon tests pass unchanged.
Part of #4649.
Validation
Base 74771e1919, head 4a05c1b3f7.
- New
daemon-client-ensure-startup-race.test.ts(real launch plus a real newer child that wins the lock).pnpm exec vitest run --project unit-core packages/daemon-client/src/__tests__/daemon-client-ensure-startup-race.test.ts: base → fails,details.reasonundefined; head → passes. Gross +140/-3; production net 0 (3/3, reordering only) against the ≤ +3 budget. packages/daemon-client(348 tests) andpackages/daemon-contracts(240) pass; the daemon-fixture-launch and mutation-scope guards pass.pnpm build,pnpm typecheck,pnpm lint,pnpm formatand the layering check (R84, R89 quiet) pass. CI owns full validation; no new allowlist, baseline or budget row.
🤖 Generated with OpenCode (Callstack Apex)
![Autofix with [code]smith](https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-dark-3x.png)
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.