openclaw - 💡(How to fix) Fix bug: undici 8.2.0 Content-Length validation fails when dispatcher is replaced via setGlobalDispatcher [1 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#78550Fetched 2026-05-07 03:35:28
View on GitHub
Comments
1
Participants
2
Timeline
2
Reactions
2
Author
Timeline (top)
closed ×1commented ×1

When OpenClaw Gateway replaces the global undici dispatcher via setGlobalDispatcher() (see undici-global-dispatcher-CxFhjJy5.js), all fetch() calls dispatched through Node.js internal undici → OpenClaw bundled undici v8.2.0 AgentDispatcher1WrapperClient chain fail with:

TypeError: fetch failed
  cause: InvalidArgumentError: invalid content-length header

The error occurs in isValidContentLengthHeaderValue() at undici/lib/core/request.js:503.

Error Message

InvalidArgumentError: invalid content-length header
    at processHeader (undici/lib/core/request.js:503:13)
    at new Request (undici/lib/core/request.js:264:11)
    at Client.[dispatch] (undici/lib/dispatcher/client.js:340:21)
    at Client.dispatch (undici/lib/dispatcher/dispatcher-base.js:171:29)
    at Pool.[dispatch] (undici/lib/dispatcher/pool-base.js:163:28)
    at Pool.dispatch (undici/lib/dispatcher/dispatcher-base.js:171:29)
    at Agent.[dispatch] (undici/lib/dispatcher/agent.js:138:23)
    at Agent.dispatch (undici/lib/dispatcher/dispatcher-base.js:171:29)
    at Dispatcher1Wrapper.dispatch (undici/lib/dispatcher/dispatcher1-wrapper.js:95:29)
    at node:internal/deps/undici/undici:13616:55

Root Cause

Node.js internal undici passes headers to the OpenClaw bundled undici Client via dispatch(opts, handler). The Content-Length header value arrives in a format that undici v8.2.0's isValidContentLengthHeaderValue() rejects.

Fix Action

Workaround

Patching isValidContentLengthHeaderValue() in undici/lib/core/request.js to return true bypasses the validation issue. The parseInt(val, 10) call on the next line (line 505) correctly handles both single and multi-value formats via JS coercion.

But this is only a temporary workaround since it affects node_modules.

Code Example

TypeError: fetch failed
  cause: InvalidArgumentError: invalid content-length header

---

InvalidArgumentError: invalid content-length header
    at processHeader (undici/lib/core/request.js:503:13)
    at new Request (undici/lib/core/request.js:264:11)
    at Client.[dispatch] (undici/lib/dispatcher/client.js:340:21)
    at Client.dispatch (undici/lib/dispatcher/dispatcher-base.js:171:29)
    at Pool.[dispatch] (undici/lib/dispatcher/pool-base.js:163:28)
    at Pool.dispatch (undici/lib/dispatcher/dispatcher-base.js:171:29)
    at Agent.[dispatch] (undici/lib/dispatcher/agent.js:138:23)
    at Agent.dispatch (undici/lib/dispatcher/dispatcher-base.js:171:29)
    at Dispatcher1Wrapper.dispatch (undici/lib/dispatcher/dispatcher1-wrapper.js:95:29)
    at node:internal/deps/undici/undici:13616:55
RAW_BUFFERClick to expand / collapse

Description

When OpenClaw Gateway replaces the global undici dispatcher via setGlobalDispatcher() (see undici-global-dispatcher-CxFhjJy5.js), all fetch() calls dispatched through Node.js internal undici → OpenClaw bundled undici v8.2.0 AgentDispatcher1WrapperClient chain fail with:

TypeError: fetch failed
  cause: InvalidArgumentError: invalid content-length header

The error occurs in isValidContentLengthHeaderValue() at undici/lib/core/request.js:503.

Root Cause

Node.js internal undici passes headers to the OpenClaw bundled undici Client via dispatch(opts, handler). The Content-Length header value arrives in a format that undici v8.2.0's isValidContentLengthHeaderValue() rejects.

Format analysis

Debug logging revealed Content-Length values passing validation include formats like:

  • "66, 66" (comma-separated, multi-value)
  • "183, 183" (comma-separated, multi-value)
  • "35735" (single value - passes)

The validation function isValidContentLengthHeaderValue() only accepts pure digit strings. Values like "66, 66" contain commas and spaces, causing the function to return false.

This suggests that the Dispatcher1Wrapper or Node.js internal undici → OpenClaw undici 8.2.0 handoff converts single Content-Length values into multi-value format for certain request types.

Stack trace

InvalidArgumentError: invalid content-length header
    at processHeader (undici/lib/core/request.js:503:13)
    at new Request (undici/lib/core/request.js:264:11)
    at Client.[dispatch] (undici/lib/dispatcher/client.js:340:21)
    at Client.dispatch (undici/lib/dispatcher/dispatcher-base.js:171:29)
    at Pool.[dispatch] (undici/lib/dispatcher/pool-base.js:163:28)
    at Pool.dispatch (undici/lib/dispatcher/dispatcher-base.js:171:29)
    at Agent.[dispatch] (undici/lib/dispatcher/agent.js:138:23)
    at Agent.dispatch (undici/lib/dispatcher/dispatcher-base.js:171:29)
    at Dispatcher1Wrapper.dispatch (undici/lib/dispatcher/dispatcher1-wrapper.js:95:29)
    at node:internal/deps/undici/undici:13616:55

Impact

  • All external HTTPS requests made via fetch() within the Gateway process fail if they carry a Content-Length header
  • Affects any channel plugin (weixin, feishu, etc.) that makes HTTP API calls
  • Error occurs immediately (< 2s), not a timeout

Environment

  • OpenClaw: 2026.5.5 (b1abf9d)
  • Node.js: v25.9.0
  • OS: macOS (Darwin arm64)
  • Bundled undici: 8.2.0 (at /opt/homebrew/lib/node_modules/openclaw/node_modules/undici/)

Workaround

Patching isValidContentLengthHeaderValue() in undici/lib/core/request.js to return true bypasses the validation issue. The parseInt(val, 10) call on the next line (line 505) correctly handles both single and multi-value formats via JS coercion.

But this is only a temporary workaround since it affects node_modules.

Reproduction

  1. Start an OpenClaw gateway with any channel plugin that makes external fetch() calls (e.g., openclaw-weixin)
  2. Observe fetch() calls from the channel subprocess fail with "invalid content-length header"
  3. Compare: same fetch() call from a standalone Node.js process (not through OpenClaw's dispatcher) works fine

Expected Behavior

Content-Length header values passed from Node.js internal undici to OpenClaw bundled undici 8.2.0 should be accepted without validation errors, regardless of the value format (single value, multi-value, or array).

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 bug: undici 8.2.0 Content-Length validation fails when dispatcher is replaced via setGlobalDispatcher [1 comments, 2 participants]