fix(telegram): disable autoSelectFamily by default on WSL2 (#21916)

Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 431fd96670
Co-authored-by: MizukiMachine <185313792+MizukiMachine@users.noreply.github.com>
Co-authored-by: obviyus <22031114+obviyus@users.noreply.github.com>
Reviewed-by: @obviyus
This commit is contained in:
miz-cha
2026-02-22 14:24:49 +09:00
committed by GitHub
parent 73b4330d4c
commit 2f023a4775
3 changed files with 81 additions and 2 deletions

View File

@@ -1,6 +1,7 @@
import process from "node:process";
import type { TelegramNetworkConfig } from "../config/types.telegram.js";
import { isTruthyEnvValue } from "../infra/env.js";
import { isWSL2Sync } from "../infra/wsl.js";
export const TELEGRAM_DISABLE_AUTO_SELECT_FAMILY_ENV =
"OPENCLAW_TELEGRAM_DISABLE_AUTO_SELECT_FAMILY";
@@ -11,6 +12,16 @@ export type TelegramAutoSelectFamilyDecision = {
source?: string;
};
let wsl2SyncCache: boolean | undefined;
function isWSL2SyncCached(): boolean {
if (typeof wsl2SyncCache === "boolean") {
return wsl2SyncCache;
}
wsl2SyncCache = isWSL2Sync();
return wsl2SyncCache;
}
export function resolveTelegramAutoSelectFamilyDecision(params?: {
network?: TelegramNetworkConfig;
env?: NodeJS.ProcessEnv;
@@ -31,8 +42,16 @@ export function resolveTelegramAutoSelectFamilyDecision(params?: {
if (typeof params?.network?.autoSelectFamily === "boolean") {
return { value: params.network.autoSelectFamily, source: "config" };
}
// WSL2 has unstable IPv6 connectivity; disable autoSelectFamily to use IPv4 directly
if (isWSL2SyncCached()) {
return { value: false, source: "default-wsl2" };
}
if (Number.isFinite(nodeMajor) && nodeMajor >= 22) {
return { value: true, source: "default-node22" };
}
return { value: null };
}
export function resetTelegramNetworkConfigStateForTests(): void {
wsl2SyncCache = undefined;
}