Skip to content

Commit 9b1ffd3

Browse files
authored
fix(supervisor): report why the pool could not place a sandbox (ai-openshell#4985)
A launch the supervisor pool could not place was refused as AssignmentError::Capacity, so a pool with no attached member, a pool not ready yet, and a placement failure all surfaced as "the shared supervisor has no capacity for another sandbox instance". Add LaunchError::Unplaced carrying the pool's reason, and report a pool with no live member as having no attached replica instead of no replica with room. Capacity refusals of a full host are unchanged. Signed-off-by: divesh <dgude@nvidia.com>
1 parent 3a512d2 commit 9b1ffd3

5 files changed

Lines changed: 36 additions & 24 deletions

File tree

‎crates/openshell-driver-kubernetes/src/driver.rs‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3863,11 +3863,15 @@ impl KubernetesComputeDriver {
38633863
.await
38643864
.map_err(|error| match error {
38653865
LaunchError::Persist(error) => error,
3866-
// The host is at capacity; the create fails before
3867-
// its workload runs.
3866+
// The host is at capacity, or the pool could not
3867+
// place the instance; the create fails before its
3868+
// workload runs.
38683869
LaunchError::Refused(error) => {
38693870
KubernetesDriverError::Precondition(error.to_string())
38703871
}
3872+
LaunchError::Unplaced(reason) => {
3873+
KubernetesDriverError::Precondition(reason)
3874+
}
38713875
LaunchError::Invalid(error) => {
38723876
KubernetesDriverError::Message(error.to_string())
38733877
}

‎crates/openshell-server/README.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ replica, independent of which replica runs the compute driver's watch:
7171
the owner record, charges the member's capacity, and publishes the
7272
`Admitting` record, conditioned on that record's version, so an owner always
7373
has its published instance and a removed record never gains one. A member at
74-
its 256-instance capacity is skipped. With no live member with room the
75-
launch is refused as a capacity refusal: it removes the admitting record it
76-
created, only at the version it created (a concurrent launch of the same
74+
its 256-instance capacity is skipped. With no live member, or none with
75+
room, the launch is refused with that reason: it removes the admitting
76+
record it created, only at the version it created (a concurrent launch of the same
7777
generation that admitted it first wins), and then that record's candidate
7878
and material; a removal that fails is left to fencing. One
7979
`supervisor_instance_owner` record per instance names the member, its

‎crates/openshell-server/src/supervisor_pool.rs‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,6 +1865,9 @@ impl SupervisorPool {
18651865
.await
18661866
.map_err(|error| format!("read supervisor pool capacity: {error}"))?,
18671867
);
1868+
if members.is_empty() {
1869+
return Err("no shared supervisor replica is attached to the gateway".to_string());
1870+
}
18681871
let ring = ring_of(&members);
18691872
let targets = candidates(
18701873
&ring,
@@ -3267,12 +3270,14 @@ mod tests {
32673270
assert_eq!(view.members.len(), 3);
32683271
// With no live member a launch is refused before its workload runs.
32693272
let empty = Fixture::new().await;
3273+
let refused = empty
3274+
.replica("gw-b")
3275+
.place_launch(launch("rt-route-none", "sandbox-x", "generation-1"))
3276+
.await
3277+
.unwrap_err();
32703278
assert!(
3271-
empty
3272-
.replica("gw-b")
3273-
.place_launch(launch("rt-route-none", "sandbox-x", "generation-1"))
3274-
.await
3275-
.is_err()
3279+
refused.contains("no shared supervisor replica is attached"),
3280+
"{refused}"
32763281
);
32773282
}
32783283

‎crates/openshell-supervisor-control/README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ re-implementing the control contracts.
6666
only then assigns the instance; a host at capacity is refused before the
6767
workload runs. For a pool, the gateway's installed `InstancePlacement`
6868
durably records the instance and its launch term's owner before the
69-
assignment, and a launch no member can take is refused like a full host
70-
(`LaunchError::Refused`). A pool's withdrawals are removed from the durable
69+
assignment, and a launch no member can take fails with the pool's reason
70+
(`LaunchError::Unplaced`). A pool's withdrawals are removed from the durable
7171
records by the gateway, and a recovery reconciles those records with the
7272
driver's listing instead of replacing the desired set. `begin_recovery` captures
7373
the revision before the driver lists its durable records and

‎crates/openshell-supervisor-control/src/coordinator.rs‎

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,16 @@ pub enum LaunchError<E> {
4848
/// The driver could not persist the launch material; nothing was assigned.
4949
#[error("{0}")]
5050
Persist(E),
51-
/// The host, or every member of a pool, is at capacity or unavailable.
51+
/// The host is at capacity. The material was persisted; the caller rolls
52+
/// the generation back before its workload runs.
53+
#[error("{0}")]
54+
Refused(AssignmentError),
55+
/// The pool could not place the instance: it is not ready, no member is
56+
/// attached or has room, or its records could not be read or written.
5257
/// The material was persisted; the caller rolls the generation back
5358
/// before its workload runs.
5459
#[error("{0}")]
55-
Refused(AssignmentError),
60+
Unplaced(String),
5661
}
5762

5863
/// A new pool instance to record durably before it is assigned.
@@ -196,10 +201,10 @@ impl SharedSupervision {
196201
/// assign the instance so the host starts it. The launch material is
197202
/// persisted first so a restarted gateway recovers the assignment from the
198203
/// generation's own records. The pool records the instance durably for
199-
/// every gateway replica, on a live member with room; without one, or
200-
/// beyond the pool's capacity, the launch is refused as
201-
/// [`LaunchError::Refused`], so the caller fails its create before the
202-
/// workload runs. An identical assignment changes nothing.
204+
/// every gateway replica, on a live member with room; without one the
205+
/// launch fails as [`LaunchError::Unplaced`], and beyond the pool's
206+
/// capacity as [`LaunchError::Refused`], so the caller fails its create
207+
/// before the workload runs. An identical assignment changes nothing.
203208
pub async fn launch<E, F>(
204209
&self,
205210
registration: &SandboxInstanceRegistration,
@@ -218,11 +223,9 @@ impl SharedSupervision {
218223
// any member is assigned it, so every gateway replica serves it and a
219224
// later failure of that member is recovered by takeover.
220225
let Some(placement) = self.controller.placement() else {
221-
tracing::warn!(
222-
route = %registration.route,
223-
"the supervisor pool is not ready to place sandbox instances"
224-
);
225-
return Err(LaunchError::Refused(AssignmentError::Capacity));
226+
const NOT_READY: &str = "the supervisor pool is not ready to place sandbox instances";
227+
tracing::warn!(route = %registration.route, "{NOT_READY}");
228+
return Err(LaunchError::Unplaced(NOT_READY.to_string()));
226229
};
227230
if let Err(error) = placement
228231
.place_launch(PlacementRequest {
@@ -237,7 +240,7 @@ impl SharedSupervision {
237240
%error,
238241
"could not place a shared sandbox instance in the supervisor pool"
239242
);
240-
return Err(LaunchError::Refused(AssignmentError::Capacity));
243+
return Err(LaunchError::Unplaced(error));
241244
}
242245
let route = assignment.route.clone();
243246
self.controller.assign(assignment).map_err(|error| {

0 commit comments

Comments
 (0)