Skip to content

Commit 44ef984

Browse files
FrostGoddrew
andauthored
fix(supervisor): guard shared supervisor pool configuration (ai-openshell#4988)
* fix(supervisor): guard shared supervisor pool configuration Raise the gateway's minimum supervisor pool recovery timeout from 10 to 30 seconds. A failed pool member takes up to about 24 seconds to detect, so a shorter deadline ended workloads another member would have adopted. The Sandbox Protocol range stays 10 to 300 seconds for compatibility. Refuse an [openshell.gateway.supervisor_pool] table during config preflight, and at startup before the compute driver is built, unless the selected driver hosts sandboxes on the shared supervisor pool. A new ComputeDriverFactory::uses_shared_supervision hook reports this; the Kubernetes factory returns true with supervisor_topology = "gateway". Widen the readiness deadline of a shared-startup supervisor test that timed out under full-workspace load. Signed-off-by: divesh <dgude@nvidia.com> * fix(gateway): require driver selection for pool preflight Signed-off-by: Drew Newberry <anewberry@nvidia.com> * docs(gateway): remove pool preflight note Signed-off-by: Drew Newberry <anewberry@nvidia.com> --------- Signed-off-by: divesh <dgude@nvidia.com> Signed-off-by: Drew Newberry <anewberry@nvidia.com> Co-authored-by: Drew Newberry <anewberry@nvidia.com>
1 parent 9b1ffd3 commit 44ef984

14 files changed

Lines changed: 213 additions & 32 deletions

File tree

‎crates/openshell-gateway/src/lib.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,13 @@ impl openshell_server::ComputeDriverFactory for KubernetesFactory {
278278
.map_err(openshell_core::Error::config)
279279
}
280280

281+
fn uses_shared_supervision(
282+
&self,
283+
context: openshell_server::ComputeDriverConfigContext<'_>,
284+
) -> openshell_core::Result<bool> {
285+
Ok(kubernetes_config(context)?.shared_supervisor.is_some())
286+
}
287+
281288
async fn build(
282289
&self,
283290
context: openshell_server::ComputeDriverBuildContext<'_>,

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

Lines changed: 105 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,16 +1013,32 @@ fn run_effective_config_preflight(
10131013
let mut selected_driver = None;
10141014
if let Some(selection) = selection.as_ref() {
10151015
validate_preflight_isolation_backend(semantic_file, selection.name())?;
1016-
selected_driver = Some(crate::validate_compute_driver_config(
1016+
let driver = crate::validate_compute_driver_config(
10171017
compute_drivers,
10181018
selection.name(),
10191019
run.name.trim(),
10201020
SocketAddr::new(run.bind_address, run.port),
10211021
&run.log_level,
10221022
driver_startup,
10231023
true,
1024-
)?);
1024+
)?;
1025+
crate::validate_supervisor_pool_consumer(
1026+
&driver,
1027+
run.name.trim(),
1028+
SocketAddr::new(run.bind_address, run.port),
1029+
&run.log_level,
1030+
driver_startup,
1031+
)?;
1032+
selected_driver = Some(driver);
10251033
} else if file.is_some() {
1034+
// Preflight cannot run driver detection probes. A pool table must
1035+
// name its consumer so this check cannot silently pass for a
1036+
// driver that will reject the table at startup.
1037+
if semantic_file.openshell.gateway.supervisor_pool.is_some() {
1038+
return Err(miette::miette!(
1039+
"openshell.gateway.supervisor_pool requires an explicit compute driver for config preflight"
1040+
));
1041+
}
10261042
// Runtime auto-detection may connect local API sockets or launch a
10271043
// bounded discovery command. Preflight must not perform those
10281044
// side effects, so validate every configured table that could be
@@ -1676,6 +1692,30 @@ mod tests {
16761692
}
16771693
}
16781694

1695+
#[derive(Clone, Copy)]
1696+
struct SharedSupervisionFactory;
1697+
1698+
#[async_trait::async_trait]
1699+
impl crate::ComputeDriverFactory for SharedSupervisionFactory {
1700+
fn supports_config_preflight(&self) -> bool {
1701+
true
1702+
}
1703+
1704+
fn uses_shared_supervision(
1705+
&self,
1706+
_context: crate::ComputeDriverConfigContext<'_>,
1707+
) -> openshell_core::Result<bool> {
1708+
Ok(true)
1709+
}
1710+
1711+
async fn build(
1712+
&self,
1713+
_context: crate::ComputeDriverBuildContext<'_>,
1714+
) -> openshell_core::Result<crate::ComputeDriverInstance> {
1715+
unreachable!("preflight must not build the selected driver")
1716+
}
1717+
}
1718+
16791719
#[derive(Clone, Copy)]
16801720
struct LegacyFactory;
16811721

@@ -2416,6 +2456,69 @@ mod tests {
24162456
});
24172457
}
24182458

2459+
#[test]
2460+
fn config_preflight_rejects_supervisor_pool_without_a_shared_supervision_driver() {
2461+
let config_home = tempfile::tempdir().unwrap();
2462+
let config = config_home.path().join("gateway.toml");
2463+
std::fs::write(
2464+
&config,
2465+
"[openshell]\nversion = 2\n\n[openshell.gateway.supervisor_pool]\nrecovery_timeout_secs = 60\n",
2466+
)
2467+
.unwrap();
2468+
let preflight = |registry: &crate::ComputeDriverRegistry| {
2469+
let (run, matches) = parse_with_args(&[
2470+
"openshell-gateway",
2471+
"--compute-driver",
2472+
"local",
2473+
"--disable-tls",
2474+
]);
2475+
super::run_config_preflight_with_drivers(
2476+
super::ConfigPreflightArgs {
2477+
path: Some(config.clone()),
2478+
..Default::default()
2479+
},
2480+
run,
2481+
&matches,
2482+
registry,
2483+
)
2484+
};
2485+
2486+
Environment::new()
2487+
.remove("OPENSHELL_GATEWAY_CONFIG")
2488+
.remove("OPENSHELL_COMPUTE_DRIVER")
2489+
.remove("OPENSHELL_DRIVERS")
2490+
.run(|| {
2491+
preflight(&test_registry("local", false))
2492+
.expect_err("a pool table without a shared supervision driver must fail");
2493+
2494+
let mut registry = crate::ComputeDriverRegistry::new();
2495+
registry
2496+
.install(
2497+
crate::ComputeDriverRegistration::new(
2498+
"local",
2499+
100,
2500+
None,
2501+
SharedSupervisionFactory,
2502+
)
2503+
.unwrap(),
2504+
)
2505+
.unwrap();
2506+
preflight(&registry).expect("a shared supervision driver consumes the pool table");
2507+
2508+
let (run, matches) = parse_with_args(&["openshell-gateway", "--disable-tls"]);
2509+
super::run_config_preflight_with_drivers(
2510+
super::ConfigPreflightArgs {
2511+
path: Some(config.clone()),
2512+
..Default::default()
2513+
},
2514+
run,
2515+
&matches,
2516+
&detected_local_registry(),
2517+
)
2518+
.expect_err("a pool table without an explicit driver cannot be preflighted");
2519+
});
2520+
}
2521+
24192522
#[test]
24202523
fn config_preflight_rejects_factory_without_side_effect_free_validation() {
24212524
let config_home = tempfile::tempdir().unwrap();

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ pub struct GatewayFileSection {
224224
#[serde(deny_unknown_fields)]
225225
pub struct SupervisorPoolConfig {
226226
/// Seconds a sandbox runtime keeps its workload frozen after losing its
227-
/// supervisor before terminating it, from 10 to 300. The pool's
227+
/// supervisor before terminating it, from 30 to 300. The pool's
228228
/// supervisors offer it to each runtime; unset offers
229229
/// [`openshell_supervisor_control::POOL_RECOVERY_TIMEOUT_SECS`].
230230
#[serde(default, skip_serializing_if = "Option::is_none")]
@@ -864,12 +864,12 @@ fn parse_and_validate(path: &Path, contents: &str) -> Result<ConfigFile, ConfigF
864864
.supervisor_pool
865865
.and_then(|pool| pool.recovery_timeout_secs)
866866
.is_some_and(|timeout| {
867-
!openshell_supervisor_control::SUPERVISOR_RECOVERY_TIMEOUT_RANGE.contains(&timeout)
867+
!openshell_supervisor_control::POOL_RECOVERY_TIMEOUT_RANGE.contains(&timeout)
868868
})
869869
{
870870
return Err(ConfigFileError::InvalidValue {
871871
field: "openshell.gateway.supervisor_pool.recovery_timeout_secs",
872-
message: "must be between 10 and 300 seconds",
872+
message: "must be between 30 and 300 seconds",
873873
});
874874
}
875875
if let Some((name, _)) = file
@@ -1970,7 +1970,14 @@ database_lock_max_connections = 0
19701970
);
19711971
// Recovery stays bounded, and unknown keys, including the removed
19721972
// `enabled` switch, are refused.
1973-
for out_of_range in ["9", "301"] {
1973+
assert_eq!(
1974+
pool("recovery_timeout_secs = 30\n")
1975+
.unwrap()
1976+
.unwrap()
1977+
.recovery_timeout_secs,
1978+
Some(30)
1979+
);
1980+
for out_of_range in ["10", "29", "301"] {
19741981
assert!(matches!(
19751982
pool(&format!("recovery_timeout_secs = {out_of_range}\n")),
19761983
Err(ConfigFileError::InvalidValue {

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

Lines changed: 57 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,6 +1456,12 @@ pub trait ComputeDriverFactory: Send + Sync {
14561456
false
14571457
}
14581458

1459+
/// Whether this configuration hosts sandboxes on the gateway's shared
1460+
/// supervisor pool. Same constraints as [`Self::validate_config`].
1461+
fn uses_shared_supervision(&self, _context: ComputeDriverConfigContext<'_>) -> Result<bool> {
1462+
Ok(false)
1463+
}
1464+
14591465
async fn build(&self, context: ComputeDriverBuildContext<'_>) -> Result<ComputeDriverInstance>;
14601466
}
14611467

@@ -1865,6 +1871,13 @@ async fn build_compute_runtime(
18651871
driver_startup,
18661872
false,
18671873
)?;
1874+
validate_supervisor_pool_consumer(
1875+
&driver,
1876+
&config.name,
1877+
config.bind_address,
1878+
&config.log_level,
1879+
driver_startup,
1880+
)?;
18681881
let telemetry_compute_driver = driver.telemetry_compute_driver(registry);
18691882
let admission = match &driver {
18701883
ConfiguredComputeDriver::Registered(registration) => registration
@@ -1905,11 +1918,7 @@ async fn build_compute_runtime(
19051918
.into_inner()
19061919
.map(|supervision| supervision.controller().clone());
19071920
if supervisor_pool.is_some() && supervisor_host.is_none() {
1908-
return Err(Error::config(
1909-
"openshell.gateway.supervisor_pool tunes the shared supervisor pool, but no \
1910-
compute driver hosts sandboxes on it; set the Kubernetes driver's \
1911-
supervisor_topology = \"gateway\" or remove the table",
1912-
));
1921+
return Err(Error::config(SUPERVISOR_POOL_WITHOUT_HOST));
19131922
}
19141923
match instance {
19151924
ComputeDriverInstance::InProcess(driver) => ComputeRuntime::from_driver(
@@ -1949,12 +1958,6 @@ async fn build_compute_runtime(
19491958
}
19501959
}
19511960
}
1952-
ConfiguredComputeDriver::Remote { .. } if supervisor_pool.is_some() => {
1953-
return Err(Error::config(
1954-
"openshell.gateway.supervisor_pool tunes the shared supervisor pool, which \
1955-
only an in-process compute driver can use; remove the table",
1956-
));
1957-
}
19581961
ConfiguredComputeDriver::Remote { name } => {
19591962
let remote_config =
19601963
compute::driver_config::remote_driver_config_from_context(driver_startup, &name)?;
@@ -2061,6 +2064,49 @@ fn validate_compute_driver_config(
20612064
Ok(driver)
20622065
}
20632066

2067+
const SUPERVISOR_POOL_WITHOUT_HOST: &str = "openshell.gateway.supervisor_pool tunes the shared \
2068+
supervisor pool, but no compute driver hosts sandboxes on it; set the Kubernetes driver's \
2069+
supervisor_topology = \"gateway\" or remove the table";
2070+
2071+
/// Refuse `[openshell.gateway.supervisor_pool]` unless the selected driver
2072+
/// hosts sandboxes on the shared supervisor pool.
2073+
fn validate_supervisor_pool_consumer(
2074+
driver: &ConfiguredComputeDriver,
2075+
gateway_name: &str,
2076+
gateway_bind_address: SocketAddr,
2077+
gateway_log_level: &str,
2078+
driver_startup: compute::driver_config::DriverStartupContext<'_>,
2079+
) -> Result<()> {
2080+
if driver_startup
2081+
.file
2082+
.is_none_or(|file| file.openshell.gateway.supervisor_pool.is_none())
2083+
{
2084+
return Ok(());
2085+
}
2086+
match driver {
2087+
ConfiguredComputeDriver::Registered(registration) => {
2088+
if registration
2089+
.factory
2090+
.uses_shared_supervision(ComputeDriverConfigContext {
2091+
driver_name: &registration.name,
2092+
gateway_name,
2093+
gateway_bind_address,
2094+
gateway_log_level,
2095+
driver_startup,
2096+
})?
2097+
{
2098+
Ok(())
2099+
} else {
2100+
Err(Error::config(SUPERVISOR_POOL_WITHOUT_HOST))
2101+
}
2102+
}
2103+
ConfiguredComputeDriver::Remote { .. } => Err(Error::config(
2104+
"openshell.gateway.supervisor_pool tunes the shared supervisor pool, which only an \
2105+
in-process compute driver can use; remove the table",
2106+
)),
2107+
}
2108+
}
2109+
20642110
fn resolve_configured_compute_driver(
20652111
registry: &ComputeDriverRegistry,
20662112
driver_name: &str,

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ use crate::proto::{
5151
/// startup fit with room to spare.
5252
pub const POOL_RECOVERY_TIMEOUT_SECS: u32 = 60;
5353

54+
/// Recovery deadlines, in seconds, a gateway may configure for its pool. The
55+
/// minimum outlasts detecting a failed member.
56+
pub const POOL_RECOVERY_TIMEOUT_RANGE: std::ops::RangeInclusive<u32> = 30..=300;
57+
5458
/// Heartbeat interval of pool members, whose liveness drives failover.
5559
pub const POOL_HEARTBEAT_INTERVAL: Duration = crate::pool_timing::HEARTBEAT_INTERVAL;
5660
/// Silence after which the gateway closes a pool member's stream.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ pub mod proto {
4040
pub use controller::{
4141
AssignmentError, ConnectedMember, HostIdentity, InstanceOwner, MAX_ASSIGNED_INSTANCES,
4242
MAX_POOL_INSTANCES, MAX_REPORTED_INSTANCES, MemberReport, MemberView, ObservedInstance,
43-
POOL_HEARTBEAT_INTERVAL, POOL_RECOVERY_TIMEOUT_SECS, PoolView, SupervisorCredential,
44-
SupervisorHostController,
43+
POOL_HEARTBEAT_INTERVAL, POOL_RECOVERY_TIMEOUT_RANGE, POOL_RECOVERY_TIMEOUT_SECS, PoolView,
44+
SupervisorCredential, SupervisorHostController,
4545
};
4646
pub use coordinator::{
4747
InstancePlacement, InstanceSupervision, LaunchError, PlacementFuture, PlacementRequest,

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,20 @@ mod tests {
118118
MEMBER_TTL * 2
119119
< Duration::from_secs(u64::from(crate::controller::POOL_RECOVERY_TIMEOUT_SECS))
120120
);
121+
assert!(
122+
GATEWAY_SILENCE_TIMEOUT
123+
+ MEMBER_REFRESH_INTERVAL
124+
+ MEMBER_TTL
125+
+ MEMBER_REFRESH_INTERVAL
126+
+ Duration::from_secs(5)
127+
<= Duration::from_secs(u64::from(
128+
*crate::controller::POOL_RECOVERY_TIMEOUT_RANGE.start()
129+
))
130+
);
131+
assert!(
132+
crate::controller::POOL_RECOVERY_TIMEOUT_RANGE
133+
.contains(&crate::controller::POOL_RECOVERY_TIMEOUT_SECS)
134+
);
121135
assert_eq!(host_backoff_bound(1), Duration::from_millis(150));
122136
assert_eq!(host_backoff_bound(10), Duration::from_millis(600));
123137
}

‎crates/openshell-supervisor/src/backend_setup/tests.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ async fn shared_startup_uses_selected_backend_through_readiness_and_shutdown() {
787787
root.path().join("tls"),
788788
)
789789
.kill_on_drop(true);
790-
let output = tokio::time::timeout(Duration::from_secs(30), child.output())
790+
let output = tokio::time::timeout(Duration::from_mins(1), child.output())
791791
.await
792792
.expect("shared startup child exceeded its deadline")
793793
.expect("run isolated shared startup test");
@@ -923,7 +923,7 @@ async fn shared_startup_uses_selected_backend_through_readiness_and_shutdown() {
923923
.deny_confirmation
924924
.store(false, Ordering::SeqCst);
925925
let observe_and_shutdown = async {
926-
tokio::time::timeout(Duration::from_secs(10), async {
926+
tokio::time::timeout(Duration::from_secs(30), async {
927927
loop {
928928
if marker.exists()
929929
&& tokio::net::UnixStream::connect(&readiness).await.is_ok()

‎deploy/helm/openshell/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ discovery endpoint or its TLS CA.
704704
| supervisor.podSecurityContext.runAsNonRoot | bool | `true` | Require the shared supervisor to run as a non-root user. |
705705
| supervisor.podSecurityContext.runAsUser | int | `65534` | UID assigned to the shared supervisor pod. |
706706
| supervisor.podSecurityContext.seccompProfile.type | string | `"RuntimeDefault"` | Seccomp profile applied to the shared supervisor pod. |
707-
| supervisor.recoveryTimeoutSeconds | int | `60` | Seconds a sandbox workload stays frozen after losing its pool member's supervision before the sandbox runtime terminates it, rendered as [openshell.gateway.supervisor_pool] recovery_timeout_secs. Must be an integer from 10 to 300. Null leaves the gateway's pool default of 60 seconds. |
707+
| supervisor.recoveryTimeoutSeconds | int | `60` | Seconds a sandbox workload stays frozen after losing its pool member's supervision before the sandbox runtime terminates it, rendered as [openshell.gateway.supervisor_pool] recovery_timeout_secs. Must be an integer from 30 to 300. Null leaves the gateway's pool default of 60 seconds. |
708708
| supervisor.replicas | int | `1` | Shared supervisor pool members, used only when gatewayConfig selects supervisor_topology = "gateway". The gateway always coordinates the shared supervisor as a high-availability pool: when a member fails or leaves, another member takes over its sandboxes without restarting their workloads. 1 has no failover; use 2 or more to survive losing a member. Only the supervisor Deployment's replica count depends on this value, so changing it neither restarts the gateway nor replaces running members. Ignored when supervisor.autoscaling.enabled is true. |
709709
| supervisor.sandboxRuntime.boundaryPort | int | `5500` | Workload boundary TLS listener port. |
710710
| tolerations | list | `[]` | Tolerations for the gateway pod. |

‎deploy/helm/openshell/templates/_helpers.tpl‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,8 @@ default.
437437
{{- $value := get $supervisor "recoveryTimeoutSeconds" -}}
438438
{{- if and (hasKey $supervisor "recoveryTimeoutSeconds") (not (kindIs "invalid" $value)) (ne (toString $value) "") -}}
439439
{{- $timeout := include "openshell.wholeNumber" $value -}}
440-
{{- if or (eq $timeout "") (lt (int64 $timeout) 10) (gt (int64 $timeout) 300) -}}
441-
{{- fail "supervisor.recoveryTimeoutSeconds must be an integer between 10 and 300, or null for the default" -}}
440+
{{- if or (eq $timeout "") (lt (int64 $timeout) 30) (gt (int64 $timeout) 300) -}}
441+
{{- fail "supervisor.recoveryTimeoutSeconds must be an integer between 30 and 300, or null for the default" -}}
442442
{{- end -}}
443443
{{- $timeout -}}
444444
{{- end -}}

0 commit comments

Comments
 (0)