fix(runtime): avoid no-proxy undici fetch side effects#78143
Conversation
|
Codex review: needs maintainer review before merge. Summary Reproducibility: yes. Current-main source inspection shows plugin-facing fetch runtime imports the proxy-fetch and dispatcher modules that statically import Undici, and the PR body provides before/after Weixin login output showing the failure and QR startup after the patch. Real behavior proof Next step before merge Security Review detailsBest possible solution: Land the lazy-loading fix through normal maintainer review and merge gates so #78007 is closed by the merged implementation while preserving configured proxy and timeout behavior. Do we have a high-confidence way to reproduce the issue? Yes. Current-main source inspection shows plugin-facing fetch runtime imports the proxy-fetch and dispatcher modules that statically import Undici, and the PR body provides before/after Weixin login output showing the failure and QR startup after the patch. Is this the best way to solve the issue? Yes. Lazy-loading the existing Undici dependencies only when proxy fetch or dispatcher work is requested is the narrow maintainable fix because it avoids external plugin fetch side effects without changing plugin code or the proxy env contract. What I checked:
Likely related people:
Remaining risk / open question:
Codex review notes: model gpt-5.5, reasoning high; reviewed against f531eff6292e. |
6ead753 to
f92989e
Compare
Summary
globalThis.fetch.openclaw channels login --channel openclaw-weixinfailed for@tencent-weixin/openclaw-weixin@2.4.1withTypeError: fetch failedeven though the same request worked in plain Node fetch.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
Real behavior proof (required for external PRs)
HOME, isolatedOPENCLAW_STATE_DIR, and@tencent-weixin/openclaw-weixin@2.4.1installed throughopenclaw plugins install.pnpm openclaw plugins install @tencent-weixin/openclaw-weixin@2.4.1 --pinpnpm openclaw channels login --channel openclaw-weixin --verboseTypeError: fetch failed.Trace before fix showed the underlying cause:
Root Cause (if applicable)
src/infra/net/proxy-fetch.tsimported Undici at module load time. That module is exported through plugin runtime helper surfaces, so loading external plugin code could initialize Undici's package dispatcher state even when no proxy was configured. With the current Undici dependency, that changed Node global fetch behavior and caused plugin requests with explicitContent-Lengthto fail.Content-Lengthheader; plain Node fetch accepts the request, but OpenClaw's import side effect made the same request fail.Regression Test Plan (if applicable)
src/infra/net/undici-global-dispatcher.test.tssrc/infra/net/proxy-fetch.test.tssrc/infra/net/fetch-guard.ssrf.test.tsUser-visible / Behavior Changes
External channel plugins that use plain
fetch()no longer inherit OpenClaw's packaged Undici dispatcher behavior on clean no-proxy startup. This fixes the Weixin QR login regression in #78007.Diagram (if applicable)
Security Impact (required)
Yes, explain risk + mitigation: N/ARepro + Verification
Environment
@tencent-weixin/openclaw-weixin@2.4.1Steps
@tencent-weixin/openclaw-weixin@2.4.1into an isolated state dir.pnpm openclaw channels login --channel openclaw-weixin --verbose.TypeError: fetch failed.Expected
Actual
Evidence
Human Verification (required)
What I personally verified:
pnpm test src/infra/net/proxy-fetch.test.ts src/infra/net/undici-global-dispatcher.test.ts src/infra/net/fetch-guard.ssrf.test.tspnpm exec oxfmt --check --threads=1 CHANGELOG.md src/infra/net/proxy-fetch.ts src/infra/net/proxy-fetch.test.ts src/infra/net/undici-runtime.ts src/infra/net/undici-global-dispatcher.ts src/infra/net/undici-global-dispatcher.test.ts src/infra/net/fetch-guard.ssrf.test.tsgit diff --checkopenclaw channels login --channel openclaw-weixin --verbosereached QR login output.Edge cases checked:
EnvHttpProxyAgent.ProxyAgentlazily.content-length/content-typein proxy fetch paths.What I did not verify:
Note:
pnpm check:changedwas run in Blacksmith Testbox after rebase and failed intsgo:core:testonsrc/agents/model-fallback.test.ts, which this PR does not touch:Review Conversations
Compatibility / Migration
Risks and Mitigations