Skip to content

sandbox2: hardlink CS mirror contents into rootfs (#228 follow-up) - #234

Merged
bryan-minimal merged 1 commit into
mainfrom
bryan/sandbox2-cs-mirror-hardlink
May 26, 2026
Merged

bryan-minimal merged 1 commit into
mainfrom
bryan/sandbox2-cs-mirror-hardlink

Conversation

@bryan-minimal

@bryan-minimal bryan-minimal commented May 26, 2026 •

Copy link
Copy Markdown
Member

sandbox2: hardlink CS mirror contents into rootfs (fix #228 follow-up)

Follow-up to #228 (sandbox2 + op: CS-compatible nested-sandbox plumbing). The MINIMAL_INTERNAL_CS_BUILD=1 bundle landed with the right intent, but the cache-delivery half didn't survive integration: the container.symlink("/state/cs-mirror/<X>", "/<X>") calls pointed at /state/cs-mirror/... assuming /state was shared across all sandboxes — but /state inside each per-build sandbox is base_dir.join("state"), a per-build location, so every symlink dangled. Pkg build.shs that probe [ -d /cargo-vendor ] all took their online-fallback branch, which fails in CS because there's no egress.

Fix

Replace the six broken symlinks with a single hardlink_dir_contents call from a hardcoded convention path. Same mechanism the (since-removed) public extra_rootfs field used; now triggered behind the existing CS flag with no new public API.

// In Sandbox::new, right after the synth-dir hardlink:
if std::env::var("MINIMAL_INTERNAL_CS_BUILD").as_deref() == Ok("1") {
    let cs_mirror = Path::new("/root/.cache/minimal/cs-mirror");
    if cs_mirror.exists() {
        hardlink_dir_contents(cs_mirror, &rootfs)?;
    }
}

The convention: minimalmertic's hermetic-builder-rs stages its CS bundle (cargo-vendor, npm-cache, pnpm-store, bun-cache, pip-wheels, rust-stage0, goproxy) at /root/.cache/minimal/cs-mirror/. The hardlink presents these as /cargo-vendor, /goproxy, etc. at sandbox rootfs root — the same top-level paths the build.sh offline-cache idiom already references.

The /proc bind-mount + MountFallback runctl from #228 stay — that half of the bundle was correct.

Why hardlink + convention path rather than a config field

Per the #228 review thread, the constraint was no new configurables / boolean-flag-only. This PR honors that:

  • Still one env var: MINIMAL_INTERNAL_CS_BUILD
  • Still boolean semantics (== "1")
  • The path /root/.cache/minimal/cs-mirror is a project-internal convention (same category as /state, /run) — not operator-configurable

If a future use case needs operator configurability, the right move is a separate proposal for that use case, not a config.extra_rootfs field that could be repurposed.

Safety

  • Inert when flag unset: gated on MINIMAL_INTERNAL_CS_BUILD == "1"; minimal package invocations see no behavior change
  • Inert when path doesn't exist: cs_mirror.exists() check before the call. Tests, dev environments, and any non-CS caller with the flag accidentally set won't break.
  • Mechanism is already exercised: hardlink_dir_contents runs just above this call for the synth-dir copy. The same code path that's been working in minimal package since forever.

Validation

Validated end-to-end in the minimalmertic deployment over 2026-05-25/26:

  • 260+ pkgs signed under the new sandbox bundle (C, Go, Cargo, npm, pnpm, pypi)
  • bash-bootstrap@5.3 reproducibility: built three times — once against gominimal's prebuilt, once as a rebuild, once against its own CS output — all produced sha 1d99e33f…
  • perl@5.42.0 builds from source CS-side after a separate -std=gnu17 fix to its build.sh

Both formerly-trust-pinned bootstrap_artifacts (bash-bootstrap, perl) graduated out via this mechanism. The bundle is exercised continuously by the production builder.

Diff size

 crates/sandbox2/src/lib.rs | 64 +++++++++++++++++++++++++++++++---------------
 1 file changed, 44 insertions(+), 20 deletions(-)

Single file, single commit, applies cleanly to current main.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • Updated sandbox cache delivery mechanism to use hardlink-based installation instead of symlink bridging, improving cache efficiency in containerized build environments.

Review Change Stack

PR #228's MINIMAL_INTERNAL_CS_BUILD bundle had the right intent but
the cache-delivery half didn't survive integration. The
container.symlink("/state/cs-mirror/<cache>", "/<cache>") calls
assumed /state was shared across all sandboxes — but /state inside
each per-build sandbox defaults to base_dir.join("state"), a
per-build location not shared with the orchestrator's outer state
dir. The symlinks all dangled, and `[ -d /cargo-vendor ]` checks
in package build.shs took their online-fallback branch (which
fails in CS because there's no egress).

Fix: when the flag is set, hardlink contents from the convention
path /root/.cache/minimal/cs-mirror into the sandbox rootfs root.
This is the same mechanism the (since-removed) public extra_rootfs
field used; here it's triggered behind the existing CS flag with
a hardcoded internal-convention path, so no new public API surface.

  - Still one env var: MINIMAL_INTERNAL_CS_BUILD
  - Still boolean semantics (== "1")
  - /root/.cache/minimal/cs-mirror is project-internal convention
    (same category as /state and /run — convention, not configuration)

The /proc bind-mount + MountFallback runctl from #228 stay — that
part of the bundle was correct.

Inert when the env var is unset; inert when the convention path
doesn't exist (tests, dev environments, non-CS callers). The
hardlink_dir_contents call is the same one already exercised
immediately above for the synth-dir copy.

Validated end-to-end in the minimalmertic deployment over
2026-05-25/26: 260+ packages signed under the new bundle (C, Go,
Cargo, npm, pnpm, pypi), and `bash-bootstrap@5.3` reached a
self-reproducing fixed point across three build cycles using the
mechanism (CS-attested artifact → trust anchor for cycle 2 → same
sha out, no Mac/CI prebuilt left in the chain).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented May 26, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Sandbox::new conditionally hardlinks a CS-only cache mirror into the sandbox rootfs during initialization when MINIMAL_INTERNAL_CS_BUILD=1 is set, replacing sandbox-time symlink creation. new_container's CS-only path removes the previous symlink bridge logic and now relies on the earlier hardlinking step for cache delivery.

Changes

CS-Only Cache Delivery Refactoring

Layer / File(s) Summary
CS cache hardlink delivery in Sandbox::new
crates/sandbox2/src/lib.rs
Initialization-time hardlink of /root/.cache/minimal/cs-mirror into sandbox rootfs when MINIMAL_INTERNAL_CS_BUILD=1 env var is set and the convention directory exists; includes detailed comments on CS-only cache delivery flow.
Remove symlink-based cache bridge from new_container
crates/sandbox2/src/lib.rs
new_container's CS-only path removes symlink creation for /cargo-vendor, /npm-cache, /pnpm-store, /bun-cache, /pip-wheels, /rust-stage0 pointing to /state/cs-mirror/*; retains /proc bind-mount and MountFallback behavior while delegating cache delivery to earlier Sandbox::new step.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • gominimal/minimal#228: Shares the same CS-compatible nested-sandbox plumbing context; the main PR refactors the CS mirror cache wiring originally added by #228.
  • gominimal/minimal#208: Also modifies crates/sandbox2/src/lib.rs Sandbox::new_container and /state mount behavior.

Suggested reviewers

  • msample
  • twitchyliquid64

Poem

🐰 A mirror hardlinked at dawn,
No symlinks dancing at the sandbox gate,
Cache flows swifter, bridges withdrawn—
CS builds await their eager fate! 🚀

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately summarizes the main change: hardlinking CS mirror contents into rootfs as a follow-up to issue #228.
Linked Issues check ✅ Passed The PR addresses the cache-delivery mechanism for MINIMAL_INTERNAL_CS_BUILD=1 sandboxes mentioned in #228, replacing broken symlinks with hardlink-based delivery.
Out of Scope Changes check ✅ Passed All changes in lib.rs are scoped to fixing the CS cache-delivery mechanism; the /proc bind-mount and MountFallback from #228 remain unchanged.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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

@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)
crates/sandbox2/src/lib.rs (1)

478-486: 💤 Low value

Avoid hardcoded line numbers in comments.

Line 480 references "lib.rs near line ~105" but the CS hardlink logic is at lines 124–128, and will drift further as the file evolves. Consider removing the line number or referencing the construct by name only.

-            // by the hardlink_dir_contents call in Sandbox::new — see
-            // lib.rs near line ~105. Earlier iteration of this PR
+            // by the hardlink_dir_contents call in Sandbox::new (search
+            // for "MINIMAL_INTERNAL_CS_BUILD" in this file). Earlier iteration of this PR
🤖 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 `@crates/sandbox2/src/lib.rs` around lines 478 - 486, The comment uses a
hardcoded line number ("lib.rs near line ~105"); update it to reference the code
by symbol/name instead: remove the numeric line reference and mention
Sandbox::new and the hardlink_dir_contents call (and optionally
base_dir.join("state")) so readers can find the logic by identifier rather than
a drifting line number.
🤖 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 `@crates/sandbox2/src/lib.rs`:
- Around line 478-486: The comment uses a hardcoded line number ("lib.rs near
line ~105"); update it to reference the code by symbol/name instead: remove the
numeric line reference and mention Sandbox::new and the hardlink_dir_contents
call (and optionally base_dir.join("state")) so readers can find the logic by
identifier rather than a drifting line number.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0c008d79-9166-466d-9282-1b0b52bbec9c

📥 Commits

Reviewing files that changed from the base of the PR and between 992f514 and 80797b8.

📒 Files selected for processing (1)
  • crates/sandbox2/src/lib.rs

@bryan-minimal
bryan-minimal merged commit 002fb9e into main May 26, 2026
8 checks passed
@bryan-minimal
bryan-minimal deleted the bryan/sandbox2-cs-mirror-hardlink branch May 26, 2026 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants