Skip to content

improvement(sandbox): pause idle chat workbenches instead of keeping them running - #9452

Merged
waleedlatif1 merged 3 commits into
stagingfrom
feat/session-sandbox-pause
Oct 29, 2026
Merged

waleedlatif1 merged 3 commits into
stagingfrom
feat/session-sandbox-pause

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • Chat workbench sandboxes pause after a 5-minute idle lease instead of running for 20 minutes and then being killed. Resume keeps files, packages and processes and takes well under a second. Paused sandboxes aren't billed and don't count toward the provider's concurrency limit
  • New cleanup-session-sandboxes cron (every 5 min) kills workbenches paused for more than 15 min, so retention stays where it was: a workbench is discarded about 20 min after its last use
  • Each kill runs under the session lock and re-checks the sandbox's own getInfo, because the provider's list trails resumes and kills by a few seconds. autoResume: false, so only a locked reconnect can wake a paused sandbox
  • Streamed workbench writes and upload snapshots now lease their full 10-min transfer budget, so a machine can't pause mid-transfer under the shorter idle lease
  • E2B Mothership sandboxes are priced at their template's real 2 vCPU / 1 GiB instead of the 4 GiB Function profile (sandbox time was overcharged by ~41%)
  • Cron registered in helm, docker crontab, the self-hosting docs and the API-validation allowlist. The hosted schedule needs the matching infra cron entry (separate PR)

Replaying a day of real sandbox activity through the new policy: ~38% fewer running sandbox-hours, ~23% lower peak concurrency, and idle gaps of 5–20 min resume the same machine instead of keeping it running.

Type of Change

  • Improvement

Testing

  • New opt-in live E2E session-pause.live.test.ts against real E2B, with a real mothership-shell sandbox: auto-pause on lease expiry; reconnect resumes with a file intact; kill is refused for a too-recent pause and for a running sandbox; kill succeeds once expired. Red-checked: with kill-on-timeout instead of pause, it fails
  • New pricing row for the Mothership profile and the write-lease assertion: both fail with their fix reverted
  • Targeted vitest across lib/execution/remote-sandbox, lib/billing and lib/mothership, all passing
  • Biome on changed files; check:api-validation:strict, check:unused-exports, check:comment-hygiene, check:source-conventions pass locally. Type-check and the full audit gate run in CI

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing (new tests pass the test-audit authoring gate)
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercel Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Oct 29, 2026 8:39pm UTC

Request Review

…them running

- Session sandboxes now pause after a 5-minute idle lease (was: kept running for
  20 minutes, then killed). Resume keeps files, packages and processes and takes
  well under a second; paused sandboxes are not billed and do not count toward
  the provider's concurrency limit.
- A new cleanup-session-sandboxes cron kills workbenches paused for more than 15
  minutes, so a workbench is still discarded about 20 minutes after its last use.
  Each kill runs under the session lock and re-checks the sandbox's own info,
  so a just-resumed workbench is never killed.
- Streamed workbench writes and upload snapshots lease their full transfer
  budget so a machine cannot pause mid-transfer.
- E2B Mothership sandboxes are priced at their template's 2 vCPU / 1 GiB
  instead of the 4 GiB Function profile.
@waleedlatif1
waleedlatif1 force-pushed the feat/session-sandbox-pause branch from 402c17f to bd119ea Compare October 29, 2026 20:23
@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no new blocking issues were found.

Summary

Chat workbenches now pause after their idle lease expires instead of being destroyed.

  • Chat workbenches pause after five idle minutes and resume intact.
  • A five-minute cleanup sweep removes workbenches that have stayed paused too long.
  • E2B Mothership sandbox charges use its actual template resources.

No new actionable issues were found. The earlier, unnumbered cleanup-duration thread was rechecked; the sweep now defers remaining work once its deadline expires.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  Running["Running workbench"] -->|"Idle lease expires"| Paused["Paused; files retained"]
  Paused -->|"Locked reconnect"| Running
  Paused -->|"Paused over 15 minutes"| Check["Take session lock and check current state"]
  Check -->|"Still paused and expired"| Killed["Workbench removed"]
  Check -->|"Running or recently paused"| Keep["Leave workbench intact"]
Loading

Reviews (2) · Last reviewed commit: "fix(sandbox): bound the session sandbox ..." · Reviewed by Greptile

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed

Reply with feedback, questions, or to request a fix.

Turn on auto-fix | Re-trigger cubic

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 21 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Turn on auto-fix | Re-trigger cubic

@waleedlatif1
waleedlatif1 merged commit 322abb2 into staging Oct 29, 2026
74 checks passed
@waleedlatif1
waleedlatif1 deleted the feat/session-sandbox-pause branch October 29, 2026 20:51

This branch was previously deployed

1 inactive deployment
Preview — 4944839e Deployed Oct 29, 2026 by vercel[bot]
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