Skip to content

bug(supervisor): exec fails in bursts when a shared supervisor is killed or restarted #5659

Open

Description

@FrostGod

User Story

I ran a mini scale test of OpenShell on Kubernetes with a shared supervisor pool and kept openshell sandbox exec traffic running against the sandboxes. When a supervisor was killed or restarted, hundreds of execs failed even though the sandboxes recovered. I need supervisor restarts and upgrades to be invisible, or close to it, for callers that run commands in sandboxes.

Problem Statement

When a shared supervisor goes away and its sandboxes move to another supervisor, execs fail in a burst:

  • SIGKILL of one supervisor: about 220 exec failures within about 10 seconds, then full recovery.
  • Rolling restart of the supervisors: about 415 failures over about 20 seconds. Some sandboxes moved twice, and one sandbox ended up permanently Stopped.

The errors:

  • Most common: sandbox is not ready (phase: Provisioning)
  • Second: relay open timed out, from execs that were already running on the supervisor that died

Why This Happens

  1. The sandbox is marked not ready during the handoff. When a supervisor's session ends, the gateway moves the sandbox from Ready back to Provisioning (finish_supervisor_session). It stays there until the new supervisor takes the sandbox and reconnects. There is a short grace period that keeps the sandbox Ready, but it only applies when a gateway shuts down and redirects its supervisors. It doesn't apply when a supervisor dies or restarts.
  2. Exec gives up right away. openshell sandbox exec checks the phase first and fails at once if it isn't Ready, with no retry (run.rs). A handoff that takes a few seconds therefore turns into a burst of failures.
  3. Rolling restarts move sandboxes twice. A new home for a sandbox is picked from all live supervisors (supervisor_pool.rs). The pick doesn't prefer supervisors that have already been restarted, so a sandbox can land on an old supervisor that is restarted next and has to move again.
  4. One sandbox ended up Stopped. I haven't found the cause yet. It may be related to bug(supervisor): gate rollout readiness on gateway attachment #4960 (supervisors reporting ready before they attach to the gateway).

Impact / Why This Matters

  • Every supervisor crash, node drain, or upgrade causes a burst of failed commands for every sandbox on that supervisor.
  • Agents and scripts that call exec see hard failures, not a short delay, unless they write their own retry logic.
  • Moving twice during rollouts doubles the disruption, and a sandbox left Stopped needs a manual restart.

Acceptance Criteria

  • During a single supervisor takeover, openshell sandbox exec waits for the sandbox to come back for a bounded time instead of failing immediately.
  • A rolling restart of the supervisor pool moves each sandbox at most once.
  • No sandbox ends up Stopped after a rolling restart.
  • A regression test runs exec traffic through a supervisor SIGKILL and a rolling restart, and checks the failure count and recovery.

Reproduction Steps

  1. Deploy OpenShell on Kubernetes with a shared supervisor pool of at least 2 supervisors.
  2. Create several sandboxes and run openshell sandbox exec <name> -- true in a loop against each one.
  3. Kill one supervisor pod (kubectl delete pod --grace-period=0 --force <supervisor-pod>), or start a rolling restart of the supervisors (kubectl rollout restart deployment/<supervisor-deployment>).
  4. Watch the exec failures (sandbox is not ready (phase: Provisioning), relay open timed out) and the sandbox phases (openshell sandbox list).

Environment

  • OpenShell: mini scale test build; code paths confirmed on main at 624acee
  • Deployment: Kubernetes (Helm), multi-replica gateway, shared supervisor pool, PostgreSQL

Activity

  1. EmilienM commented on Nov 25, 2026

    @EmilienM
    Contributor

    Taking this one. The fix splits into a client-side PR that's up now, plus two server-side follow-ups, because one PR can't carry all four acceptance criteria without doubling the review surface.

    The exec-side half is PR #5971, which closes issue #5967 (criteria a and d here):

    sandbox exec now waits up to 45 seconds by default (--exec-wait-timeout / OPENSHELL_EXEC_WAIT_TIMEOUT, off with --no-exec-wait) for a sandbox that reads Provisioning or Starting to reach Ready. Only those two phases wait, so a stopped or suspended sandbox still fails immediately, and the polls are jittered so hundreds of concurrent execs don't hammer a gateway that is mid-recovery. When the gateway's readiness gate rejects an exec before a relay opens, the CLI re-waits within the same budget and sends once more; the gate now carries a structured SANDBOX_NOT_READY reason so that retry doesn't depend on error wording. That closes the relay open timed out race too, since the rejection proves the command never started.

    The regression test runs exec traffic through both scenarios from the report. With the fix, both pass. With the pre-fix CLI, the SIGKILL scenario records 10 failed probes against an allowance of 2, which is the burst from the report, so the assertion does discriminate.

    I deliberately did not add a server-side grace for dead supervisors. It would have to run 20-30 seconds, it keeps sandboxes Ready with no live supervisor behind them (which hides real outages from phase-based monitoring), and for callers without a client wait it just trades the instant phase error for a relay-open timeout.

    The follow-ups:

    • Issue #5968 (criterion b): placement should prefer members that were already restarted, so a rollout moves each sandbox at most once. No age or generation signal reaches placement today, so the main work is picking one.
    • Issue #5970 (criterion c): the sandbox left Stopped. Strongest lead is the expired-route recovery chain, possibly compounded by bug(supervisor): gate rollout readiness on gateway attachment #4960; it needs a reproduction before a fix. The rollout scenario in the PR reports a known-Stopped sandbox separately instead of failing, so the lane doubles as a detector.
    • Issue #5969: while validating the lane locally I found supervisors_spread_evenly_across_gateways does not converge on kind. Pre-existing, reproduced on a fresh deployment with server code identical to main, and worth its own look.

    The PR is a draft waiting on state:accepted for #5967 and /ok to test.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions