fix(python-sdk): align sync/async error handling and claim cleanup

AB
1mo ago
+447-78

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 from delete_sandbox() instead of only logging them, and AsyncSandboxClient._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_deletes so list_active_sandboxes() (both clients) and close() / __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: Adds warmpool_name to SandboxClient.get_sandbox(), adds AsyncSandboxClient.get_sandbox_claim_warmpool_name(), and shares claim_warmpool_name() and validate_claim_warmpool() in claim_adoption.py. Both clients raise the new SandboxWarmPoolMismatchError(SandboxError, ValueError) unwrapped on a mismatch and wrap other get_sandbox() lookup failures in SandboxNotFoundError.
  • Connection state & port-forward errors: AsyncSandbox resets _pod_name in close_connection() and _close_for_atexit(), and SandboxdPodTunnelStrategy raises SandboxPortForwardError on kubectl port-forward OSError and readiness timeout.
  • Packaging & docs: Adds aiohttp to the async and test extras, removes unused opentelemetry-instrumentation-requests from tracing, and regenerates docs/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.