Skip to content

refactor(client): share the registered service decision between clients - #53241

Merged
kitlangton merged 2 commits into
v2from
share-service-decision
Oct 6, 2026
Merged

kitlangton merged 2 commits into
v2from
share-service-decision

Conversation

@kitlangton

@kitlangton kitlangton commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Why

When a registered service answers, both ensure() loops decide what to do with the same chain of matchesVersion / compatible / state checks. #50825 had to add the protocol guard to both copies. The rules are easier to review, and to test without child processes, as one function.

What Changes

decide(service, options) in service-probe.ts returns what to do. Each client performs it in the same order as before.

Service answered Version requirement decide() Client then
no health endpoint (compatible: false) none, matching, or accepting fail (incompatible health protocol) fails
no health endpoint not met replace, pty: "handoff" announce, stop, evict
compatible, ready met reuse completes terminal handoff, returns it
compatible, starting met wait keeps polling
compatible, failed met fail ("Background service failed to start") fails
compatible, any state not met replace, pty: "handoff" only when ready, otherwise "clear" warns if not ready, stops, evicts

Error messages are byte-identical.

Scope

Stacked on #53240, with no behavior change intended. That completes the shared lifecycle core: the probe, startup attempts, and this decision. terminate() and stop() stay in each client because they are almost all IO.

Verification

cd packages/client
bun typecheck
bun run test test/service-decision.test.ts test/service-contender-pool.test.ts test/service.test.ts test/promise-service.test.ts test/service-reconnect.test.ts --rerun-each 3
  • 180/180 across three runs of each. The black-box service tests are unchanged.
  • New service-decision.test.ts covers the table above as plain unit tests.
  • Mutation check: disabling the protocol guard in decide() fails fix(client): preserve service on protocol-only reconnect mismatch #50825's three reconnect tests in both the Effect and Promise suites, plus the unit test.

Stack

  1. fix(client): preserve background service startup failures #50784
  2. refactor(client): share the service health probe between clients #53237
  3. refactor(client): share startup attempt bookkeeping between clients #53240
  4. refactor(client): share the registered service decision between clients #53241 👈 current

@kitlangton
kitlangton force-pushed the share-service-decision branch from 61808b2 to 167dffa Compare October 6, 2026 04:18
@kitlangton
kitlangton merged commit 2bddf58 into v2 Oct 6, 2026
9 checks passed
@kitlangton
kitlangton deleted the share-service-decision branch October 6, 2026 04:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant