8000 fix(sandbox): remove a sandbox directory whose build failed by bryan-minimal · Pull Request #2357 · gominimal/minimal · GitHub
[go: up one dir, main page]

Skip to content

fix(sandbox): remove a sandbox directory whose build failed - #2357

Merged
bryan-minimal merged 2 commits into
mainfrom
fix/sandbox-cleanup-on-error
Oct 22, 2026
Merged

bryan-minimal merged 2 commits into
mainfrom
fix/sandbox-cleanup-on-error

Conversation

@bryan-minimal
@bryan-minimal bryan-minimal commented Oct 19, 2026 •
Copy link
Copy Markdown
Member

Config::build creates the sandbox's directory, then can still fail before a Sandbox exists to own it: fs-mapping validation, the synth user/group config, or any step of Sandbox::new (hardlinking inputs, and copying them since #2234). Every one of those returns with the directory still there, because only Sandbox's Drop removes it. A failed build left a partial tree behind, and the next build made a new uniquely-named directory instead of reusing it. CodeRabbit raised this on #2234 for the new copy path, but it applies to all of them.

Change: a RemoveUnlessKept guard is armed right after the directory is created. Any early return removes the directory (and logs if removal fails). Once Sandbox::new succeeds, the guard is disarmed and the Sandbox's own Drop owns cleanup, as before. With keep_dirs set, the guard is never armed, so a failed build's directory is kept for inspection, matching the debugging option's intent.

Testing (Linux): fmt is clean, clippy -p sandbox --all-targets -D warnings is clean, and the new test a_failed_build_removes_its_directory passes. It drives Config::build into Sandbox::new's MappedFile rejection, which happens after the directory and its synth config exist, and asserts the base directory is empty afterwards.

Follow-up to a review thread on #2234.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Failed sandbox creation now removes the newly created build directory unless directory retention is enabled. Cleanup failures are logged as warnings.

Config::build creates the sandbox's directory, then any later failure
(fs-mapping validation, the synth user/group config, any step of
Sandbox::new, including hardlinking or copying inputs) returned before a
Sandbox existed, so its Drop never removed the directory: a failed build
left a partial tree behind, and the next one made a new directory.

A RemoveUnlessKept guard removes the directory unless the Sandbox was
built (its Drop owns cleanup from then on), and stays out of the way
when keep_dirs is set.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bryan-minimal
bryan-minimal requested a review from a team as a code owner October 19, 2026 19:34
@coderabbitai
coderabbitai Bot commented Oct 19, 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: Organization UI
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: cd6551eb-c4f2-4948-9da0-15a4d8b3df7f
📥 Commits

Reviewing files that changed from the base of the PR and between 559a1d8 and 2ac318e.

📒 Files selected for processing: 2
  • crates/sandbox/src/config.rs
  • crates/sandbox/src/lib.rs

Included review availability: This review used your included allowance. 0 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 5 reviews per hour.

📝 Walkthrough

8000 Config::build now removes its sandbox directory if construction fails, unless keep_dirs is set. A regression test checks cleanup after a mapped-file error.

Changes: Sandbox build cleanup

Layer / File(s) Summary
Guarded sandbox construction
crates/sandbox/src/config.rs, crates/sandbox/src/lib.rs
Config::build uses a cleanup guard and disarms it after successful construction. The guard removes the directory on failure unless keep_dirs is set. A regression test verifies that a mapped-file error leaves the build directory empty.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: mitodrummer

Merge Risk: ⚪ Minimal · up to 00551

Merge Risk: ⚪ Minimal · up to 00551

No actionable merge-blocking risk remains in the reviewed cleanup change.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: removing sandbox directories when a build fails.
Description check Passed The description explains the failure scenario, implementation, keep_dirs behavior, and testing results. It includes the required summary and testing information, although it does not reproduce the che…
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.
Full details: Description check

Explanation

The description explains the failure scenario, implementation, keep_dirs behavior, and testing results. It includes the required summary and testing information, although it does not reproduce the checklist section or provide command output.

✨ 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

A rabbit checks the sandbox door,
The failed build leaves no crumbs on the floor.
A guard keeps watch, then steps aside,
When Sandbox is safely inside.
The rabbit hops along, content once more.

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

@minimal-foundry
minimal-foundry Bot commented Oct 19, 2026 •
Copy link
Copy Markdown
Contributor

Approved: no findings at 00551578b2a2.

Nothing to do.

Clobber: none seen.

@minimal-foundry minimal-foundry Bot left a comment
8000 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.

minimal-review — approved

Verdict APPROVE — No findings.

Panel: 3 of 3 personas ran (correctness, security, supply-chain).

@minimal-foundry minimal-foundry Bot added the review:approved minimal-review approved the current head label Oct 19, 2026
@bryan-minimal
Copy link
Copy Markdown
Member Author

recheck

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

minimal-review — advisory review

Verdict COMMENT — No findings.

Panel: 1 of 3 personas ran (correctness); did not complete: security, supply-chain.

@bryan-minimal
bryan-minimal added this pull request to the merge queue Oct 22, 2026
Merged via the queue into main with commit 02f68e2 Oct 22, 2026
36 checks passed
@bryan-minimal
bryan-minimal deleted the fix/sandbox-cleanup-on-error branch October 22, 2026 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review:approved minimal-review approved the current head

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0