Title: perf(sandbox): grant the run_code session lease in the reconnect instead of extra E2B round trips by waleedlatif1 · Pull Request #8621 · simstudioai/sim · GitHub
Open Graph Title: perf(sandbox): grant the run_code session lease in the reconnect instead of extra E2B round trips by waleedlatif1 · Pull Request #8621 · simstudioai/sim
X Title: perf(sandbox): grant the run_code session lease in the reconnect instead of extra E2B round trips by waleedlatif1 · Pull Request #8621 · simstudioai/sim
Description: Summary Mothership run_code on a reused chat workbench makes 5 E2B control-plane requests per call: list and connect; then getInfo + setTimeout to extend the lease; then another getInfo on release. The acquire-time setTimeout always fires: the previous call left the deadline at about prev + 21 min, and the new lease asks for now + 21 min. In production each request is about 80–90 ms. A trivial reused call spends about 1.65 s in executeInSandbox (p50), mostly on serial remote round trips. This change grants the lease in the request that already happens, and trusts deadlines the handle itself requested: findSessionSandbox(key, { lifetimeMs }) connects with max(5 min, remaining, lease). That is the same final deadline the separate getInfo + setTimeout produced, in one request. create already granted the lease. E2BSandboxHandle records the deadline it requested (create, connect, or setTimeout). outlives() and extendLifetime() skip the provider while that lower bound covers the request. ensureSessionSandbox skips the post-acquisition extend when the granted lease covers the budget, which is anchored before acquisition. Release skips the idle refresh (session lock + getInfo) when the lease already covers the 20-minute idle window. Result: 5 → 2 control-plane requests per reused call, and 3 → 1 on create. That is about 0.25 s per call at production latency, out of a fixed cost of about 2 s. Why behavior is unchanged Same deadlines as before. After acquisition the deadline is max(previous, now + lease). After release it is ≥ 20 minutes of idle. A run that overruns its budget still falls through to the locked getInfo/setTimeout path. The recorded deadline is a valid lower bound. Session deadlines only move later. connect is given at least the remaining time. extendLifetime reads before it sets. Recovery connects preserve the deadline. No cross-call state. Handles are created per call, so nothing is cached and nothing needs invalidation. Unrequested deadlines are still read back. A reconnect without lifetimeMs, or a create without a lifetime, goes through getInfo exactly as before. Untouched: what user code sees, chat isolation, the session lock around allocation, provenance, and process supervision. Tests All 5 new tests fail on the previous code: e2b-session.test.ts › "E2B session lease": a stateful fake control plane (connect never shortens, setTimeout sets). It checks both the resulting deadline and the request count for four cases: a reused lease, a created lease, a later deadline from a parallel job, and a lease the handle did not grant. session-sandbox.test.ts: a reconnect that takes time to grant the lease still needs no extend at acquisition or release. This test also fails if the acquisition check is not anchored to the request time. Measurement The control-plane request count is covered by the tests above. The wall-clock before/after against real E2B needs keys. A benchmark script was written for that: N small Python executeInSandbox session calls, counting and timing control-plane vs envd requests. It will be run separately. Type of Change Performance improvement Testing bun run test lib/execution/remote-sandbox/e2b-session.test.ts lib/execution/remote-sandbox/session-sandbox.test.ts (72 passed), bun run check:audits, bun run type-check (apps/sim). Checklist Code follows project style guidelines Self-reviewed my changes Tests added/updated and passing No new warnings introduced
Open Graph Description: Summary Mothership run_code on a reused chat workbench makes 5 E2B control-plane requests per call: list and connect; then getInfo + setTimeout to extend the lease; then another getInfo on release...
X Description: Summary Mothership run_code on a reused chat workbench makes 5 E2B control-plane requests per call: list and connect; then getInfo + setTimeout to extend the lease; then another getInfo on release...
Opengraph URL: https://github.com/simstudioai/sim/pull/8621
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:0e8d5f92-e39b-73e8-0330-c7064b090743 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | DF4C:3ED756:27FC61:37CE67:6AFB52CC |
| html-safe-nonce | 473b05182dee70bbd3f9cd8804cf0b87c56061512fb042a028afc262cdfae64e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERjRDOjNFRDc1NjoyN0ZDNjE6MzdDRTY3OjZBRkI1MkNDIiwidmlzaXRvcl9pZCI6IjY3OTA0MTgzMDgzNzQ2ODAyNjgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 2e348060b92023fcf1695b41f7075386745bbe5094369fd4cf8f78ecb4e8cba8 |
| hovercard-subject-tag | pull_request:4743236717 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/simstudioai/sim/pull/8621/files |
| twitter:image | https://avatars.githubusercontent.com/u/40672544?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/40672544?s=400&v=4 |
| og:image:alt | Summary Mothership run_code on a reused chat workbench makes 5 E2B control-plane requests per call: list and connect; then getInfo + setTimeout to extend the lease; then another getInfo on release... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7122bb414b542dba14d71a3f0b9f6fd2abce715b9f5912d082800563e6c806d1 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/simstudioai/sim git https://github.com/simstudioai/sim.git |
| octolytics-dimension-user_id | 199344406 |
| octolytics-dimension-user_login | simstudioai |
| octolytics-dimension-repository_id | 912559512 |
| octolytics-dimension-repository_nwo | simstudioai/sim |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 912559512 |
| octolytics-dimension-repository_network_root_nwo | simstudioai/sim |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | cbf66c024bb6d10e6955baa7413c54cf13a201bb |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width