Skip to content

fix(rebuild): warn when rebuild drops user-managed sandbox files - #5765

Merged
cv merged 6 commits into
mainfrom
fix/rebuild-warn-user-managed-files
Jun 25, 2026
Merged

fix(rebuild): warn when rebuild drops user-managed sandbox files#5765
cv merged 6 commits into
mainfrom
fix/rebuild-warn-user-managed-files

Conversation

@laitingsheng

@laitingsheng laitingsheng commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Summary

Rebuild silently destroyed user-created .env / .mcp.json files inside Deep Agents sandboxes because the backup engine only enumerates state_dirs / state_files from the agent manifest, which intentionally omits user credential files. The CLI gave no hint that those files were about to be dropped. This change adds a declarative user_managed_files manifest field, probes the sandbox during rebuild for files declared but not preserved, and emits a clear warning naming the affected files.

Related Issue

Fixes #5750

Changes

  • Added user_managed_files: string[] to the agent manifest schema and an AgentDefinition.userManagedFiles accessor.
  • Declared .env and .mcp.json under user_managed_files in the LangChain Deep Agents Code manifest.
  • New probeUserManagedFiles(sandboxName) in src/lib/state/sandbox.ts — opens a short SSH session, runs a test -f probe per declared file, and reports which actually exist inside the live sandbox.
  • backupSandboxStateForRebuild now invokes the probe after State backed up (…) and prints a yellow ⚠ User-managed files in sandbox not preserved by rebuild: … line followed by Re-add them after rebuild, or manage them from the host. when any declared file is present.
  • Probe is defensive: tolerates absent userManagedFiles, missing SSH config, and non-zero probe exit codes; rebuild flow swallows probe errors so the warning never blocks a rebuild.
  • Added userManagedFiles: [] to existing AgentDefinition test fixtures required by the tightened type, plus assertions on the new field for OpenClaw, Hermes, and Deep Agents.
  • New src/lib/actions/sandbox/rebuild-flow-helpers.test.ts covers: warning emit, no-emit-when-none-present, no-emit-when-nothing-declared, staleRecovery short-circuit, swallowed probe errors.

Type of Change

  • 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

  • PR description includes the DCO sign-off declaration and every commit appears as Verified in GitHub
  • Git hooks passed during commit and push, or npx prek run --from-ref main --to-ref HEAD passes
  • Targeted tests pass for changed behavior
  • Full npm test passes (broad runtime changes only)
  • Tests added or updated for new or changed behavior
  • No secrets, API keys, or credentials committed
  • Docs updated for user-facing behavior changes
  • npm run docs builds without warnings (doc changes only)
  • Doc pages follow the style guide (doc changes only)
  • New doc pages include SPDX header and frontmatter (new pages only)

Signed-off-by: Tinson Lai tinsonl@nvidia.com

Summary by CodeRabbit

  • New Features

    • Added user_managed_files support in agent manifests, exposed as userManagedFiles, with safe relative-path validation.
    • Added user-managed file probing to detect which declared files already exist in the sandbox.
    • Built-in agents now declare their default user-managed files (including .env / .mcp.json, and Hermes .hermes/.env).
  • Bug Fixes

    • Sandbox rebuild recovery now surfaces guidance when declared user-managed files aren’t preserved; recovery still succeeds even if probing can’t run.
  • Tests

    • Expanded test coverage for manifest validation, probing behavior, and rebuild warning flows.

Signed-off-by: Tinson Lai <tinsonl@nvidia.com>
Signed-off-by: Tinson Lai <tinsonl@nvidia.com>
@laitingsheng laitingsheng added area: sandbox OpenShell sandbox lifecycle, runtime, config, or recovery bug-fix PR fixes a bug or regression labels Jun 25, 2026
@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

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

This PR adds user_managed_files manifest support, exposes it on loaded agent definitions, probes sandbox files during rebuild, and warns when declared user-managed files exist but are not preserved. Related fixtures and tests were updated.

Changes

User-managed file rebuild flow

