Skip to content

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

Open
kagura-agent wants to merge 1 commit 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 1 commit intoNVIDIA:mainfrom
kagura-agent:fix/587-telegram-bridge-status-is-mis

Conversation

@kagura-agent
Copy link

@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

    • Reorganized sandbox environment variable configuration handling, centralizing the logic to improve code structure and maintainability across service operations.
  • Tests

    • Added comprehensive test suite validating that sandbox environment variables are consistently propagated and applied across all service management operations including start, stop, and status.

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.
@coderabbitai
Copy link

coderabbitai bot commented Mar 22, 2026

📝 Walkthrough

Walkthrough

Introduced a centralized sandboxEnvPrefix() helper function that consistently derives and propagates the SANDBOX_NAME environment variable across start, stop, and status service operations. Updated all three operations to prepend this computed prefix to bash script invocations, replacing inline sandbox handling.

Changes

Cohort / File(s) Summary
Sandbox Environment Prefix Helper
bin/nemoclaw.js
Added sandboxEnvPrefix() function to derive validated SANDBOX_NAME prefix from registry. Updated start(), stop(), and showStatus() to prepend this prefix when invoking start-services.sh, centralizing sandbox context handling across all operations.
Service Environment Consistency Tests
test/service-env.test.js
Added node:path import and new test suite validating that stop(), showStatus(), and sandboxEnvPrefix() implementations consistently propagate sandbox environment context via regex assertion on source code.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Hoppy changes bring sandbox peace,
Start, stop, status all aligned at last,
No more phantom bridges in the mist,
The prefix hops through every path! 🎯

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Title check ⚠️ Warning The PR title describes fixing Telegram bridge status detection, but the actual changes are about centralizing sandbox name resolution across start/stop/showStatus commands to align PID file paths. Update the title to reflect the actual changes, such as: 'fix: align sandbox name resolution in start/stop/status to fix Telegram bridge status detection' or 'fix: centralize sandbox name prefix in service status commands (fixes #587)'.
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 The PR successfully addresses issue #587 by implementing the shared sandboxEnvPrefix() helper and applying it consistently across start(), stop(), and showStatus() commands, aligning sandbox name resolution and fixing the PID file path mismatch.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing issue #587: the bin/nemoclaw.js refactoring centralizes sandbox name handling, and test/service-env.test.js adds regression tests validating the fix without introducing unrelated modifications.

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

Tip

CodeRabbit can approve the review once all CodeRabbit's comments are resolved.

Enable the reviews.request_changes_workflow setting to automatically approve the review once all CodeRabbit's comments are resolved.

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.

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

1 participant