fix: normalize FormData body in proxy fetch for undici compatibility#879
Open
BingqingLyu wants to merge 1 commit into
Open
fix: normalize FormData body in proxy fetch for undici compatibility#879BingqingLyu wants to merge 1 commit into
BingqingLyu wants to merge 1 commit into
Conversation
In Node 22+, globalThis.FormData and undici's FormData are different classes. When HTTPS_PROXY is set, resolveProxyFetchFromEnv() and makeProxyFetch() wrap undici.fetch as a drop-in for globalThis.fetch. But undici.fetch doesn't recognize globalThis.FormData — it calls .toString() on it, sending "[object FormData]" as text/plain instead of proper multipart/form-data. This breaks audio transcription (Telegram/Discord voice messages) and batch file uploads for any user behind an HTTP proxy. Add normalizeInitForUndici() that converts globalThis.FormData bodies to undici's FormData before dispatch. The helper is a no-op when the classes are identical or when the body is not a FormData instance. Closes openclaw#48554
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.
Summary
HTTPS_PROXYis set,resolveProxyFetchFromEnv()andmakeProxyFetch()wrapundici.fetchas a drop-in forglobalThis.fetch. But in Node 22+,globalThis.FormDataandundici.FormDataare different classes — undici doesn't recognize the global one and serializes it as"[object FormData]"instead ofmultipart/form-data.normalizeInitForUndici()inproxy-fetch.tsthat convertsglobalThis.FormDatato undici'sFormDatabefore dispatch. Applied to bothmakeProxyFetch()andresolveProxyFetchFromEnv().audio.ts,batch-upload.ts) — they correctly usenew FormData(). The proxy wrapper was the broken contract.Change Type
Scope
Linked Issue
Closes openclaw#48554
User-visible / Behavior Changes
Audio transcription via Telegram/Discord voice messages now works correctly when
HTTPS_PROXYorHTTP_PROXYis set.Security Impact
Reproduction + Verification
Environment
HTTPS_PROXYset,tools.media.audioconfigured with OpenAI-compatible provider (Speaches/local Whisper)Steps
HTTPS_PROXYin OpenClaw containertools.media.audiowith a local Whisper endpointExpected
Audio transcribed, agent responds to transcript
Actual (before fix)
Request body is literal string
[object FormData], Content-Type istext/plain;charset=UTF-8. Transcription fails with HTTP 422 (missing file and model fields).Evidence
pnpm checkpasses (build + format + lint + full test suite)Human Verification
globalThis.FormData !== require("undici").FormDatain Node 24AI Assistance
Compatibility / Migration
Failure Recovery
Risks and Mitigations
FormData.entries()returns all entries including duplicates;append()preserves themglobalThis.FormDatamight not exist in some environmentstypeof GlobalFormData === "function"beforeinstanceof