From e49157b34c9c2b9475c4510e2e21ef5c15c2401d Mon Sep 17 00:00:00 2001 From: Luke Parker <10430890+Hona@users.noreply.github.com> Date: Fri, 23 Oct 2026 14:34:28 +1000 Subject: [PATCH] fix(core): keep remote MCP requests open past Bun's fetch idle timeout (#58341) --- packages/core/src/mcp/oauth.ts | 6 ++++-- packages/util/src/no-timeout-fetch.ts | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/core/src/mcp/oauth.ts b/packages/core/src/mcp/oauth.ts index 8653c166d40..2e72bd2d256 100644 --- a/packages/core/src/mcp/oauth.ts +++ b/packages/core/src/mcp/oauth.ts @@ -19,6 +19,7 @@ import { OAuthMetadataSchema, OpenIdProviderDiscoveryMetadataSchema } from "@mod import { Cause, Deferred, Effect } from "effect" import type { ServerResponse } from "node:http" import { ConfigMCP } from "@opencode/schema/config/mcp" +import { noTimeoutFetch } from "@opencode/util/no-timeout-fetch" import { Credential } from "../credential.js" import { OauthCallbackPage } from "../oauth/page.js" import type { Integration } from "../integration.js" @@ -36,8 +37,9 @@ const refreshKey = (url: string | URL, init: RequestInit | undefined) => { } // Bun's and Node's fetch types both apply here and the SDK's FetchLike wants Bun's Response, so the -// overload is picked by annotation and clone() is pinned to the type it was called on. -const base: FetchLike = fetch +// overload is picked by annotation and clone() is pinned to the type it was called on. A tool call +// can stay silent for minutes, so Bun's idle deadline is off; the MCP execution timeout still applies. +const base: FetchLike = noTimeoutFetch const share = (pending: ReturnType) => pending.then((response) => response.clone() as typeof response) const send: FetchLike = (url, init) => { diff --git a/packages/util/src/no-timeout-fetch.ts b/packages/util/src/no-timeout-fetch.ts index e96c24b000c..d3933ea5fd1 100644 --- a/packages/util/src/no-timeout-fetch.ts +++ b/packages/util/src/no-timeout-fetch.ts @@ -1,5 +1,5 @@ // Bun's fetch aborts requests after its default idle deadline (about five minutes). Clients that // hold requests open for long-running work (session waits, event streams, plugin commands, // shell calls) opt out while keeping every other init option, including `signal`. -export const noTimeoutFetch = ((request: RequestInfo | URL, init?: RequestInit) => +export const noTimeoutFetch = ((request: Parameters[0], init?: RequestInit) => fetch(request, { ...init, timeout: false } as BunFetchRequestInit)) as typeof fetch