mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-23 22:55:24 +00:00
fix(telegram): disable autoSelectFamily by default on WSL2
WSL2 has unstable IPv6 connectivity. This change auto-detects WSL2 environment and sets autoSelectFamily=false to use IPv4 directly, avoiding IPv6 connection timeouts. Resolves #21909
This commit is contained in:
committed by
Ayaan Zaidi
parent
73b4330d4c
commit
99e0a86458
@@ -1,6 +1,13 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { resolveTelegramAutoSelectFamilyDecision } from "./network-config.js";
|
||||
|
||||
// Mock isWSL2Sync at the top level
|
||||
vi.mock("../infra/wsl.js", () => ({
|
||||
isWSL2Sync: vi.fn(),
|
||||
}));
|
||||
|
||||
import { isWSL2Sync } from "../infra/wsl.js";
|
||||
|
||||
describe("resolveTelegramAutoSelectFamilyDecision", () => {
|
||||
it("prefers env enable over env disable", () => {
|
||||
const decision = resolveTelegramAutoSelectFamilyDecision({
|
||||
@@ -69,4 +76,44 @@ describe("resolveTelegramAutoSelectFamilyDecision", () => {
|
||||
const decision = resolveTelegramAutoSelectFamilyDecision({ env: {}, nodeMajor: 20 });
|
||||
expect(decision).toEqual({ value: null });
|
||||
});
|
||||
|
||||
describe("WSL2 detection", () => {
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it("disables autoSelectFamily on WSL2", () => {
|
||||
vi.mocked(isWSL2Sync).mockReturnValue(true);
|
||||
const decision = resolveTelegramAutoSelectFamilyDecision({ env: {}, nodeMajor: 22 });
|
||||
expect(decision).toEqual({ value: false, source: "default-wsl2" });
|
||||
});
|
||||
|
||||
it("respects config override on WSL2", () => {
|
||||
vi.mocked(isWSL2Sync).mockReturnValue(true);
|
||||
const decision = resolveTelegramAutoSelectFamilyDecision({
|
||||
env: {},
|
||||
network: { autoSelectFamily: true },
|
||||
nodeMajor: 22,
|
||||
});
|
||||
expect(decision).toEqual({ value: true, source: "config" });
|
||||
});
|
||||
|
||||
it("respects env override on WSL2", () => {
|
||||
vi.mocked(isWSL2Sync).mockReturnValue(true);
|
||||
const decision = resolveTelegramAutoSelectFamilyDecision({
|
||||
env: { OPENCLAW_TELEGRAM_ENABLE_AUTO_SELECT_FAMILY: "1" },
|
||||
nodeMajor: 22,
|
||||
});
|
||||
expect(decision).toEqual({
|
||||
value: true,
|
||||
source: "env:OPENCLAW_TELEGRAM_ENABLE_AUTO_SELECT_FAMILY",
|
||||
});
|
||||
});
|
||||
|
||||
it("uses Node 22 default when not on WSL2", () => {
|
||||
vi.mocked(isWSL2Sync).mockReturnValue(false);
|
||||
const decision = resolveTelegramAutoSelectFamilyDecision({ env: {}, nodeMajor: 22 });
|
||||
expect(decision).toEqual({ value: true, source: "default-node22" });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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";
|
||||
@@ -31,6 +32,10 @@ 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 (isWSL2Sync()) {
|
||||
return { value: false, source: "default-wsl2" };
|
||||
}
|
||||
if (Number.isFinite(nodeMajor) && nodeMajor >= 22) {
|
||||
return { value: true, source: "default-node22" };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user