Repository navigation
fix: preserve raw headers in dispatch handler bridge - #5345
Merged
Merged
Conversation
Signed-off-by: Matteo Collina <hello@matteocollina.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## v7.x #5345 +/- ##
==========================================
- Coverage 92.91% 92.90% -0.01%
==========================================
Files 112 112
Lines 35837 35843 +6
==========================================
+ Hits 33297 33299 +2
- Misses 2540 2544 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
ronag
approved these changes
Jun 3, 2026
metcoder95
approved these changes
Jun 3, 2026
Merged
QuiiBz
added a commit
to vercel/sandbox
that referenced
this pull request
Jun 4, 2026
Closes #198 Update the Undici version we use to fix an issue where using Undici v7 `Agent` with a Undici v8 `fetch` (e.g. using Node.js 26 with the global, bundled `fetch`) would cause response headers to be dropped, and response body to not be decompressed Upstream Undici fix: nodejs/undici#5345
griffinwork40
added a commit
to griffinwork40/agent-afk
that referenced
this pull request
Sep 29, 2026
…2525) (#2535) * fix(deps): raise undici floor to ^7.27.1; add Node 26 CI leg (issue #2525) ## Problem On Node 26.0.0, importing npm undici 7.27.0 installs a broken global dispatcher that corrupts built-in fetch: gzip-encoded responses lose all headers and arrive as a still-compressed buffer. The Anthropic SDK receives a string instead of JSON and `oneShotCompletion` throws `response.content is not iterable`. Both the global dispatcher slot and the per-request `dispatcher: new Agent()` path in `src/http-client/egress-guard.ts` (web_scrape / web_request) are affected. Root cause: a bug in undici 7.27.0 only, where `UnwrapController` loses `rawHeaders`/`rawTrailers` in the dispatch handler bridge. Fixed in 7.27.1 by nodejs/undici#5345. ## Changes - package.json: undici ^7.27.0 -> ^7.27.1 (resolves 7.30.0) - pnpm-lock.yaml: updated specifier and snapshot - .github/workflows/ci.yml: add test-node26 job - src/http-client/undici-gzip-compat.test.ts: regression test Fixes #2525 * test(http-client): make the undici gzip-bridge regression test discriminate The first version never loaded npm undici, so Node's built-in fetch ran through its own bundled dispatcher and the test passed on the broken undici 7.27.0 + Node 26.0.0 pair as well. Now both paths agent-afk depends on go through an npm-undici Agent: - global slot: setGlobalDispatcher(new Agent()), with the prior Symbol.for('undici.globalDispatcher.{1,2}') values restored afterwards (vitest's worker may already have filled the slot with the built-in Agent, so relying on import side effects is not enough) - per-request: `dispatcher: new Agent()`, the shape egress-guard.ts uses Verified on Node 26.0.0: both cases fail with undici 7.27.0 installed and pass with 7.30.0. They pass on Node 24.11 with 7.30.0. Refs #2525 --------- Co-authored-by: Griffin Long <griffinlong@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Preserve
rawHeadersandrawTrailerson the synthetic controller used byUnwrapHandlerwhen bridging modern dispatch handlers to the legacy handler interface.This keeps Node.js bundled
fetchcompatible with an imported Undici v7Agent, so response headers remain visible and compressed bodies continue to be decoded.Fixes: #5341
Changes
rawHeaderson the controller before invokingonRequestUpgrade/onResponseStartrawTrailersbefore invokingonResponseEndtypes/dispatcher.d.tsfetchwith both the global dispatcher and an explicitdispatcher: new Agent()Testing
npm run lint -- lib/handler/unwrap-handler.js test/node-test/global-dispatcher-version.js types/dispatcher.d.tsnpx borp -p "test/node-test/global-dispatcher-version.js"source ~/.nvm/nvm.sh && nvm use 26.3.0 >/dev/null && npx borp -p "test/node-test/global-dispatcher-version.js"