improvement(sandbox): pause idle chat workbenches instead of keeping them running
Merged
WA
10d ago+320+320+012345678901234567890123456789-42-42-01234567890123456789
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-sandboxescron (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.tsagainst real E2B, with a realmothership-shellsandbox: 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/billingandlib/mothership, all passing - Biome on changed files;
check:api-validation:strict,check:unused-exports,check:comment-hygiene,check:source-conventionspass 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-auditauthoring gate) - No new warnings introduced
- I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)