Skip to content

Commit 7a4da31

Browse files
authored
fix(supervisor): keep session retries during startup (ai-openshell#3765)
Signed-off-by: Drew Newberry <anewberry@nvidia.com>
1 parent d009f30 commit 7a4da31

4 files changed

Lines changed: 36 additions & 32 deletions

File tree

‎architecture/compute-runtimes.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ whose compute resource is still provisioning without exposing contradictory publ
107107
readiness signals. When the driver reports runtime readiness, its ready condition
108108
is published without waiting for a supervisor session.
109109

110+
The supervisor keeps retrying session establishment while the gateway is unavailable.
111+
Its control readiness socket remains absent until the gateway accepts a session and
112+
is removed if that session disconnects. A transient gateway delay during startup
113+
therefore leaves the sandbox provisioning without terminating the supervisor.
114+
110115
**Session precedence over lagging driver snapshots:** A supervisor session can only be
111116
established by a running workload. When `set_supervisor_session_state` promotes the
112117
store record to `Ready` on session connect, a driver watch event may still arrive

‎crates/openshell-supervisor-process/src/delegated.rs‎

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ pub async fn start_boundary_access(
156156

157157
let (session_task, session_readiness) = match (openshell_endpoint, sandbox_id) {
158158
(Some(endpoint), Some(id)) => {
159-
let (task, mut accepted) = crate::supervisor_session::spawn_with_readiness(
159+
let (task, accepted) = crate::supervisor_session::spawn_with_readiness(
160160
endpoint.to_string(),
161161
id.to_string(),
162162
ssh_socket_path,
@@ -168,25 +168,10 @@ pub async fn start_boundary_access(
168168
session_id_updates: supervisor_session_updates,
169169
},
170170
);
171-
let accepted_result =
172-
tokio::time::timeout(Duration::from_secs(10), accepted.wait_for(|ready| *ready))
173-
.await
174-
.map(|result| result.map(|_| ()));
175-
match accepted_result {
176-
Ok(Ok(())) => (Some(task), Some(accepted)),
177-
Ok(Err(_)) => {
178-
task.abort();
179-
return Err(miette::miette!(
180-
"supervisor session ended before gateway acceptance"
181-
));
182-
}
183-
Err(_) => {
184-
task.abort();
185-
return Err(miette::miette!(
186-
"gateway did not accept supervisor session within 10 seconds"
187-
));
188-
}
189-
}
171+
// Session establishment retries through gateway restarts. The
172+
// readiness socket remains absent until the gateway accepts the
173+
// session, so a transient delay cannot kill the supervisor.
174+
(Some(task), Some(accepted))
190175
}
191176
_ => (None, None),
192177
};

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

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,21 +100,24 @@ impl ControlReadiness {
100100
path: std::path::PathBuf,
101101
mut session_readiness: Option<tokio::sync::watch::Receiver<bool>>,
102102
) -> Result<Self> {
103-
if session_readiness
103+
prepare_control_readiness_path(&path)?;
104+
let listener = if session_readiness
104105
.as_ref()
105106
.is_some_and(|readiness| !*readiness.borrow())
106107
{
107-
return Err(miette::miette!(
108-
"supervisor session is not ready when starting health listener"
109-
));
110-
}
111-
prepare_control_readiness_path(&path)?;
112-
let listener = tokio::net::UnixListener::bind(&path)
113-
.into_diagnostic()
114-
.wrap_err_with(|| format!("bind supervisor readiness socket on {}", path.display()))?;
108+
None
109+
} else {
110+
Some(
111+
tokio::net::UnixListener::bind(&path)
112+
.into_diagnostic()
113+
.wrap_err_with(|| {
114+
format!("bind supervisor readiness socket on {}", path.display())
115+
})?,
116+
)
117+
};
115118
let task_path = path.clone();
116119
let task = tokio::spawn(async move {
117-
let mut listener = Some(listener);
120+
let mut listener = listener;
118121
loop {
119122
let session_unready = session_readiness
120123
.as_ref()
@@ -4754,10 +4757,19 @@ mod tests {
47544757
async fn control_readiness_tracks_supervisor_session() {
47554758
let root = tempfile::tempdir().unwrap();
47564759
let path = root.path().join("health.sock");
4757-
let (session_tx, session_rx) = tokio::sync::watch::channel(true);
4760+
let (session_tx, session_rx) = tokio::sync::watch::channel(false);
47584761
let _readiness = ControlReadiness::start(path.clone(), Some(session_rx))
47594762
.expect("start readiness listener");
4760-
check_control_readiness(&path).expect("accepted session is ready");
4763+
assert!(check_control_readiness(&path).is_err());
4764+
4765+
session_tx.send_replace(true);
4766+
timeout(Duration::from_secs(1), async {
4767+
while check_control_readiness(&path).is_err() {
4768+
tokio::task::yield_now().await;
4769+
}
4770+
})
4771+
.await
4772+
.expect("first accepted session creates readiness socket");
47614773

47624774
session_tx.send_replace(false);
47634775
timeout(Duration::from_secs(1), async {

‎docs/how-it-works/sandboxes/runtimes.mdx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ The driver looks up sandbox images in local Docker or Podman before pulling from
176176

177177
VM sandboxes have no network interface. All traffic flows through the OpenShell supervisor on the host. For networks that require a corporate proxy, the VM driver accepts the same `https_proxy` and `proxy_*` options as Podman. To reach a proxy on the gateway host, use `http://host.openshell.internal:<port>`.
178178

179+
If the gateway is briefly unavailable while a VM starts, its supervisor retries the session connection. The sandbox stays in provisioning until the gateway accepts the session.
180+
179181
## Kubernetes Driver
180182

181183
The Kubernetes driver runs sandboxes as pods in a sandbox namespace. It requires the [Agent Sandbox](https://github.com/kubernetes-sigs/agent-sandbox) controller. Install the gateway with the Helm chart; see [Kubernetes setup](/kubernetes/setup).

0 commit comments

Comments
 (0)