Skip to content

feat: add browser routing cache#93

Merged
rgarcia merged 23 commits intonextfrom
raf/browser-scoped-client
Apr 24, 2026
Merged

feat: add browser routing cache#93
rgarcia merged 23 commits intonextfrom
raf/browser-scoped-client

Conversation

@rgarcia
Copy link
Copy Markdown
Contributor

@rgarcia rgarcia commented Apr 13, 2026

Summary

  • remove the public browser_routing= client constructor config and move rollout control to KERNEL_BROWSER_ROUTING_SUBRESOURCES
  • default direct-to-VM request rewriting to curl when the env var is unset, and treat an explicit empty string as disabling browser subresource routing
  • keep browser_route_cache public for inspection/debugging while deriving routing behavior internally from the environment on Kernel / AsyncKernel
  • keep browsers.request() and browsers.stream() cache-backed so raw HTTP continues to go directly to the browser VM’s /curl/raw path with protected url / jwt params

Rollout behavior

  • env var unset: route only curl subresources directly to the browser VM
  • env var set to "": disable browser subresource routing entirely
  • env var set to a comma-separated list: route exactly those subresources directly to the browser VM
  • browsers.request() / browsers.stream() still always go direct to the browser VM because they resolve through the cached browser route and /curl/raw

Test plan

  • .venv/bin/pytest tests/test_browser_routing.py tests/test_client.py -o addopts=
  • .venv/bin/ruff check src/kernel/_client.py src/kernel/lib/browser_routing/routing.py src/kernel/resources/browsers/browsers.py src/kernel/__init__.py tests/test_browser_routing.py examples/browser_routing.py
  • PYTHONPATH=src KERNEL_API_KEY=... KERNEL_BASE_URL=https://api.onkernel.com .venv/bin/python examples/browser_routing.py

Note

Medium Risk
Medium risk because it changes core HTTP request/response processing in Kernel/AsyncKernel, including URL rewriting and stripping Authorization headers based on cached routes, which could impact request routing or auth if misapplied.

Overview
Adds a browser route cache to Kernel/AsyncKernel and hooks it into the client lifecycle: responses from browser metadata endpoints populate the cache, successful browser deletes/pool releases evict it, and outgoing requests can be rewritten to hit the browser VM directly.

Introduces env-controlled direct routing via KERNEL_BROWSER_ROUTING_SUBRESOURCES (defaulting to curl, empty string disables) and ensures routed requests inject jwt while removing API Authorization headers.

Adds browsers.request()/browsers.stream() (sync + async) to perform raw HTTP via the browser VM’s /curl/raw endpoint with reserved query keys (url, jwt) protected, plus an example script and comprehensive tests for cache warming/eviction and allowlisted routing behavior.

Reviewed by Cursor Bugbot for commit 5328730. Bugbot is set up for automated code reviews on this repo. Configure here.

@firetiger-agent
Copy link
Copy Markdown

Firetiger deploy monitoring skipped

This PR didn't match the auto-monitor filter configured on your GitHub connection:

Any PR that changes the kernel API. Monitor changes to API endpoints (packages/api/cmd/api/) and Temporal workflows (packages/api/lib/temporal) in the kernel repo

Reason: PR adds browser-scoped session client functionality but does not appear to modify API endpoints (packages/api/cmd/api/) or Temporal workflows (packages/api/lib/temporal) as specified in the filter.

To monitor this PR anyway, reply with @firetiger monitor this.

Comment thread src/kernel/lib/browser_scoped/client.py Outdated
Comment thread src/kernel/lib/browser_scoped/client.py Outdated
rgarcia added 9 commits April 21, 2026 13:09
Bind browser subresource calls to a browser session's base_url and expose raw HTTP through request and stream helpers so metro-routed access feels like normal httpx usage.

Made-with: Cursor
Prevent browser-scoped raw HTTP helpers from letting user params override internal routing query keys, and clean up wording around browser session base_url routing.

Made-with: Cursor
Keep the browser-scoped request helpers aligned with repo linting and reserve internal raw-request query keys without exposing implementation details.

Made-with: Cursor
Keep the browser-scoped test file aligned with the repo lint configuration so the follow-up typing fixes pass CI.

Made-with: Cursor
Tighten browser-scoped helper typing and test casts so the Python SDK passes the repository's lint and pyright checks cleanly.

Made-with: Cursor
Replace the handwritten Python browser-scoped façade with deterministic generated bindings from the browser resource graph, and enforce regeneration during lint.

