Skip to content

fix: correct Telegram bridge status detection (fixes #587)#614

Open
kagura-agent wants to merge 2 commits intoNVIDIA:mainfrom
kagura-agent:fix/587-telegram-bridge-status-is-mis
Open

fix: correct Telegram bridge status detection (fixes #587)#614
kagura-agent wants to merge 2 commits intoNVIDIA:mainfrom
kagura-agent:fix/587-telegram-bridge-status-is-mis

Conversation

@kagura-agent
Copy link
Contributor

@kagura-agent kagura-agent commented Mar 22, 2026

Problem

nemoclaw start launches the Telegram bridge correctly, but nemoclaw status reports it as stopped and nemoclaw stop says it's not running (even though the process is alive).

Root Cause

In bin/nemoclaw.js:

  • start() resolves the sandbox name from the registry and passes SANDBOX_NAME=<name> to start-services.sh, which saves the PID file in /tmp/nemoclaw-services-<name>/.
  • stop() called start-services.sh --stop without passing SANDBOX_NAME, so the shell script defaulted to "default" and looked in /tmp/nemoclaw-services-default/ — a different directory.
  • showStatus() had the same problem — no SANDBOX_NAME passed, so it always checked the wrong PID directory.

This meant the PID file written by start was invisible to both status and stop.

Fix

Extract a shared sandboxEnvPrefix() helper that resolves the default sandbox name from the registry (same logic start() already had), and use it in all three functions: start(), stop(), and showStatus().

Changes

  • bin/nemoclaw.js: Extract sandboxEnvPrefix(), apply it to stop() and showStatus()
  • test/service-env.test.js: Add regression tests verifying stop() and showStatus() use the shared helper, preventing future drift

Testing

All 189 existing tests pass (1 pre-existing unrelated failure in install-preflight.test.js). 3 new regression tests added.

Fixes #587

Summary by CodeRabbit

  • Refactor

    • Service management (start/stop/status) now consistently applies an optional sandbox environment prefix so operations target the intended sandbox reliably.
  • Tests

    • Added static tests to ensure sandbox environment variables are propagated consistently across service start, stop and status operations.

@coderabbitai
Copy link

coderabbitai bot commented Mar 22, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: db44fafe-3f2b-4835-be89-284fe51aaaf2

📥 Commits

Reviewing files that changed from the base of the PR and between 2371060 and 568b2f5.

📒 Files selected for processing (2)
  • bin/nemoclaw.js
  • test/service-env.test.js
🚧 Files skipped from review as they are similar to previous changes (2)
  • bin/nemoclaw.js
  • test/service-env.test.js

📝 Walkthrough

Walkthrough

Added a centralized sandboxEnvPrefix() helper in bin/nemoclaw.js and updated start, stop, and showStatus to prepend the computed SANDBOX_NAME=... environment prefix when invoking the service script; added tests that assert the helper is referenced consistently across those functions.

Changes

Cohort / File(s) Summary
Sandbox Environment Prefix Helper
bin/nemoclaw.js
Added function sandboxEnvPrefix() to compute a validated SANDBOX_NAME=... assignment from registry.listSandboxes().defaultSandbox. start() now calls ensureApiKey() and uses the helper when running bash "${SCRIPTS}/start-services.sh". stop() and showStatus() were updated to compute and prepend the same prefix when invoking the service script with --stop / --status.
Service Environment Consistency Tests
test/service-env.test.js
Added node:path/fs imports and a new test SANDBOX_NAME consistency across start/stop/status (#587) that reads bin/nemoclaw.js as text, uses regex to verify stop() and showStatus() include sandboxEnvPrefix, and asserts sandboxEnvPrefix() appears at least three times (covering start/stop/status).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I dug a prefix, tidy and bright,

SANDBOX_NAME snug for day and night,
Start, stop, status hop in line,
All together — neat and fine,
A bunny cheers: "Consistency's right!"

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Title check ⚠️ Warning PR title references Telegram bridge status detection, but changes actually implement sandbox environment prefix refactoring for consistency across service commands. Update title to accurately reflect the main change, such as 'fix: ensure sandbox name consistency in start/stop/status commands' or similar.
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 (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Code changes directly address issue #587 by extracting sandboxEnvPrefix() helper and applying it consistently to start(), stop(), and showStatus() to resolve the same PID file locations.
Out of Scope Changes check ✅ Passed All changes (helper function, command updates, and regression tests) are directly scoped to fixing the sandbox name resolution issue described in #587.

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

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@test/service-env.test.js`:
- Around line 151-162: The test currently counts occurrences of
sandboxEnvPrefix() which can include the helper declaration and thus miss a
missing call in start(); update the test to explicitly assert that the start()
implementation calls sandboxEnvPrefix() (in addition to stop() and showStatus())
— e.g., search the source for the start function body and assert it contains
sandboxEnvPrefix(), and keep the existing count/assertions for stop() and
showStatus() to ensure all three call sites exist; reference sandboxEnvPrefix()
and start(), stop(), showStatus() to locate the relevant checks in the test.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 1d6c88c6-c7df-402a-963b-87540432b60f

📥 Commits

Reviewing files that changed from the base of the PR and between 1dbf82f and 593edb8.

📒 Files selected for processing (2)
  • bin/nemoclaw.js
  • test/service-env.test.js

Comment on lines +151 to +162
it("sandboxEnvPrefix() is a shared helper used by start, stop, and status", () => {
const fs = require("fs");
const src = fs.readFileSync(
path.join(__dirname, "..", "bin", "nemoclaw.js"),
"utf-8"
);
const uses = (src.match(/sandboxEnvPrefix\(\)/g) || []).length;
// At least 3 call sites: start(), stop(), showStatus()
assert.ok(
uses >= 3,
`sandboxEnvPrefix() should be called at least 3 times (start/stop/status), found ${uses}`
);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

sandboxEnvPrefix() count check can miss a start() regression.

At Line 157, the regex also matches the helper declaration, so uses >= 3 can still pass with only declaration + stop() + showStatus() and no start() usage.

✅ Suggested test hardening
-    it("sandboxEnvPrefix() is a shared helper used by start, stop, and status", () => {
+    it("start() passes SANDBOX_NAME via sandboxEnvPrefix", () => {
       const fs = require("fs");
       const src = fs.readFileSync(
         path.join(__dirname, "..", "bin", "nemoclaw.js"),
         "utf-8"
       );
-      const uses = (src.match(/sandboxEnvPrefix\(\)/g) || []).length;
-      // At least 3 call sites: start(), stop(), showStatus()
-      assert.ok(
-        uses >= 3,
-        `sandboxEnvPrefix() should be called at least 3 times (start/stop/status), found ${uses}`
-      );
+      const startFn = src.match(/async function start\(\)[^]*?^}/m);
+      assert.ok(startFn, "start() function must exist");
+      assert.ok(
+        startFn[0].includes("sandboxEnvPrefix"),
+        "start() must call sandboxEnvPrefix() to resolve SANDBOX_NAME"
+      );
     });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
it("sandboxEnvPrefix() is a shared helper used by start, stop, and status", () => {
const fs = require("fs");
const src = fs.readFileSync(
path.join(__dirname, "..", "bin", "nemoclaw.js"),
"utf-8"
);
const uses = (src.match(/sandboxEnvPrefix\(\)/g) || []).length;
// At least 3 call sites: start(), stop(), showStatus()
assert.ok(
uses >= 3,
`sandboxEnvPrefix() should be called at least 3 times (start/stop/status), found ${uses}`
);
it("start() passes SANDBOX_NAME via sandboxEnvPrefix", () => {
const fs = require("fs");
const src = fs.readFileSync(
path.join(__dirname, "..", "bin", "nemoclaw.js"),
"utf-8"
);
const startFn = src.match(/async function start\(\)[^]*?^}/m);
assert.ok(startFn, "start() function must exist");
assert.ok(
startFn[0].includes("sandboxEnvPrefix"),
"start() must call sandboxEnvPrefix() to resolve SANDBOX_NAME"
);
});
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/service-env.test.js` around lines 151 - 162, The test currently counts
occurrences of sandboxEnvPrefix() which can include the helper declaration and
thus miss a missing call in start(); update the test to explicitly assert that
the start() implementation calls sandboxEnvPrefix() (in addition to stop() and
showStatus()) — e.g., search the source for the start function body and assert
it contains sandboxEnvPrefix(), and keep the existing count/assertions for
stop() and showStatus() to ensure all three call sites exist; reference
sandboxEnvPrefix() and start(), stop(), showStatus() to locate the relevant
checks in the test.

Copy link

@WuKongAI-CMU WuKongAI-CMU left a comment

Choose a reason for hiding this comment

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

Nice fix — extracting sandboxEnvPrefix() as a shared helper is the right call. The root cause (PIDDIR mismatch between start/stop/status) explains the misreported status cleanly.

A couple of observations:

  1. The showStatus regex in the test ([^]*?^}) uses a multiline anchor that depends on the function ending at column 0. If someone indents the closing brace or adds a nested function, this test would silently pass with a partial match. The stop() regex ([^}]*\}) is more resilient. Maybe use the same greedy-to-brace pattern for both?

  2. Minor: sandboxEnvPrefix() calls registry.listSandboxes() on every invocation. For showStatus() this means it's called twice (once explicitly for sandbox info, once via the prefix). Not a real perf issue since it's just reading a JSON file, but worth noting.

Overall this is clean and well-scoped. 👍

@kagura-agent
Copy link
Contributor Author

Thanks for the thoughtful review @WuKongAI-CMU!

On your two observations:

  1. Test regex resilience — Good catch. The showStatus regex ([^]*?^}) is indeed more fragile than the stop() pattern. I'll update it to use the same greedy-to-brace approach for consistency.

  2. Double listSandboxes() call — You're right, it's a minor redundancy. Since it's just reading a JSON file the perf impact is negligible, but I can hoist the result if you'd prefer.

Let me push a fix for point 1 — it's a real improvement.

Kagura Chen added 2 commits March 23, 2026 18:37
stop() and showStatus() were not passing SANDBOX_NAME to
start-services.sh, causing it to default to 'default' while start()
passed the actual sandbox name from the registry. This meant the PID
directory used by stop/status (/tmp/nemoclaw-services-default/) was
different from the one used by start (/tmp/nemoclaw-services-<name>/),
so status always reported 'stopped' and stop never found the running
process.

Extract sandboxEnvPrefix() helper and use it consistently in start(),
stop(), and showStatus() so all three resolve SANDBOX_NAME the same way.
Address review feedback from @WuKongAI-CMU: both stop() and
showStatus() regex patterns now use the same approach
(`\{[\s\S]*?\n\}`) that handles nested braces and indented
closing braces instead of relying on column-0 anchors.
@kagura-agent kagura-agent force-pushed the fix/587-telegram-bridge-status-is-mis branch from 2371060 to 568b2f5 Compare March 23, 2026 10:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Telegram bridge status is mis-reported

3 participants