Commit cb3fccf
authored
browser TTLs (#380)
Currently we destroy non-persistent browsers on first CDP disconnect.
This is a challenging pattern for people who want browsers to live
longer than the duration of their first CDP connection. Or users who
want browsers to automatically get cleaned up after a period of
inactivity. It also breaks from how other providers let you do it:
- bb: set keepAlive: true and then configure a project-level default
timeout: 1, 5, 10, 15, 30 mins, 1, 3, or 6 hours
[link](https://docs.browserbase.com/guides/long-running-sessions)
- hyperbrowser: configurable timeoutMinutes, min 1, max 720 (12 hours)
[link](https://docs.hyperbrowser.ai/sessions/overview/session-parameters#set-a-specific-timeout-for-the-session-with-timeoutminutes)
- steel: configurable timeout , defaults to 5 minutes, no max specified
[link](https://docs.steel.dev/api-reference#tag/sessions/post/v1/sessions)
Interestingly compared to us: all of these services will charge for idle
time, whereas we only charge for active time for a CDP or live view
connection.
This PR:
- removes the destruction of a browser session on first CDP disconnect
- add timeout_seconds to the `POST /browsers`
[endpoint](https://docs.onkernel.com/api-reference/browsers/create-a-browser-session)
- store this in the db for reference
- initiate the browser workflow with this value and have it kill the
browser if no CDP or live view activity for the duration of the timeout
configuration
- default to a 1 minute timeout, allow a maxium of 24 hours
https://linear.app/onkernel/issue/KERNEL-235/ttl-browsers
---
---
---
---
---
---
---
<span data-mesa-description="start"></span>
## TL;DR
Removed automatic browser session destruction on first CDP disconnect
and introduced configurable `timeout_seconds` for browser sessions,
allowing them to persist and be cleaned up based on inactivity.
## Why we made these changes
To allow browser sessions to persist beyond the first CDP disconnect and
to be automatically cleaned up after inactivity, aligning our session
management with industry standards and user expectations for
long-running or idle sessions.
## What changed?
* **Browser Session Lifecycle:** Eliminated immediate browser
destruction on first CDP disconnect. Refactored internal session
management to use `timeout_seconds` and `createdAt` for inactivity-based
cleanup (default 1 min, max 24 hours).
* **API & Schema Updates:** Modified `POST /browsers` to accept
`timeout_seconds` and updated API responses to include
`timeout_seconds`, `createdAt`, `stealth`, and `headless`. Added
`timeout_seconds` column to the `sessions` database table and updated
Ent ORM schemas and generated code accordingly. OpenAPI specification
was also updated.
* **CLI Enhancements:** Added a `--timeout` flag to `browsers create`
and updated `browsers list` to display session creation timestamps.
* **Internal Refactoring:** Updated `SessionManager`, `SessionToken`,
and `UnikraftSessionManager` structs to replace `Ttl` with
`TimeoutSeconds` and `CreatedAt`.
<sup>_Description generated by Mesa. [Update
settings](https://app.mesa.dev/onkernel/settings/pull-requests)_</sup>
<span data-mesa-description="end"></span>1 parent eb23096 commit cb3fccf
3 files changed
+11
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| 51 | + | |
51 | 52 | | |
52 | 53 | | |
53 | 54 | | |
| |||
79 | 80 | | |
80 | 81 | | |
81 | 82 | | |
82 | | - | |
| 83 | + | |
83 | 84 | | |
84 | 85 | | |
85 | 86 | | |
| |||
90 | 91 | | |
91 | 92 | | |
92 | 93 | | |
| 94 | + | |
93 | 95 | | |
94 | 96 | | |
95 | 97 | | |
| |||
107 | 109 | | |
108 | 110 | | |
109 | 111 | | |
| 112 | + | |
110 | 113 | | |
111 | 114 | | |
112 | 115 | | |
| |||
119 | 122 | | |
120 | 123 | | |
121 | 124 | | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
122 | 129 | | |
123 | 130 | | |
124 | 131 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
90 | | - | |
91 | | - | |
| 90 | + | |
| 91 | + | |
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
| |||
0 commit comments