Repository navigation
Commit 69403e0
fix(cli): stop in-sandbox messaging channels on nemoclaw stop (#1977)
<!-- markdownlint-disable MD041 -->
## Summary
`nemoclaw stop` only killed the host-side `cloudflared` process but left
the OpenClaw gateway (and its Telegram/Discord/Slack messaging channels)
running inside the sandbox. After PR #1081 moved bridges into the
sandbox, no stop mechanism was added. This PR adds
`stopSandboxChannels()` which execs into the sandbox via `openshell
sandbox exec` to SIGTERM the gateway process, stopping all messaging
channel polling.
## Related Issue
Fixes #1825
## Changes
- Add `stopSandboxChannels()` to `src/lib/services.ts` — resolves
`openshell`, execs `pkill -TERM -f "openclaw gateway"` inside the
sandbox, and handles all pkill exit codes (0 = stopped, 1 = already
stopped, >1 = unreachable)
- Update `stopAll()` to call `stopSandboxChannels()` before stopping
host-side services; reads sandbox name from opts, `NEMOCLAW_SANDBOX`, or
`SANDBOX_NAME` env vars; warns when no sandbox name is available
- Import `spawnSync` from `node:child_process` and `resolveOpenshell`
from `./resolve-openshell`
- Add `src/lib/services-sandbox.test.ts` with 9 tests covering:
successful gateway stop, pkill exit 1 (no match), unreachable sandbox,
null status (timeout), openshell not found, stopAll with sandbox name,
stopAll without sandbox name, cloudflared cleanup on exec failure, and
env var fallback
## 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
- [x] `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
- [ ] `make 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)
## AI Disclosure
- [x] AI-assisted — tool: Claude Code
---
Signed-off-by: Brandon Pelfrey <[email protected]>
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features**
* Introduced sandbox-aware shutdown flow: attempts in-sandbox gateway
cleanup when a validated sandbox name is available, prefers validated
env-provided sandbox names (with correct precedence), and logs clearer
success/warning outcomes for varied exit statuses and missing in-sandbox
tooling.
* **Tests**
* Added tests for sandbox shutdown paths, missing/failed in-sandbox
tooling, env-var vs registry name selection and validation (rejecting
unsafe names), and ensuring host-side cleanup still runs.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Signed-off-by: Brandon Pelfrey <[email protected]>
Co-authored-by: Aaron Erickson 🦞 <[email protected]>1 parent defeffc commit 69403e0
4 files changed
Lines changed: 686 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
13 | 36 | | |
14 | 37 | | |
15 | 38 | | |
| |||
21 | 44 | | |
22 | 45 | | |
23 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
24 | 62 | | |
25 | 63 | | |
26 | 64 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
21 | 29 | | |
22 | 30 | | |
23 | 31 | | |
| |||
0 commit comments