Repository navigation
feat(sandbox): support deleting a sandbox only if it has an expected ID - #1
Open
rodrigosetti wants to merge 2 commits into
Open
rodrigosetti wants to merge 2 commits into
rodrigosetti wants to merge 2 commits into
Conversation
3 tasks
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Fail-open paths and name-based forward cleanup can still affect same-name replacements, while Python cleanup can rebind to a replacement.
Review effort: Balanced
Findings: 4
Open (10)
Fail closed when the create response lacks a sandbox ID · New Prevent unconditional deletion when sandbox ID is missing · New Reject sessions without an immutable sandbox ID · New Preserve the original sandbox ID during readiness polling · New Make forward cleanup conditional on the expected sandbox ID · New Stop forwards only for records matching the sandbox ID · New Preserve deletion status and skip cleanup for unconfirmed outcomes · New Document stale-list guarantee limitations with older gateways · New Qualify safety guidance for older gateway versions · New Require conditional-delete gateway support for the guarantee · New
What changed in this PR
Adds identity-conditioned sandbox deletion to prevent stale clients from deleting same-name replacements.
Changes:
- Adds
expected_sandbox_idvalidation and enforcement. - Integrates conditional deletion across CLI, TUI, and SDKs.
- Adds tests, documentation, and schema updates.
| File | Description |
|---|---|
skills/openshell-cli/SKILL.md |
Documents ID-based deletion. |
sdk/typescript/src/index.ts |
Exports deletion options. |
sdk/typescript/src/client.ts |
Forwards expected sandbox IDs. |
sdk/typescript/src/client.test.ts |
Tests TypeScript forwarding. |
sdk/go/proto/openshellv1/openshell.pb.go |
Regenerates Go bindings. |
python/openshell/sandbox.py |
Adds conditional session cleanup. |
python/openshell/sandbox_test.py |
Tests Python request binding. |
python/openshell/sandbox_cleanup_test.py |
Tests replacement-safe cleanup. |
proto/openshell.proto |
Defines the optional ID precondition. |
e2e/python/test_sandbox_api.py |
Tests replacement preservation end-to-end. |
docs/sdk/api-errors.mdx |
Documents mismatch errors and usage. |
docs/how-it-works/sandboxes/overview.mdx |
Documents CLI flags. |
crates/openshell-tui/src/lib.rs |
Handles conditional TUI deletion. |
crates/openshell-tui/src/app.rs |
Builds ID-bound delete requests. |
crates/openshell-server/src/storage_proto.rs |
Updates schema fingerprint. |
crates/openshell-server/src/grpc/sandbox.rs |
Validates and forwards the condition. |
crates/openshell-server/src/grpc/mutation_replay/ordinary/tests.rs |
Updates request fixtures. |
crates/openshell-server/src/compute/mod.rs |
Enforces identity before deletion. |
crates/openshell-sdk/tests/client_mock.rs |
Tests Rust SDK forwarding. |
crates/openshell-sdk/src/types.rs |
Adds sandbox deletion options. |
crates/openshell-sdk/src/lib.rs |
Exports the new options. |
crates/openshell-sdk/src/client.rs |
Supports conditional Rust SDK deletion. |
crates/openshell-cli/tests/sandbox_create_lifecycle_integration.rs |
Tests CLI flags and cleanup. |
crates/openshell-cli/src/run.rs |
Implements ID lookup and conditional deletion. |
crates/openshell-cli/src/main.rs |
Adds --id and --expected-id. |
.agents/skills/tui-development/SKILL.md |
Updates TUI deletion guidance. |
Files not reviewed (1)
- sdk/go/proto/openshellv1/openshell.pb.go: Generated file
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
DeleteSandbox addressed sandboxes only by name, so a client that observed a sandbox and later deleted it by name could delete a same-name replacement created in between. Add an optional expected_sandbox_id precondition: the gateway deletes only if the name still resolves to that ID and otherwise returns ABORTED with reason SANDBOX_IDENTITY_MISMATCH in ErrorInfo, so clients can tell it apart from other conflicts. The existing ID-pinned delete path then carries the request through, so a replacement created after resolution is not deleted either. An explicitly empty value is rejected so it cannot silently become an unconditional delete. Requests without the field keep name-based behavior. Add `openshell sandbox delete --id <ID>`, which finds the name that currently has the ID and sends a delete conditioned on it, reporting the ID as already deleted if it was deleted or replaced in between. Add `openshell sandbox delete NAME --expected-id <ID>`, which fails instead of deleting a same-name replacement. Expose the condition in the Rust, Python, and TypeScript SDKs and the regenerated Go bindings. Python sandbox sessions and managed-sandbox cleanup, CLI --no-keep cleanup, and TUI deletes now bind to the sandbox they hold, treating a same-name replacement as the original already being gone where appropriate. CLI --no-keep cleanup and TUI deletes refuse to delete when the sandbox ID is unknown. Document the condition, its error reason, and that gateways predating the field ignore it and delete by name. Closes ai-openshell#3210 Signed-off-by: rodrigosetti <[email protected]>
rodrigosetti
force-pushed
the
feat/3210-conditional-sandbox-delete/rodrigosetti
branch
from
October 26, 2026 14:00
4ade185 to
7608d2c
Compare
SandboxSession.delete fell back to an unconditional delete by name when the session's sandbox ID was empty, so it could remove a same-name replacement. The CLI --no-keep cleanup and TUI already refuse in that case. Raise SandboxError instead, which also makes managed-sandbox cleanup fail closed. Refs ai-openshell#3210 Signed-off-by: rodrigosetti <[email protected]>
|
This pull request has had no activity for 14 days and is now marked stale. |
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.



