Skip to content

fix: make delete_sandbox idempotent when data plane returns "sandbox not found"#89

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-terminated-sandbox-issue
Draft

fix: make delete_sandbox idempotent when data plane returns "sandbox not found"#89
Copilot wants to merge 2 commits intomainfrom
copilot/fix-terminated-sandbox-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 20, 2026

Control plane (list_sandboxes) and data plane (delete_sandbox) can diverge: a TERMINATED sandbox remains visible in list results, but the data plane has already removed it, causing delete_sandbox to raise ClientError('Failed to stop sandbox: sandbox not found') instead of succeeding silently.

Changes

  • agentrun/sandbox/client.py — In both delete_sandbox and delete_sandbox_async, when the data plane returns a non-SUCCESS response with a message containing "sandbox not found", return a Sandbox with the given sandbox_id instead of raising. Existing HTTP-level 404 handling (raises ResourceNotExistError) is unchanged.

  • tests/unittests/sandbox/test_client.py — Added test_delete_sandbox_not_found_in_response_is_idempotent and its async counterpart covering the new code path.

Before / After

# Before — raises on already-gone TERMINATED sandbox
client.delete_sandbox("91d970881b8d4dcaa5636df64577545b--18ee62652b")
# ClientError: Failed to stop sandbox: sandbox not found

# After — idempotent success
result = client.delete_sandbox("91d970881b8d4dcaa5636df64577545b--18ee62652b")
result.sandbox_id  # "91d970881b8d4dcaa5636df64577545b--18ee62652b"

Copilot AI changed the title [WIP] Fix list_sandboxes returning TERMINATED instances when deleting fix: make delete_sandbox idempotent when data plane returns "sandbox not found" Apr 20, 2026
Copilot AI requested a review from OhYee April 20, 2026 16:08
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】AgentRun Python SDK 中 list_sandboxes 仍能查到 TERMINATED 实例,但 delete_sandbox 删除同一 sandbox_id 时返回 sandbox not found

2 participants