Skip to content

feat(cli): wait for sandbox readiness before exec during supervisor takeover - #5971

Open
EmilienM wants to merge 1 commit into
ai-openshell:mainfrom
EmilienM:fix/5659-supervisor-exec-bursts/EmilienM
Open

EmilienM wants to merge 1 commit into
ai-openshell:mainfrom
EmilienM:fix/5659-supervisor-exec-bursts/EmilienM

Conversation

@EmilienM

Copy link
Copy Markdown
Contributor

Summary

sandbox exec now waits, within a bounded budget, for a sandbox to come back to Ready while a shared supervisor takeover moves it, instead of failing on the first Provisioning read. The wait is client-side; the server only gained a machine-readable reason on its existing readiness rejection. Adds the two regression scenarios from the issue (supervisor SIGKILL, supervisor rollout restart) and wires the shared-supervisor-ha lane into branch e2e behind the test:e2e-kubernetes label.

Related Issue

Closes #5967
Part of #5659 (criteria a and d). Follow-ups filed for criterion b (placement) and criterion c (the Stopped sandbox).

Changes

  • Pure wait policy in openshell-core (exec_wait): only Provisioning and Starting wait, jittered 1-5s polls, wall-clock budget as the only bound
  • CLI: wait before the first exec RPC in both exec paths, one bounded re-wait when the gateway rejects before a relay opens (structured SANDBOX_NOT_READY reason, message fallback for older gateways), transient Unavailable reads retried within the budget
  • Flags: --exec-wait-timeout (default 45s, OPENSHELL_EXEC_WAIT_TIMEOUT, 0 disables) and --no-exec-wait
  • E2E: the harness pins the old instant failure so existing suites keep their timing; the new scenarios assert failure count and probe latency; the scaling sampler is lifted into shared_supervisor
  • CI: kubernetes-shared-supervisor-ha-e2e job in branch-e2e.yml, label-gated, non-required

Release Notes

sandbox exec waits up to 45 seconds by default for a sandbox that is Provisioning or Starting to become Ready, such as during a shared supervisor takeover, instead of failing immediately. Tune or disable with --exec-wait-timeout, OPENSHELL_EXEC_WAIT_TIMEOUT, or --no-exec-wait.

Testing

  • Checks appropriate to the affected code and behavior pass
  • Unit tests added/updated
  • E2E tests added/updated

Unit and integration: the 12-phase policy table, flag and env resolution, the re-wait (structured reason and message fallback), transient read tolerance, and the interactive resend. The server gained a test pinning the structured reason.

E2E on local kind: both new scenarios pass. The lane is 11 of 12; supervisors_spread_evenly_across_gateways fails pre-existing (see #5969). The pre-fix CLI fails the SIGKILL scenario with 10 probe failures against an allowance of 2, which is the discrimination proof the issue asked for. The scaling lane passes 8 of 8 and conformance 77 of 77.

Checklist

  • Follows Conventional Commits
  • Commits are signed off (DCO)
  • Architecture docs updated (exec flag table and lifecycle section in the docs, CLI skill)

…akeover

When a shared supervisor dies or its pool rolls, the gateway hands the
sandbox's supervisor session to another member and the sandbox reads
Provisioning or Starting for the ten to twenty seconds the takeover
takes. `sandbox exec` failed on that first observation, so one supervisor
kill turned into a burst of instant failures for every exec in flight.

Exec now waits, within a bounded wall-clock budget, for the sandbox to
reach Ready before it collects stdin or issues anything: only
Provisioning and Starting wait, every other phase fails immediately as
before, and a wait that ends without Ready names its elapsed budget and
last observed phase. The budget defaults to 45 seconds, is set with
--exec-wait-timeout or OPENSHELL_EXEC_WAIT_TIMEOUT (clamped to 24
hours), and is disabled with --no-exec-wait or a zero budget. The wait
polls GetSandbox with the create-retry jitter and backoff so hundreds
of waiting execs do not poll a recovering gateway in lockstep, and it
shares one implementation with the create-retry policy in openshell-core.
One safe exception retries the exec a single time when the gateway's
own readiness gate rejects it before any relay opens, which proves the
command never started; every other failure, including a relay timeout,
stays fatal.

The exec e2e harness pins --no-exec-wait so existing suites keep their
timing, and two regression scenarios in the shared-supervisor HA lane
run exec traffic through an abrupt supervisor kill and a supervisor
Deployment rollout restart, asserting the failure count stays within a
race allowance, that probes succeed within the wait budget, and that
sandboxes recover on their adopted process. A sandbox the rollout
leaves Stopped is reported separately as the known follow-up failure
rather than silently passing. The lane is wired into branch e2e behind
the test:e2e-kubernetes label.

Also imports kubectl_json in the shared-supervisor HA test, which
origin/main omits while using it, so the test binary builds.

Closes ai-openshell#5967

Signed-off-by: Emilien Macchi <emacchi@redhat.com>
@EmilienM
EmilienM marked this pull request as ready for review November 25, 2026 13:33
@EmilienM
EmilienM requested a review from a team as a code owner November 25, 2026 13:33

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(cli): sandbox exec fails instantly during a shared supervisor takeover

1 participant