Summary
DeleteSandboxonly takes a name, so a client that looked up a sandbox and later deletes it by name can delete a same-name replacement created in between. This adds an optionalexpected_sandbox_idprecondition: the gateway deletes only if the name still resolves to that ID, and otherwise fails withABORTEDand reasonSANDBOX_IDENTITY_MISMATCHwithout deleting anything.Related Issue
Closes ai-openshell#3210 (ai-openshell#3210)
Changes
DeleteSandboxRequest.expected_sandbox_id(optional string, field 5). Absent keeps today's name-based behavior. An explicitly empty value returnsINVALID_ARGUMENTso it cannot silently become unconditional. A mismatch is an error even withallow_missing=true; a missing name still followsallow_missing.ABORTEDwith a structuredSANDBOX_IDENTITY_MISMATCHreason via a newrpc_error::abortedhelper, matching how the API already reports conditional-write conflicts. Clients should match on theErrorInforeason, since otherABORTEDerrors exist on this path.openshell sandbox delete --id IDdeletes the sandbox with that ID. The API stays name-addressed (perproto/README.md), so the CLI looks up the name that currently has the ID and sends a delete conditioned on it; if the sandbox is deleted or replaced in between, the gateway refuses and the CLI reports the ID as already deleted.openshell sandbox delete NAME --expected-id IDalso requires that the name still refers to that ID (one name only, conflicts with--all); a mismatch exits non-zero.sandbox create --no-keepcleanup now deletes by the created sandbox's ID and treats a replacement as the original already being gone. Port forwards are stopped only after a conditional delete is confirmed.[d]sends the selected row's sandbox ID; a mismatch shows a status message and refreshes the list.SandboxDeleteOptions { allow_missing, expected_sandbox_id };delete_sandboxtakesimpl Into<SandboxDeleteOptions>, so existingDeleteOptionscallers compile unchanged.SandboxClient.delete(..., expected_sandbox_id=...).SandboxSession.deleteandSandboxcontext-manager cleanup now pass the session's own ID (behavior change); cleanup treats a mismatch as already absent. If the session's ID is empty, they raiseSandboxErrorinstead of deleting by name, matching the CLI--no-keepcleanup and the TUI.SandboxDeleteOptions.expectedSandboxIdonsandbox.delete.ExpectedSandboxIdon the raw request; no curated option, sinceDeleteOptionsis shared across resource types.openshell-cliandtui-developmentskills.Gateways that predate the field ignore it and delete by name; the docs call this out.
Testing
cargo testforopenshell-server,-sdk,-cli,-tui,-core: 3,255 passedcargo clippy --workspace --all-targets -D warnings,mise run pre-commit,mise run go:ci,mise run docssandbox_test.py/sandbox_cleanup_test.py, ruff, tytsc, Vitest;buf lintallow_missing), match, empty value, and missing-name cases; Rust SDK request forwarding; CLI flag parsing, forwarding, stale-ID failure,--idlookup with missing and replaced sandboxes, and--no-keepcleanup with a replacement; TUI request binding; Python request presence, session binding, empty-ID refusal, and context-manager cleanup against a rich-status mismatch; TypeScript forwarding.test_conditional_delete_preserves_same_name_replacementine2e/python/test_sandbox_api.py.--expected-idwas refused withSANDBOX_IDENTITY_MISMATCHand the replacement survived; a matching ID was accepted.sandbox delete --id <stale ID>reported the sandbox as already deleted and left the same-name replacement alone;--id <current ID>deleted it.Readybecause the supervisor container cannot connect back to the gateway. The existing, untouchedtest_mutation_replay_preserves_sandbox_lifecycle_and_replacementfails the same way there, so the full e2e test still needs a Linux CI run.Checklist