Layer / File(s) Summary
Manifest and agent definition support
agents/langchain-deepagents-code/manifest.yaml, agents/openclaw/manifest.yaml, agents/hermes/manifest.yaml, src/lib/agent/defs.ts, src/lib/agent/*.test.ts, src/lib/agent/hermes-recovery-boundary-fixtures.ts
user_managed_files is loaded from agent manifests into userManagedFiles, validated for invalid values, and reflected in agent fixtures/tests.
Sandbox user-managed file probe
src/lib/state/sandbox.ts, src/lib/state/user-managed-files-probe.ts, src/lib/state/user-managed-files-probe.test.ts
USER_MANAGED_FILES_BASE, UserManagedFilesProbe, and probeUserManagedFiles(sandboxName) load declared files, check SSH availability, probe for existing files, and return declared/existing paths.
Rebuild warning flow
src/lib/actions/sandbox/rebuild-flow-helpers.ts, src/lib/actions/sandbox/rebuild-flow-helpers.test.ts
backupSandboxStateForRebuild calls a warning helper after backup creation, and the helper logs probe failures, empty results, and warnings for existing user-managed files. Tests cover those paths.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • NVIDIA/NemoClaw#5197: Adds the user_managed_files manifest declarations that this PR loads, validates, probes, and warns about.

Suggested labels

integration: openclaw, integration: hermes, area: cli

Suggested reviewers

  • prekshivyas
  • cv

Poem

A bunny peeks in /sandbox bright,
Finds .env and .mcp.json in sight.
“Rebuild may hop, but please beware:
Re-add those files with a careful care.” 🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 13.04% 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately reflects the main change: warning when rebuild would drop user-managed sandbox files.
Linked Issues check ✅ Passed The changes add manifest support, probing, and rebuild warnings for user-managed files like .env and .mcp.json, matching issue #5750.
Out of Scope Changes check ✅ Passed The additional test and helper changes appear directly related to manifest support and rebuild warning behavior, with no clear unrelated scope creep.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/rebuild-warn-user-managed-files

Comment @coderabbitai help to get the list of available commands.

@github-code-quality

github-code-quality Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Code Coverage Overview

Languages: TypeScript

TypeScript / code-coverage/plugin

The overall coverage in the fix/rebuild-warn-use... branch is 96%. Coverage data for the main branch is not yet available.

Show a code coverage summary of the most covered files.
File main fix/rebuild-warn-use... 55f454f +/-
nemoclaw/src/se...cret-scanner.ts 100%
nemoclaw/src/commands/slash.ts 100%
nemoclaw/src/li...bprocess-env.ts 100%
nemoclaw/src/bl...eprint/state.ts 98%
nemoclaw/src/onboard/config.ts 98%
nemoclaw/src/bl...int/snapshot.ts 97%
nemoclaw/src/bl...print/runner.ts 95%
nemoclaw/src/co...ration-state.ts 94%
nemoclaw/src/bl...ate-networks.ts 94%
nemoclaw/src/index.ts 94%

TypeScript / code-coverage/cli

The overall coverage in the fix/rebuild-warn-use... branch is 47%. Coverage data for the main branch is not yet available.

Show a code coverage summary of the most covered files.
File main fix/rebuild-warn-use... 55f454f +/-
src/lib/state/o...oard-session.ts 91%
src/lib/inference/local.ts 76%
src/lib/sandbox/config.ts 72%
src/lib/actions...dbox/rebuild.ts 71%
src/lib/onboard/preflight.ts 64%
src/lib/actions...licy-channel.ts 60%
src/lib/state/sandbox.ts 56%
src/lib/policy/index.ts 49%
src/lib/onboard...er-gpu-patch.ts 44%
src/lib/onboard.ts 19%

Updated June 25, 2026 22:13 UTC
Code Coverage is in Public Preview. Learn more and provide us with your feedback.

@github-actions

github-actions Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

E2E Advisor Recommendation

Required E2E: sandbox-rebuild-vitest, rebuild-openclaw-vitest, rebuild-hermes-vitest, state-backup-restore-vitest, credential-sanitization-vitest
Optional E2E: hermes-sandbox-secret-boundary-vitest, cloud-onboard-vitest

Dispatch hint: sandbox-rebuild-vitest,rebuild-openclaw-vitest,rebuild-hermes-vitest,state-backup-restore-vitest,credential-sanitization-vitest

Workflow run

Full advisor summary

E2E Recommendation Advisor

Base: origin/main
Head: HEAD
Confidence: high

Required E2E

  • sandbox-rebuild-vitest (high): Required because the core nemoclaw <sandbox> rebuild backup flow now invokes a live user-managed-file SSH probe after backup. This job exercises the real sandbox rebuild lifecycle against OpenShell rather than only mocked unit coverage.
  • rebuild-openclaw-vitest (high): Required because the OpenClaw manifest now declares .env and .mcp.json as user-managed files and the rebuild helper must warn without breaking a real OpenClaw rebuild or state backup.
  • rebuild-hermes-vitest (high): Required because the Hermes manifest now declares /sandbox/.hermes/.env as user-managed and Hermes has agent-specific config and rebuild behavior. This validates the real Hermes rebuild/backup boundary.
  • state-backup-restore-vitest (medium): Required because the PR changes the relationship between manifest state_files and user-managed files and exports SSH backup/probe helpers. This job validates live state backup/restore semantics after manifest-loader changes.
  • credential-sanitization-vitest (medium): Required because .env and .mcp.json are secret-bearing credential files and this PR changes how they are declared and surfaced during rebuild. This validates that backup/rebuild credential redaction and runtime credential boundaries still hold.

Optional E2E

  • hermes-sandbox-secret-boundary-vitest (medium): Useful adjacent confidence for the Hermes .env declaration: it validates Hermes image/startup secret boundaries, but the required Hermes rebuild and credential-sanitization jobs are the direct coverage for this PR.
  • cloud-onboard-vitest (high): Optional smoke for the hosted onboarding path because agent manifest parsing is shared with onboarding. The changed behavior is rebuild-focused and does not modify onboarding state-machine resume/repair code, so this is not merge-blocking.

New E2E recommendations

  • LangChain Deep Agents Code rebuild user-managed files (medium): The PR adds user_managed_files to the LangChain Deep Agents Code manifest, but there does not appear to be an existing live Deep Agents rebuild E2E that creates .env/.mcp.json, runs rebuild, and asserts the user-visible warning and post-rebuild behavior for the terminal-agent path.
    • Suggested test: Add a Deep Agents Code rebuild/user-managed-files live scenario that provisions a Deep Agents sandbox, creates declared user-managed files, runs rebuild, and verifies warning text plus no accidental preservation of secret-bearing files.

Dispatch hint

  • Workflow: .github/workflows/e2e-vitest-scenarios.yaml
  • jobs input: sandbox-rebuild-vitest,rebuild-openclaw-vitest,rebuild-hermes-vitest,state-backup-restore-vitest,credential-sanitization-vitest

@github-actions

github-actions Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Vitest E2E Scenario Recommendation

Required Vitest E2E scenarios: sandbox-rebuild-vitest, rebuild-hermes-vitest
Optional Vitest E2E scenarios: rebuild-openclaw-vitest

Dispatch required Vitest E2E scenarios:

  • gh workflow run e2e-vitest-scenarios.yaml --ref <pr-head-ref> --field jobs=sandbox-rebuild-vitest
  • gh workflow run e2e-vitest-scenarios.yaml --ref <pr-head-ref> --field jobs=rebuild-hermes-vitest

Workflow run

Full Vitest E2E advisor summary

Vitest E2E Scenario Advisor

Base: origin/main
Head: HEAD
Confidence: medium

Required Vitest E2E scenarios

  • sandbox-rebuild-vitest: The PR changes manifest parsing, OpenClaw user-managed file metadata, SSH probing, and the rebuild backup flow. The sandbox-rebuild free-standing Vitest job exercises a real OpenClaw onboard followed by nemoclaw <sandbox> rebuild --yes, covering the changed rebuild helper and probe integration on the primary OpenClaw path.
    • Dispatch: gh workflow run e2e-vitest-scenarios.yaml --ref <pr-head-ref> --field jobs=sandbox-rebuild-vitest
  • rebuild-hermes-vitest: The PR adds Hermes user-managed file metadata and routes rebuild through the new user-managed-file probe. The Hermes rebuild free-standing Vitest job exercises a real Hermes rebuild boundary, including Hermes-specific config/state paths where .hermes/.env handling is most likely to be observed.
    • Dispatch: gh workflow run e2e-vitest-scenarios.yaml --ref <pr-head-ref> --field jobs=rebuild-hermes-vitest

Optional Vitest E2E scenarios

  • rebuild-openclaw-vitest: Additional OpenClaw rebuild coverage for the older-base/version-upgrade boundary. Useful if reviewers want broader assurance that the new rebuild warning/probe path does not regress the legacy OpenClaw rebuild migration scenario.
    • Dispatch: gh workflow run e2e-vitest-scenarios.yaml --ref <pr-head-ref> --field jobs=rebuild-openclaw-vitest

Relevant changed files

  • agents/hermes/manifest.yaml
  • agents/langchain-deepagents-code/manifest.yaml
  • agents/openclaw/manifest.yaml
  • src/lib/actions/sandbox/rebuild-flow-helpers.ts
  • src/lib/agent/defs.ts
  • src/lib/state/sandbox.ts
  • src/lib/state/user-managed-files-probe.ts

@github-actions

github-actions Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

PR Review Advisor — No blocking findings

Merge posture: No blocking advisor findings
Primary next action: Add or justify PRA-T1 and any related test follow-ups.
Open items: 0 required · 0 warnings · 0 suggestions · 8 test follow-ups
Since last review: 1 prior item resolved · 0 still apply · 0 new items found

Action checklist

  • PRA-T1 Add or justify test follow-up: Runtime validation
  • PRA-T2 Add or justify test follow-up: Runtime validation
  • PRA-T3 Add or justify test follow-up: Runtime validation
  • PRA-T4 Add or justify test follow-up: Runtime validation
  • PRA-T5 Add or justify test follow-up: Runtime validation
  • PRA-T6 Add or justify test follow-up: Acceptance clause
  • PRA-T7 Add or justify test follow-up: Acceptance clause
  • PRA-T8 Add or justify test follow-up: Acceptance clause
Test follow-ups to resolve or justify

If these cover changed behavior, prefer adding them in this PR; otherwise state why existing coverage is enough or link the follow-up.

  • PRA-T1 Runtime validation — Create a Deep Agents sandbox with `/sandbox/.env` and `/sandbox/.mcp.json`, run `nemoclaw <name> rebuild`, verify the warning names both files, and verify post-rebuild files are absent or no longer contain placeholder contents.. Unit coverage is strong for manifest parsing, path validation, remote command quoting, temp cleanup, rebuild warnings, no-warning paths, stale recovery, and probe failures. Runtime validation is still useful because the changed behavior crosses manifest loading, registry agent resolution, OpenShell SSH config generation, live sandbox filesystem state, destructive rebuild sequencing, and top-level CLI output.
  • PRA-T2 Runtime validation — Create an OpenClaw sandbox with `/sandbox/.env` and `/sandbox/.mcp.json`, run `nemoclaw <name> rebuild`, and verify the same user-managed-files warning names both files.. Unit coverage is strong for manifest parsing, path validation, remote command quoting, temp cleanup, rebuild warnings, no-warning paths, stale recovery, and probe failures. Runtime validation is still useful because the changed behavior crosses manifest loading, registry agent resolution, OpenShell SSH config generation, live sandbox filesystem state, destructive rebuild sequencing, and top-level CLI output.
  • PRA-T3 Runtime validation — Create a Hermes sandbox with `/sandbox/.hermes/.env`, run `nemoclaw <name> rebuild`, and verify the warning names `.hermes/.env`.. Unit coverage is strong for manifest parsing, path validation, remote command quoting, temp cleanup, rebuild warnings, no-warning paths, stale recovery, and probe failures. Runtime validation is still useful because the changed behavior crosses manifest loading, registry agent resolution, OpenShell SSH config generation, live sandbox filesystem state, destructive rebuild sequencing, and top-level CLI output.
  • PRA-T4 Runtime validation — Rebuild a Deep Agents or OpenClaw sandbox with neither declared file present and verify no `User-managed files in sandbox not preserved by rebuild` warning is printed.. Unit coverage is strong for manifest parsing, path validation, remote command quoting, temp cleanup, rebuild warnings, no-warning paths, stale recovery, and probe failures. Runtime validation is still useful because the changed behavior crosses manifest loading, registry agent resolution, OpenShell SSH config generation, live sandbox filesystem state, destructive rebuild sequencing, and top-level CLI output.
  • PRA-T5 Runtime validation — Force the user-managed-file probe to lack an SSH config after backup starts and verify the CLI prints `Could not check declared user-managed files before rebuild (probe failed)` without aborting the rebuild solely due to the probe.. Unit coverage is strong for manifest parsing, path validation, remote command quoting, temp cleanup, rebuild warnings, no-warning paths, stale recovery, and probe failures. Runtime validation is still useful because the changed behavior crosses manifest loading, registry agent resolution, OpenShell SSH config generation, live sandbox filesystem state, destructive rebuild sequencing, and top-level CLI output.
  • PRA-T6 Acceptance clause — **Platform:** DGX Spark (reproduced on Linux with Docker GPU patch disabled via `NEMOCLAW_DOCKER_GPU_PATCH=0`) — add test evidence or identify existing coverage. The diff is platform-neutral TypeScript/YAML and does not add GPU-patch-specific logic. No changed test creates a DGX Spark/Linux sandbox with `NEMOCLAW_DOCKER_GPU_PATCH=0`; runtime validation is listed in testDepth.
  • PRA-T7 Acceptance clause — NemoClaw installed and authenticated. — add test evidence or identify existing coverage. This is an environment precondition for reproducing the issue. Static review did not execute an installed/authenticated NemoClaw runtime.
  • PRA-T8 Acceptance clause — A Deep Agents / OpenClaw sandbox named `dcode-msg` or `dcode-rebuild-secrets` in Ready state. — add test evidence or identify existing coverage. `agents/langchain-deepagents-code/manifest.yaml` and `agents/openclaw/manifest.yaml` now declare `.env` and `.mcp.json` under `user_managed_files`, and `src/lib/agent/defs.test.ts` asserts both manifests load those declarations. No changed test creates a live Ready sandbox.

Workflow run details

This is an automated, non-binding review; it still expects maintainers and agents to respond to each required or warning item. Treat suggestions as current-PR improvements when they touch changed code; defer only with maintainer rationale or a linked follow-up. A human maintainer must make the final merge decision.

@laitingsheng laitingsheng added the integration: dcode LangChain Deep Code integration behavior label Jun 25, 2026
…ifest contract

Signed-off-by: Tinson Lai <tinsonl@nvidia.com>

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/lib/state/sandbox.ts (1)

469-495: 🩺 Stability & Availability | 🔵 Trivial

Please run the sandbox lifecycle E2Es for this export change.

These helpers are now a public dependency for rebuild probing, so I’d still run state-backup-restore-e2e, snapshot-commands-e2e, and rebuild-openclaw-e2e before merge to make sure the rebuild path stays clean. As per path instructions, src/lib/state/sandbox.ts “manages sandbox state (backup, restore, rebuild, snapshot)” and those selective E2Es are the recommended coverage.

🤖 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/lib/state/sandbox.ts` around lines 469 - 495, This export change in
getSshConfig and sshArgs should be validated with the sandbox lifecycle E2Es
before merge. Run state-backup-restore-e2e, snapshot-commands-e2e, and
rebuild-openclaw-e2e to confirm the rebuild probing path still works cleanly and
that the public sandbox helpers behave correctly under lifecycle coverage.

Source: Path instructions

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

Inline comments:
In `@src/lib/state/user-managed-files-probe.test.ts`:
- Around line 211-217: The temp SSH config test is only checking os.tmpdir() and
not the actual directory used by the probe. Update the test around loadProbe() /
probeUserManagedFiles to assert the intercepted mkdtempSync base path or spy on
createTempSshConfig, so it verifies the SSH config is created under the OS temp
directory rather than just rechecking Node’s tmpdir contract.

In `@src/lib/state/user-managed-files-probe.ts`:
- Around line 47-53: The probe command built in user-managed-files-probe should
not fail when none of the declared files exist; the current `[ -f ... ] &&
printf ...` chain returns a non-zero status on missing files, which then
triggers the error path in the probe result handling. Update the command
construction and the success check in the probe flow so “no matches” is treated
as a valid empty result, while still surfacing real shell errors; use the
probeCmd builder and the lines that throw on non-zero status to locate the fix.

---

Nitpick comments:
In `@src/lib/state/sandbox.ts`:
- Around line 469-495: This export change in getSshConfig and sshArgs should be
validated with the sandbox lifecycle E2Es before merge. Run
state-backup-restore-e2e, snapshot-commands-e2e, and rebuild-openclaw-e2e to
confirm the rebuild probing path still works cleanly and that the public sandbox
helpers behave correctly under lifecycle coverage.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 3016b988-ffba-44a6-b98c-33465f15c966

📥 Commits

Reviewing files that changed from the base of the PR and between 1030267 and e038075.

📒 Files selected for processing (7)
  • src/lib/actions/sandbox/rebuild-flow-helpers.test.ts
  • src/lib/actions/sandbox/rebuild-flow-helpers.ts
  • src/lib/agent/defs.test.ts
  • src/lib/agent/defs.ts
  • src/lib/state/sandbox.ts
  • src/lib/state/user-managed-files-probe.test.ts
  • src/lib/state/user-managed-files-probe.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/lib/actions/sandbox/rebuild-flow-helpers.test.ts
  • src/lib/actions/sandbox/rebuild-flow-helpers.ts

Comment thread src/lib/state/user-managed-files-probe.test.ts Outdated
Comment thread src/lib/state/user-managed-files-probe.ts
…clared

Signed-off-by: Tinson Lai <tinsonl@nvidia.com>

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

♻️ Duplicate comments (1)
src/lib/state/user-managed-files-probe.ts (1)

48-67: ⚠️ Potential issue | 🟠 Major

Still valid: “no files present” is treated as a probe failure.

Lines 48-52 build the remote command with [ -f ... ] && printf ..., which exits 1 when a declared file is absent. If every declared file is missing, stdout stays empty and Lines 61-67 throw, so the rebuild flow falls back to the generic probe-failed warning instead of staying quiet for the intended “nothing to warn about” case.

🤖 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/lib/state/user-managed-files-probe.ts` around lines 48 - 67, The probe in
user-managed-files-probe.ts is treating “no declared files exist” as an SSH
failure instead of a valid empty result. Update the command built in the
user-managed files probe flow so that the remote check in the probe path does
not rely on [ -f ... ] returning a failure exit when files are missing; instead,
have the probe return success with empty output when none of the declared paths
exist, and only throw from the spawnSync/ssh handling when SSH itself fails.
Keep the logic around probeCmd, spawnSync, and the stdout/status check in sync
so the rebuild flow stays quiet for the no-files-present case.
🤖 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.

Duplicate comments:
In `@src/lib/state/user-managed-files-probe.ts`:
- Around line 48-67: The probe in user-managed-files-probe.ts is treating “no
declared files exist” as an SSH failure instead of a valid empty result. Update
the command built in the user-managed files probe flow so that the remote check
in the probe path does not rely on [ -f ... ] returning a failure exit when
files are missing; instead, have the probe return success with empty output when
none of the declared paths exist, and only throw from the spawnSync/ssh handling
when SSH itself fails. Keep the logic around probeCmd, spawnSync, and the
stdout/status check in sync so the rebuild flow stays quiet for the
no-files-present case.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 5bc34852-00d7-4f6a-8037-d9d3948da706

📥 Commits

Reviewing files that changed from the base of the PR and between e038075 and e70b7d4.

📒 Files selected for processing (5)
  • src/lib/actions/sandbox/rebuild-flow-helpers.test.ts
  • src/lib/agent/defs.test.ts
  • src/lib/agent/defs.ts
  • src/lib/state/user-managed-files-probe.test.ts
  • src/lib/state/user-managed-files-probe.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/lib/agent/defs.test.ts
  • src/lib/actions/sandbox/rebuild-flow-helpers.test.ts
  • src/lib/agent/defs.ts

…g on absent files

Signed-off-by: Tinson Lai <tinsonl@nvidia.com>
@prekshivyas prekshivyas self-assigned this Jun 25, 2026

@prekshivyas prekshivyas left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hermes is missing. The PR adds .env/.mcp.json to user_managed_files for OpenClaw and dcode, but agents/hermes/manifest.yaml has no declaration — the [] in defs.test.ts is the schema default, not an intentional choice. Hermes users keep .env for API keys (Anthropic, OpenAI, etc.) and will silently lose them on rebuild with no warning. This is the exact bug the PR claims to fix, left open for Hermes. Either add .env/.mcp.json to the Hermes manifest with the same declaration, or add a comment explaining why Hermes is excluded (different credential lifecycle, managed differently, etc.).

@jyaunches jyaunches added v0.0.69 and removed v0.0.68 labels Jun 25, 2026

@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)
agents/hermes/manifest.yaml (1)

93-96: 🩺 Stability & Availability | 🔵 Trivial

Run the Hermes rebuild E2E lanes for this manifest change.

This new user_managed_files entry feeds the rebuild-warning path, and the Hermes rebuild coverage only runs in nightly/workflow_dispatch. Please validate rebuild-hermes-e2e and rebuild-hermes-stale-base-e2e before merge. As per path instructions, "the rebuild warning behavior added in this PR should be validated via the existing Hermes rebuild E2E lanes rather than expecting it to run in PR CI."

🤖 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 `@agents/hermes/manifest.yaml` around lines 93 - 96, Validate the new
user_managed_files manifest entry by running the existing Hermes rebuild E2E
coverage for rebuild-hermes-e2e and rebuild-hermes-stale-base-e2e, since the
rebuild-warning path is only exercised in those nightly/workflow_dispatch lanes.
Use the Hermes manifest handling around user_managed_files and the rebuild
warning flow to confirm the .hermes/.env entry is picked up correctly before
merging.

Source: Path instructions

🤖 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 `@agents/hermes/manifest.yaml`:
- Around line 93-96: Validate the new user_managed_files manifest entry by
running the existing Hermes rebuild E2E coverage for rebuild-hermes-e2e and
rebuild-hermes-stale-base-e2e, since the rebuild-warning path is only exercised
in those nightly/workflow_dispatch lanes. Use the Hermes manifest handling
around user_managed_files and the rebuild warning flow to confirm the
.hermes/.env entry is picked up correctly before merging.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 6870cc0b-a8a5-48ea-9767-fc945c47d584

📥 Commits

Reviewing files that changed from the base of the PR and between 799c87c and 55f454f.

📒 Files selected for processing (3)
  • agents/hermes/manifest.yaml
  • src/lib/agent/defs.test.ts
  • src/lib/state/user-managed-files-probe.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/lib/state/user-managed-files-probe.test.ts

@github-actions

Copy link
Copy Markdown
Contributor

Selective E2E Results — ✅ All requested jobs passed

Run: 28203973460
Target ref: fix/rebuild-warn-user-managed-files
Requested jobs: rebuild-hermes-e2e,rebuild-hermes-stale-base-e2e
Summary: 2 passed, 0 failed, 0 cancelled, 0 skipped

Job Result
rebuild-hermes-e2e ✅ success
rebuild-hermes-stale-base-e2e ✅ success

@cv
cv dismissed prekshivyas’s stale review June 25, 2026 22:50

issue was addressed

@cv
cv merged commit 681767b into main Jun 25, 2026
115 checks passed
@cv
cv deleted the fix/rebuild-warn-user-managed-files branch June 25, 2026 22:51
@wscurran wscurran added the NV QA Bugs found by the NVIDIA QA Team label Jun 26, 2026
Hadar301 pushed a commit to Hadar301/NemoClaw-OpenShift that referenced this pull request Jul 12, 2026
…DIA#5765)

## Summary
Rebuild silently destroyed user-created `.env` / `.mcp.json` files
inside Deep Agents sandboxes because the backup engine only enumerates
`state_dirs` / `state_files` from the agent manifest, which
intentionally omits user credential files. The CLI gave no hint that
those files were about to be dropped. This change adds a declarative
`user_managed_files` manifest field, probes the sandbox during rebuild
for files declared but not preserved, and emits a clear warning naming
the affected files.

## Related Issue
Fixes NVIDIA#5750

## Changes
- Added `user_managed_files: string[]` to the agent manifest schema and
an `AgentDefinition.userManagedFiles` accessor.
- Declared `.env` and `.mcp.json` under `user_managed_files` in the
LangChain Deep Agents Code manifest.
- New `probeUserManagedFiles(sandboxName)` in `src/lib/state/sandbox.ts`
— opens a short SSH session, runs a `test -f` probe per declared file,
and reports which actually exist inside the live sandbox.
- `backupSandboxStateForRebuild` now invokes the probe after `State
backed up (…)` and prints a yellow `⚠ User-managed files in sandbox not
preserved by rebuild: …` line followed by `Re-add them after rebuild, or
manage them from the host.` when any declared file is present.
- Probe is defensive: tolerates absent `userManagedFiles`, missing SSH
config, and non-zero probe exit codes; rebuild flow swallows probe
errors so the warning never blocks a rebuild.
- Added `userManagedFiles: []` to existing `AgentDefinition` test
fixtures required by the tightened type, plus assertions on the new
field for OpenClaw, Hermes, and Deep Agents.
- New `src/lib/actions/sandbox/rebuild-flow-helpers.test.ts` covers:
warning emit, no-emit-when-none-present, no-emit-when-nothing-declared,
staleRecovery short-circuit, swallowed probe errors.

## 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] PR description includes the DCO sign-off declaration and every
commit appears as `Verified` in GitHub
- [x] Git hooks passed during commit and push, or `npx prek run
--from-ref main --to-ref HEAD` passes
- [x] Targeted tests pass for changed behavior
- [ ] Full `npm test` passes (broad runtime changes only)
- [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
- [ ] `npm run 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: Tinson Lai <tinsonl@nvidia.com>

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Added `user_managed_files` support in agent manifests, exposed as
`userManagedFiles`, with safe relative-path validation.
* Added user-managed file probing to detect which declared files already
exist in the sandbox.
* Built-in agents now declare their default user-managed files
(including `.env` / `.mcp.json`, and Hermes `.hermes/.env`).

* **Bug Fixes**
* Sandbox rebuild recovery now surfaces guidance when declared
user-managed files aren’t preserved; recovery still succeeds even if
probing can’t run.

* **Tests**
* Expanded test coverage for manifest validation, probing behavior, and
rebuild warning flows.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Tinson Lai <tinsonl@nvidia.com>
Co-authored-by: Carlos Villela <cvillela@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: sandbox OpenShell sandbox lifecycle, runtime, config, or recovery bug-fix PR fixes a bug or regression integration: dcode LangChain Deep Code integration behavior NV QA Bugs found by the NVIDIA QA Team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[All Platforms][Sandbox][GitHub Issue #5750] nemoclaw <name> rebuild silently drops user-managed .env / .mcp.json files without warning

5 participants