Skip to content

fix(cli): warn that telegram/discord/slack presets don't enable messaging - #1898

Merged
cv merged 4 commits into
NVIDIA:mainfrom
latenighthackathon:fix/telegram-policy-add-warning
May 5, 2026
Merged

fix(cli): warn that telegram/discord/slack presets don't enable messaging#1898
cv merged 4 commits into
NVIDIA:mainfrom
latenighthackathon:fix/telegram-policy-add-warning

Conversation

@latenighthackathon

@latenighthackathon latenighthackathon commented Apr 15, 2026

Copy link
Copy Markdown
Collaborator

Summary

When a sandbox is created without enabling Telegram (or Discord, or Slack) during nemoclaw onboard, applying the matching policy preset via nemoclaw <name> policy-add only opens network egress to the channel's API. The bot token, channel configuration, and in-sandbox bridge are wired up at onboard time, so users who apply the preset later can reasonably believe they have enabled messaging when only the firewall has been widened.

Problem

sandboxPolicyAdd lists preset endpoints and asks for confirmation, but treats telegram/discord/slack identically to npm/pypi/github. There is no indication that the messaging preset alone won't make messaging work — the user-visible effect is a successful ● telegram marker in policy-list followed by a non-responding bot, which is easy to misdiagnose as broken integration or missing tokens (#1691).

Fix

Add getMessagingPresetWarning(presetName) to lib/policies, which returns a short note for the three messaging presets (telegram, discord, slack) and null for everything else. sandboxPolicyAdd prints the note between the endpoint disclosure and the apply confirmation so the user reads it at the decision point:

  Endpoints that would be opened: api.telegram.org

  Note: the 'telegram' preset only opens network egress to the Telegram API.
  To actually enable Telegram messaging, re-run 'nemoclaw onboard' and select Telegram
  in the messaging channels step — the bot token and channel bridge are wired
  up at onboard time and are not added by applying this preset alone.

  Apply 'telegram' to sandbox 'my-assistant'? [Y/n]:

The warning is universally true (even if Telegram was onboarded, the preset still doesn't do the wiring), so it also serves as accurate documentation of what policy-add actually does.

Test plan

  • Unit tests for getMessagingPresetWarning: returns a warning for telegram/discord/slack, null for all other presets and unknown names
  • Integration test: selecting the telegram preset in policy-add prints the warning and the expected confirmation prompt
  • Integration test: selecting a non-messaging preset (pypi) does not print the warning
  • All 68 policies.test.ts tests pass (64 existing + 4 new)
  • npm run lint / npm run typecheck / npm run build:cli clean

Closes #1691


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

Summary by CodeRabbit

  • New Features
    • Added messaging preset warnings: selecting Telegram, Discord, or Slack now shows a preset-specific warning after endpoint disclosure and before the apply confirmation, including instructions to re-run onboarding to fully enable messaging (also shown during dry-run).
  • Tests
    • Added and updated tests to verify messaging warnings, their content for messaging vs non-messaging presets, and correct CLI output order.

@coderabbitai

coderabbitai Bot commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds an exported helper that returns a user-facing warning for messaging presets telegram, discord, and slack. The CLI prints that warning during the policy-add flow immediately after listing endpoints and before the confirmation prompt or early --dry-run exit.

Changes

Cohort / File(s) Summary
Messaging Preset Warning Core
src/lib/policies.ts
Added and exported getMessagingPresetWarning(presetName) which returns a multi-line warning for telegram, discord, and slack, otherwise null.
CLI integration
src/nemoclaw.ts
sandboxPolicyAdd now calls policies.getMessagingPresetWarning(answer) and prints any returned warning to stdout immediately after listing endpoints and before the --dry-run early return and the user confirmation prompt.
Tests
test/policies.test.ts
Parameterized runPolicyAdd with presetName, adjusted mocked presets/endpoints (default endpoint -> example.com), updated dry-run assertions, added unit tests for getMessagingPresetWarning(), and added CLI tests verifying warning text and placement for telegram vs non-messaging presets.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I nibbled code and found three names,
Telegram, Discord, Slack — not full flames.
"Re-run onboard," I kindly say,
Egress is open, channels still astray.
Hop back, rebuild, then messages play.

🚥 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
Title check ✅ Passed The title accurately reflects the main change: adding a warning for messaging presets (telegram/discord/slack) that clarifies policy-add doesn't enable messaging.
Linked Issues check ✅ Passed The PR implements the second suggested remedy from #1691: clearly warning users that policy changes alone do not enable messaging and instructing them to rerun nemoclaw onboard.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing the messaging preset warning feature requested in #1691; no unrelated modifications detected.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ 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.

@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.

🧹 Nitpick comments (1)
test/policies.test.ts (1)

754-762: Consider asserting warning appears before confirmation prompt.

The current test validates message presence; adding an ordering assertion would lock in the UX-critical sequencing.

Suggested test hardening
 it("warns the user that the telegram preset alone does not enable Telegram messaging", () => {
   const result = runPolicyAdd("y", [], "telegram");

   expect(result.status).toBe(0);
   expect(result.stdout).toMatch(
     /Note: the 'telegram' preset only opens network egress to the Telegram API\./,
   );
   expect(result.stdout).toMatch(/re-run 'nemoclaw onboard' and select Telegram/);
+  const warningIdx = result.stdout.indexOf("Note: the 'telegram' preset only opens network egress");
+  const promptIdx = result.stdout.indexOf("Apply 'telegram' to sandbox 'test-sandbox'?");
+  expect(warningIdx).toBeGreaterThanOrEqual(0);
+  expect(promptIdx).toBeGreaterThanOrEqual(0);
+  expect(warningIdx).toBeLessThan(promptIdx);
 });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/policies.test.ts` around lines 754 - 762, The test "warns the user that
the telegram preset alone does not enable Telegram messaging" currently only
checks that two messages exist; update the assertion to lock in ordering by
verifying the warning about the 'telegram' preset appears before the
confirmation prompt text in runPolicyAdd's output. Locate the spec (the it
block) and add an ordering check using result.stdout.indexOf(...) or a regex
capture to ensure the warning string (/Note: the 'telegram' preset only opens
network egress to the Telegram API\./) has a lower index than the confirmation
prompt string (/re-run 'nemoclaw onboard' and select Telegram/), failing the
test if the prompt appears first.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@test/policies.test.ts`:
- Around line 754-762: The test "warns the user that the telegram preset alone
does not enable Telegram messaging" currently only checks that two messages
exist; update the assertion to lock in ordering by verifying the warning about
the 'telegram' preset appears before the confirmation prompt text in
runPolicyAdd's output. Locate the spec (the it block) and add an ordering check
using result.stdout.indexOf(...) or a regex capture to ensure the warning string
(/Note: the 'telegram' preset only opens network egress to the Telegram API\./)
has a lower index than the confirmation prompt string (/re-run 'nemoclaw
onboard' and select Telegram/), failing the test if the prompt appears first.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 94a999bb-e6ac-4b87-bffd-42b0ef049800

📥 Commits

Reviewing files that changed from the base of the PR and between ef39d7e and e4d3f0f.

📒 Files selected for processing (3)
  • src/lib/policies.ts
  • src/nemoclaw.ts
  • test/policies.test.ts

@latenighthackathon

Copy link
Copy Markdown
Collaborator Author

Added the ordering assertion (04d6aa33). Slight adjustment to CodeRabbit's suggestion: the apply prompt isn't printed via console.log in the test harness — it's passed to the mocked credentials.prompt and captured in the calls array — so the test now verifies that (a) the warning appears after the Endpoints that would be opened disclosure and (b) the prompt call happened (which in this synchronous code path can only occur after the warning was logged).

@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.

🧹 Nitpick comments (1)
test/policies.test.ts (1)

23-65: Consider cleaning up temporary test directories after spawnSync.

runPolicyAdd creates a unique temp directory per invocation and never removes it. This can accumulate temp files across local/CI runs.

♻️ Proposed cleanup
 function runPolicyAdd(confirmAnswer, extraArgs = [], presetName = "pypi") {
   const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-policy-add-"));
   const scriptPath = path.join(tmpDir, "policy-add-check.js");
   const script = String.raw`
@@
 `;
 
   fs.writeFileSync(scriptPath, script);
 
-  return spawnSync(process.execPath, [scriptPath], {
-    cwd: REPO_ROOT,
-    encoding: "utf-8",
-    env: {
-      ...process.env,
-      HOME: tmpDir,
-    },
-  });
+  try {
+    return spawnSync(process.execPath, [scriptPath], {
+      cwd: REPO_ROOT,
+      encoding: "utf-8",
+      env: {
+        ...process.env,
+        HOME: tmpDir,
+      },
+    });
+  } finally {
+    fs.rmSync(tmpDir, { recursive: true, force: true });
+  }
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/policies.test.ts` around lines 23 - 65, runPolicyAdd creates a temp
directory via fs.mkdtempSync (tmpDir) and writes scriptPath but never removes
it; update runPolicyAdd to ensure the temporary directory is removed after
spawnSync finishes (and on errors) by wrapping the spawnSync call in a
try/finally or equivalent and deleting tmpDir (e.g., fs.rmSync or fs.rmdirSync
with recursive/force options) in the finally block so cleanup always runs; keep
references to tmpDir and scriptPath so you remove the written file(s) and
directory.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@test/policies.test.ts`:
- Around line 23-65: runPolicyAdd creates a temp directory via fs.mkdtempSync
(tmpDir) and writes scriptPath but never removes it; update runPolicyAdd to
ensure the temporary directory is removed after spawnSync finishes (and on
errors) by wrapping the spawnSync call in a try/finally or equivalent and
deleting tmpDir (e.g., fs.rmSync or fs.rmdirSync with recursive/force options)
in the finally block so cleanup always runs; keep references to tmpDir and
scriptPath so you remove the written file(s) and directory.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 6629d118-a197-4aac-9d24-d061b2bea576

📥 Commits

Reviewing files that changed from the base of the PR and between e4d3f0f and 04d6aa3.

📒 Files selected for processing (1)
  • test/policies.test.ts

@wscurran

Copy link
Copy Markdown
Contributor

✨ Thanks for submitting this PR, which proposes a way to improve the NemoClaw CLI by warning about messaging presets.


Possibly related open issues:

@copy-pr-bot

copy-pr-bot Bot commented Apr 22, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@latenighthackathon
latenighthackathon force-pushed the fix/telegram-policy-add-warning branch 2 times, most recently from 65e6b1d to 0831f57 Compare April 26, 2026 18:38
@cv
cv enabled auto-merge (squash) April 27, 2026 17:19
auto-merge was automatically disabled April 27, 2026 21:54

Head branch was pushed to by a user without write access

@latenighthackathon
latenighthackathon force-pushed the fix/telegram-policy-add-warning branch from df6d543 to 0477938 Compare April 27, 2026 21:54
…aging (NVIDIA#1691)

When a sandbox is created without enabling Telegram (or Discord, or
Slack) during `nemoclaw onboard`, applying the matching policy preset
via `nemoclaw <name> policy-add` only opens network egress to the
channel API. The bot token, channel configuration, and in-sandbox
bridge are wired up at onboard time, so users who apply the preset
after onboarding without having enabled the channel can reasonably
believe they have enabled messaging when only the firewall has been
widened.

Add `getMessagingPresetWarning()` in `src/lib/policies.ts` and surface
it in `addSandboxPolicy()` (now in `src/lib/policy-channel-actions.ts`
after the recent CLI dispatch refactor) before the apply confirmation
so users see, for example, that the `telegram` preset alone does not
enable Telegram bots and that re-running `nemoclaw onboard` with
Telegram selected is the path to actually enabling the channel.

This is a rebase of an earlier branch onto current main:

- Hook moved from the legacy `src/nemoclaw.ts` dispatcher to the new
  `src/lib/policy-channel-actions.ts:addSandboxPolicy` after NVIDIA#2899 /
  NVIDIA#2901 / NVIDIA#2907 extracted dispatch.
- `getMessagingPresetWarning` got an explicit TS signature
  (`presetName: string): string | null`) to match the rest of
  `src/lib/policies.ts`.
- Replaced the em dash in the warning message with a period for
  consistency with project style.

Originally three commits (warning logic + ordering assertion + tmpDir
cleanup) on the prior branch; consolidated here because the rebase
needed the dispatcher hook ported to a new file.

Closes NVIDIA#1691

Re-ran `npx vitest run test/policies.test.ts` after rebase: 120/120 pass.

Signed-off-by: latenighthackathon <latenighthackathon@users.noreply.github.com>
@latenighthackathon
latenighthackathon force-pushed the fix/telegram-policy-add-warning branch from 0477938 to 5248b9c Compare May 5, 2026 02:24
latenighthackathon and others added 2 commits May 5, 2026 02:45
Wrap the spawnSync call in try/finally so the tmpDir created by
fs.mkdtempSync is removed after each invocation, regardless of test
outcome. Without this, every runPolicyAdd call leaves behind a
nemoclaw-policy-add-* directory under os.tmpdir(); across full test
suites and CI runs that adds up.

This restores the cleanup that was on the prior branch as a separate
commit but was lost during the rebase consolidation. Addresses the
CodeRabbit nit from 2026-04-15 that pointed at the same gap.

Re-ran `npx vitest run test/policies.test.ts`: 120/120 pass.

Signed-off-by: latenighthackathon <latenighthackathon@users.noreply.github.com>
@cv
cv enabled auto-merge (squash) May 5, 2026 17:43
@cv
cv merged commit 7eaeb5a into NVIDIA:main May 5, 2026
10 checks passed
@latenighthackathon
latenighthackathon deleted the fix/telegram-policy-add-warning branch May 6, 2026 01:24
@wscurran wscurran added area: cli Command line interface, flags, terminal UX, or output feature PR adds or expands user-visible functionality and removed NemoClaw CLI labels Jun 3, 2026
@wscurran wscurran added needs: review PR is conflict-free and awaiting maintainer review and removed status: rfr needs: review PR is conflict-free and awaiting maintainer review labels Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: cli Command line interface, flags, terminal UX, or output feature PR adds or expands user-visible functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Ubuntu 24.04.4 ][UX]:adding Telegram policy after onboarding does not clearly indicate that Telegram messaging is still disabled

3 participants