Skip to content

fix(messaging): resolve the Discord per-account proxy so the gateway WebSocket connects#5248

Merged
cv merged 4 commits into
NVIDIA:mainfrom
latenighthackathon:fix/discord-proxy-template-resolver
Jun 13, 2026
Merged

fix(messaging): resolve the Discord per-account proxy so the gateway WebSocket connects#5248
cv merged 4 commits into
NVIDIA:mainfrom
latenighthackathon:fix/discord-proxy-template-resolver

Conversation

@latenighthackathon

@latenighthackathon latenighthackathon commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Summary

A sandbox with the Discord channel comes up degraded: the bot sends via the Discord REST API but never establishes the gateway WebSocket, so it receives zero inbound events. This is the regression tracked in #5075 (originally #3894).

channels.discord.accounts.default.proxy is rendered from the {{discordProxyUrl}} template, but src/lib/messaging/channels/discord/template-resolver.ts resolved that reference to undefined, so the Discord account was emitted with no proxy. The Discord gateway client honors only the per-account proxy (it ignores the managed env proxy), so the gateway WebSocket cannot egress the deny-by-default sandbox network namespace.

Telegram's resolver already resolves its proxyUrl to the sandbox proxy; Discord was the lone gap.

Related Issue

Closes #5075.

Note: an earlier PR (#5081) fixed this in scripts/generate-openclaw-config.mts, but channel-config generation has since moved to the manifest + template-resolver path, so that fix site no longer exists. This re-targets the same bug at the current site.

Changes

  • src/lib/messaging/channels/discord/template-resolver.ts: resolve discordProxyUrl to the sandbox proxy URL (NEMOCLAW_PROXY_HOST/NEMOCLAW_PROXY_PORT, default http://10.200.0.1:3128) instead of undefined, mirroring the telegram resolver.
  • test/discord-template-resolver-proxy.test.ts: assert discordProxyUrl resolves to the default proxy and honors host/port overrides.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Verification

  • npx vitest run --project cli test/discord-template-resolver-proxy.test.ts test/messaging-build-applier.test.ts — 18/18 pass
  • npm run typecheck:cli and npm run build:cli — clean

Signed-off-by: latenighthackathon latenighthackathon@users.noreply.github.com

Summary by CodeRabbit

  • New Features

    • Discord messaging now consistently resolves a proxy URL, using configured host/port or sensible defaults.
  • Bug Fixes

    • Fixed case where Discord proxy URL could be missing; now reliably populated.
  • Tests

    • Added and updated tests to validate Discord proxy URL resolution for default and custom proxy configurations.

@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR makes discordProxyUrl resolve to an HTTP proxy URL derived from environment variables (NEMOCLAW_PROXY_HOST / NEMOCLAW_PROXY_PORT) with default host/port fallbacks, and updates tests and config-generator expectations to assert the Discord account-level proxy is populated.

Changes

Discord Proxy URL Implementation

Layer / File(s) Summary
Proxy URL helper and constants
src/lib/messaging/channels/discord/template-resolver.ts
Imports nonEmptyString and adds DEFAULT_PROXY_HOST / DEFAULT_PROXY_PORT; implements proxyUrl(env) that builds http://{host}:{port} from NEMOCLAW_PROXY_HOST/NEMOCLAW_PROXY_PORT with defaults.
Template resolver integration and validation
src/lib/messaging/channels/discord/template-resolver.ts, test/discord-template-resolver-proxy.test.ts
Changes discordProxyUrl branch to return resolvedRenderTemplateReference(proxyUrl(context.env)); adds Vitest tests verifying default sandbox proxy URL and override via NEMOCLAW_PROXY_HOST/NEMOCLAW_PROXY_PORT.
Config generator test expectation updates
test/generate-openclaw-config.test.ts
Reorders Node built-in imports and updates multiple tests to expect channels.discord.accounts.default.proxy to be populated with the managed or per-account proxy URL across scenarios.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A tiny rabbit hops the net so wide,
It reads the env where proxy secrets hide,
Builds a URL with host and port in tune,
Falls back to defaults beneath the moon,
Now Discord's gateway hums — hooray, relay! 🚀

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the fix as resolving the Discord per-account proxy for gateway WebSocket connectivity, which directly matches the main change in the pull request.
Linked Issues check ✅ Passed The pull request fully addresses issue #5075 by restoring per-account Discord proxy assignment in the template resolver and updating test expectations to verify proxy URL resolution.
Out of Scope Changes check ✅ Passed All changes are directly related to the linked issue #5075: template resolver fixes, new proxy tests, and test expectation updates for proxy configuration.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

…connects

channels.discord.accounts.default.proxy is rendered from {{discordProxyUrl}},
but the Discord template-resolver resolved that reference to undefined, so the
Discord account was emitted with no proxy. The Discord gateway client honors
only the per-account proxy (it ignores the managed env proxy), so the gateway
WebSocket could not egress the deny-by-default sandbox network namespace: the
bot sent via the Discord REST API but never established the gateway socket and
received zero inbound events.

Resolve discordProxyUrl to the sandbox proxy URL (NEMOCLAW_PROXY_HOST/PORT,
default http://10.200.0.1:3128), mirroring how the telegram resolver resolves
its proxyUrl. Telegram already routed its per-account proxy this way; Discord
was the lone gap.

Closes NVIDIA#5075

Signed-off-by: latenighthackathon <latenighthackathon@users.noreply.github.com>
@latenighthackathon latenighthackathon force-pushed the fix/discord-proxy-template-resolver branch from 54265be to 0b51186 Compare June 11, 2026 19:25

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
test/generate-openclaw-config.test.ts (1)

661-671: ⚠️ Potential issue | 🟡 Minor

Remove/rename NEMOCLAW_DISCORD_PROXY_PORT in the OpenShell loopback proxy test

  • NEMOCLAW_DISCORD_PROXY_PORT is only set in test/generate-openclaw-config.test.ts and is not read by the Discord proxy resolver (src/lib/messaging/channels/discord/template-resolver.ts uses only NEMOCLAW_PROXY_HOST / NEMOCLAW_PROXY_PORT).
  • If the intent is to ensure OPENSHELL_LOOPBACK_PROXY_URL doesn’t affect the managed proxy, drop NEMOCLAW_DISCORD_PROXY_PORT or replace it with NEMOCLAW_PROXY_PORT (or NEMOCLAW_PROXY_HOST) as the negative control.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/generate-openclaw-config.test.ts` around lines 661 - 671, The test sets
NEMOCLAW_DISCORD_PROXY_PORT which is not used by the Discord proxy resolver;
update the test (the runConfigScript call in the spec) to remove
NEMOCLAW_DISCORD_PROXY_PORT or replace it with the real control env var
NEMOCLAW_PROXY_PORT (and/or NEMOCLAW_PROXY_HOST) so the negative-control
assertion verifies that OPENSHELL_LOOPBACK_PROXY_URL is ignored; ensure the test
still asserts config.proxy.proxyUrl and
config.channels.discord.accounts.default.proxy remain the managed proxy value
and reference the resolver logic in
src/lib/messaging/channels/discord/template-resolver.ts to match expected env
names.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@test/generate-openclaw-config.test.ts`:
- Around line 661-671: The test sets NEMOCLAW_DISCORD_PROXY_PORT which is not
used by the Discord proxy resolver; update the test (the runConfigScript call in
the spec) to remove NEMOCLAW_DISCORD_PROXY_PORT or replace it with the real
control env var NEMOCLAW_PROXY_PORT (and/or NEMOCLAW_PROXY_HOST) so the
negative-control assertion verifies that OPENSHELL_LOOPBACK_PROXY_URL is
ignored; ensure the test still asserts config.proxy.proxyUrl and
config.channels.discord.accounts.default.proxy remain the managed proxy value
and reference the resolver logic in
src/lib/messaging/channels/discord/template-resolver.ts to match expected env
names.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 299d4b31-65ac-4b6f-b762-31fd09da5735

📥 Commits

Reviewing files that changed from the base of the PR and between 54265be and 0b51186.

📒 Files selected for processing (3)
  • src/lib/messaging/channels/discord/template-resolver.ts
  • test/discord-template-resolver-proxy.test.ts
  • test/generate-openclaw-config.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/lib/messaging/channels/discord/template-resolver.ts

@wscurran wscurran added area: messaging Messaging channels, bridges, manifests, or channel lifecycle bug-fix PR fixes a bug or regression integration: discord Discord integration or channel behavior labels Jun 12, 2026
@cv cv enabled auto-merge (squash) June 13, 2026 05:33
@cv cv merged commit 4d0c6ff into NVIDIA:main Jun 13, 2026
30 checks passed
@cv cv added the v0.0.65 Release target label Jun 13, 2026
cv pushed a commit that referenced this pull request Jun 13, 2026
## Summary
Updates the messaging providers E2E M9b assertion so Discord now expects
`channels.discord.accounts.default.proxy` to match the sandbox proxy
while the top-level managed proxy remains configured. This aligns the
test with the Discord proxy behavior restored by PR #5248 for issue
#5075.

## Changes
- Updated `test/e2e/test-messaging-providers.sh` M9b comments and
pass/fail messages to describe per-account Discord proxy routing.
- Changed the M9b assertion to require both `account.proxy` and
`proxy.proxyUrl` to equal the expected sandbox proxy URL.
- Reviewed `docs/` and found no user-facing docs update needed because
this is a stale E2E expectation change with no product behavior change.

## Type of Change
- [x] Code change (feature, bug fix, or refactor)
- [ ] Code change with doc updates
- [ ] Doc only (prose changes, no code sample modifications)
- [ ] Doc only (includes code sample changes)

## Verification
- [ ] `npx prek run --all-files` passes
- [ ] `npm test` passes
- [x] Tests added or updated for new or changed behavior
- [x] No secrets, API keys, or credentials committed
- [ ] Docs updated for user-facing behavior changes
- [ ] `npm run docs` builds without warnings (doc changes only)
- [ ] Doc pages follow the [style
guide](https://github.com/NVIDIA/NemoClaw/blob/main/docs/CONTRIBUTING.md)
(doc changes only)
- [ ] New doc pages include SPDX header and frontmatter (new pages only)

Additional verification:
- `bash -n test/e2e/test-messaging-providers.sh` passed.
- `shellcheck test/e2e/test-messaging-providers.sh` passed.
- `npx prek run --files test/e2e/test-messaging-providers.sh` passed.
- `npx vitest run --project cli
test/discord-template-resolver-proxy.test.ts
test/generate-openclaw-config.test.ts` passed.
- Docs review completed: no docs changes needed.
- Full `npx prek run --all-files` and `npm test` were attempted and fail
in unrelated existing suites outside this change.

---
Signed-off-by: San Dang <sdang@nvidia.com>

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Tests**
* Updated Discord proxy configuration validation in end-to-end tests to
reflect current proxy-wiring expectations during configuration patching.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Signed-off-by: San Dang <sdang@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: messaging Messaging channels, bridges, manifests, or channel lifecycle bug-fix PR fixes a bug or regression integration: discord Discord integration or channel behavior v0.0.65 Release target

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Discord gateway WebSocket never connects (regression of #3894): config generator no longer sets the per-account Discord proxy

3 participants