Skip to content

fix(weixin): drop manual Content-Length header rejected by undici#56

Open
yikkuro wants to merge 1 commit into
mainfrom
yikkuro/fix-wechat-content-length-55
Open

fix(weixin): drop manual Content-Length header rejected by undici#56
yikkuro wants to merge 1 commit into
mainfrom
yikkuro/fix-wechat-content-length-55

Conversation

@yikkuro

@yikkuro yikkuro commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

What

Removes the manual Content-Length header from the WeChat (weixin) plugin's buildHeaders().

Why

The WeChat channel was completely broken: inbound messages went unanswered and the WeChat client showed "暂无法连接 OpenClaw". The gateway logged an endless stream of TypeError: fetch failed for getUpdates, sendMessage, and sendTyping.

Root cause: buildHeaders() set Content-Length manually on every request. The gateway's bundled undici forbids this and throws InvalidArgumentError: invalid content-length header (UND_ERR_INVALID_ARG), which fetch re-wraps as the opaque TypeError: fetch failed. Because buildHeaders() backs every API call, the entire channel failed.

The real cause was hidden — fetch failed never exposes err.cause in the logs, and the same request succeeds from a standalone Node process (top-level built-in fetch is more lenient than the gateway's undici). It was confirmed by temporarily wrapping globalThis.fetch in the gateway to capture err.cause.

Fix

Delete the manual Content-Length header (and the now-unused body param of buildHeaders). fetch/undici computes Content-Length from the string body automatically.

Verification

Applied to the live gateway plugin and restarted:

  • Before: getUpdates/sendMessage/sendTyping failed every ~2s with fetch failed.
  • After: monitor holds a stable long-poll (ESTABLISHED connection), zero fetch failed, and a real WeChat "Hello" round-trips and receives a reply (confirmed by the reporter).

Fixes #55

buildHeaders() set a manual Content-Length on every WeChat API request.
The gateway's bundled undici rejects a manually-set Content-Length with
InvalidArgumentError: invalid content-length header (UND_ERR_INVALID_ARG),
surfaced as 'TypeError: fetch failed'. Since buildHeaders() is used by every
call (getUpdates, sendMessage, sendTyping, getConfig, getUploadUrl), the whole
channel failed and WeChat showed '暂无法连接 OpenClaw'.

Let fetch/undici compute Content-Length from the body automatically.

Fixes #55

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WeChat channel: all requests fail with 'TypeError: fetch failed' (manual Content-Length header rejected by undici)

1 participant