Made-with: Cursor
Keep the browser-scoped Python generator compatible with the repo lint pipeline by suppressing strict pyright diagnostics that are not meaningful for the AST-walking build script.

Made-with: Cursor
Keep the Python generator and generated browser-scoped façade aligned with pyright and mypy so the deterministic regeneration path passes the repo lint pipeline.

Made-with: Cursor
Sort the generator script imports and keep the deterministic browser-scoped generation path aligned with the repo lint pipeline.

Made-with: Cursor
@rgarcia rgarcia force-pushed the raf/browser-scoped-client branch from 8f1d506 to a80716b Compare April 21, 2026 17:09
Comment thread src/kernel/lib/browser_scoped/client.py Outdated
rgarcia added 2 commits April 21, 2026 16:24
Turn the browser-scoped Python example into a runnable demonstration of both process execution and /curl/raw-backed request and stream usage.

Made-with: Cursor
Move browser raw HTTP and direct-to-VM routing onto the main browsers resource so the SDK uses the shared browser route cache instead of a generated wrapper layer.

Made-with: Cursor
Comment thread src/kernel/resources/browsers/browsers.py Outdated
Comment thread src/kernel/resources/browsers/browsers.py Outdated
Remove the public cache priming helpers, keep jwt-required routes, and rename the example and tests so the python browser routing diff stays focused on cache-backed direct-to-VM behavior.

Made-with: Cursor
@rgarcia rgarcia changed the title feat: add browser-scoped session client feat: add browser routing cache Apr 22, 2026
Comment thread src/kernel/lib/browser_routing/routing.py
Comment thread src/kernel/lib/browser_scoped/browser_session_kernel.py Outdated
rgarcia added 2 commits April 22, 2026 12:57
Shorten the browser_routing allowlist field to subresources so the direct-to-VM configuration stays concise while keeping the same routing behavior.

Made-with: Cursor
Move the handwritten routing helpers out of the old browser_scoped package, delete the unused browser session clone helper, warm the async browser list cache, and drop the generated type churn from the branch.

Made-with: Cursor
Comment thread src/kernel/resources/browsers/browsers.py Outdated
rgarcia added 3 commits April 22, 2026 20:05
Preserve browser routing settings across copy(), skip cache warming for raw response wrappers, and clean up the handwritten routing files so lint can pass on the current branch.

Made-with: Cursor
Make the browser routing helpers type-check cleanly in CI, keep copy() signatures aligned with __init__, and avoid cache-warming errors on raw response wrappers.

Made-with: Cursor
Encode string request bodies before building raw /curl/raw request options so the browser routing helpers satisfy CI type checks while preserving the public request API.

Made-with: Cursor
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is ON. A cloud agent has been kicked off to fix the reported issue. You can view the agent here.

Reviewed by Cursor Bugbot for commit 3ce80e7. Configure here.

Comment thread src/kernel/lib/browser_routing/routing.py
rgarcia added 2 commits April 24, 2026 11:08
Remove the public browser routing constructor config and derive direct-to-VM subresource routing from KERNEL_BROWSER_ROUTING_SUBRESOURCES instead, defaulting to curl while keeping the raw request helpers direct to the browser.
Store browser routes under a normalized session ID so cache lookups and deletes stay consistent when route data includes surrounding whitespace. Add a regression test to lock in the normalization behavior.

Made-with: Cursor
rgarcia added 3 commits April 24, 2026 16:00
Move browser route cache warming into the shared sync and async response hooks so browser metadata endpoints populate the cache consistently, including raw responses. Remove the handwritten browsers resource priming and cover the narrowed sniffing behavior with focused routing tests.

Made-with: Cursor
Drop cached browser routes after successful DELETE /browsers/{id} responses so stale direct-to-VM session URLs are not reused. Cover both the success and failure paths with focused browser routing regressions.

Made-with: Cursor
Remove the leftover result/page wrappers from browser create, retrieve, update, and list now that route cache warming lives in the shared response hooks. Keep the actual curl and raw HTTP browser routing surface unchanged.

Made-with: Cursor
Copy link
Copy Markdown
Collaborator

@Sayan- Sayan- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great stuff - thanks for iterating on the shape!

Keep the browser route cache in sync for pool acquire and release flows so leased sessions can use direct VM routing without resource-specific cache handling.

Made-with: Cursor
Copy link
Copy Markdown
Collaborator

@Sayan- Sayan- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great stuff - thanks for iterating on the shape!

@rgarcia rgarcia merged commit 9817c9f into next Apr 24, 2026
7 checks passed
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.

2 participants