Improve local sandbox list reconciliation#394
Merged
Conversation
Send a base64-encoded cli_state (cwd, branch, configFile) when creating sandbox runs so the server can associate runs with their CLI context. Replace the N+1 GetSandboxConnectionInfo loop in ListSandboxes with a single ListSandboxRuns bulk API call, and merge remotely-discovered runs (e.g. from agents) into local storage.
When ExecSandbox finds no local session, call ListSandboxRuns to check if a matching sandbox already exists remotely before auto-creating a new one. This prevents spinning up duplicates when a sandbox is running but the local storage was lost (e.g. different machine, cleared state).
When a local session's run ID is not in the bulk API response, it may still be initializing (not yet sandboxed). Fall back to a per-run GetSandboxConnectionInfo check before pruning to avoid removing sessions for runs that are still alive.
Save the session to sandboxes.json right after InitiateRun returns, before scoped token creation. This minimizes the window where a crash could lose the run ID, ensuring sandbox list can recover the run via the per-run fallback check even while it's still initializing.
…sResult The client method ListSandboxRuns() hard-codes query params that scope it to sandbox runs. Rename the types to match so the client-side intent is clear.
be8cdb1 to
94e13c1
Compare
TAGraves
approved these changes
Mar 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Blocked by https://github.com/rwx-cloud/cloud/pull/6975
Summary
cli_state(CWD, branch, config file) with every sandbox run so the server can associate runs with their local context.sandbox listuses a bulk API (GET /mint/api/runs?result_status=sandboxed&my_runs=true) instead of N individual connection-info calls, and merges remotely-discovered runs into local storage so sandboxes started on other machines (or otherwise not persisted locally) appear automatically.sandbox execrecovers from the API when no local session exists — reuses a matching remote sandbox instead of creating a new one.sandbox startpersists the session immediately after run creation (before scoped token), so a crash mid-setup doesn't orphan the run from local storage.Test plan
sandbox listshows active sandboxes using bulk APIsandbox listdiscovers sandboxes not in local storage viacli_statesandbox listprunes expired/cancelled sandboxes (404, 410, non-404/410 errors)sandbox listkeeps initializing sandboxes not yet in bulk APIsandbox execrecovers matching sandbox from API when local session is missingsandbox execfalls through to create when no remote match existssandbox startpersists session immediately after run creationgo test ./internal/... ./cmd/...)PUML raw