🔧 fix undici erroneously grabing previous request Agents by default - #480
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses a dispatcher-resolution bug where the SDK could accidentally reuse a foreign undici global dispatcher (e.g., the one registered by Node’s built-in fetch), leading to transport-level failures. It adds logic to only reuse the global dispatcher when it was created by the same undici copy as the SDK, otherwise falling back to a library-owned Agent.
Changes:
- Add
resolveDefaultDispatcher()inBaseSettingsto ignore foreign global dispatchers and use a shared fallbackAgent. - Add unit tests validating dispatcher selection behavior (explicit, same-copy global, foreign global, and fallback reuse).
- Add an integration test that reproduces the failure when explicitly passing a foreign dispatcher and verifies the default client succeeds.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| tests/v2/client/foreignDispatcher.integration.ts | New integration test covering foreign global dispatcher repro + expected fixed behavior. |
| tests/http/baseSettings.spec.ts | New unit tests for dispatcher resolution logic in BaseSettings. |
| src/http/baseSettings.ts | Implements foreign-global-dispatcher detection and fallback dispatcher creation. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.
Suppressed comments (1)
Previously missed (1) — in code that hasn't changed since the last review.
src/input/urlInput.ts:6
- There’s an extra space after the opening
{in the undici import, which is inconsistent with the rest of the codebase and may trip formatting/lint rules.
import { request, Dispatcher } from "undici";
Description
Types of changes