Skip to content

[core][sandbox] Publish warm pools to a store so callers on any actor find ready sandboxes - #67728

Open
xyuzh wants to merge 39 commits into
ray-project:masterfrom
xyuzh:sandbox-warm-pool-store
Open

xyuzh wants to merge 39 commits into
ray-project:masterfrom
xyuzh:sandbox-warm-pool-store

Conversation

@xyuzh

@xyuzh xyuzh commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Description

Stacked on #67077: this PR's own commits are 08fe650, 4d402b8 and 883a9ad (review fixes), about 1,300 lines on top of #67077's head.

A warm pool belongs to the SandboxRuntime that boots it, and only that runtime's creates take its sandboxes. With pools on many actors, a caller can't tell which actor has a sandbox ready. This adds a store that the pools publish to:

  • SandboxRuntime(warm_pool=..., warm_pool_store=store) publishes every sandbox its pool holds, ready or claimed, with its host, profile name, slot, state and node. It publishes whenever that changes (coalesced, at most every 50 ms) and every 10 s. Each publish replaces the host's records, records expire 30 s after the last one, and closing the pool removes them.
  • Callers call store.ready(profile) and send their create to a host that has one, naming the record's sandbox: create(..., warm_sandbox=entry.sandbox_id) takes that sandbox while it's still ready. A caller that sends one create per record then never sends a host more creates than it has ready, even when the store lags a publish (example in the docs). Without it, a host hands out any ready sandbox, so the caller can't tell which listed one a create took.
  • WarmPoolStore has two methods, publish(host, entries) and ready(profile), so a database can keep the records; the docs show a Postgres one. RayWarmPoolStore keeps them in a detached actor, which the hosts' next publishes refill if it restarts.
  • The store is an index, not the claim authority. Only the host hands out its sandboxes, and only ones still ready on it, so a stale record costs a cold boot, never a sandbox handed to two creates. Stores need no transactions or leases, and correctness doesn't depend on them.
  • Profiles can have a name (default: the image). A runtime publishes as its actor's name unless warm_pool_host says otherwise. An actor without a name has to pass one, since callers reach a host by the name it publishes.

With #67077's fixed-size pools, a slot's record keeps its (host, profile, slot) while new sandboxes boot in it, so a database can treat each slot as a permit.

Related issues

Follows #67077.

Additional information

  • Not a duplicate: the only open PR matching "warm pool sandbox" is [core][sandbox] Keep sandboxes booted with SandboxRuntime warm pools #67077.
  • Tests: test_warm_pool_store.py has 18 tests: publish states and slots, profile names, heartbeats, a failing store, host names (also while a closed pool's last publish is in flight), a SQLite store, RayWarmPoolStore across hosts, after its actor is killed and while it can't answer, creates routed through named host actors, and creates that name listed sandboxes getting exactly those; test_sandbox_runtime.py adds test_a_create_takes_the_warm_sandbox_it_names. The store tests now shut down a Ray session an earlier test left running. With test_sandbox_runtime.py and test_sandbox_config.py: 97 passed in a ray 2.58 venv with the package linked. At 31a89f5 ([core][sandbox] Keep sandboxes booted with SandboxRuntime warm pools #67077 and master a83e55e merged in), the real-gVisor suites in a privileged container (aarch64, runsc release-20261026.0, erofs-utils 1.9.4), test_warm_pool_store.py included: 512 passed, 25 skipped, and the same two GPU failures as master (473 passed); on a 352-CPU NVIDIA Vera node, test_warm_pool_store.py 12 passed and the other sandbox suites match. pre-commit and the API parameter coverage check pass.
  • On that Vera node, 8 host actors with pools of 64/32/16/8/4/2/1/1 and 128 creates at once from 64 threads: creates routed by the store got a pooled sandbox for 116-127 of 128 with either store (Ray's, or a SQLite database every process opens), against 57-72 sent to random hosts, and the burst's p99 fell from about 3 s to 7 ms with Ray's store.
  • I used Claude Code to help write and test this change.

xyuzh added 5 commits October 22, 2026 15:01
Callers that drive SandboxRuntime directly, such as actors that create
sandboxes in bursts, pay a gVisor boot on every create.

`SandboxRuntime(warm_pool=[...])` takes profiles, each the create()
arguments of one boot configuration plus a pool `size`, and keeps that
many sandboxes booted per profile, a few boots at a time. A create
whose boot-time arguments match a profile takes a booted sandbox at
once and a replacement boots in the background. The create's `env` goes
on every command the sandbox runs, and its TTL starts at the create.
`wait_for_warm_pool()` waits for full pools, and `close()` deletes the
sandboxes the pool still holds. A profile whose boot fails boots no
replacements for 30 s, and two profiles that boot the same sandboxes
are refused.

The pool never hands out a sandbox that died while it waited, because
the gVisor backend's `get_status` reports one whose launch process
exited (ray-project#66932).

Signed-off-by: xyuzh <[email protected]>
A failed boot pauses a profile's refills for a while, and only __init__
and take() refilled. So after one failed boot during the initial fill,
nothing booted the missing sandbox again, and wait_for_warm_pool timed
out even once the pause was over and the other boots had succeeded.

wait_for_warm_pool now refills every profile while it waits. Refills
still respect the pause.

Signed-off-by: xyuzh <[email protected]>
…pool

Review follow-ups:

- A sandbox taken from the warm pool booted with the profile's env and
  TTL. The backend now takes the create's config (assign_config), with
  its env on top of the boot's, and runs every command with that env.
  Sandbox.get_config(), the backend's own exec_command and checkpoints
  all see the create's config, and the runtime keeps no env of its own.
- Boots run on a 4-worker executor instead of a thread each parked on a
  semaphore, wait_for_warm_pool waits on a condition instead of polling,
  and a timer refills a profile once the pause after a failed boot is
  over. Boots still queued when one fails are skipped until then.

Signed-off-by: xyuzh <[email protected]>
…t taken

A profile's size is now the number of sandboxes it holds, ready or in use.
Taking a sandbox no longer boots a replacement: its slot stays claimed
until the sandbox is deleted, by delete, its TTL, or a checkpoint that
stops it, and only then does the pool boot a new sandbox in it. So a pool
never holds more than its size, and a create that finds none ready boots
cold, outside the pool, as before.

The pool keeps one slot per sandbox: empty, booting, ready, claimed, or
deleting (a ready sandbox that died, deleted before its slot boots again).
wait_for_warm_pool waits until every slot holds a sandbox, ready or in use.
close deletes the ready sandboxes and leaves the claimed ones, whose
deletes then boot nothing. A boot that ends after close deletes its
sandbox and logs a failed delete instead of losing it in the boot thread.

Signed-off-by: xyuzh <[email protected]>
@xyuzh
xyuzh requested a review from a team as a code owner November 3, 2026 06:23
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

…to a create

If assign_config fails after take claimed a sandbox (it died in between,
say), nothing held the sandbox's ID, so its slot stayed claimed and the
pool shrank for good. The create now deletes it, which boots a new one in
its slot, and boots cold itself.

Signed-off-by: xyuzh <[email protected]>
@xyuzh
xyuzh force-pushed the sandbox-warm-pool-store branch from b8a67bc to 4f56d3c Compare November 3, 2026 06:33

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

@ray-gardener ray-gardener Bot added docs An issue or change related to documentation core Issues that should be addressed in Ray Core labels Nov 3, 2026
xyuzh added 2 commits November 2, 2026 23:55
Signed-off-by: xyuzh <[email protected]>

# Conflicts:
#	doc/source/core/sandboxes.md
Master added SandboxConfig.gpu_ids and mounts, which are fixed when a
sandbox boots, so a create takes a pooled sandbox only if they match.

Signed-off-by: xyuzh <[email protected]>
…r find ready sandboxes

A warm pool belongs to the SandboxRuntime that boots it, and only that
runtime's creates take its sandboxes. With pools on many actors, a caller
couldn't tell which actor had a sandbox ready.

SandboxRuntime takes a warm_pool_store. The runtime publishes every
sandbox its pool holds, ready or claimed, with its host, profile name,
slot and node, whenever that changes (coalesced) and every 10 seconds.
Each publish replaces the host's records, which expire 30 seconds after
the last one, and closing the pool removes them. Callers ask the store
for a profile's ready sandboxes and send their create to that host.

Only the runtime hands its sandboxes out, and only those still ready on
it, so a store that lags or loses records never hands a sandbox out
twice: a create sent on a stale record boots cold. A store needs just
publish(host, entries) and ready(profile), so a database can hold the
records. RayWarmPoolStore keeps them in a detached actor, which the hosts'
next publishes refill if it restarts.

Profiles can carry a "name", which defaults to the image. A runtime
publishes as its actor's name or ID unless warm_pool_host says otherwise.

Signed-off-by: xyuzh <[email protected]>
@xyuzh
xyuzh force-pushed the sandbox-warm-pool-store branch from 706466b to 08fe650 Compare November 3, 2026 15:01
xyuzh added a commit to xyuzh/enhancements that referenced this pull request Nov 3, 2026

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

Docs review from Douglas Strodtman on the Ray docs team, assisted by Claude Code. I've read every comment here and stand behind each one.

Scope: style, grammar, and docs conventions only, against Ray's writing-style guide. Technical accuracy and final approval belong to the Core maintainers. Every suggestion keeps the existing claims as written and changes only wording and structure.

This branch sits on #67077, so the sandboxes.md diff also contains the "Keep sandboxes booted with a warm pool" section. I reviewed that section on #67077 and haven't repeated those comments here. This review covers only the new "store" subsection and the API reference entries. The API reference additions look good as written.

The new subsection explains the routing model clearly, and the Postgres example is a useful template. My suggestions split the two dense paragraphs and replace "create" used as a noun with "create call." No objection from the docs side.

Comment thread doc/source/core/sandboxes.md Resolved
Comment thread doc/source/core/sandboxes.md Resolved
Comment thread doc/source/core/sandboxes.md Resolved
Comment thread doc/source/core/sandboxes.md Resolved
xyuzh added 5 commits November 5, 2026 18:12
…point ends it

A checkpoint with leave_running=False freed the sandbox's warm-pool slot
only after checkpoint_sandbox returned. If it raised after the backend
had deleted the sandbox, or after it stopped the sandbox and couldn't
restore it, the slot stayed claimed and the profile stayed one sandbox
short. Now a failed stop-checkpoint frees the slot when the sandbox is
terminated. A sandbox that still runs keeps its slot until it's deleted.

Signed-off-by: xyuzh <[email protected]>
Applies the docs review's suggestions.

Signed-off-by: xyuzh <[email protected]>
Signed-off-by: xyuzh <[email protected]>

ray-project#67688 added SandboxConfig.oom_score_adj, which the launch applies to the sandbox's processes, so a pooled sandbox can stand in only for creates that ask for the same score. test_boot_key_covers_every_boot_time_field caught it.
Applies the docs review's suggestions.

Signed-off-by: xyuzh <[email protected]>

@xyuzh xyuzh left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks for the review, Douglas. I also merged #67077's new heads into this branch (c26d422, f2b6a89, 31a89f5), which brings in master and its warm pool fixes, and clears the Read the Docs failure that master's docs build caused at the old base (fixed on master by #67741).

Comment thread doc/source/core/sandboxes.md Resolved
Comment thread doc/source/core/sandboxes.md Resolved
Comment thread doc/source/core/sandboxes.md Resolved
Comment thread doc/source/core/sandboxes.md Resolved
xyuzh added 8 commits November 8, 2026 22:46
GitHub sent no webhooks for 8b92c6b, so no checks ran on it.

Signed-off-by: xyuzh <[email protected]>
The jobs that failed in microcheck build 58569 failed only on downloads from GitHub during GitHub's incident on 2026-11-09.

Signed-off-by: xyuzh <[email protected]>
The jobs that failed in microcheck build 58560 failed only on downloads from GitHub during GitHub's incident on 2026-11-09.

Signed-off-by: xyuzh <[email protected]>
microcheck build 58575 failed before running tests: GitHub's incident on 2026-11-09 still blocked downloads from CI then. It's resolved now.

Signed-off-by: xyuzh <[email protected]>
microcheck build 58576 failed before running tests: GitHub's incident on 2026-11-09 still blocked downloads from CI then. It's resolved now.

Signed-off-by: xyuzh <[email protected]>
…-pool key

ray-project#67974 made a GPU sandbox's NVIDIA_DRIVER_CAPABILITIES (from the create's
env) set runsc's --nvproxy-allowed-driver-capabilities at boot. The warm
pool treats env as per-create, so a GPU sandbox booted with the default
capabilities could serve a create that asks for profiling. The boot key
now includes that variable for GPU sandboxes; other env stays per-create.

Signed-off-by: xyuzh <[email protected]>
Comment on lines +89 to +104
def _default_host() -> str:
"""The current actor's name, else its ID, else this host and process."""
try:
import ray

if ray.is_initialized():
context = ray.get_runtime_context()
name = context.get_actor_name()
if name:
return name
actor_id = context.get_actor_id()
if actor_id:
return actor_id
except Exception:
pass
return f"{socket.gethostname()}:{os.getpid()}"

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.

_default_host() falls back to actor_id (which ray.get_actor() rejects with ValueError) and omits context.namespace on named actors, so unnamed actors publish unroutable host strings and same-named actors in different namespaces overwrite each other in the singleton RayWarmPoolStore.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed for unnamed actors in 883a9ad: with a store, an actor without a name has to pass warm_pool_host, and the constructor raises a ValueError that says so, since there's no name ray.get_actor could resolve. For namespaces I documented the rule rather than change the default: a store keeps one set of records for each host name, so actors that share a name across namespaces need a warm_pool_host each. Putting the namespace into the default would break the ray.get_actor(entry.host) lookup for everyone else. Test: test_an_actor_without_a_name_needs_a_host_to_publish.

Comment on lines +180 to +188
def _call(self, method: str, *args):
try:
return ray.get(getattr(self._directory(), method).remote(*args))
except ray.exceptions.RayActorError:
# The actor is gone for good, say killed without a restart: start
# a new one, which the hosts' next publishes fill.
self._actor = None
return ray.get(getattr(self._directory(), method).remote(*args))

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.

While _WarmPoolDirectory is restarting, the immediate retry raises ActorUnavailableError out of ready() (failing caller create instead of falling back to cold boot), ray.get has no timeout if the directory node hangs, and concurrent callers race mutating self._actor.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 883a9ad: every call to the directory has a 10 s timeout, only an ActorDiedError makes a new actor, and ready() and entries() return nothing, with a warning, while the actor restarts or doesn't answer, so a caller boots cold instead of failing its create. publish() still raises, which the pool's publisher logs and retries at its next publish. The unlocked self._actor assignment yields two handles to one named actor at worst, so I left it. Test: test_a_ray_store_that_cant_answer_lists_nothing.

Comment on lines +116 to +122
def ready(self, profile: str) -> List[WarmPoolEntry]:
self._drop_expired()
return [
entry
for entries in self._ready.get(profile, {}).values()
for entry in entries
]

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.

Returning the same ordered ready() snapshot to every caller during the 50ms publish window makes concurrent callers stampede onto entry[0].host. Have you considered an optimistic claim(profile, limit=1) method on WarmPoolStore (or shuffling/round-robining hosts in ready())?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done with a shuffle in 883a9ad: RayWarmPoolStore.ready() returns the entries in random order, and the WarmPoolStore contract now says the order is unspecified, so callers that each take the first entry spread over the hosts (test_ray_warm_pool_store_spreads_callers_over_hosts). I didn't add claim(): the store is an index and the host is the only authority on claims, which is what lets a store work without transactions or leases. A caller that loses the race boots cold on that host.

Comment on lines +437 to +453
def entries(self, expires_at: float) -> List[WarmPoolEntry]:
"""The pool's ready and claimed sandboxes. The caller holds the lock."""
return [
WarmPoolEntry(
host=self._host,
profile=self._names[key],
slot=slot.index,
sandbox_id=slot.sandbox_id,
state=slot.state,
node_id=self._node_id,
since=slot.since,
expires_at=expires_at,
)
for key, slots in self._slots.items()
for slot in slots
if slot.state in (_READY, _CLAIMED)
]

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.

Have you considered publishing only READY entries (or adding entries() to the WarmPoolStore ABC if claimed-slot inspection is part of the contract), so SQL-backed stores don't rewrite all claimed rows on every state change?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not changing this: claimed sandboxes are part of what a pool publishes, so a reader can tell a host whose pool is in use from one that's gone, and a slot keeps its record across the sandboxes that boot in it. A publish replaces its host's records as a whole, at most once per 50 ms for each host, so a SQL store does one delete and insert per publish whatever the mix of states. entries() stays on RayWarmPoolStore because reading claimed records back isn't needed to route creates.

Comment on lines +255 to +263
preferred = self._held.get(prefer) if prefer is not None else None
if (
preferred is not None
and preferred.key == key
and preferred.state == _READY
):
ready.remove(preferred)
ready.appendleft(preferred)
while ready and taken is None:

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.

Claiming preferred directly instead of ready.remove(preferred) + appendleft avoids an O(pool_size) deque scan while line 265 already skips non-_READY entries.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not changing this: claiming the preferred slot directly would leave its old place in the queue behind, and when callers always name a sandbox nothing ever pops those places, so the queue would grow by one per create. The scan is over at most size slots, 2.7 µs for a pool of 500 and 26 µs for 5,000 on my machine.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

…warm pool's cleanup

- A create that matches a profile gets the profile's env under its own
  whether it takes a booted sandbox or boots cold. A cold one used to get
  only its own, so a create's env depended on load.
- A profile matches every spelling of its image.
- Sandboxes that died while ready are deleted on a few threads, not one
  thread each.
- close() waits for the boots under way and those deletes, so the pool
  holds nothing once it returns.
- A failed boot pauses its profile for a second, then twice as long after
  each failure that follows, up to 30 s. Boots that fail together cause
  one pause.
- BaseSandboxBackend declares assign_config.

Signed-off-by: xyuzh <[email protected]>
… safe while the store restarts

- Profile names must differ only when a store records them. A pool that
  publishes nowhere may hold several profiles of one image again.
- An actor without a name must pass warm_pool_host to publish: callers
  reach a host by the name it publishes, and Ray finds only named actors.
- A host name is reserved per store, so pools that publish to different
  stores may share one. A pool that fails to start frees its name.
- RayWarmPoolStore.ready() lists nothing while its actor can't answer,
  with a timeout, so a caller boots cold instead of failing its create.
- ready() returns entries in a shuffled order, so callers that each take
  the first one spread over the hosts.
- The publisher waits out its pause on a condition, so close() doesn't
  wait for it.

Signed-off-by: xyuzh <[email protected]>

@xyuzh xyuzh left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks for the review. 883a9ad addresses the profile names, the default host, the store's behaviour while its actor restarts, the host reservation, the stampede and the publisher's pause. It also carries #67077's review fixes, merged in. Two points are answered inline without a change.

Comment on lines +89 to +104
def _default_host() -> str:
"""The current actor's name, else its ID, else this host and process."""
try:
import ray

if ray.is_initialized():
context = ray.get_runtime_context()
name = context.get_actor_name()
if name:
return name
actor_id = context.get_actor_id()
if actor_id:
return actor_id
except Exception:
pass
return f"{socket.gethostname()}:{os.getpid()}"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed for unnamed actors in 883a9ad: with a store, an actor without a name has to pass warm_pool_host, and the constructor raises a ValueError that says so, since there's no name ray.get_actor could resolve. For namespaces I documented the rule rather than change the default: a store keeps one set of records for each host name, so actors that share a name across namespaces need a warm_pool_host each. Putting the namespace into the default would break the ray.get_actor(entry.host) lookup for everyone else. Test: test_an_actor_without_a_name_needs_a_host_to_publish.

Comment on lines +180 to +188
def _call(self, method: str, *args):
try:
return ray.get(getattr(self._directory(), method).remote(*args))
except ray.exceptions.RayActorError:
# The actor is gone for good, say killed without a restart: start
# a new one, which the hosts' next publishes fill.
self._actor = None
return ray.get(getattr(self._directory(), method).remote(*args))

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 883a9ad: every call to the directory has a 10 s timeout, only an ActorDiedError makes a new actor, and ready() and entries() return nothing, with a warning, while the actor restarts or doesn't answer, so a caller boots cold instead of failing its create. publish() still raises, which the pool's publisher logs and retries at its next publish. The unlocked self._actor assignment yields two handles to one named actor at worst, so I left it. Test: test_a_ray_store_that_cant_answer_lists_nothing.

Comment on lines +116 to +122
def ready(self, profile: str) -> List[WarmPoolEntry]:
self._drop_expired()
return [
entry
for entries in self._ready.get(profile, {}).values()
for entry in entries
]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done with a shuffle in 883a9ad: RayWarmPoolStore.ready() returns the entries in random order, and the WarmPoolStore contract now says the order is unspecified, so callers that each take the first entry spread over the hosts (test_ray_warm_pool_store_spreads_callers_over_hosts). I didn't add claim(): the store is an index and the host is the only authority on claims, which is what lets a store work without transactions or leases. A caller that loses the race boots cold on that host.

Comment on lines +437 to +453
def entries(self, expires_at: float) -> List[WarmPoolEntry]:
"""The pool's ready and claimed sandboxes. The caller holds the lock."""
return [
WarmPoolEntry(
host=self._host,
profile=self._names[key],
slot=slot.index,
sandbox_id=slot.sandbox_id,
state=slot.state,
node_id=self._node_id,
since=slot.since,
expires_at=expires_at,
)
for key, slots in self._slots.items()
for slot in slots
if slot.state in (_READY, _CLAIMED)
]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not changing this: claimed sandboxes are part of what a pool publishes, so a reader can tell a host whose pool is in use from one that's gone, and a slot keeps its record across the sandboxes that boot in it. A publish replaces its host's records as a whole, at most once per 50 ms for each host, so a SQL store does one delete and insert per publish whatever the mix of states. entries() stays on RayWarmPoolStore because reading claimed records back isn't needed to route creates.

Comment on lines +255 to +263
preferred = self._held.get(prefer) if prefer is not None else None
if (
preferred is not None
and preferred.key == key
and preferred.state == _READY
):
ready.remove(preferred)
ready.appendleft(preferred)
while ready and taken is None:

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not changing this: claiming the preferred slot directly would leave its old place in the queue behind, and when callers always name a sandbox nothing ever pops those places, so the queue would grow by one per create. The scan is over at most size slots, 2.7 µs for a pool of 500 and 26 µs for 5,000 on my machine.

… works

A boot that failed left its profile paused, and its slot empty, until the
pause's timer fired, even when another boot of the same wave had worked.
A boot that works now clears the pause and refills the profile at once.

Signed-off-by: xyuzh <[email protected]>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

…t boot

A boot that failed, or was skipped for a pause, emptied its slot in a
second step. A boot that worked in between ended the pause, cancelled its
timer and refilled, and missed that slot, which then stayed empty until a
later delete. The boot now empties its slot and either leaves it to the
pause's timer or refills at once, under one lock.

Signed-off-by: xyuzh <[email protected]>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit e65fd85. Configure here.

if paused_for > 0:
self._refill_later(slot.key, paused_for)
else:
refill = not self._closed

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Mixed boot wave restarts pause

Medium Severity

A successful warm-pool boot only clears backoff if a failure was already recorded. When a sibling from the same wave fails afterward, failed still sees no pause and starts one, so empty slots wait out the delay instead of refilling at once. Concurrent boots of a working image can therefore stall for 1–30s, and _failures grows as if the profile could not boot.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit e65fd85. Configure here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not changing this: a failure that comes after a sibling's success is still the newest thing known about the profile, so it gets the shortest pause, 1 s, before that slot boots again. The pause only grows when the retry fails too with no working boot in between, because any boot that works clears the count (test_a_boot_that_works_ends_its_profiles_pause, test_a_failing_profile_pauses_longer_after_each_failure). So a working image waits at most 1 s for the slot whose boot failed, and a node that can hold only part of a pool backs off instead of retrying the rest in a loop.

pcmoritz pushed a commit that referenced this pull request Nov 18, 2026
## Description

`readonly=True` is the default today, and it buys little. A read-only
sandbox boots no faster than a writable one (27 ms both), and it's
slower once it does anything: with an explicit `workdir` it needs a
kernel overlay and takes 87 ms to create, and Python's stdlib imports
take 203 ms instead of 45 ms because nothing can cache `.pyc` files. On
a worker that can't mount a kernel overlay, a read-only sandbox with a
`workdir` already ran writable, with a warning. The mode also needs
special cases across the package, which keep complicating other sandbox
PRs.

This PR removes the option. Every sandbox writes to a private overlay
over its cached image, which is discarded with the sandbox. That
deletes:

- the host-backed scratch `workdir` and the `/tmp` tmpfs,
- the kernel overlay for missing mount points and the writable-root
fallback (`needs_rootfs_overlay` is hooks only now),
- `_seed_mountpoints` in the image build, since runsc creates mount
points in the sandbox's overlay,
- the `workdir` branches in `disk` capping (`--overlay2 all:`),
checkpoint, and restore.

About 600 lines net. Read `image_manager.py` and `backend/gvisor.py`
first. Most of the rest is tests and docs.

Behavior changes:

- The root filesystem is writable by default. A `workdir` is a plain
directory in the overlay, and `/tmp` is on the root filesystem.
- `readonly=False` passed to `create()`, `restore()`, `Sandbox`, or
`SandboxRuntime` is ignored with a `RayDeprecationWarning`, and the HTTP
API ignores `readonly: false`, so callers that pass it keep working.
`readonly=True` raises a `ValueError`, and the HTTP API answers `422`,
because ignoring it would hand the caller a writable sandbox.
- `disk` works without a `workdir`, and counts the `workdir` too.
- A relative `workdir` raises a `ValueError`, or gets a `422` over HTTP,
instead of failing when the container starts.
- Restore refuses a checkpoint of a `readonly=True` sandbox, whose saved
state depends on the read-only root. Checkpoints of writable sandboxes
restore as before. Restore also refuses a different `workdir`, which
runsc rejects anyway.
- Without `disk`, any sandbox can now fill the node's disk. A node-wide
default cap is a follow-up.
- `commit()` from #67972 works on every sandbox, so its read-only check
is gone. Its new layer leaves out the mount points runsc creates when
the base image lacks them, such as an empty `/etc/hosts`.

## Related issues

None filed. This comes from review feedback that the read-only mode
complicates other sandbox PRs.

## Additional information

- Not a duplicate: no open PR removes the option. It overlaps #67810
(its `_seed_erofs_image` pass can go), #67076 (the fallback's warning),
and #67077 and #67728 (`readonly` in the warm-pool key). #67972 merged
since, and the merge with master drops its read-only check. #66782 and
#67010 pass `readonly=False`, which still works.
- Numbers: measured on master on November 9 with `python:3.10-slim`,
medians of 10 rounds.
- Tests: new tests cover the writable default, `disk` with and without a
`workdir`, the ignored `readonly=False` and the refused `readonly=True`
in Python and over HTTP, the refused read-only checkpoint, and an image
with only `/bin` and `/lib`, which boots with host mounts, `/etc/hosts`,
and `/etc/resolv.conf`. I also booted that image from a kernel overlay
with a hook, and as a non-root user.
- Tested in a privileged container with runsc release-20261026.0, as
root. `pytest python/ray/experimental/sandbox/tests`: 651 passed, 39
skipped (no GPU, `erofsfuse`, or delegated cgroup there), 3 failed. The
3 are GPU and CDI tests that fail the same way on master in that
container, whose Ray core predates `get_cdi_kind`. `pytest
python/ray/experimental/sandbox/http/tests`: 185 passed, 10 skipped. The
skipped ones are the Modal SDK tests, which passed on the first commit
with the SDK installed. pre-commit and the API param coverage lint pass.
- I used Claude Code to help write and test this change.

---------

Signed-off-by: xyuzh <[email protected]>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Issues that should be addressed in Ray Core docs An issue or change related to documentation sandbox

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants