refactor(cli): extract sandbox destroy action - #2895
Conversation
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
📝 WalkthroughWalkthroughSandbox destruction logic is extracted from the runtime bridge interface and distributed across files into a dedicated ChangesSandbox Destruction Extraction
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Review rate limit: 9/10 reviews remaining, refill in 6 minutes. Comment |
## Summary Extract sandbox doctor diagnostics from `src/nemoclaw.ts` into a dedicated action module and route the command through oclif. This removes another legacy-dispatched public sandbox command while preserving the existing host, gateway, sandbox, inference, messaging, and local service diagnostics. ## Stack Navigation - Position: 5 of 60 - Previous PR: [#2892 — refactor(cli): extract sandbox status action](#2892) - Next PR: [#2895 — refactor(cli): extract sandbox destroy action](#2895) ## Changes - Added `src/lib/sandbox-doctor-action.ts` for doctor checks and report rendering. - Added `src/lib/sandbox-doctor-cli-command.ts` and registered `sandbox:doctor` in the oclif command map. - Updated legacy sandbox dispatch to route `doctor` through oclif instead of the legacy target path. - Removed doctor-specific helpers and `sandboxDoctor` from `src/nemoclaw.ts`. - Added a dispatch unit test for the new doctor route. ## 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 - [x] `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) --- Signed-off-by: Carlos Villela <cvillela@nvidia.com> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **New Features** * Added `sandbox doctor` command to diagnose sandbox and gateway health, running comprehensive checks across host, gateway, inference, messaging, and local services. * Supports `--json` flag for structured diagnostic output with status details and summary. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Carlos Villela <cvillela@nvidia.com>
Signed-off-by: Carlos Villela <cvillela@nvidia.com>
prekshivyas
left a comment
There was a problem hiding this comment.
LGTM with growing scope-hygiene debt.
Extraction is correct. destroySandbox and its helpers move cleanly into src/lib/sandbox-destroy-action.ts. Public surface preserved (--yes/--force, confirmation prompt, exit codes, "already gone" / NIM / Ollama cleanup paths all byte-identical). The new removeSandboxRegistryEntry consolidates the image-then-registry ordering invariant that was previously duplicated at both destroy and rebuild sites — clean win.
Test rework is a strict improvement. test/image-cleanup.test.ts swaps source-shape regex assertions on src/nemoclaw.ts for actual functional tests via dependency injection (removeImage/removeSandbox/getSandbox/dockerRmi seams). Behavior coverage replaces structural coverage. Net +4 lines, real assertions.
But src/nemoclaw.ts is accumulating dead code across the stack. After this PR it carries:
New orphans introduced here (3):
NEMOCLAW_GATEWAY_NAME(line 117) — only consumer wascleanupGatewayAfterLastSandbox, moved outDASHBOARD_FORWARD_PORT(line 118) — samedockerRemoveVolumesByPrefix(line 34) — same
Carryover orphans from prior stack PRs that should have been swept (7):
parseForwardList(#2891)probeProviderHealth,buildStatusCommandDeps,GATEWAY_PORT,OLLAMA_PORT,recoverNamedGatewayRuntime,isErrnoException(all from #2893)
Plus two stale comments at lines 362 and 373 referencing sandboxDestroy() which no longer exists in this file.
Each individual PR's "while I'm here" cleanup feels out of scope, but the debt is compounding. Suggest either:
- A dedicated cleanup PR at the end of this extraction phase, or
- Letting later extractions opportunistically remove imports as their last consumers leave.
Not blocking — approving so you can keep moving.
Also: self-hosted e2e suite (build-sandbox-images, arm64, test-e2e-sandbox, etc.) was still in flight at review time. Worth confirming green on this hash before merging.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/nemoclaw.ts (1)
390-390: Keep the lifecycle E2Es in the merge checklist.This refactor now shares destroy cleanup between direct destroy and rebuild, so I'd still run the recommended sandbox lifecycle workflows on the branch before merging.
As per coding guidelines, "
src/nemoclaw.ts: This file contains CLI dispatch, status, recovery, and connect functions. Changes affect sandbox lifecycle commands. E2E test recommendation:sandbox-survival-e2e— gateway restart recovery;sandbox-operations-e2e— process recovery after gateway kill."🤖 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 `@src/nemoclaw.ts` at line 390, The refactor centralizes teardown (removeSandboxRegistryEntry(sandboxName)) between direct destroy and rebuild, so add a merge-checklist/action item and an inline comment near removeSandboxRegistryEntry(sandboxName) to ensure the sandbox lifecycle E2Es are retained and run before merging: explicitly list and run sandbox-survival-e2e (gateway restart recovery) and sandbox-operations-e2e (process recovery after gateway kill) to validate the shared cleanup path; update any project merge checklist (or CI gating) to require these tests and mention the shared cleanup in the comment so future changes remember to validate both destroy and rebuild flows.
🤖 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.
Nitpick comments:
In `@src/nemoclaw.ts`:
- Line 390: The refactor centralizes teardown
(removeSandboxRegistryEntry(sandboxName)) between direct destroy and rebuild, so
add a merge-checklist/action item and an inline comment near
removeSandboxRegistryEntry(sandboxName) to ensure the sandbox lifecycle E2Es are
retained and run before merging: explicitly list and run sandbox-survival-e2e
(gateway restart recovery) and sandbox-operations-e2e (process recovery after
gateway kill) to validate the shared cleanup path; update any project merge
checklist (or CI gating) to require these tests and mention the shared cleanup
in the comment so future changes remember to validate both destroy and rebuild
flows.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 15ab0845-de9a-4a0a-91be-06b80990be44
📒 Files selected for processing (5)
src/lib/nemoclaw-runtime-bridge.tssrc/lib/sandbox-destroy-action.tssrc/lib/sandbox-runtime-actions.tssrc/nemoclaw.tstest/image-cleanup.test.ts
💤 Files with no reviewable changes (1)
- src/lib/nemoclaw-runtime-bridge.ts
## Summary Extract sandbox rebuild orchestration from `src/nemoclaw.ts` into a dedicated action module. This removes `sandboxRebuild` from the transitional runtime bridge while preserving rebuild preflight, backup, recreate, restore, policy preset restore, and post-upgrade checks. ## Stack Navigation - Position: 7 of 60 - Previous PR: [#2895 — refactor(cli): extract sandbox destroy action](#2895) - Next PR: [#2897 — refactor(cli): extract upgrade sandboxes action](#2897) ## Changes - Added `src/lib/sandbox-rebuild-action.ts` for rebuild confirmation, credential preflight, backup, delete/recreate, restore, policy preset replay, and post-restore checks. - Updated `src/lib/sandbox-runtime-actions.ts` to call the extracted rebuild action. - Updated `upgrade-sandboxes` to call the extracted rebuild action directly. - Removed `sandboxRebuild` from `src/nemoclaw.ts` and `NemoClawRuntimeBridge`. ## 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 - [x] `npx prek run --all-files` passes - [x] `npm test` passes - [ ] 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) --- Signed-off-by: Carlos Villela <cvillela@nvidia.com> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Safer, user-facing sandbox rebuild flow with interactive confirmations, SSH-session warnings, credential preflight, workspace backup/restore, and clear completion/recovery messages. * **Refactor** * Moved sandbox rebuild responsibilities to a dedicated action; runtime bridge no longer exposes a direct rebuild method. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Carlos Villela <cvillela@nvidia.com> Co-authored-by: Prekshi Vyas <34834085+prekshivyas@users.noreply.github.com>
Summary
Extract sandbox destroy and image cleanup helpers from
src/nemoclaw.tsinto a dedicated action module. This removessandboxDestroyfrom the transitional runtime bridge while preserving sandbox deletion, messaging provider cleanup, gateway teardown, and Docker image cleanup behavior.Stack Navigation
Changes
src/lib/sandbox-destroy-action.tsfor sandbox destroy orchestration, delete-result classification, gateway cleanup, service cleanup, and image cleanup helpers.src/lib/sandbox-runtime-actions.tsto call the extracted destroy action.sandboxDestroyand destroy-specific helpers fromsrc/nemoclaw.tsandNemoClawRuntimeBridge.src/nemoclaw.ts.Type of Change
Verification
npx prek run --all-filespassesnpm testpassesmake docsbuilds without warnings (doc changes only)Signed-off-by: Carlos Villela cvillela@nvidia.com
Summary by CodeRabbit