fix(python-sdk): align sync/async error handling and claim cleanup
AB
1mo ago+447+447+012345678901234567890123456789-78-78-01234567890123456789
What this PR does / why we need it:
Aligns error handling, automatic cleanup tracking, and warm-pool validation between SandboxClient and AsyncSandboxClient in k8s-agent-sandbox:
delete_sandbox()error propagation and automatic cleanup: Both clients now propagate non-404 errors fromdelete_sandbox()instead of only logging them, andAsyncSandboxClient._delete_automatic_sandboxes()catches per-claim errors so remaining automatic claims are still cleaned up.- Retry tracking for failed deletions: When
terminate()fails, the claim key is recorded in_failed_deletessolist_active_sandboxes()(both clients) andclose()/__aexit__(async) keep the handle registered for automatic cleanup retry until deletion succeeds or a new handle replaces it. - Warm-pool lookup parity and
SandboxWarmPoolMismatchError: Addswarmpool_nametoSandboxClient.get_sandbox(), addsAsyncSandboxClient.get_sandbox_claim_warmpool_name(), and sharesclaim_warmpool_name()andvalidate_claim_warmpool()inclaim_adoption.py. Both clients raise the newSandboxWarmPoolMismatchError(SandboxError, ValueError)unwrapped on a mismatch and wrap otherget_sandbox()lookup failures inSandboxNotFoundError. - Connection state & port-forward errors:
AsyncSandboxresets_pod_nameinclose_connection()and_close_for_atexit(), andSandboxdPodTunnelStrategyraisesSandboxPortForwardErroronkubectl port-forwardOSErrorand readiness timeout. - Packaging & docs: Adds
aiohttpto theasyncandtestextras, removes unusedopentelemetry-instrumentation-requestsfromtracing, and regeneratesdocs/python_sdk_reference.md.
Which issue(s) this PR is related to:
Ref #1785
Release Note
Python SDK (`k8s-agent-sandbox`): `delete_sandbox()` now raises on any non-404 failure instead of only logging it; failed deletions of auto-named claims are retried at exit when automatic cleanup is enabled (`cleanup=True`, the default for `AsyncSandboxClient`). `SandboxClient.get_sandbox()` now accepts `warmpool_name`, both clients raise `SandboxWarmPoolMismatchError` (a `ValueError`) on a pool mismatch, and `SandboxdPodTunnelStrategy` raises `SandboxPortForwardError` instead of `OSError`/`TimeoutError`.
Summary by CodeRabbit
- New Features
- Sandbox lookups can optionally verify that a claim belongs to the expected warm pool. A new error identifies mismatches, and you can retrieve a claim’s warm-pool name when available.
- Bug Fixes
- Failed sandbox deletions are surfaced and retained for retry, while automatic cleanup continues with other sandboxes.
- Port-forward startup and readiness failures now report a consistent error with sandbox context.
- Closing a sandbox connection clears its cached pod name.