diff --git a/bin.ts b/bin.ts index f4bb1bd5..2f0b2036 100644 --- a/bin.ts +++ b/bin.ts @@ -1,5 +1,6 @@ #!/usr/bin/env node import { satisfies } from 'semver'; +import { Agent, setGlobalDispatcher } from 'undici'; import { ErrorCodes } from './src/lib/errors/codes.js'; import { emitWizardError } from './src/lib/errors/emit.js'; @@ -9,6 +10,19 @@ import { emitWizardError } from './src/lib/errors/emit.js'; // TypeError on Node < 22.10). const NODE_VERSION_RANGE = '>=22.22.0'; +/* + * TODO(#1198): remove when fetch over HTTP/2 is safe on Node 26. Remove when all + * of these are true: + * - nodejs/node no longer creates an orphan ClientHttp2Stream when a client + * session gets HEADERS for a stream id it already reset. Repro: abort a fetch + * before its response headers, then idle 4s on Node 26. Fixed when the + * process survives. + * - modelcontextprotocol/typescript-sdk#2526 is closed. + * - pi-coding-agent's CLI drops `allowH2: false` from its http-dispatcher. + * Same workaround as pi's CLI and typescript-sdk#2526: HTTP/1.1 only. + */ +setGlobalDispatcher(new Agent({ allowH2: false })); + // Have to run this above the other imports because they are importing clack that // has the problematic imports. if (!satisfies(process.version, NODE_VERSION_RANGE)) { diff --git a/package.json b/package.json index cdb312cf..4ec58c5e 100644 --- a/package.json +++ b/package.json @@ -60,6 +60,7 @@ "recast": "^0.23.3", "semver": "^7.5.3", "typebox": "1.1.38", + "undici": "8.5.0", "uuid": "^11.1.0", "xcode": "3.0.1", "xml-js": "^1.6.11", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e0fab155..7c2d2ae3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -92,6 +92,9 @@ importers: typebox: specifier: 1.1.38 version: 1.1.38 + undici: + specifier: 8.5.0 + version: 8.5.0 uuid: specifier: ^11.1.0 version: 11.1.0