Skip to content

refactor(core): use Latch for MCP startup gate - #43570

Merged
kitlangton merged 1 commit into
v2from
latch-mcp-startup
Aug 20, 2026
Merged

refactor(core): use Latch for MCP startup gate#43570
kitlangton merged 1 commit into
v2from
latch-mcp-startup

Conversation

@kitlangton

Copy link
Copy Markdown
Contributor

What

Each MCP server entry's startup signal is a pure open-once gate: it is only ever completed with Exit.void — deliberately, even on registration failure or replacement interruption, so readers cannot hang ("Settle startup even when registration fails..." comment). A Deferred<void> leaves "never delivers a failure" as a convention enforced by three completion sites; Latch makes it structural — the type cannot fail or interrupt waiters.

How

packages/core/src/mcp/index.ts:

  • ServerEntry.startup is now Latch.Latch, created with Latch.makeUnsafe() (starts closed).
  • The three completion sites collapse to entry.startup.open / entry.startup.openUnsafe(); the ensuring(Effect.sync(() => Deferred.doneUnsafe(..., Exit.void))) wrapper becomes plain ensuring(entry.startup.open).
  • The four waiters use entry.startup.await.

No behavior change. Found by a repo-wide audit of Deferred<void>-as-gate patterns; sibling PRs convert the other pure-gate sites.

Testing

  • packages/core: bun typecheck, bun test test/mcp.test.ts test/mcp-instructions.test.ts test/mcp-oauth.test.ts test/mcp-import-boundary.test.ts (38 pass), and the full bun run test suite (0 fail across 1908 tests).

@kitlangton
kitlangton enabled auto-merge (squash) August 20, 2026 15:37
@kitlangton
kitlangton merged commit 38eeed5 into v2 Aug 20, 2026
10 checks passed
@kitlangton
kitlangton deleted the latch-mcp-startup branch August 20, 2026 15:37
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