fix(telegram): avoid overriding undici dispatcher when proxy env is set#30406
fix(telegram): avoid overriding undici dispatcher when proxy env is set#30406edoublezh wants to merge 2 commits intoopenclaw:mainfrom
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3461734fb8
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
src/telegram/fetch.ts
Outdated
| if (hasProxyEnvConfigured()) { | ||
| log.info( | ||
| "skip global undici dispatcher autoSelectFamily override because proxy env is configured", | ||
| ); |
There was a problem hiding this comment.
Preserve autoSelectFamily override for explicit disable paths
This unconditional proxy-env guard skips setGlobalDispatcher(...) even when autoSelectFamily is explicitly resolved to false (WSL2 default, config, or env override). In processes that already touched globalThis.fetch before Telegram initialization, the file itself notes that net.setDefaultAutoSelectFamily() no longer affects fetch’s existing undici agent, so the disable decision is silently ignored whenever proxy env vars are present. That reintroduces the stale-agent behavior this workaround was added to prevent for those environments.
Useful? React with 👍 / 👎.
Greptile SummaryAdded proxy environment detection to prevent overriding the global undici dispatcher when proxy is configured. The implementation correctly checks for common proxy env variables ( Key Changes:
Issue Found:
Confidence Score: 4/5
Last reviewed commit: 3461734 |
src/telegram/fetch.ts
Outdated
| if (hasProxyEnvConfigured()) { | ||
| log.info( | ||
| "skip global undici dispatcher autoSelectFamily override because proxy env is configured", | ||
| ); |
There was a problem hiding this comment.
appliedGlobalDispatcherAutoSelectFamily never updated when proxy is detected, causing the condition on line 56 to remain true and this log to repeat on every resolveTelegramFetch() call
| if (hasProxyEnvConfigured()) { | |
| log.info( | |
| "skip global undici dispatcher autoSelectFamily override because proxy env is configured", | |
| ); | |
| if (hasProxyEnvConfigured()) { | |
| log.info( | |
| "skip global undici dispatcher autoSelectFamily override because proxy env is configured", | |
| ); | |
| appliedGlobalDispatcherAutoSelectFamily = autoSelectDecision.value; |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/telegram/fetch.ts
Line: 59-62
Comment:
`appliedGlobalDispatcherAutoSelectFamily` never updated when proxy is detected, causing the condition on line 56 to remain true and this log to repeat on every `resolveTelegramFetch()` call
```suggestion
if (hasProxyEnvConfigured()) {
log.info(
"skip global undici dispatcher autoSelectFamily override because proxy env is configured",
);
appliedGlobalDispatcherAutoSelectFamily = autoSelectDecision.value;
```
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
Thanks for the review. I pushed a follow-up commit (930f8f1) to address the state tracking issue when proxy env is present and added test coverage for the proxy -> no-proxy transition.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 930f8f16a0
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if (hasProxyEnvConfigured()) { | ||
| if (skippedGlobalDispatcherAutoSelectFamily !== autoSelectDecision.value) { |
There was a problem hiding this comment.
Honor explicit autoSelectFamily disable under proxy env
applyTelegramNetworkWorkarounds now unconditionally skips setGlobalDispatcher(...) whenever a proxy env var is set, even when autoSelectDecision.value is false. That regresses explicit disable paths (OPENCLAW_TELEGRAM_DISABLE_AUTO_SELECT_FAMILY, network.autoSelectFamily=false, or WSL2 default): only net.setDefaultAutoSelectFamily(false) is applied, but this same file notes that an already-created globalThis.fetch agent ignores that setter, so processes that touched fetch before Telegram init can keep the old dispatcher behavior and still hit the IPv6 failure mode this workaround was meant to avoid.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Thanks for the review. I pushed a follow-up commit (930f8f16a).
I intentionally kept the proxy guard behavior unchanged (still skipping the global dispatcher override when proxy env is configured), to avoid clobbering proxy-aware dispatcher behavior.
I also added follow-up coverage around the proxy -> no-proxy transition.
Summary
In proxy-enabled environments, Telegram startup currently overrides the global undici dispatcher to apply
autoSelectFamily.This can unintentionally bypass or conflict with existing proxy dispatcher settings and lead to request failures like
fetch failedin embedded runs.This PR changes Telegram network workaround behavior:
HTTPS_PROXY,HTTP_PROXY,ALL_PROXY, including lowercase variants).setGlobalDispatcher(new Agent(...)).autoSelectFamilyand DNS result-order handling.Why
When users rely on a proxy, replacing the global dispatcher in Telegram path can break other request paths that depend on proxy-aware dispatch behavior.
Changes
src/telegram/fetch.tssrc/telegram/fetch.test.tsVerification
pnpm buildpnpm vitest run src/telegram/fetch.test.ts(12 passed)skip global undici dispatcher autoSelectFamily override because proxy env is configuredchat.sendrun completed withisError=falseImpact