Skip to content

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

Open
kitlangton wants to merge 1 commit into
v2from
latch-mcp-startup
Open

refactor(core): use Latch for MCP startup gate#43570
kitlangton wants to merge 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).

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