Bug Description
When running OpenClaw Gateway with an HTTP proxy (e.g., on WSL2, macOS, or any system behind a regional/corporate proxy), all LLM requests and Telegram API calls fail after the Telegram channel initializes.
Root cause: At startup, a proxy-aware ProxyAgent is set as the global undici dispatcher (either via EnvHttpProxyAgent in http-proxy.js, or via a user-provided --require script using NODE_OPTIONS). About 10 seconds later, the Telegram channel calls applyTelegramNetworkWorkarounds (defined in src/telegram/fetch.ts, compiled into multiple dist chunks), which unconditionally calls:
```js
setGlobalDispatcher(new Agent({ connect: { autoSelectFamily: ..., ... } }));
```
This replaces the proxy-aware dispatcher with a plain Agent, causing all subsequent fetch calls to bypass the proxy. Since globalThis.fetch in Node.js 18+ respects the undici global dispatcher, this affects both:
- LLM requests to providers like Anthropic — they time out because the API is unreachable without the proxy
- Telegram's own API calls (
deleteWebhook, setMyCommands, getUpdates, etc.) — they fail if api.telegram.org also requires a proxy (e.g., in mainland China)
Environment
- OpenClaw version: 2026.2.26
- Platform: WSL2 (Ubuntu 24.04) with mirrored networking / macOS — any platform where
HTTPS_PROXY is set
- Proxy: HTTP proxy set via
HTTPS_PROXY / HTTP_PROXY env var
Steps to Reproduce
- Set
HTTPS_PROXY=http://... in the Gateway environment
- Enable Telegram channel
- Start Gateway — LLM requests succeed initially
- After Telegram initializes (~10s), send an LLM request — it times out
- (On systems where
api.telegram.org requires a proxy): Telegram channel also fails entirely with repeated Network request for 'deleteWebhook' failed! / Network request for 'setMyCommands' failed! errors
Expected Behavior
The setGlobalDispatcher call in the Telegram workaround should preserve proxy settings when HTTPS_PROXY/HTTP_PROXY is set.
Additional Notes: Bug Exists in Multiple Compiled Chunks
applyTelegramNetworkWorkarounds is compiled into at least 5 separate dist files:
dist/send-C4dK3vop.js
dist/send-k3kiiQd1.js
dist/send-CVJNwTGe.js
dist/send-6vB8BriV.js
dist/plugin-sdk/send-Wiujuiup.js
The fix must be applied in the source (src/telegram/fetch.ts) so all output chunks are patched consistently. Patching only one dist file will not fix the issue.
Suggested Fix
```js
// Before
import { Agent, setGlobalDispatcher } from "undici"
// ...
setGlobalDispatcher(new Agent({ connect: { autoSelectFamily: ..., autoSelectFamilyAttemptTimeout: 300 } }));
// After
import { Agent, ProxyAgent, setGlobalDispatcher } from "undici"
// ...
const _proxyUrl = process.env.HTTPS_PROXY || process.env.https_proxy
|| process.env.HTTP_PROXY || process.env.http_proxy;
if (_proxyUrl) {
setGlobalDispatcher(new ProxyAgent({ uri: _proxyUrl, connect: { autoSelectFamily: ..., autoSelectFamilyAttemptTimeout: 300 } }));
} else {
setGlobalDispatcher(new Agent({ connect: { autoSelectFamily: ..., autoSelectFamilyAttemptTimeout: 300 } }));
}
```
Bug Description
When running OpenClaw Gateway with an HTTP proxy (e.g., on WSL2, macOS, or any system behind a regional/corporate proxy), all LLM requests and Telegram API calls fail after the Telegram channel initializes.
Root cause: At startup, a proxy-aware
ProxyAgentis set as the global undici dispatcher (either viaEnvHttpProxyAgentinhttp-proxy.js, or via a user-provided--requirescript usingNODE_OPTIONS). About 10 seconds later, the Telegram channel callsapplyTelegramNetworkWorkarounds(defined insrc/telegram/fetch.ts, compiled into multiple dist chunks), which unconditionally calls:```js
setGlobalDispatcher(new Agent({ connect: { autoSelectFamily: ..., ... } }));
```
This replaces the proxy-aware dispatcher with a plain
Agent, causing all subsequentfetchcalls to bypass the proxy. SinceglobalThis.fetchin Node.js 18+ respects the undici global dispatcher, this affects both:deleteWebhook,setMyCommands,getUpdates, etc.) — they fail ifapi.telegram.orgalso requires a proxy (e.g., in mainland China)Environment
HTTPS_PROXYis setHTTPS_PROXY/HTTP_PROXYenv varSteps to Reproduce
HTTPS_PROXY=http://...in the Gateway environmentapi.telegram.orgrequires a proxy): Telegram channel also fails entirely with repeatedNetwork request for 'deleteWebhook' failed!/Network request for 'setMyCommands' failed!errorsExpected Behavior
The
setGlobalDispatchercall in the Telegram workaround should preserve proxy settings whenHTTPS_PROXY/HTTP_PROXYis set.Additional Notes: Bug Exists in Multiple Compiled Chunks
applyTelegramNetworkWorkaroundsis compiled into at least 5 separate dist files:The fix must be applied in the source (
src/telegram/fetch.ts) so all output chunks are patched consistently. Patching only one dist file will not fix the issue.Suggested Fix
```js
// Before
import { Agent, setGlobalDispatcher } from "undici"
// ...
setGlobalDispatcher(new Agent({ connect: { autoSelectFamily: ..., autoSelectFamilyAttemptTimeout: 300 } }));
// After
import { Agent, ProxyAgent, setGlobalDispatcher } from "undici"
// ...
const _proxyUrl = process.env.HTTPS_PROXY || process.env.https_proxy
|| process.env.HTTP_PROXY || process.env.http_proxy;
if (_proxyUrl) {
setGlobalDispatcher(new ProxyAgent({ uri: _proxyUrl, connect: { autoSelectFamily: ..., autoSelectFamilyAttemptTimeout: 300 } }));
} else {
setGlobalDispatcher(new Agent({ connect: { autoSelectFamily: ..., autoSelectFamilyAttemptTimeout: 300 } }));
}
```