Repository navigation
[core][sandbox] Build sandbox EROFS images reproducibly - #67484
sunnylovestiramisu wants to merge 8 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the sandbox image builder to produce byte-identical EROFS images across different nodes and builds by utilizing extended inodes, a fixed UUID, and the --mkfs-time flag (available in erofs-utils 1.8+), while preserving individual file modification times. Feedback on these changes suggests caching the result of mkfs_erofs_pins_build_time to avoid redundant disk I/O from shutil.which, and refactoring the test helper shell script to avoid using eval when extracting command-line arguments.
| return res.stdout + res.stderr | ||
|
|
||
|
|
||
| def mkfs_erofs_pins_build_time() -> bool: |
There was a problem hiding this comment.
No change needed: shutil.which only runs inside mkfs_erofs_path(), which is already @lru_cached, and the --help probe is cached per binary in _mkfs_erofs_help. So mkfs_erofs_pins_build_time() does no repeated PATH search or subprocess. Leaving it uncached also lets the tests' mkfs_erofs_path.cache_clear() cover it.
| 'eval "tar_arg=\\${$#}"\n' | ||
| 'eval "out_arg=\\${$(($# - 1))}"\n' | ||
| 'cp "$tar_arg" "$out_arg"\n' |
There was a problem hiding this comment.
Using eval in shell scripts can be fragile and is generally discouraged. We can extract the last and second-to-last arguments safely and in a standard POSIX-compliant way using a simple loop, avoiding eval entirely.
'for arg in "$@"; do\n'\n ' out_arg=$tar_arg\n'\n ' tar_arg=$arg\n'\n 'done\n'\n 'cp "$tar_arg" "$out_arg"\n'There was a problem hiding this comment.
Done in 31db03d: the fake mkfs.erofs now picks its last two arguments with a loop instead of eval.
- tests/conftest.py: the fake mkfs.erofs finds its last two arguments with a loop instead of eval. ray-project#67484 (comment) Signed-off-by: Sunny Song <[email protected]>
31db03d to
09c36f0
Compare
- tests/conftest.py: the fake mkfs.erofs finds its last two arguments with a loop instead of eval. ray-project#67484 (comment) Signed-off-by: Sunny Song <[email protected]>
…nsc (#66471) ## Description This PR introduces native **Checkpoint, Restore, Pause, and Resume** capabilities to Ray Sandboxes (`ray.experimental.sandbox`), leveraging gVisor's underlying `runsc checkpoint`, `runsc restore`, `runsc pause`, and `runsc resume` mechanisms. ### Why is this needed? Instantiating a fresh container sandbox from scratch for every exploration step incurs substantial cold-start overhead (hundreds of milliseconds to seconds). Furthermore, complex RL agents, code execution environments, and LLM rollouts need efficient primitives to fork environments and manage resource consumption: 1. **Parallel Branching for Tree Search (e.g. MCTS, Speculative Decoding):** - A golden base sandbox is initialized and warmed up once with heavy dependencies, caches, or repository clones. - Point-in-time snapshots are captured while keeping the parent sandbox running (`leave_running=True`). - Multiple parallel child sandboxes can be restored with low latency (< 10ms), achieving **> 30x faster startup** with full copy-on-write state isolation across exploration branches. 2. **Cold Suspend & Resume for Multi-Turn Rollouts (Resource Reclaim):** - Idle sandboxes waiting for long external LLM inference or human feedback can be checkpointed to disk and stopped (`leave_running=False`), **freeing 100% of host RAM and CPU**. - The environment can later be resumed with low latency on demand. 3. **In-Memory Concurrency Throttling (`pause()` / `resume()`):** - Halts sandbox scheduling in-place without disk I/O, allowing CPU yielding and rate-limiting while keeping guest memory hot in host RAM. --- ## Scope after the review split As suggested in [review](#66471 (review)), this PR now covers node-local checkpoint/restore and pause/resume only. Two follow-ups take the rest: - #67485 adds `remote=True`, which restores checkpoints from shared storage on any node. It's stacked on this PR. - #67484 makes EROFS image builds reproducible (fixed UUID and build time, extended inodes), so a restore works on another node or after the cached image is rebuilt. It's independent of this PR. In this PR, `sandbox.restore()` always pins the restored actor to the node that took the checkpoint, and reserves the checkpointed CPU and memory. A restore over a different build of the image fails with a clear error instead of a gVisor panic. **Tests:** `TEST_SANDBOX=1 pytest python/ray/experimental/sandbox/tests/ --ignore=python/ray/experimental/sandbox/tests/test_sandbox.py` gave 270 passed, 21 failed. The 21 failures are identical on `master` on the same machine, which lacks `mkfs.erofs` and `runsc`. `pre-commit run --files <changed files>` passes. **Follow-ups, not in this PR:** - A Modal-style snapshot-handle API on top of `CheckpointPath`. - Snapshot RPCs and `SandboxHost` support in the SDK facade. This change was prepared with AI assistance and reviewed by the author. --- ## Related issues - Related to Ray Enhancement Proposal: `reps/2026-09-24-ray-sandboxing-checkpoint-restore.md` (ray-project/enhancements#77) - Follow-up to Ray Sandboxing base implementation (`reps/2026-07-14-ray-sandboxing.md`). --- ## Key Additions & Changes 1. **High-Level API (`ray.experimental.sandbox`)**: - `sandbox.restore(checkpoint_path, ...)`: Instantiates a new `Sandbox` actor from a saved checkpoint bundle. - `Sandbox.checkpoint.remote(checkpoint_path=..., leave_running=True)`: Captures sandbox state to disk. If `checkpoint_path=None`, Ray automatically generates a default path under `/tmp/ray/sandbox/checkpoints/<sandbox_id>-<uuid>`. `leave_running=False` stops the sandbox to reclaim host memory. - `Sandbox.pause.remote()` / `Sandbox.resume.remote()`: Directly controls guest CPU thread execution in-place via `runsc pause` and `runsc resume`. - `Sandbox.get_status.remote()`: Returns operational status (`RUNNING`, `PAUSED`, `TERMINATED`). 2. **Low-Level Interface (`SandboxRuntime` & `GVisorSandboxBackend`)**: - Added `checkpoint_sandbox()`, `restore_sandbox()`, `pause_sandbox()`, and `resume_sandbox()` across `base.py`, `runtime.py`, and `gvisor.py`. - Manifest creation (`manifest.json`): Preserves base image config, environment variables, working directories, OCI transforms, and resource allocations. - Filesystem snapshotting: Persists upper copy-on-write overlay layers and writable workdirs while safely ignoring ephemeral runtime backing files (e.g. `.gvisor.filestore*`). - Privilege management: Handled permission propagation and rootful container operations (`rootless=False`). 3. **Documentation & Unit Tests**: - Updated documentation in `doc/source/core/sandboxes.md` clarifying tree-search branching vs. suspend/resume rollouts. - Unit tests in `python/ray/experimental/sandbox/tests/test_sandbox.py` and `python/ray/experimental/sandbox/tests/test_sandbox_runtime.py` covering status tracking, pause/resume forwarding, and checkpoint/restore parameter validation. Formatted and validated against `ruff` and `black`. --- ## Usage Example ```python import ray from ray.experimental import sandbox from ray.experimental.sandbox.backend.base import SandboxStatus ray.init() # ====================================================================== # 1. Branching Workflow (Tree Search, MCTS) # ====================================================================== # Warm up base sandbox (requires rootless=False) base_sb = sandbox.create( image="python:3.10-slim", rootless=False, workdir="/workspace", ) ray.get(base_sb.exec.remote("python3 -c 'import math; print(\"Environment warmed!\")'")) # Checkpoint state to local disk / SSD (leave_running=True keeps parent sandbox running) checkpoint_path = ray.get(base_sb.checkpoint.remote("/tmp/ray/checkpoints/base_snap")) # Fast restore parallel branches (< 10ms startup) branch_1 = sandbox.restore(checkpoint_path) branch_2 = sandbox.restore(checkpoint_path) # Execute independently without cross-branch pollution res1 = ray.get(branch_1.exec.remote("echo 'branch 1' > /workspace/branch.txt && cat /workspace/branch.txt")) res2 = ray.get(branch_2.exec.remote("echo 'branch 2' > /workspace/branch.txt && cat /workspace/branch.txt")) print("Branch 1:", res1.stdout.strip()) # Output: branch 1 print("Branch 2:", res2.stdout.strip()) # Output: branch 2 # ====================================================================== # 2. In-Memory Pause and Resume (CPU Throttling / Concurrency Yielding) # ====================================================================== # Freeze sandbox execution in-place (keeps memory hot in RAM, 0 disk I/O) ray.get(base_sb.pause.remote()) print("Status:", ray.get(base_sb.get_status.remote())) # SandboxStatus.PAUSED # Resume sandbox execution ray.get(base_sb.resume.remote()) print("Status:", ray.get(base_sb.get_status.remote())) # SandboxStatus.RUNNING # ====================================================================== # 3. Cold Suspend & Resume (Freeing 100% Host Memory Between Turns) # ====================================================================== # Checkpoint and stop sandbox to release all RAM/CPU during multi-turn LLM waits suspend_path = ray.get(base_sb.checkpoint.remote(leave_running=False)) # Later, resume execution when next turn is ready resumed_sb = sandbox.restore(suspend_path) res_resumed = ray.get(resumed_sb.exec.remote("python3 -c 'print(\"Resumed successfully!\")'")) print(res_resumed.stdout.strip()) # Clean up ray.get(branch_1.delete.remote()) ray.get(branch_2.delete.remote()) ray.get(resumed_sb.delete.remote()) ``` ## Testing & Verification ### 1. Unit Tests - test_sandbox_runtime.py: Verified pause and resume delegation, and checkpoint / restore config forwarding to the backend. - test_sandbox.py: Verified actor wrapper methods, status tracking (RUNNING -> PAUSED -> RUNNING), and file I/O. ### 2. End-to-End Testing on Live Kubernetes Cluster (GKE) - Scenario A (User Code Snippet): Verified warmup, explicit checkpoint to /tmp/ray/checkpoints/base_snap, restore of 2 parallel branches, and verified branch filesystem isolation. - Scenario B (Default Path Generation): Verified auto-generation of checkpoint directory under /tmp/ray/sandbox/checkpoints/<sandbox_id>-<uuid> when checkpoint_path=None, verified directory contents (manifest.json, config.json, state/, fs/), and restored child sandbox. - Scenario C (Multi-Branch Parallel Restoration Benchmark): Checkpointed complex pre-warmed state to disk with leave_running=False (cold suspend), restored concurrent forks, and verified branch mutation independence. - Scenario D (Pause & Resume Lifecycle): Verified in-memory status transitions (RUNNING -> PAUSED -> RUNNING), confirmed CPU pause in 0.023s, resume in 0.021s, and verified filesystem state persistence and python command execution post-resume. - Ray job: https://gist.github.com/sunnylovestiramisu/7cd607727920186b6759a69967d7d37d - Logs: https://gist.github.com/sunnylovestiramisu/9d051ddff7bce1ec475f7992ff276818 --------- Signed-off-by: Sunny Song <[email protected]>
- tests/conftest.py: the fake mkfs.erofs finds its last two arguments with a loop instead of eval. ray-project#67484 (comment) Signed-off-by: Sunny Song <[email protected]>
26535eb to
782307b
Compare
- tests/conftest.py: the fake mkfs.erofs finds its last two arguments with a loop instead of eval. ray-project#67484 (comment) Signed-off-by: Sunny Song <[email protected]>
782307b to
f0abe08
Compare
…nsc (ray-project#66471) ## Description This PR introduces native **Checkpoint, Restore, Pause, and Resume** capabilities to Ray Sandboxes (`ray.experimental.sandbox`), leveraging gVisor's underlying `runsc checkpoint`, `runsc restore`, `runsc pause`, and `runsc resume` mechanisms. ### Why is this needed? Instantiating a fresh container sandbox from scratch for every exploration step incurs substantial cold-start overhead (hundreds of milliseconds to seconds). Furthermore, complex RL agents, code execution environments, and LLM rollouts need efficient primitives to fork environments and manage resource consumption: 1. **Parallel Branching for Tree Search (e.g. MCTS, Speculative Decoding):** - A golden base sandbox is initialized and warmed up once with heavy dependencies, caches, or repository clones. - Point-in-time snapshots are captured while keeping the parent sandbox running (`leave_running=True`). - Multiple parallel child sandboxes can be restored with low latency (< 10ms), achieving **> 30x faster startup** with full copy-on-write state isolation across exploration branches. 2. **Cold Suspend & Resume for Multi-Turn Rollouts (Resource Reclaim):** - Idle sandboxes waiting for long external LLM inference or human feedback can be checkpointed to disk and stopped (`leave_running=False`), **freeing 100% of host RAM and CPU**. - The environment can later be resumed with low latency on demand. 3. **In-Memory Concurrency Throttling (`pause()` / `resume()`):** - Halts sandbox scheduling in-place without disk I/O, allowing CPU yielding and rate-limiting while keeping guest memory hot in host RAM. --- ## Scope after the review split As suggested in [review](ray-project#66471 (review)), this PR now covers node-local checkpoint/restore and pause/resume only. Two follow-ups take the rest: - ray-project#67485 adds `remote=True`, which restores checkpoints from shared storage on any node. It's stacked on this PR. - ray-project#67484 makes EROFS image builds reproducible (fixed UUID and build time, extended inodes), so a restore works on another node or after the cached image is rebuilt. It's independent of this PR. In this PR, `sandbox.restore()` always pins the restored actor to the node that took the checkpoint, and reserves the checkpointed CPU and memory. A restore over a different build of the image fails with a clear error instead of a gVisor panic. **Tests:** `TEST_SANDBOX=1 pytest python/ray/experimental/sandbox/tests/ --ignore=python/ray/experimental/sandbox/tests/test_sandbox.py` gave 270 passed, 21 failed. The 21 failures are identical on `master` on the same machine, which lacks `mkfs.erofs` and `runsc`. `pre-commit run --files <changed files>` passes. **Follow-ups, not in this PR:** - A Modal-style snapshot-handle API on top of `CheckpointPath`. - Snapshot RPCs and `SandboxHost` support in the SDK facade. This change was prepared with AI assistance and reviewed by the author. --- ## Related issues - Related to Ray Enhancement Proposal: `reps/2026-09-24-ray-sandboxing-checkpoint-restore.md` (ray-project/enhancements#77) - Follow-up to Ray Sandboxing base implementation (`reps/2026-07-14-ray-sandboxing.md`). --- ## Key Additions & Changes 1. **High-Level API (`ray.experimental.sandbox`)**: - `sandbox.restore(checkpoint_path, ...)`: Instantiates a new `Sandbox` actor from a saved checkpoint bundle. - `Sandbox.checkpoint.remote(checkpoint_path=..., leave_running=True)`: Captures sandbox state to disk. If `checkpoint_path=None`, Ray automatically generates a default path under `/tmp/ray/sandbox/checkpoints/<sandbox_id>-<uuid>`. `leave_running=False` stops the sandbox to reclaim host memory. - `Sandbox.pause.remote()` / `Sandbox.resume.remote()`: Directly controls guest CPU thread execution in-place via `runsc pause` and `runsc resume`. - `Sandbox.get_status.remote()`: Returns operational status (`RUNNING`, `PAUSED`, `TERMINATED`). 2. **Low-Level Interface (`SandboxRuntime` & `GVisorSandboxBackend`)**: - Added `checkpoint_sandbox()`, `restore_sandbox()`, `pause_sandbox()`, and `resume_sandbox()` across `base.py`, `runtime.py`, and `gvisor.py`. - Manifest creation (`manifest.json`): Preserves base image config, environment variables, working directories, OCI transforms, and resource allocations. - Filesystem snapshotting: Persists upper copy-on-write overlay layers and writable workdirs while safely ignoring ephemeral runtime backing files (e.g. `.gvisor.filestore*`). - Privilege management: Handled permission propagation and rootful container operations (`rootless=False`). 3. **Documentation & Unit Tests**: - Updated documentation in `doc/source/core/sandboxes.md` clarifying tree-search branching vs. suspend/resume rollouts. - Unit tests in `python/ray/experimental/sandbox/tests/test_sandbox.py` and `python/ray/experimental/sandbox/tests/test_sandbox_runtime.py` covering status tracking, pause/resume forwarding, and checkpoint/restore parameter validation. Formatted and validated against `ruff` and `black`. --- ## Usage Example ```python import ray from ray.experimental import sandbox from ray.experimental.sandbox.backend.base import SandboxStatus ray.init() # ====================================================================== # 1. Branching Workflow (Tree Search, MCTS) # ====================================================================== # Warm up base sandbox (requires rootless=False) base_sb = sandbox.create( image="python:3.10-slim", rootless=False, workdir="/workspace", ) ray.get(base_sb.exec.remote("python3 -c 'import math; print(\"Environment warmed!\")'")) # Checkpoint state to local disk / SSD (leave_running=True keeps parent sandbox running) checkpoint_path = ray.get(base_sb.checkpoint.remote("/tmp/ray/checkpoints/base_snap")) # Fast restore parallel branches (< 10ms startup) branch_1 = sandbox.restore(checkpoint_path) branch_2 = sandbox.restore(checkpoint_path) # Execute independently without cross-branch pollution res1 = ray.get(branch_1.exec.remote("echo 'branch 1' > /workspace/branch.txt && cat /workspace/branch.txt")) res2 = ray.get(branch_2.exec.remote("echo 'branch 2' > /workspace/branch.txt && cat /workspace/branch.txt")) print("Branch 1:", res1.stdout.strip()) # Output: branch 1 print("Branch 2:", res2.stdout.strip()) # Output: branch 2 # ====================================================================== # 2. In-Memory Pause and Resume (CPU Throttling / Concurrency Yielding) # ====================================================================== # Freeze sandbox execution in-place (keeps memory hot in RAM, 0 disk I/O) ray.get(base_sb.pause.remote()) print("Status:", ray.get(base_sb.get_status.remote())) # SandboxStatus.PAUSED # Resume sandbox execution ray.get(base_sb.resume.remote()) print("Status:", ray.get(base_sb.get_status.remote())) # SandboxStatus.RUNNING # ====================================================================== # 3. Cold Suspend & Resume (Freeing 100% Host Memory Between Turns) # ====================================================================== # Checkpoint and stop sandbox to release all RAM/CPU during multi-turn LLM waits suspend_path = ray.get(base_sb.checkpoint.remote(leave_running=False)) # Later, resume execution when next turn is ready resumed_sb = sandbox.restore(suspend_path) res_resumed = ray.get(resumed_sb.exec.remote("python3 -c 'print(\"Resumed successfully!\")'")) print(res_resumed.stdout.strip()) # Clean up ray.get(branch_1.delete.remote()) ray.get(branch_2.delete.remote()) ray.get(resumed_sb.delete.remote()) ``` ## Testing & Verification ### 1. Unit Tests - test_sandbox_runtime.py: Verified pause and resume delegation, and checkpoint / restore config forwarding to the backend. - test_sandbox.py: Verified actor wrapper methods, status tracking (RUNNING -> PAUSED -> RUNNING), and file I/O. ### 2. End-to-End Testing on Live Kubernetes Cluster (GKE) - Scenario A (User Code Snippet): Verified warmup, explicit checkpoint to /tmp/ray/checkpoints/base_snap, restore of 2 parallel branches, and verified branch filesystem isolation. - Scenario B (Default Path Generation): Verified auto-generation of checkpoint directory under /tmp/ray/sandbox/checkpoints/<sandbox_id>-<uuid> when checkpoint_path=None, verified directory contents (manifest.json, config.json, state/, fs/), and restored child sandbox. - Scenario C (Multi-Branch Parallel Restoration Benchmark): Checkpointed complex pre-warmed state to disk with leave_running=False (cold suspend), restored concurrent forks, and verified branch mutation independence. - Scenario D (Pause & Resume Lifecycle): Verified in-memory status transitions (RUNNING -> PAUSED -> RUNNING), confirmed CPU pause in 0.023s, resume in 0.021s, and verified filesystem state persistence and python command execution post-resume. - Ray job: https://gist.github.com/sunnylovestiramisu/7cd607727920186b6759a69967d7d37d - Logs: https://gist.github.com/sunnylovestiramisu/9d051ddff7bce1ec475f7992ff276818 --------- Signed-off-by: Sunny Song <[email protected]>
…e as it goes (#67493) ## Description While mkfs.erofs builds a cold-pulled image, the node holds the extracted tree and a flat tar of it: two full copies on top of the image. Running SkyRL's Harbor integration with 64 SWE-bench Verified tasks at once on two 60-CPU nodes, 32 concurrent cold pulls per node filled the host's 200 GB disk within 20 seconds and both nodes died. This PR streams the tar into mkfs.erofs's stdin, which it reads when given no source (erofs-utils 1.7, Ray's minimum, already does), and deletes each file from the tree once it's in the stream. - Members keep `tar.add`'s order, so the image is byte-identical. - Files with other hard links stay until the caller removes the tree, so links aren't stored as copies. - A read-only directory gets owner write once its header is in the stream, so a worker that isn't root can delete its files. The image keeps the original mode. - If mkfs.erofs exits early, the build reports its error. Any other failure kills and reaps it first. On django-13279 (2.8 GiB tree and image), two four-round A/B runs on Anyscale: | | master | this PR | | --- | --- | --- | | Peak disk use beyond the tree | 5.5-6.1 GiB | 0.67-0.74 GiB | | Build time, 8 builds | 48-177 s, median 72 s | 48-50 s, one 99 s during another pod's large write | With the UUID and build time pinned, both give byte-identical images, and `fsck.erofs` passes. mkfs.erofs still spools file data under `$TMPDIR` (default `--sort=path`). `--sort=none` (erofs-utils 1.8.2+) would drop that too, but it changes the data layout, so it's a separate change. ## Related issues None filed. Found while validating SkyRL's Harbor integration on Ray Sandbox (skyrl-project/SkyRL#2467). ## Additional information - Not a duplicate: no open PR streams the build or frees the tree. #67484 edits the same mkfs.erofs call and fake mkfs.erofs fixture, so whichever lands second needs a small rebase. - Tests: three new tests in `test_image_utils.py` cover the streamed tar matching `tar.add` member for member (hard links, a read-only directory, a file larger than a pipe), mkfs.erofs failing before it reads, and mkfs.erofs being killed when reading the tree fails. The first and third fail on master. - Tested: `TEST_SANDBOX=1 pytest python/ray/experimental/sandbox/tests/test_image_utils.py`: 44 passed on macOS as a non-root user. The A/B ran on Linux with erofs-utils 1.9.4. pre-commit passes. - I used Claude Code to help write and test this change. Signed-off-by: xyuzh <[email protected]>
…nsc (ray-project#66471) ## Description This PR introduces native **Checkpoint, Restore, Pause, and Resume** capabilities to Ray Sandboxes (`ray.experimental.sandbox`), leveraging gVisor's underlying `runsc checkpoint`, `runsc restore`, `runsc pause`, and `runsc resume` mechanisms. ### Why is this needed? Instantiating a fresh container sandbox from scratch for every exploration step incurs substantial cold-start overhead (hundreds of milliseconds to seconds). Furthermore, complex RL agents, code execution environments, and LLM rollouts need efficient primitives to fork environments and manage resource consumption: 1. **Parallel Branching for Tree Search (e.g. MCTS, Speculative Decoding):** - A golden base sandbox is initialized and warmed up once with heavy dependencies, caches, or repository clones. - Point-in-time snapshots are captured while keeping the parent sandbox running (`leave_running=True`). - Multiple parallel child sandboxes can be restored with low latency (< 10ms), achieving **> 30x faster startup** with full copy-on-write state isolation across exploration branches. 2. **Cold Suspend & Resume for Multi-Turn Rollouts (Resource Reclaim):** - Idle sandboxes waiting for long external LLM inference or human feedback can be checkpointed to disk and stopped (`leave_running=False`), **freeing 100% of host RAM and CPU**. - The environment can later be resumed with low latency on demand. 3. **In-Memory Concurrency Throttling (`pause()` / `resume()`):** - Halts sandbox scheduling in-place without disk I/O, allowing CPU yielding and rate-limiting while keeping guest memory hot in host RAM. --- ## Scope after the review split As suggested in [review](ray-project#66471 (review)), this PR now covers node-local checkpoint/restore and pause/resume only. Two follow-ups take the rest: - ray-project#67485 adds `remote=True`, which restores checkpoints from shared storage on any node. It's stacked on this PR. - ray-project#67484 makes EROFS image builds reproducible (fixed UUID and build time, extended inodes), so a restore works on another node or after the cached image is rebuilt. It's independent of this PR. In this PR, `sandbox.restore()` always pins the restored actor to the node that took the checkpoint, and reserves the checkpointed CPU and memory. A restore over a different build of the image fails with a clear error instead of a gVisor panic. **Tests:** `TEST_SANDBOX=1 pytest python/ray/experimental/sandbox/tests/ --ignore=python/ray/experimental/sandbox/tests/test_sandbox.py` gave 270 passed, 21 failed. The 21 failures are identical on `master` on the same machine, which lacks `mkfs.erofs` and `runsc`. `pre-commit run --files <changed files>` passes. **Follow-ups, not in this PR:** - A Modal-style snapshot-handle API on top of `CheckpointPath`. - Snapshot RPCs and `SandboxHost` support in the SDK facade. This change was prepared with AI assistance and reviewed by the author. --- ## Related issues - Related to Ray Enhancement Proposal: `reps/2026-09-24-ray-sandboxing-checkpoint-restore.md` (ray-project/enhancements#77) - Follow-up to Ray Sandboxing base implementation (`reps/2026-07-14-ray-sandboxing.md`). --- ## Key Additions & Changes 1. **High-Level API (`ray.experimental.sandbox`)**: - `sandbox.restore(checkpoint_path, ...)`: Instantiates a new `Sandbox` actor from a saved checkpoint bundle. - `Sandbox.checkpoint.remote(checkpoint_path=..., leave_running=True)`: Captures sandbox state to disk. If `checkpoint_path=None`, Ray automatically generates a default path under `/tmp/ray/sandbox/checkpoints/<sandbox_id>-<uuid>`. `leave_running=False` stops the sandbox to reclaim host memory. - `Sandbox.pause.remote()` / `Sandbox.resume.remote()`: Directly controls guest CPU thread execution in-place via `runsc pause` and `runsc resume`. - `Sandbox.get_status.remote()`: Returns operational status (`RUNNING`, `PAUSED`, `TERMINATED`). 2. **Low-Level Interface (`SandboxRuntime` & `GVisorSandboxBackend`)**: - Added `checkpoint_sandbox()`, `restore_sandbox()`, `pause_sandbox()`, and `resume_sandbox()` across `base.py`, `runtime.py`, and `gvisor.py`. - Manifest creation (`manifest.json`): Preserves base image config, environment variables, working directories, OCI transforms, and resource allocations. - Filesystem snapshotting: Persists upper copy-on-write overlay layers and writable workdirs while safely ignoring ephemeral runtime backing files (e.g. `.gvisor.filestore*`). - Privilege management: Handled permission propagation and rootful container operations (`rootless=False`). 3. **Documentation & Unit Tests**: - Updated documentation in `doc/source/core/sandboxes.md` clarifying tree-search branching vs. suspend/resume rollouts. - Unit tests in `python/ray/experimental/sandbox/tests/test_sandbox.py` and `python/ray/experimental/sandbox/tests/test_sandbox_runtime.py` covering status tracking, pause/resume forwarding, and checkpoint/restore parameter validation. Formatted and validated against `ruff` and `black`. --- ## Usage Example ```python import ray from ray.experimental import sandbox from ray.experimental.sandbox.backend.base import SandboxStatus ray.init() # ====================================================================== # 1. Branching Workflow (Tree Search, MCTS) # ====================================================================== # Warm up base sandbox (requires rootless=False) base_sb = sandbox.create( image="python:3.10-slim", rootless=False, workdir="/workspace", ) ray.get(base_sb.exec.remote("python3 -c 'import math; print(\"Environment warmed!\")'")) # Checkpoint state to local disk / SSD (leave_running=True keeps parent sandbox running) checkpoint_path = ray.get(base_sb.checkpoint.remote("/tmp/ray/checkpoints/base_snap")) # Fast restore parallel branches (< 10ms startup) branch_1 = sandbox.restore(checkpoint_path) branch_2 = sandbox.restore(checkpoint_path) # Execute independently without cross-branch pollution res1 = ray.get(branch_1.exec.remote("echo 'branch 1' > /workspace/branch.txt && cat /workspace/branch.txt")) res2 = ray.get(branch_2.exec.remote("echo 'branch 2' > /workspace/branch.txt && cat /workspace/branch.txt")) print("Branch 1:", res1.stdout.strip()) # Output: branch 1 print("Branch 2:", res2.stdout.strip()) # Output: branch 2 # ====================================================================== # 2. In-Memory Pause and Resume (CPU Throttling / Concurrency Yielding) # ====================================================================== # Freeze sandbox execution in-place (keeps memory hot in RAM, 0 disk I/O) ray.get(base_sb.pause.remote()) print("Status:", ray.get(base_sb.get_status.remote())) # SandboxStatus.PAUSED # Resume sandbox execution ray.get(base_sb.resume.remote()) print("Status:", ray.get(base_sb.get_status.remote())) # SandboxStatus.RUNNING # ====================================================================== # 3. Cold Suspend & Resume (Freeing 100% Host Memory Between Turns) # ====================================================================== # Checkpoint and stop sandbox to release all RAM/CPU during multi-turn LLM waits suspend_path = ray.get(base_sb.checkpoint.remote(leave_running=False)) # Later, resume execution when next turn is ready resumed_sb = sandbox.restore(suspend_path) res_resumed = ray.get(resumed_sb.exec.remote("python3 -c 'print(\"Resumed successfully!\")'")) print(res_resumed.stdout.strip()) # Clean up ray.get(branch_1.delete.remote()) ray.get(branch_2.delete.remote()) ray.get(resumed_sb.delete.remote()) ``` ## Testing & Verification ### 1. Unit Tests - test_sandbox_runtime.py: Verified pause and resume delegation, and checkpoint / restore config forwarding to the backend. - test_sandbox.py: Verified actor wrapper methods, status tracking (RUNNING -> PAUSED -> RUNNING), and file I/O. ### 2. End-to-End Testing on Live Kubernetes Cluster (GKE) - Scenario A (User Code Snippet): Verified warmup, explicit checkpoint to /tmp/ray/checkpoints/base_snap, restore of 2 parallel branches, and verified branch filesystem isolation. - Scenario B (Default Path Generation): Verified auto-generation of checkpoint directory under /tmp/ray/sandbox/checkpoints/<sandbox_id>-<uuid> when checkpoint_path=None, verified directory contents (manifest.json, config.json, state/, fs/), and restored child sandbox. - Scenario C (Multi-Branch Parallel Restoration Benchmark): Checkpointed complex pre-warmed state to disk with leave_running=False (cold suspend), restored concurrent forks, and verified branch mutation independence. - Scenario D (Pause & Resume Lifecycle): Verified in-memory status transitions (RUNNING -> PAUSED -> RUNNING), confirmed CPU pause in 0.023s, resume in 0.021s, and verified filesystem state persistence and python command execution post-resume. - Ray job: https://gist.github.com/sunnylovestiramisu/7cd607727920186b6759a69967d7d37d - Logs: https://gist.github.com/sunnylovestiramisu/9d051ddff7bce1ec475f7992ff276818 --------- Signed-off-by: Sunny Song <[email protected]> Signed-off-by: Pawel Beza <[email protected]> Co-authored-by: Copilot <[email protected]> Copilot-Session: 4b9df5c4-6ec3-4e1f-ac3e-54f320ebd8c4
…e as it goes (ray-project#67493) ## Description While mkfs.erofs builds a cold-pulled image, the node holds the extracted tree and a flat tar of it: two full copies on top of the image. Running SkyRL's Harbor integration with 64 SWE-bench Verified tasks at once on two 60-CPU nodes, 32 concurrent cold pulls per node filled the host's 200 GB disk within 20 seconds and both nodes died. This PR streams the tar into mkfs.erofs's stdin, which it reads when given no source (erofs-utils 1.7, Ray's minimum, already does), and deletes each file from the tree once it's in the stream. - Members keep `tar.add`'s order, so the image is byte-identical. - Files with other hard links stay until the caller removes the tree, so links aren't stored as copies. - A read-only directory gets owner write once its header is in the stream, so a worker that isn't root can delete its files. The image keeps the original mode. - If mkfs.erofs exits early, the build reports its error. Any other failure kills and reaps it first. On django-13279 (2.8 GiB tree and image), two four-round A/B runs on Anyscale: | | master | this PR | | --- | --- | --- | | Peak disk use beyond the tree | 5.5-6.1 GiB | 0.67-0.74 GiB | | Build time, 8 builds | 48-177 s, median 72 s | 48-50 s, one 99 s during another pod's large write | With the UUID and build time pinned, both give byte-identical images, and `fsck.erofs` passes. mkfs.erofs still spools file data under `$TMPDIR` (default `--sort=path`). `--sort=none` (erofs-utils 1.8.2+) would drop that too, but it changes the data layout, so it's a separate change. ## Related issues None filed. Found while validating SkyRL's Harbor integration on Ray Sandbox (skyrl-project/SkyRL#2467). ## Additional information - Not a duplicate: no open PR streams the build or frees the tree. ray-project#67484 edits the same mkfs.erofs call and fake mkfs.erofs fixture, so whichever lands second needs a small rebase. - Tests: three new tests in `test_image_utils.py` cover the streamed tar matching `tar.add` member for member (hard links, a read-only directory, a file larger than a pipe), mkfs.erofs failing before it reads, and mkfs.erofs being killed when reading the tree fails. The first and third fail on master. - Tested: `TEST_SANDBOX=1 pytest python/ray/experimental/sandbox/tests/test_image_utils.py`: 44 passed on macOS as a non-root user. The A/B ran on Linux with erofs-utils 1.9.4. pre-commit passes. - I used Claude Code to help write and test this change. Signed-off-by: xyuzh <[email protected]> Signed-off-by: Pawel Beza <[email protected]> Co-authored-by: Copilot <[email protected]> Copilot-Session: 4b9df5c4-6ec3-4e1f-ac3e-54f320ebd8c4
200d46b to
e85377f
Compare
e85377f to
bbc5819
Compare
- Hardlinks take their target's recorded mode and owner instead of the ones in their own header. Tar writers may leave a hardlink's mode at 0, and the re-pack walks names in sorted order, so a link that sorts before its target was emitted as the file with mode 0, leaving both names unexecutable. The owner had the same order dependence. A link whose target has no record drops any stale record of its own name. (ray-project#67484 (comment)) Signed-off-by: Sunny Song <[email protected]>
Review: ray-project#67484 (review) - image_utils.py: zero mtimes only for the root and the exact canonical paths Ray created (seeds, missing parents, implied layer dirs) instead of matching static mount point names, so shipped entries keep their archived mtimes and seeds placed through symlinks are covered (ray-project#67484 (comment)) - image_utils.py: record every directory Ray creates, missing parents included, and set created dirs to 0755, stub files to 0644 and the rootfs dir to 0755 regardless of the umask (ray-project#67484 (comment)) - image_utils.py: give parent dirs a layer implies without an entry mode 0755 and mtime 0 unless a later entry ships them, and restore the mtimes of existing dirs a later layer adds to or whites out in (ray-project#67484 (comment)) - image_utils.py, conftest.py: include the mkfs.erofs -V version in the cache marker so an erofs-utils upgrade rebuilds cached images; the fake mkfs.erofs answers -V (ray-project#67484 (comment)) - sandboxes.md: state that byte-identical builds need the same erofs-utils version on every node (ray-project#67484 (comment)) - sandboxes.md: split the Container images paragraph into short paragraphs and a list (ray-project#67484 (comment)) - test_image_utils.py: cover images without /etc, seeds through tmp and etc symlinks, implied parents, multi-layer dir mtimes, shipped mount points, a 0077 umask, and the versioned marker (ray-project#67484 (comment)) Signed-off-by: Sunny Song <[email protected]>
Review: ray-project#67484 (review) - image_utils.py: extraction records each shipped file's and directory's archived permission bits, and the image build applies them through _owner_filter instead of the modes on disk. Mode-0000 entries such as /etc/shadow and 0000 directories no longer pick up the worker's umask, so builds match across umasks and stay unreadable to other users. On disk, extracted files always keep owner read access (whatever the archived mode or umask), so a non-root worker can read 0000 or 4111 files for the build. ray-project#67484 (comment) - image_utils.py: _mkfs_erofs_version takes the version from the first line even when mkfs.erofs exits non-zero, as erofs-utils 1.7 does after printing it for -V. ray-project#67484 (comment) Signed-off-by: Sunny Song <[email protected]>
- image_utils.py: _seed_tmp drops /tmp's archived mode from the recorded modes after making it 1777, so a /tmp the image ships with another mode (or one it names through a symlink) is still world-writable and sticky in the image. The keep file stops runsc from mounting a tmpfs over it. ray-project#67484 (comment) Signed-off-by: Sunny Song <[email protected]>
- Hardlinks take their target's recorded mode and owner instead of the ones in their own header. Tar writers may leave a hardlink's mode at 0, and the re-pack walks names in sorted order, so a link that sorts before its target was emitted as the file with mode 0, leaving both names unexecutable. The owner had the same order dependence. A link whose target has no record drops any stale record of its own name. (ray-project#67484 (comment)) Signed-off-by: Sunny Song <[email protected]>
6b5b532 to
b2efbfb
Compare
Review: ray-project#67484 (review) - image_utils.py: zero mtimes only for the root and the exact canonical paths Ray created (seeds, missing parents, implied layer dirs) instead of matching static mount point names, so shipped entries keep their archived mtimes and seeds placed through symlinks are covered (ray-project#67484 (comment)) - image_utils.py: record every directory Ray creates, missing parents included, and set created dirs to 0755, stub files to 0644 and the rootfs dir to 0755 regardless of the umask (ray-project#67484 (comment)) - image_utils.py: give parent dirs a layer implies without an entry mode 0755 and mtime 0 unless a later entry ships them, and restore the mtimes of existing dirs a later layer adds to or whites out in (ray-project#67484 (comment)) - image_utils.py, conftest.py: include the mkfs.erofs -V version in the cache marker so an erofs-utils upgrade rebuilds cached images; the fake mkfs.erofs answers -V (ray-project#67484 (comment)) - sandboxes.md: state that byte-identical builds need the same erofs-utils version on every node (ray-project#67484 (comment)) - sandboxes.md: split the Container images paragraph into short paragraphs and a list (ray-project#67484 (comment)) - test_image_utils.py: cover images without /etc, seeds through tmp and etc symlinks, implied parents, multi-layer dir mtimes, shipped mount points, a 0077 umask, and the versioned marker (ray-project#67484 (comment)) Signed-off-by: Sunny Song <[email protected]>
Review: ray-project#67484 (review) - image_utils.py: extraction records each shipped file's and directory's archived permission bits, and the image build applies them through _owner_filter instead of the modes on disk. Mode-0000 entries such as /etc/shadow and 0000 directories no longer pick up the worker's umask, so builds match across umasks and stay unreadable to other users. On disk, extracted files always keep owner read access (whatever the archived mode or umask), so a non-root worker can read 0000 or 4111 files for the build. ray-project#67484 (comment) - image_utils.py: _mkfs_erofs_version takes the version from the first line even when mkfs.erofs exits non-zero, as erofs-utils 1.7 does after printing it for -V. ray-project#67484 (comment) Signed-off-by: Sunny Song <[email protected]>
- image_utils.py: _seed_tmp drops /tmp's archived mode from the recorded modes after making it 1777, so a /tmp the image ships with another mode (or one it names through a symlink) is still world-writable and sticky in the image. The keep file stops runsc from mounting a tmpfs over it. ray-project#67484 (comment) Signed-off-by: Sunny Song <[email protected]>
- Hardlinks take their target's recorded mode and owner instead of the ones in their own header. Tar writers may leave a hardlink's mode at 0, and the re-pack walks names in sorted order, so a link that sorts before its target was emitted as the file with mode 0, leaving both names unexecutable. The owner had the same order dependence. A link whose target has no record drops any stale record of its own name. (ray-project#67484 (comment)) Signed-off-by: Sunny Song <[email protected]>
b2efbfb to
1feef97
Compare
Review: ray-project#67484 (review) - image_utils.py: zero mtimes only for the root and the exact canonical paths Ray created (seeds, missing parents, implied layer dirs) instead of matching static mount point names, so shipped entries keep their archived mtimes and seeds placed through symlinks are covered (ray-project#67484 (comment)) - image_utils.py: record every directory Ray creates, missing parents included, and set created dirs to 0755, stub files to 0644 and the rootfs dir to 0755 regardless of the umask (ray-project#67484 (comment)) - image_utils.py: give parent dirs a layer implies without an entry mode 0755 and mtime 0 unless a later entry ships them, and restore the mtimes of existing dirs a later layer adds to or whites out in (ray-project#67484 (comment)) - image_utils.py, conftest.py: include the mkfs.erofs -V version in the cache marker so an erofs-utils upgrade rebuilds cached images; the fake mkfs.erofs answers -V (ray-project#67484 (comment)) - sandboxes.md: state that byte-identical builds need the same erofs-utils version on every node (ray-project#67484 (comment)) - sandboxes.md: split the Container images paragraph into short paragraphs and a list (ray-project#67484 (comment)) - test_image_utils.py: cover images without /etc, seeds through tmp and etc symlinks, implied parents, multi-layer dir mtimes, shipped mount points, a 0077 umask, and the versioned marker (ray-project#67484 (comment)) Signed-off-by: Sunny Song <[email protected]>
Review: ray-project#67484 (review) - image_utils.py: extraction records each shipped file's and directory's archived permission bits, and the image build applies them through _owner_filter instead of the modes on disk. Mode-0000 entries such as /etc/shadow and 0000 directories no longer pick up the worker's umask, so builds match across umasks and stay unreadable to other users. On disk, extracted files always keep owner read access (whatever the archived mode or umask), so a non-root worker can read 0000 or 4111 files for the build. ray-project#67484 (comment) - image_utils.py: _mkfs_erofs_version takes the version from the first line even when mkfs.erofs exits non-zero, as erofs-utils 1.7 does after printing it for -V. ray-project#67484 (comment) Signed-off-by: Sunny Song <[email protected]>
- image_utils.py: _seed_tmp drops /tmp's archived mode from the recorded modes after making it 1777, so a /tmp the image ships with another mode (or one it names through a symlink) is still world-writable and sticky in the image. The keep file stops runsc from mounting a tmpfs over it. ray-project#67484 (comment) Signed-off-by: Sunny Song <[email protected]>
- Hardlinks take their target's recorded mode and owner instead of the ones in their own header. Tar writers may leave a hardlink's mode at 0, and the re-pack walks names in sorted order, so a link that sorts before its target was emitted as the file with mode 0, leaving both names unexecutable. The owner had the same order dependence. A link whose target has no record drops any stale record of its own name. (ray-project#67484 (comment)) Signed-off-by: Sunny Song <[email protected]>
1feef97 to
2c9d7bc
Compare
Review: ray-project#67484 (review) - image_utils.py: zero mtimes only for the root and the exact canonical paths Ray created (seeds, missing parents, implied layer dirs) instead of matching static mount point names, so shipped entries keep their archived mtimes and seeds placed through symlinks are covered (ray-project#67484 (comment)) - image_utils.py: record every directory Ray creates, missing parents included, and set created dirs to 0755, stub files to 0644 and the rootfs dir to 0755 regardless of the umask (ray-project#67484 (comment)) - image_utils.py: give parent dirs a layer implies without an entry mode 0755 and mtime 0 unless a later entry ships them, and restore the mtimes of existing dirs a later layer adds to or whites out in (ray-project#67484 (comment)) - image_utils.py, conftest.py: include the mkfs.erofs -V version in the cache marker so an erofs-utils upgrade rebuilds cached images; the fake mkfs.erofs answers -V (ray-project#67484 (comment)) - sandboxes.md: state that byte-identical builds need the same erofs-utils version on every node (ray-project#67484 (comment)) - sandboxes.md: split the Container images paragraph into short paragraphs and a list (ray-project#67484 (comment)) - test_image_utils.py: cover images without /etc, seeds through tmp and etc symlinks, implied parents, multi-layer dir mtimes, shipped mount points, a 0077 umask, and the versioned marker (ray-project#67484 (comment)) Signed-off-by: Sunny Song <[email protected]>
Review: ray-project#67484 (review) - image_utils.py: extraction records each shipped file's and directory's archived permission bits, and the image build applies them through _owner_filter instead of the modes on disk. Mode-0000 entries such as /etc/shadow and 0000 directories no longer pick up the worker's umask, so builds match across umasks and stay unreadable to other users. On disk, extracted files always keep owner read access (whatever the archived mode or umask), so a non-root worker can read 0000 or 4111 files for the build. ray-project#67484 (comment) - image_utils.py: _mkfs_erofs_version takes the version from the first line even when mkfs.erofs exits non-zero, as erofs-utils 1.7 does after printing it for -V. ray-project#67484 (comment) Signed-off-by: Sunny Song <[email protected]>
- image_utils.py: _seed_tmp drops /tmp's archived mode from the recorded modes after making it 1777, so a /tmp the image ships with another mode (or one it names through a symlink) is still world-writable and sticky in the image. The keep file stops runsc from mounting a tmpfs over it. ray-project#67484 (comment) Signed-off-by: Sunny Song <[email protected]>
- Hardlinks take their target's recorded mode and owner instead of the ones in their own header. Tar writers may leave a hardlink's mode at 0, and the re-pack walks names in sorted order, so a link that sorts before its target was emitted as the file with mode 0, leaving both names unexecutable. The owner had the same order dependence. A link whose target has no record drops any stale record of its own name. (ray-project#67484 (comment)) Signed-off-by: Sunny Song <[email protected]>
2c9d7bc to
30cad59
Compare
Split out of ray-project#66471 in review (ray-project#66471 (review)). gVisor restores a checkpointed sandbox only onto an EROFS root filesystem whose superblock matches the one it was saved with, and panics otherwise ("superblock mismatch detected on restore"). Two builds of the same image differ today: mkfs.erofs writes a random UUID and the current time into the superblock, and picks compact or extended inodes depending on that time. So a checkpoint can't be restored on another node, or on the same node once its cached image is evicted and rebuilt. build_erofs_image now passes: - -Eforce-inode-extended, so the layout doesn't depend on when mkfs runs (extended inodes carry each file's own mtime); - a fixed all-zero UUID; - -T0 --mkfs-time when mkfs.erofs supports it (erofs-utils 1.8+), which fixes only the superblock's build time and keeps file mtimes. The minimum stays 1.7, where builds share the layout but not the build time. The image cache format goes to 4 so cached images are rebuilt this way. mkfs.erofs --help is now probed once per binary (_mkfs_erofs_help). Signed-off-by: Sunny Song <[email protected]>
…ilds Signed-off-by: Sunny Song <[email protected]>
…ts and tmp Signed-off-by: Sunny Song <[email protected]>
Signed-off-by: Sunny Song <[email protected]>
Review: ray-project#67484 (review) - image_utils.py: zero mtimes only for the root and the exact canonical paths Ray created (seeds, missing parents, implied layer dirs) instead of matching static mount point names, so shipped entries keep their archived mtimes and seeds placed through symlinks are covered (ray-project#67484 (comment)) - image_utils.py: record every directory Ray creates, missing parents included, and set created dirs to 0755, stub files to 0644 and the rootfs dir to 0755 regardless of the umask (ray-project#67484 (comment)) - image_utils.py: give parent dirs a layer implies without an entry mode 0755 and mtime 0 unless a later entry ships them, and restore the mtimes of existing dirs a later layer adds to or whites out in (ray-project#67484 (comment)) - image_utils.py, conftest.py: include the mkfs.erofs -V version in the cache marker so an erofs-utils upgrade rebuilds cached images; the fake mkfs.erofs answers -V (ray-project#67484 (comment)) - sandboxes.md: state that byte-identical builds need the same erofs-utils version on every node (ray-project#67484 (comment)) - sandboxes.md: split the Container images paragraph into short paragraphs and a list (ray-project#67484 (comment)) - test_image_utils.py: cover images without /etc, seeds through tmp and etc symlinks, implied parents, multi-layer dir mtimes, shipped mount points, a 0077 umask, and the versioned marker (ray-project#67484 (comment)) Signed-off-by: Sunny Song <[email protected]>
Review: ray-project#67484 (review) - image_utils.py: extraction records each shipped file's and directory's archived permission bits, and the image build applies them through _owner_filter instead of the modes on disk. Mode-0000 entries such as /etc/shadow and 0000 directories no longer pick up the worker's umask, so builds match across umasks and stay unreadable to other users. On disk, extracted files always keep owner read access (whatever the archived mode or umask), so a non-root worker can read 0000 or 4111 files for the build. ray-project#67484 (comment) - image_utils.py: _mkfs_erofs_version takes the version from the first line even when mkfs.erofs exits non-zero, as erofs-utils 1.7 does after printing it for -V. ray-project#67484 (comment) Signed-off-by: Sunny Song <[email protected]>
- image_utils.py: _seed_tmp drops /tmp's archived mode from the recorded modes after making it 1777, so a /tmp the image ships with another mode (or one it names through a symlink) is still world-writable and sticky in the image. The keep file stops runsc from mounting a tmpfs over it. ray-project#67484 (comment) Signed-off-by: Sunny Song <[email protected]>
- Hardlinks take their target's recorded mode and owner instead of the ones in their own header. Tar writers may leave a hardlink's mode at 0, and the re-pack walks names in sorted order, so a link that sorts before its target was emitted as the file with mode 0, leaving both names unexecutable. The owner had the same order dependence. A link whose target has no record drops any stale record of its own name. (ray-project#67484 (comment)) Signed-off-by: Sunny Song <[email protected]>
30cad59 to
ab06773
Compare
Description
Split out of #66471 in review (comment).
gVisor restores a checkpointed sandbox only onto an EROFS root filesystem whose superblock matches the one it was saved with. Any other superblock makes it panic with "superblock mismatch detected on restore". Today two builds of the same image differ:
mkfs.erofswrites a random UUID and the current time into the superblock.So a checkpoint can't be restored on another node, or on the same node once its cached image is evicted and rebuilt.
build_erofs_imagenow passes:-Eforce-inode-extended, so the layout doesn't depend on when mkfs runs. Extended inodes carry each file's own mtime.-U00000000-0000-0000-0000-000000000000).-T0 --mkfs-timewhenmkfs.erofs --helplists it (erofs-utils 1.8+). This fixes only the superblock's build time and keeps file mtimes. The minimum version stays 1.7. There, builds share the layout but not the build time, and [core][sandbox] Add checkpoint/restore, pause/resume support using runsc #66471's restore-time superblock check reports the mismatch clearly instead of letting gVisor panic.The image cache format goes from 3 to 4, so cached images are rebuilt this way.
mkfs.erofs --helpis now probed once per binary.This PR doesn't depend on #66471 and merges cleanly with it.
Related issues
Split from #66471. Needed by the cross-node restore follow-up.
Additional information
TEST_SANDBOX=1 pytest python/ray/experimental/sandbox/tests/ --ignore=python/ray/experimental/sandbox/tests/test_sandbox.pygave 213 passed, 21 failed. The 21 failures are identical onmasteron the same machine, which lacksmkfs.erofsandrunsc. New and updated tests cover file mtimes surviving into the image, the-Eforce-inode-extendedflag, the absence of-Twithout--mkfs-time, and-T0 --mkfs-timewith amkfs.erofsthat supports it.pre-commit run --files <changed files>passes.Tested with 67485 stacked together: