fix(coding-agent): preserve fetch overrides

This commit is contained in:
Armin Ronacher 2026-06-16 20:03:36 +02:00
parent a78cd7ccb1
commit a93f066607

View file

@ -10,6 +10,9 @@ export const HTTP_IDLE_TIMEOUT_CHOICES = [
{ label: "disabled", timeoutMs: 0 },
] as const;
const originalGlobalFetch = globalThis.fetch;
let installedGlobalFetch: typeof globalThis.fetch | undefined;
export function parseHttpIdleTimeoutMs(value: unknown): number | undefined {
if (typeof value === "string") {
const trimmed = value.trim();
@ -58,5 +61,13 @@ export function configureHttpDispatcher(timeoutMs: number = DEFAULT_HTTP_IDLE_TI
// Keep fetch and the dispatcher on the same undici implementation. Node 26.0's
// bundled fetch can otherwise consume compressed responses through npm undici's
// dispatcher without decompressing them, causing response.json() failures.
undici.install?.();
// If a caller replaced fetch after module load, preserve that deliberate override.
const shouldInstallGlobals =
installedGlobalFetch === undefined
? globalThis.fetch === originalGlobalFetch
: globalThis.fetch === installedGlobalFetch;
if (shouldInstallGlobals) {
undici.install?.();
installedGlobalFetch = globalThis.fetch;
}
}