Skip to content

fix(backup): clean up snapshots when native capture throws - #13010

Merged
sandl99 merged 3 commits into
mainfrom
codex/fix-strict-backup-recovery-12277
Oct 12, 2026
Merged

sandl99 merged 3 commits into
mainfrom
codex/fix-strict-backup-recovery-12277

Conversation

@hunglp6d

@hunglp6d hunglp6d commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator

Outcome

An exception during native backup capture no longer leaves its newly created timestamp directory behind when cleanup can complete. Earlier backups and a concurrent writer's backup remain intact. If cleanup fails or its deadline expires, the error identifies the retained path and preserves the original cause.

Reason

SSH temporary-directory allocation can fail after the timestamp directory is created, before a BackupResult exists. Cleanup that relies on a returned result cannot see that directory.

This PR carries forward Arjun Ganesh's contribution from #12329, retaining the original signed commit unchanged. Integration with main preserves the later lifecycle cleanup from #12250. The remaining diff addresses exceptions during native capture.

Related issues

Fixes #12277. Maintainer adoption of #12329.

Changes

  • Track the directory created by the current native capture, so an exception before a returned result can use the existing path-confined cleanup. Preserve the caller's cleanup deadline and the cleanup contract for returned results.
  • Create the timestamp directory exclusively, so another writer's backup cannot be adopted for cleanup.
  • Add four cleanup regressions for temporary-directory allocation failure, cleanup denial, deadline expiry, and concurrent backup creation. Keep the existing snapshot tests unchanged.

Verification

The validated source and test bytes are committed as cd7ddde7fa254bc57ad4b79e787810d723036af4; their hashes still match after commit hooks. Behavioral checks ran on DGX Linux aarch64, Node 22.23.3, with unchanged dependency locks and OpenShell SDK 0.0.116.

  • The four new regression tests failed at their expected assertions against unchanged production source at 0b0d699c3ac0cbe17a8938a9706f76e1b1a774ea, then passed with the fix.
  • node node_modules/vitest/vitest.mjs run --project integration test/state/snapshot-backup-cleanup.test.ts test/state/snapshot.test.ts test/state/snapshot-native-deadline.test.ts test/state/snapshot-recovery-validation.test.ts: 63 of 64 passed initially. One existing test needed the plugin build artifact. After npm --prefix nemoclaw run build, the affected snapshot.test.ts passed all 47 tests; the other 17 passing results remain applicable.
  • CLI and plugin builds, CLI/test type-check, changed-file lint, and test-project membership passed. Formatting and whitespace checks passed locally on Linux x86_64, Node 22.22.2. Normal pre-commit and commit-message hooks passed.
  • The diff was inspected and contains no secrets, API keys, or credentials.

The tests create previous and competing snapshots through the native backup API, then compare manifest and archive bytes. A test executable supplies SSH configuration; cleanup denial and deadline expiry use controlled inputs. This covers the filesystem cleanup boundary without requiring a live sandbox.

The full suite and live sandbox tests were not run for this final revision. Earlier live results apply to the original contribution and its earlier repair. The original QA trigger and the historical regression boundary remain unverified.

Review notes

Keep this PR as a draft until CI and automated reviews for the updated commit have been evaluated. Results for the original adoption commit do not validate this repair.


Signed-off-by: Hung Le [email protected]

Summary by CodeRabbit

  • Bug Fixes
    • Failed sandbox-state backups now remove any newly created backup directory when possible, while retaining the configured cleanup deadline.
    • If cleanup cannot complete, the original error and remaining backup location are reported.
    • Existing completed backups are preserved when a backup attempt fails, including when another process has created a backup concurrently.
  • Tests
    • Added coverage for backup cleanup failures, retained backup details, and protection of existing backups.

A strict pre-upgrade backup publishes its snapshot before capturing the
policy and MCP recovery handoffs. When either capture threw, the command
exited nonzero but left the new timestamped snapshot behind, even though it
lacks the handoffs needed to restore after the historical gateway is
retired. The MCP observation added in v0.0.128 made this path reachable.

Remove the snapshot through the same path-confined cleanup used for failed
strict backups, and report a cleanup failure alongside the original error.

Fixes #12277

Signed-off-by: Arjun Ganesh <[email protected]>
@hunglp6d hunglp6d self-assigned this Oct 12, 2026
@copy-pr-bot

copy-pr-bot Bot commented Oct 12, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: NVIDIA/NemoClaw/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Enterprise
  • Run ID: 27a7b3e9-6a05-4941-b7bc-0f127bb85a8c

📥 Commits

Reviewing files that changed from the base of the PR and between ccf8e4e and cd7ddde.


📒 Files selected for processing (3)
  • src/lib/state/sandbox.ts
  • test/state/snapshot-backup-cleanup-fixture.ts
  • test/state/snapshot-backup-cleanup.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.



📝 Walkthrough
📝 Walkthrough

Walkthrough

Native sandbox backup creation now claims a new backup directory and tracks its path. If backup processing fails, the code attempts deadline-bounded cleanup. Tests cover cleanup failures, deadline handling, and concurrent directory creation.

Changes

Native sandbox backup cleanup

Layer / File(s) Summary
Claim the backup directory
src/lib/state/sandbox.ts
Backup creation now creates the parent recursively, claims the backup directory as a new leaf, and reports its path through a callback.
Clean up failed backup attempts
src/lib/state/sandbox.ts, test/state/snapshot-backup-cleanup-fixture.ts, test/state/snapshot-backup-cleanup.test.ts
Failed backup processing triggers deadline-bounded cleanup. If cleanup fails, the error includes the retained path and preserves the original error as its cause. Tests cover SSH temporary-directory failures, cleanup denial, deadline handling, and concurrent directory creation. They also check that completed backup files remain unchanged.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Suggested reviewers: ericksoa, sandl99


Merge Risk: ⚪ Minimal · up to cd7dd

No confirmed backup-cleanup issue remains; the change is mergeable after normal checks.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the primary change: cleaning up snapshot backups when native capture throws.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Resolve the strict recovery conflicts using main's deferred cleanup and
deadline handling. Preserve the original signed contribution in history.

Keep the additional early-capture cleanup fix for a separate commit.

Signed-off-by: Hung Le <[email protected]>
Remove the directory created by a failed capture while preserving the
original error and earlier valid backups.

Create the timestamp directory exclusively so a concurrent backup is
not adopted for cleanup. Respect the existing cleanup deadline and
report the retained path when removal cannot complete.

Cover temporary-directory failure, denied cleanup, deadline expiry,
and a competing backup writer through the native backup path.

Refs #12277

Signed-off-by: Hung Le <[email protected]>
@hunglp6d hunglp6d changed the title fix(backup): remove strict snapshot when recovery capture fails fix(backup): clean up snapshots when native capture throws Oct 12, 2026
@github-code-quality

github-code-quality Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Code Coverage Overview

Languages: TypeScript

TypeScript / code-coverage/plugin

The overall line coverage in commit cd7ddde in the codex/fix-strict-bac... branch is 97%. The line coverage in commit 63002cd in the main branch is 96%.

Show a line coverage summary of the most impacted files.
File main 63002cd codex/fix-strict-bac... cd7ddde +/-
nemoclaw/src/onboard/config.ts 98% 96% -2%
nemoclaw/src/index.ts 94% 93% -1%
nemoclaw/src/bl...print/runner.ts 95% 95% 0%
nemoclaw/src/bl...ime-identity.ts 97% 97% 0%
nemoclaw/src/bl...t-management.ts 100% 100% 0%
nemoclaw/src/co.../config-show.ts 100% 100% 0%
nemoclaw/src/commands/slash.ts 100% 100% 0%
nemoclaw/src/on...native-route.ts 0% 100% +100%

TypeScript / code-coverage/cli

The overall line coverage in commit cd7ddde in the codex/fix-strict-bac... branch is 86%. The line coverage in commit 63002cd in the main branch is 84%.

Show a line coverage summary of the most impacted files.
File main 63002cd codex/fix-strict-bac... cd7ddde +/-
src/lib/onboard.ts 62% 47% -15%
src/lib/actions...ess-recovery.ts 65% 78% +13%
src/lib/state/l...diness-lease.ts 66% 82% +16%
src/lib/inferen...ollama/proxy.ts 41% 61% +20%
src/lib/onboard.../application.ts 55% 84% +29%
src/lib/domain/...y/dimensions.ts 0% 71% +71%
src/lib/actions...try/snapshot.ts 0% 73% +73%
src/lib/actions...ry/operation.ts 0% 76% +76%
src/lib/inferen...ovider/index.ts 0% 88% +88%
src/lib/onboard...ternal-image.ts 0% 91% +91%

Updated October 12, 2026 09:39 UTC

@github-actions

Copy link
Copy Markdown
Contributor

PR Review Advisor finished for commit cd7ddde. Include the Advisor findings in the complete PR feedback collection. Verify and group valid findings before repair.

Request review only when Require no Advisor blockers is green.

All previous runs

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

Reviewed commit cd7ddde. No actionable correctness or security findings.

The cleanup tracks the exclusively created backup directory, preserves the caller's deadline, and reports the retained path and original cause when removal fails.

Validation: 64/64 focused snapshot tests passed locally. Required CI and all nine Advisor specialist reports passed for this commit. CodeRabbit has no actionable findings. Live sandbox behavior and the original QA scenario were not independently verified.

@sandl99
sandl99 merged commit 639a4c6 into main Oct 12, 2026
@sandl99
sandl99 deleted the codex/fix-strict-backup-recovery-12277 branch October 12, 2026 10:35
@wscurran wscurran added area: sandbox OpenShell sandbox lifecycle, runtime, config, or recovery bug-fix PR fixes a bug or regression labels Oct 13, 2026
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Linux][Upgrade] v0.0.128 regression: failed strict backup again leaves an empty timestamp directory

4 participants