From d1ec157c71e0d5bfe772c700caadcb31caa05381 Mon Sep 17 00:00:00 2001 From: latenighthackathon Date: Sun, 21 Jun 2026 19:44:18 +0000 Subject: [PATCH 1/3] fix(discord): stop emitting a non-loopback per-account proxy (#5544) OpenClaw's Discord plugin validates channels.discord.accounts.default.proxy and rejects any non-loopback host (extensions/discord/src/proxy-fetch.ts validateDiscordProxyUrl: "Proxy URL must target a loopback host"), called from both the REST and gateway-plugin transports. NemoClaw was rendering it to the sandbox egress proxy http://10.200.0.1:3128, which the plugin rejects and drops, so the Discord gateway WebSocket cannot egress the deny-by-default namespace and never reaches READY. Resolve discordProxyUrl back to undefined so the per-account proxy field is omitted. Discord gateway/REST egress is carried by the top-level managed proxy (proxy.loopbackMode "gateway-only"), the mechanism OpenClaw documents for routing channel traffic through the operator proxy. Telegram keeps its per-account proxy because its Bot API transport honors a non-loopback proxy and has no loopback validator; Discord uniquely does. Flip the generate-openclaw-config and template-resolver expectations back to asserting no per-account Discord proxy, and revert the messaging-providers M9b E2E check to expect the managed proxy with no Discord account.proxy. Signed-off-by: latenighthackathon --- .../channels/discord/template-resolver.ts | 13 +------------ test/discord-template-resolver-proxy.test.ts | 19 +++++++++++-------- test/e2e/test-messaging-providers.sh | 18 ++++++++++-------- test/generate-openclaw-config.test.ts | 18 +++++++++--------- 4 files changed, 31 insertions(+), 37 deletions(-) diff --git a/src/lib/messaging/channels/discord/template-resolver.ts b/src/lib/messaging/channels/discord/template-resolver.ts index 9569a3d1d39..e866a4e3b28 100644 --- a/src/lib/messaging/channels/discord/template-resolver.ts +++ b/src/lib/messaging/channels/discord/template-resolver.ts @@ -8,16 +8,12 @@ import { nonEmptyArray, nonEmptyCsv, nonEmptyObject, - nonEmptyString, parseBoolean, parseList, resolvedRenderTemplateReference, stateValue, } from "../template-resolver-utils"; -const DEFAULT_PROXY_HOST = "10.200.0.1"; -const DEFAULT_PROXY_PORT = "3128"; - type DiscordGuildConfig = { readonly requireMention?: boolean; readonly users?: readonly string[]; @@ -27,8 +23,7 @@ export const resolveDiscordTemplateReference: BuiltInRenderTemplateResolver = ( reference, context, ) => { - if (reference === "discordProxyUrl") - return resolvedRenderTemplateReference(proxyUrl(context.env)); + if (reference === "discordProxyUrl") return resolvedRenderTemplateReference(undefined); switch (reference) { case "discord.guilds": @@ -88,9 +83,3 @@ function discordRequireMention(context: RenderTemplateContext): boolean { } return true; } - -function proxyUrl(env: RenderTemplateContext["env"]): string { - const host = nonEmptyString(env?.NEMOCLAW_PROXY_HOST) ?? DEFAULT_PROXY_HOST; - const port = nonEmptyString(env?.NEMOCLAW_PROXY_PORT) ?? DEFAULT_PROXY_PORT; - return `http://${host}:${port}`; -} diff --git a/test/discord-template-resolver-proxy.test.ts b/test/discord-template-resolver-proxy.test.ts index 95f0e318e2e..db31e2b7881 100644 --- a/test/discord-template-resolver-proxy.test.ts +++ b/test/discord-template-resolver-proxy.test.ts @@ -5,26 +5,29 @@ import { describe, expect, it } from "vitest"; import { resolveDiscordTemplateReference } from "../dist/lib/messaging/channels/discord/template-resolver.js"; -// The Discord gateway client honors only the per-account proxy (it ignores the -// managed env proxy), so channels.discord.accounts.default.proxy must resolve to -// the sandbox proxy or the gateway WebSocket cannot egress the deny-by-default -// network namespace. Telegram already resolves its proxy this way; #5075. +// OpenClaw's Discord plugin validates channels.discord.accounts.default.proxy +// and rejects any non-loopback host (validateDiscordProxyUrl: "Proxy URL must +// target a loopback host"). The sandbox egress proxy (10.200.0.1:3128) is not +// loopback, so a per-account proxy must NOT be emitted; Discord gateway/REST +// egress is carried by the top-level managed proxy (proxy.loopbackMode: +// "gateway-only") instead. discordProxyUrl therefore resolves to undefined so +// the proxy field is dropped from the rendered config (#5544; reverts #5248). const ctx = (env: Record) => ({ inputs: [], env }); describe("discord template-resolver: discordProxyUrl", () => { - it("resolves discordProxyUrl to the default sandbox proxy (was previously undefined, #5075)", () => { + it("resolves to undefined so no per-account proxy is emitted (#5544)", () => { expect(resolveDiscordTemplateReference("discordProxyUrl", ctx({}))).toEqual({ matched: true, - value: "http://10.200.0.1:3128", + value: undefined, }); }); - it("honors NEMOCLAW_PROXY_HOST / NEMOCLAW_PROXY_PORT overrides", () => { + it("stays undefined even when NEMOCLAW_PROXY_HOST / NEMOCLAW_PROXY_PORT are set", () => { expect( resolveDiscordTemplateReference( "discordProxyUrl", ctx({ NEMOCLAW_PROXY_HOST: "10.201.0.9", NEMOCLAW_PROXY_PORT: "43128" }), ), - ).toEqual({ matched: true, value: "http://10.201.0.9:43128" }); + ).toEqual({ matched: true, value: undefined }); }); }); diff --git a/test/e2e/test-messaging-providers.sh b/test/e2e/test-messaging-providers.sh index 4c7bef3d06b..e4aea1f86ce 100755 --- a/test/e2e/test-messaging-providers.sh +++ b/test/e2e/test-messaging-providers.sh @@ -1830,11 +1830,13 @@ print(account.get('token', '')) skip "M9: No Discord token to check" fi - # M9b: Discord Gateway WebSocket routing uses the per-account proxy. - # OpenClaw's Discord gateway client only tunnels when the Discord account - # proxy is set, while the top-level managed proxy remains configured for the - # rest of the channel stack. The fake Gateway proof in M13b-M13g exercises - # the same OpenShell relay path using the generated managed proxy config. + # M9b: Discord Gateway WebSocket routing uses OpenClaw's managed proxy. + # OpenClaw's Discord plugin validates the per-account proxy and rejects any + # non-loopback host, so NemoClaw must not bake a Discord-only account.proxy + # (the sandbox egress proxy 10.200.0.1:3128 is not loopback). Discord + # gateway/REST egress is carried by the top-level managed proxy + # (proxy.loopbackMode "gateway-only"). The fake Gateway proof in M13b-M13g + # exercises the same OpenShell relay path using that managed proxy config. dc_proxy=$(echo "$channel_json" | python3 -c " import json, sys d = json.load(sys.stdin) @@ -1851,10 +1853,10 @@ if proxy.get('enabled') is True: print(proxy.get('proxyUrl') or '') \"" 2>/dev/null || true) expected_managed_proxy="http://${NEMOCLAW_PROXY_HOST:-10.200.0.1}:${NEMOCLAW_PROXY_PORT:-3128}" - if [ -n "$dc_token" ] && [ "$dc_proxy" = "$expected_managed_proxy" ] && [ "$managed_proxy_url" = "$expected_managed_proxy" ]; then - pass "M9b: Discord uses per-account proxy while OpenClaw managed proxy config remains set" + if [ -n "$dc_token" ] && [ -z "$dc_proxy" ] && [ "$managed_proxy_url" = "$expected_managed_proxy" ]; then + pass "M9b: Discord relies on OpenClaw managed proxy config, with no per-account loopback proxy" elif [ -n "$dc_token" ]; then - fail "M9b: Discord proxy wiring wrong; expected account.proxy='${expected_managed_proxy}' and proxy.proxyUrl='${expected_managed_proxy}' (account.proxy='${dc_proxy}', proxy.proxyUrl='${managed_proxy_url}')" + fail "M9b: Discord proxy wiring wrong; expected account.proxy='' and proxy.proxyUrl='${expected_managed_proxy}' (account.proxy='${dc_proxy}', proxy.proxyUrl='${managed_proxy_url}')" else skip "M9b: No Discord channel config to check" fi diff --git a/test/generate-openclaw-config.test.ts b/test/generate-openclaw-config.test.ts index d17603ddb09..f518a6e2794 100644 --- a/test/generate-openclaw-config.test.ts +++ b/test/generate-openclaw-config.test.ts @@ -613,10 +613,10 @@ describe("generate-openclaw-config.mts: config generation", () => { "openshell:resolve:env:DISCORD_BOT_TOKEN", ); expect(config.channels.telegram.accounts.default.proxy).toBe("http://10.200.0.1:3128"); - expect(config.channels.discord.accounts.default.proxy).toBe("http://10.200.0.1:3128"); + expect(config.channels.discord.accounts.default.proxy).toBeUndefined(); }); - it("#3894: routes Discord gateway traffic through the per-account proxy", () => { + it("#3894: routes Discord gateway traffic through OpenClaw's managed proxy", () => { const channels = Buffer.from(JSON.stringify(["discord"])).toString("base64"); const config = runConfigScript({ NEMOCLAW_MESSAGING_CHANNELS_B64: channels, @@ -633,10 +633,10 @@ describe("generate-openclaw-config.mts: config generation", () => { token: "openshell:resolve:env:DISCORD_BOT_TOKEN", enabled: true, }); - expect(config.channels.discord.accounts.default.proxy).toBe("http://10.201.0.9:43128"); + expect(config.channels.discord.accounts.default.proxy).toBeUndefined(); }); - it("writes the Discord account proxy alongside the managed proxy", () => { + it("does not write a Discord account proxy when the managed proxy is configured", () => { const channels = Buffer.from(JSON.stringify(["discord"])).toString("base64"); const config = runConfigScript({ NEMOCLAW_MESSAGING_CHANNELS_B64: channels, @@ -644,7 +644,7 @@ describe("generate-openclaw-config.mts: config generation", () => { }); expect(config.proxy.proxyUrl).toBe("http://10.200.0.1:43128"); - expect(config.channels.discord.accounts.default.proxy).toBe("http://10.200.0.1:43128"); + expect(config.channels.discord.accounts.default.proxy).toBeUndefined(); }); it("can defer OpenClaw managed proxy config for build-time doctor", () => { @@ -655,7 +655,7 @@ describe("generate-openclaw-config.mts: config generation", () => { }); expect(config.proxy).toBeUndefined(); - expect(config.channels.discord.accounts.default.proxy).toBe("http://10.200.0.1:3128"); + expect(config.channels.discord.accounts.default.proxy).toBeUndefined(); }); it("ignores the OpenShell loopback proxy env var when using OpenClaw managed proxy", () => { @@ -667,10 +667,10 @@ describe("generate-openclaw-config.mts: config generation", () => { }); expect(config.proxy.proxyUrl).toBe("http://10.200.0.1:3128"); - expect(config.channels.discord.accounts.default.proxy).toBe("http://10.200.0.1:3128"); + expect(config.channels.discord.accounts.default.proxy).toBeUndefined(); }); - it("routes both Telegram and Discord through the per-account proxy", () => { + it("keeps Telegram on the OpenShell proxy while Discord relies on the managed proxy", () => { const channels = Buffer.from(JSON.stringify(["telegram", "discord"])).toString("base64"); const config = runConfigScript({ NEMOCLAW_MESSAGING_CHANNELS_B64: channels, @@ -680,7 +680,7 @@ describe("generate-openclaw-config.mts: config generation", () => { expect(config.proxy.proxyUrl).toBe("http://10.201.0.9:43128"); expect(config.channels.telegram.accounts.default.proxy).toBe("http://10.201.0.9:43128"); - expect(config.channels.discord.accounts.default.proxy).toBe("http://10.201.0.9:43128"); + expect(config.channels.discord.accounts.default.proxy).toBeUndefined(); }); it("emits Bolt-shape placeholders for Slack so the SDK's prefix regex passes", () => { From e1fbc9101df0217c122c31070d5053d44c5f0c5b Mon Sep 17 00:00:00 2001 From: Carlos Villela Date: Tue, 23 Jun 2026 10:24:47 -0700 Subject: [PATCH 2/3] test(e2e): port Discord proxy expectation to Vitest Signed-off-by: Carlos Villela --- test/e2e-scenario/live/messaging-providers.test.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/e2e-scenario/live/messaging-providers.test.ts b/test/e2e-scenario/live/messaging-providers.test.ts index 3dc931f0758..ad877d0295e 100644 --- a/test/e2e-scenario/live/messaging-providers.test.ts +++ b/test/e2e-scenario/live/messaging-providers.test.ts @@ -433,6 +433,15 @@ process.exit(Array.isArray(channels) && channels.some((c) => c?.channelId === "w ); check(discordToken.length > 0, "M8: Discord token present in openclaw.json"); check(discordToken !== state.tokens.discord, "M9: Discord token is not the host token"); + const expectedManagedProxy = `http://${state.env.NEMOCLAW_PROXY_HOST ?? "10.200.0.1"}:${state.env.NEMOCLAW_PROXY_PORT ?? "3128"}`; + const discordAccountProxy = accountString(discordAccount, "proxy"); + const managedProxyUrl = typeof config.proxy?.proxyUrl === "string" ? config.proxy.proxyUrl : ""; + check( + discordAccountProxy === "" && + config.proxy?.enabled === true && + managedProxyUrl === expectedManagedProxy, + `M9b: Discord relies on OpenClaw managed proxy config, with no per-account loopback proxy (account.proxy='${discordAccountProxy}', proxy.proxyUrl='${managedProxyUrl}')`, + ); check(accountBool(telegramAccount, "enabled") === true, "M10: Telegram account is enabled"); check(accountBool(discordAccount, "enabled") === true, "M11: Discord account is enabled"); check( From d4cd94f92623de42bf51e3a37ad4e130dd8068d1 Mon Sep 17 00:00:00 2001 From: Carlos Villela Date: Tue, 23 Jun 2026 10:33:05 -0700 Subject: [PATCH 3/3] test(e2e): match proxy fallback semantics Signed-off-by: Carlos Villela --- test/e2e-scenario/live/messaging-providers.test.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/e2e-scenario/live/messaging-providers.test.ts b/test/e2e-scenario/live/messaging-providers.test.ts index ad877d0295e..d96d591987d 100644 --- a/test/e2e-scenario/live/messaging-providers.test.ts +++ b/test/e2e-scenario/live/messaging-providers.test.ts @@ -433,7 +433,9 @@ process.exit(Array.isArray(channels) && channels.some((c) => c?.channelId === "w ); check(discordToken.length > 0, "M8: Discord token present in openclaw.json"); check(discordToken !== state.tokens.discord, "M9: Discord token is not the host token"); - const expectedManagedProxy = `http://${state.env.NEMOCLAW_PROXY_HOST ?? "10.200.0.1"}:${state.env.NEMOCLAW_PROXY_PORT ?? "3128"}`; + const expectedManagedProxyHost = nonEmpty(state.env.NEMOCLAW_PROXY_HOST) ?? "10.200.0.1"; + const expectedManagedProxyPort = nonEmpty(state.env.NEMOCLAW_PROXY_PORT) ?? "3128"; + const expectedManagedProxy = `http://${expectedManagedProxyHost}:${expectedManagedProxyPort}`; const discordAccountProxy = accountString(discordAccount, "proxy"); const managedProxyUrl = typeof config.proxy?.proxyUrl === "string" ? config.proxy.proxyUrl : ""; check(