Skip to content

fix(driver-podman): keep restarted sandboxes from failing before supervisor start - #6025

Open
pimlock wants to merge 1 commit into
mainfrom
fix/podman-restart-supervisor-race/pimlock
Open

pimlock wants to merge 1 commit into
mainfrom
fix/podman-restart-supervisor-race/pimlock

Conversation

@pimlock

@pimlock pimlock commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fix an intermittent Podman driver race: a sandbox restarted with StopSandbox then StartSandbox could go from Starting to Error (ContainerExited).

Related Issue

No issue: localized fix for an intermittent CI failure (failing run, lane rust-podman-additional-ca).

Cause

start_sandbox starts the workload, then the supervisor, in two API calls. On a restart the supervisor is still exited from StopSandbox. If the watcher inspects the pair in that gap, it sees a running workload without a running supervisor, treats it as a lost supervisor, and stops the new workload.

A related path: a late supervisor stop/die event from StopSandbox could publish the previous run's workload exit, because supervisor events skipped the previous-exit check that workload events already use.

Race details

The watcher runs this check on every workload or supervisor event:

inspect_workload():
  if workload == running && supervisor != running:
      stop(workload)   // treat as lost supervisor

On first create the supervisor is created, which counts as starting, so the check never fires. On a restart, the supervisor is still exited from StopSandbox.

Race 1: the watcher stops the new workload (the CI failure)

driver                         watcher                         gateway
------                         -------                         -------
StopSandbox
  stop(supervisor)             // workload: exited, supervisor: exited
  stop(workload)
StartSandbox
  start(workload)  ----------> event: workload start
                               inspect: workload=running, supervisor=exited
                               stop(workload)    // "lost supervisor"
                               publish workload=exited ------> Starting -> Error (ContainerExited)
  start(supervisor)            // supervisor runs, workload is gone
  return OK

Gateway log for sandbox 1a1665c3 in the failing run:

00:32:12.260  StopSandbox request completed successfully
00:32:12.271  podman.start_sandbox: Starting sandbox container
00:32:12.532  StartSandbox request completed successfully
00:32:12.537  Sandbox phase changed old_phase=Starting new_phase=Error
00:32:12.567  PushSandboxLogs from the new supervisor (no supervisor session ever opens)

With the fix, start_sandbox holds a pair-start guard between the two calls, so an inspect inside that window reports starting instead of stopping the workload.

Race 2: a late supervisor event publishes the previous exit

driver                         watcher                         gateway
------                         -------                         -------
StopSandbox
  stop(supervisor)             (supervisor die event queued)
StartSandbox                                                   -> Starting
                               event: supervisor die (late)
                               inspect: workload=exited (previous run)
                               publish workload=exited ------> Starting -> Error
  start(workload)

Workload events already drop a snapshot whose exit matches the recorded previous exit. With the fix, supervisor events apply the same check.

Why the guard is safe: the guard exists only in driver memory, and it's dropped on success, error, or cancellation. A missing supervisor, or an exited supervisor outside the driver's own start window (including after a gateway or driver restart), is still contained. The workload doesn't run the agent until the supervisor confirms it.

Changes

  • driver.rs: both restart paths start the pair through start_stopped_pair, which holds a per-sandbox pair-start guard until the supervisor start returns. While the guard is held, inspect_workload reports a running workload with a not-yet-running supervisor as starting instead of stopping it. Containment is unchanged outside that window.
  • watcher.rs: supervisor-triggered snapshots now drop a workload exit that matches the recorded previous exit.

Testing

  • cargo test -p openshell-driver-podman
  • cargo clippy -p openshell-driver-podman --all-targets -- -D warnings
  • New unit tests in watcher.rs cover a restart before supervisor start, containment outside a start, and a delayed supervisor event. The first and third fail without the fix.
  • Not reproduced under real Podman; the rust-podman* E2E lanes run the affected test.

Checklist

  • Follows Conventional Commits
  • Commits are signed off (DCO)

…rvisor start

A sandbox restart starts the workload before its supervisor. Until the
supervisor start returns, the supervisor still reports the exit from the
previous run. A watcher inspect in that window treated it as a lost
supervisor and stopped the new workload with timeout 0, which moved the
sandbox from Starting to Error with ContainerExited.

Mark the workload and supervisor start as in progress, and report the
workload as starting during that window. A missing supervisor, or an
exited one outside a start, is still contained.

Supervisor events also re-inspected the workload without the
previous-exit fence, so a delayed supervisor stop or die from the last
StopSandbox could publish the earlier run's exit. Apply the fence to
those snapshots too.

Signed-off-by: Piotr Mlocek <pmlocek@nvidia.com>
@github-actions github-actions Bot added the state:accepted A maintainer decided OpenShell should pursue this issue label Nov 26, 2026
@pimlock pimlock added the test:e2e Requires end-to-end coverage label Nov 26, 2026

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

state:accepted A maintainer decided OpenShell should pursue this issue test:e2e Requires end-to-end coverage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant