Skip to content

feat(browser_pools): typed acquire helper distinguishing got / timed-out#107

Draft
Jayko001 wants to merge 4 commits into
mainfrom
hypeship/cus-261-typed-acquire-result
Draft

feat(browser_pools): typed acquire helper distinguishing got / timed-out#107
Jayko001 wants to merge 4 commits into
mainfrom
hypeship/cus-261-typed-acquire-result

Conversation

@Jayko001
Copy link
Copy Markdown

@Jayko001 Jayko001 commented Jun 2, 2026

Summary

Adds a typed wrapper around client.browser_pools.acquire so callers can distinguish a successful lease from a long-poll timeout without inspecting raw HTTP status codes.

from kernel.lib.browser_pools import acquire, Acquired, TimedOut

result = acquire(client, "my-pool")
if isinstance(result, Acquired):
    use_browser(result.browser)
elif isinstance(result, TimedOut):
    # retry to keep waiting
    ...
  • Acquired(browser) — 200, browser leased from pool
  • TimedOut() — 204, long poll expired, retry
  • NotFoundError — 404, pool does not exist (existing exception, propagated)

Sync (acquire) and async (acquire_async) variants are provided. The generated client.browser_pools.acquire() method is unchanged for backwards compatibility.

Test plan

  • Unit tests cover 200 / 204 / 404 paths (sync) and 204 path (async)
  • Manual smoke test against staging once published

Jayko001 and others added 4 commits June 2, 2026 00:18
Add `kernel.lib.browser_pools.acquire` (and `acquire_async`) returning a
typed discriminated union — `Acquired(browser)` on 200 or `TimedOut()` on
204 — so callers can disambiguate the long-poll timeout from a successful
lease without inspecting the raw HTTP status. 404 continues to raise the
existing `NotFoundError`.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Adds PoolNotFound to AcquireResult and catches NotFoundError internally
so all three documented outcomes — Acquired, TimedOut, PoolNotFound —
are reachable via the same isinstance() switch.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
AsyncAPIResponse.parse() is itself async; without await we constructed
Acquired with a coroutine instead of the parsed model.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.

1 participant