openclaw - 💡(How to fix) Fix fetch failed with undici 8.0.0 on Node.js 22: per-request dispatcher incompatible with built-in fetch [3 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#61448Fetched 2026-04-08 02:58:30
View on GitHub
Comments
3
Participants
2
Timeline
7
Reactions
0
Author
Timeline (top)
commented ×3closed ×1cross-referenced ×1mentioned ×1

Error Message

  • Error reproduces on every call, not intermittent Error message: TypeError: fetch failed - invalid onRequestStart method

Root Cause

Node.js 22's built-in fetch uses internal undici 6.23.0. OpenClaw's fetch-guard.ts creates an undici 8.0.0 Agent via createPinnedDispatcher() and passes it as a per-request dispatcher to fetch().

undici 8.0.0 refactored the dispatcher interface (onRequestStart method signature changed), making it incompatible with Node.js 22's built-in fetch pipeline.

Error message: TypeError: fetch failed - invalid onRequestStart method

Fix Action

Workaround

  • package.json: undici ^8.0.06.23.0
  • src/infra/net/undici-global-dispatcher.ts: add as any cast on connect options (undici 6.x has stricter TypeScript types for connect than 8.x)
RAW_BUFFERClick to expand / collapse

Environment

  • Node.js v22.22.0 (built-in undici 6.23.0)
  • OpenClaw depends on undici ^8.0.0 (package.json)
  • OS: Ubuntu 25.10, Cloudflare WARP

Symptoms

  • tavily_search and web_search tools consistently return TypeError: fetch failed
  • curl and Node.js native fetch (without dispatcher) work fine
  • Error reproduces on every call, not intermittent

Root Cause

Node.js 22's built-in fetch uses internal undici 6.23.0. OpenClaw's fetch-guard.ts creates an undici 8.0.0 Agent via createPinnedDispatcher() and passes it as a per-request dispatcher to fetch().

undici 8.0.0 refactored the dispatcher interface (onRequestStart method signature changed), making it incompatible with Node.js 22's built-in fetch pipeline.

Error message: TypeError: fetch failed - invalid onRequestStart method

Verification

ScenarioResult
undici 8.0.0 Agent as per-request dispatcher❌ fetch failed
undici 8.0.0 Agent via setGlobalDispatcher✅ works (replaces entire dispatch chain)
No dispatcher (plain fetch)✅ works
undici 6.23.0 Agent as per-request dispatcher✅ works

All required APIs (Agent, EnvHttpProxyAgent, ProxyAgent, getGlobalDispatcher, setGlobalDispatcher) exist in undici 6.23.0.

Impact

  • All requests through withTrustedWebToolsEndpoint (Tavily search/extract, Brave search, etc.)
  • All requests using createPinnedDispatcher for SSRF protection
  • ensureGlobalUndiciStreamTimeouts sets a global dispatcher from external undici — version mismatch with built-in fetch is a latent risk even when global dispatcher appears to work

Workaround

  • package.json: undici ^8.0.06.23.0
  • src/infra/net/undici-global-dispatcher.ts: add as any cast on connect options (undici 6.x has stricter TypeScript types for connect than 8.x)

Suggested Fixes

  1. Downgrade undici version constraint to ^6.23.0 to match Node.js 22's built-in version
  2. Or detect Node.js built-in undici version at runtime and choose per-request vs global dispatcher accordingly
  3. Or wait for Node.js to ship undici 8.x before updating the dependency

Not Verified

  • Whether Node.js 23+ ships with undici 8.x (may already be fixed in newer Node.js)
  • Whether undici 8.x has a patch version addressing this compatibility issue

extent analysis

TL;DR

Downgrade the undici version constraint to ^6.23.0 to match Node.js 22's built-in version.

Guidance

  • Verify the undici version used by Node.js 22 to ensure it's indeed 6.23.0, which is incompatible with OpenClaw's undici 8.0.0 dependency.
  • Consider downgrading the undici version in package.json to ^6.23.0 as a temporary workaround to resolve the TypeError: fetch failed issue.
  • If upgrading Node.js to a version that includes undici 8.x is feasible, this could also resolve the compatibility issue.
  • Be cautious of the latent risk of version mismatches when using ensureGlobalUndiciStreamTimeouts and createPinnedDispatcher for SSRF protection.

Example

No code snippet is provided as the issue is primarily related to version compatibility and dependency management.

Notes

The suggested fixes and workarounds are based on the information provided and may not be applicable if the Node.js or undici versions are different. It's also important to note that downgrading dependencies can introduce other compatibility issues.

Recommendation

Apply the workaround by downgrading the undici version constraint to ^6.23.0 to immediately resolve the TypeError: fetch failed issue, as this is a straightforward and verified solution.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - 💡(How to fix) Fix fetch failed with undici 8.0.0 on Node.js 22: per-request dispatcher incompatible with built-in fetch [3 comments, 2 participants]