Skip to content

Commit e07c0c3

Browse files
rootclaude
andcommitted
fix: use undici.fetch instead of global fetch to match ProxyAgent version
Node.js v22.22.3 ships with built-in undici v6.24.1, which backs the global fetch(). However, the project depends on undici v8.3.0 (via pnpm). The ProxyAgent from undici v8.x requires handlers to implement onRequestStart, but Node.js's built-in fetch handlers (from undici v6.x) do not have this method. This version mismatch causes every proxied request to immediately fail with 'invalid onRequestStart method', making the app appear unresponsive to user input. Fix: use undici's own fetch() (from the installed v8.x) instead of the global fetch(), ensuring the fetch implementation version matches the ProxyAgent version. - anthropic.ts: pass undiciFetch to Anthropic SDK's fetch option - openai-compat.ts: replace global fetch() with undiciFetch() Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 2316f16 commit e07c0c3

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

packages/provider/src/anthropic.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import Anthropic from '@anthropic-ai/sdk';
99
import type { MessageParam, ContentBlockParam, TextBlockParam, Tool } from '@anthropic-ai/sdk/resources/messages.mjs';
10-
import { ProxyAgent } from 'undici';
10+
import { ProxyAgent, fetch as undiciFetch } from 'undici';
1111

1212
import type { Message } from '@coder/shared';
1313
import type { ToolDefinition } from '@coder/shared';
@@ -46,6 +46,13 @@ export class AnthropicProvider implements Provider {
4646
baseURL: config.baseUrl,
4747
timeout: config.timeout ?? 300_000,
4848
maxRetries: 0, // We handle retries ourselves in withRetry()
49+
// Use undici's own fetch to ensure compatibility between ProxyAgent
50+
// and the underlying fetch implementation. Node.js's global fetch is
51+
// backed by the built-in undici (v6.x), while ProxyAgent comes from
52+
// the installed undici (v8.x). Version mismatches cause
53+
// "invalid onRequestStart method" errors.
54+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
55+
fetch: undiciFetch as any,
4956
...(config.proxy ? { fetchOptions } : {}),
5057
});
5158
}

packages/provider/src/openai-compat.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import type { Message } from '@coder/shared';
1818
import type { ToolDefinition } from '@coder/shared';
19-
import { ProxyAgent } from 'undici';
19+
import { ProxyAgent, fetch as undiciFetch } from 'undici';
2020

2121
import type {
2222
Provider,
@@ -278,7 +278,12 @@ export class OpenAICompatProvider implements Provider {
278278
if (this.proxyAgent) {
279279
fetchInit.dispatcher = this.proxyAgent;
280280
}
281-
const response = await fetch(url, fetchInit as RequestInit);
281+
// Use undici's own fetch to ensure compatibility between ProxyAgent
282+
// and the underlying fetch implementation. Node.js's global fetch is
283+
// backed by the built-in undici (v6.x), while ProxyAgent comes from
284+
// the installed undici (v8.x). Version mismatches cause
285+
// "invalid onRequestStart method" errors.
286+
const response = await undiciFetch(url, fetchInit as any);
282287

283288
if (!response.ok) {
284289
const errorBody = await response.text().catch(() => '');

0 commit comments

Comments
 (0)