From e4fbf5c65797e684d0a9036a97247944750c4bf9 Mon Sep 17 00:00:00 2001 From: Kit Langton Date: Thu, 26 Mar 2026 11:16:11 -0400 Subject: [PATCH] fix(mcp): use Effect.timeoutOrElse for transport connect timeout Replace withTimeout (Promise.race) with Effect.timeoutOrElse so that fiber interruption properly triggers acquireUseRelease cleanup. The Promise.race approach left the underlying connect promise dangling, which prevented the release function from running on some platforms. --- packages/opencode/src/mcp/index.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/opencode/src/mcp/index.ts b/packages/opencode/src/mcp/index.ts index e41890396a..3626e64f9e 100644 --- a/packages/opencode/src/mcp/index.ts +++ b/packages/opencode/src/mcp/index.ts @@ -209,14 +209,18 @@ export namespace MCP { const connectTransport = (transport: Transport, timeout: number) => Effect.acquireUseRelease( Effect.succeed(transport), - (t) => - Effect.tryPromise({ - try: () => { - const client = new Client({ name: "opencode", version: Installation.VERSION }) - return withTimeout(client.connect(t), timeout).then(() => client) - }, + (t) => { + const client = new Client({ name: "opencode", version: Installation.VERSION }) + return Effect.tryPromise({ + try: () => client.connect(t).then(() => client), catch: (e) => (e instanceof Error ? e : new Error(String(e))), - }), + }).pipe( + Effect.timeoutOrElse({ + duration: `${timeout} millis`, + onTimeout: () => Effect.fail(new Error(`Operation timed out after ${timeout}ms`)), + }), + ) + }, (t, exit) => Exit.isFailure(exit) ? Effect.tryPromise(() => t.close()).pipe(Effect.ignore)