fix(telegram): add dnsResultOrder=ipv4first default on Node 22+ to fix fetch failures#5405
Conversation
| // Apply DNS result order workaround for IPv4/IPv6 issues. | ||
| // Some APIs (including Telegram) may fail with IPv6 on certain networks. | ||
| // See: https://github.com/openclaw/openclaw/issues/5311 | ||
| const dnsDecision = resolveTelegramDnsResultOrderDecision({ network }); |
There was a problem hiding this comment.
[P1] applyTelegramNetworkWorkarounds() now sets appliedDnsResultOrder/appliedAutoSelectFamily before attempting dns.setDefaultResultOrder()/net.setDefaultAutoSelectFamily(). If those setters throw (e.g. unsupported runtime), the cache still updates and prevents future attempts even if a later call runs in an environment where it would succeed.
A safer pattern is to only update applied* after the setter succeeds, or revert in the catch.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/telegram/fetch.ts
Line: 33:36
Comment:
[P1] `applyTelegramNetworkWorkarounds()` now sets `appliedDnsResultOrder`/`appliedAutoSelectFamily` *before* attempting `dns.setDefaultResultOrder()`/`net.setDefaultAutoSelectFamily()`. If those setters throw (e.g. unsupported runtime), the cache still updates and prevents future attempts even if a later call runs in an environment where it would succeed.
A safer pattern is to only update `applied*` after the setter succeeds, or revert in the `catch`.
How can I resolve this? If you propose a fix, please make it concise.| export type TelegramDnsResultOrderDecision = { | ||
| value: string | null; | ||
| source?: string; |
There was a problem hiding this comment.
[P2] TelegramDnsResultOrderDecision.value is typed as string | null, but downstream it’s treated as a strict union ("ipv4first" | "verbatim") and then cast in fetch.ts. Tightening this type to "ipv4first" | "verbatim" | null would remove the need for the cast and prevent accidental future values from compiling.
Also, resolveTelegramDnsResultOrderDecision() already normalizes/filters to those two values, so the narrower type matches current behavior.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/telegram/network-config.ts
Line: 16:18
Comment:
[P2] `TelegramDnsResultOrderDecision.value` is typed as `string | null`, but downstream it’s treated as a strict union (`"ipv4first" | "verbatim"`) and then cast in `fetch.ts`. Tightening this type to `"ipv4first" | "verbatim" | null` would remove the need for the cast and prevent accidental future values from compiling.
Also, `resolveTelegramDnsResultOrderDecision()` already normalizes/filters to those two values, so the narrower type matches current behavior.
How can I resolve this? If you propose a fix, please make it concise.| // Check config | ||
| const configValue = (params?.network as { dnsResultOrder?: string } | undefined)?.dnsResultOrder | ||
| ?.trim() | ||
| .toLowerCase(); |
There was a problem hiding this comment.
[P3] configValue is extracted via (params?.network as { dnsResultOrder?: string })?.dnsResultOrder?.trim().toLowerCase(). Since TelegramNetworkConfig.dnsResultOrder is already a union of string literals, this cast/normalization is redundant and makes the code harder to follow.
If you want case-insensitive config parsing, it might be better handled at schema/parse time rather than by casting away the type here.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/telegram/network-config.ts
Line: 74:77
Comment:
[P3] `configValue` is extracted via `(params?.network as { dnsResultOrder?: string })?.dnsResultOrder?.trim().toLowerCase()`. Since `TelegramNetworkConfig.dnsResultOrder` is already a union of string literals, this cast/normalization is redundant and makes the code harder to follow.
If you want case-insensitive config parsing, it might be better handled at schema/parse time rather than by casting away the type here.
<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>
How can I resolve this? If you propose a fix, please make it concise.bfc1ccb to
f92900f
Compare
|
@Glucksberg is attempting to deploy a commit to the 0xBuns Team on Vercel. A member of the Team first needs to authorize it. |
…x fetch failures
Some networks/ISPs have issues with IPv6 causing Telegram API fetch
failures, even with autoSelectFamily=false. This adds a complementary
fix using dns.setDefaultResultOrder('ipv4first') to prioritize IPv4
addresses in DNS resolution.
Changes:
- Add dnsResultOrder config option (ipv4first | verbatim)
- Default to 'ipv4first' on Node 22+ alongside existing autoSelectFamily=false
- Add OPENCLAW_TELEGRAM_DNS_RESULT_ORDER env var override
- Log the applied setting for debugging
The combination of autoSelectFamily=false and dnsResultOrder=ipv4first
addresses the Happy Eyeballs timeout and IPv6 resolution issues that
cause 'Network request failed' errors on certain network configurations.
Fixes openclaw#5311
) OpenRouter's 'auto' model is stored in the registry with the full id 'openrouter/auto', but parseModelRef splits 'openrouter/auto' into provider='openrouter' and modelId='auto'. The registry lookup then fails because it searches for id='auto' instead of 'openrouter/auto'. This adds a fallback that tries the full id when the initial lookup fails for this specific case.
|
Merged via squash. Thanks @Glucksberg! |
Summary
Some networks/ISPs have issues with IPv6 causing Telegram API fetch failures, even with
autoSelectFamily=false. This adds a complementary fix usingdns.setDefaultResultOrder('ipv4first')to prioritize IPv4 addresses in DNS resolution.Problem
From #5311:
messagetool withaction=sendfails with "Network request for 'sendMessage' failed!"curlto Telegram API worksautoSelectFamily=falseis already applied but not sufficientSolution
Add
dnsResultOrder=ipv4firstas default on Node 22+ alongside the existingautoSelectFamily=false:This matches the workaround suggested in the issue comments:
NODE_OPTIONS='--dns-result-order=ipv4first'Changes
dnsResultOrderconfig option (ipv4first|verbatim)ipv4firston Node 22+OPENCLAW_TELEGRAM_DNS_RESULT_ORDERenv var overrideConfiguration
{ "channels": { "telegram": { "network": { "dnsResultOrder": "ipv4first" } } } }Or via environment variable:
Fixes #5311
Greptile Overview
Greptile Summary
This PR adds a Telegram-specific network workaround for Node 22+ by introducing a new
channels.telegram.network.dnsResultOrdersetting (and env overrideOPENCLAW_TELEGRAM_DNS_RESULT_ORDER) and applying it viadns.setDefaultResultOrder('ipv4first')alongside the existingautoSelectFamilyworkaround. Config schema/UI hints and Zod validation were updated accordingly.Main risk area is the global nature of these Node defaults: the implementation caches “applied” settings and currently marks them applied even if the underlying setter throws, which can prevent later successful application in environments where the setter becomes available.
Confidence Score: 4/5
applyTelegramNetworkWorkarounds()updatingapplied*state before confirming the runtime setter succeeded, which can lock in a no-op if the call throws.