Repository navigation
Description
Problem
ADR-0042 gives each SBX0 sandbox a fixed absolute lifetime: 7 days from creation, with no extension. Using the sandbox does not reset the clock.
Concretely, expiresAt is computed once at create (packages/control-plane/src/sandbox-handlers.ts:168, now + cfg.lifetimeS) from SH_SANDBOX_LIFETIME_SECONDS, default 7 days (packages/control-plane/src/sandbox-config.ts:158). Expiry is computed, never scheduled (packages/control-plane/src/sandbox-store.ts:33-44), and minting a token past expiresAt refuses with sandbox_terminated (sandbox-token.ts), so at the deadline the record simply reads ready -> terminated (expired) and access stops.
That is the right behavior for an abandoned sandbox, and it is what bounds disk and worker capacity. It is the wrong behavior for an actively used one: a user who works in a sandbox daily for a week loses the workspace at the 7-day mark even though the sandbox was never idle. They lose work they were actively using.
Desired
Count the lifetime as idle time, not time since creation: expiresAt = lastActivityAt + lifetime. Activity pushes the deadline forward; the sandbox expires only after lifetime with no activity.
Open questions
- Maximum lifetime cap. ADR-0042's no-silent-reset invariants include "the worker's idle reclaim is set longer than any sandbox can live." A pure sliding TTL makes lifetime unbounded, so that invariant no longer holds and a long-lived sandbox can hit the worker's idle reclaim. Options:
- (a) Sliding idle TTL with no absolute cap, and change/disable the worker's idle reclaim for sandboxes — breaks the current invariant; probably not wanted.
- (b) Sliding idle TTL plus a hard max age (e.g. 30 or 90 days from creation), with expiry reporting
idlevsmax_age. Recommended. - (c) Keep the absolute lifetime but make it longer — does not fix the reported problem.
- What counts as activity. Token mint (covers both
mocactl sbxexec and the MCP tool server) and every successful Exec are the natural candidates. Read-onlylist/getshould probably not count, or a dashboard poll keeps a sandbox alive forever. Token mint is the cheapest single choke point and covers all clients. - ADR/spec change. ADR-0042 says "fixed absolute lifetime" and "the control plane owns the lifetime." This needs an ADR amendment (or a superseding ADR) and a spec §5.2 update before implementation.
- Existing records. Records created before the change carry an
expiresAtcomputed at create. If expiry only ever moves forward, no migration is needed — sliding takes effect from the next activity.
Implementation notes
- Handler:
createSandboxsets the deadline (sandbox-handlers.ts:168). Sliding needs an update path on activity;mintSandboxTokenalready reads the record and returnsexpiresAt, so it is the natural place. - Store: both backends must extend the deadline atomically.
RedisSandboxStorekeepsexpiresAtin the record hash, as the score in theliveZSET, and derives the name key'sPXATfrom it (packages/control-plane/src/sandbox-redis.ts), so extending meansHSET+ZADD+PXATin one script while preserving the samenow >= expiresAtrefusal semantics under concurrency. The in-memorySandboxStoreis the contract;test/helpers/sandbox-store-contract.tsshould gain the extend case and run against both. - Tokens: minted with
notAfter: rec.expiresAt, so a moved-forward deadline just raises the cap. - Retention/janitor: termination and retention should still count from the terminal
terminatedAt, not from the last activity. - Config:
SH_SANDBOX_LIFETIME_SECONDSchanges meaning from absolute to idle lifetime; addSH_SANDBOX_MAX_LIFETIME_SECONDSif option (b) is taken.
Acceptance criteria (draft)
- A sandbox with activity inside each
lifetimewindow does not expire. - A sandbox idle for
lifetimereadsterminated/expiredand stops minting tokens. - If a max age is adopted, the sandbox expires at max age regardless of activity, with a distinguishable reason.
- Contract tests cover extend against both stores; the Redis path is one atomic script.
- API responses'
expiresAtreflects the extended deadline. - ADR-0042 amended and the spec updated.
References
- ADR-0042:
docs/adrs/0042-sbx0-sandbox-service-on-sandbox-v1.md - SBX0 spec §5.2 (expiry computed, never scheduled)
- P4 microVM tier: WorkspaceIdle=30min deletes a HITL session's workspace mid-session, silently #338 (silent workspace reset)
Activity
docs(spec,adr): SBX0 idle lifetime - a sandbox's lifetime counts idle…
Merge pull request #820 from pdettori/docs/sbx-idle-lifetime
fix(control-plane): a touch never lowers the egress index score (#770)
fix(control-plane): extend on activity only once the maximum is confi…
Merge pull request #837 from rossoctl/feat/sbx-idle-lifetime-cp
fix(mocactl): a pre-aborted token ask starts no mint and leaks no rej…
fix(mocactl): doctor keeps the old advice when the lifetime is absolu…
docs(mocactl): --lifetime examples respect the 1 h minimum (#770)
Merge pull request #842 from rossoctl/feat/sbx-idle-lifetime-clients
docs(spec): an unset maximum idle lifetime is the default lifetime (r…
feat(control-plane): SH_SANDBOX_MAX_LIFETIME_SECONDS, the most an own…
feat(control-plane): SandboxStore.touch slides a live sandbox's deadl…
feat(control-plane): one TOUCH script moves the deadline, the record …
23 remaining items
feat(deploy/sbx): status.sh warns of a worker idle at or below the lo…
docs(deploy/sbx): the maximum idle lifetime, reinstalls, and the upgr…
fix(deploy/sbx): a lowered maximum keeps the workers' idle until SBX_…
feat(deploy/sbx): SBX_MAX_LIFETIME_DAYS=off defers idle lifetimes (#770)
fix(deploy/sbx): refuse turning idle lifetimes on when the hosts' bun…
fix(deploy/sbx): status.sh reports a missing worker idle as missing (#…
docs(deploy/sbx): idle lifetime review follow-ups (#770)
Merge pull request #843 from pdettori/feat/sbx-idle-lifetime-deploy
pdettori commentedon Nov 17, 2026
Implemented, and shipping in v0.11.0. It will be tested as part of the v0.11.0 release testing.
expiresAt; a mint never moves it back and never revives an ended sandbox.{"activity":false}don't count.idleLifetimeSat create.sandboxExpiresAtis in the token response.SH_SANDBOX_MAX_LIFETIME_SECONDSis set.mocactl sbx createanduptake--lifetime.sbx get, thesbx mcpkeepalive andsbx envmint without activity, and a command never runs on such a token.SBX_MAX_LIFETIME_DAYS(default 30, oroff) sets each worker'sSH_WORKSPACE_IDLEto the maximum + 48 h.SBX_LOWER_WORKSPACE_IDLE=1.status.shwarns about a worker whose idle doesn't outlast the maximum.SBX0 rollout (part of v0.11.0): run
deploy/sbx/setup.shwithSBX_ACK_HOSTS=1. That raises the worker idle from 216 h to 768 h and turns idle lifetimes on. Reinstall every host's workers the same day, then check thatdeploy/sbx/status.shshows noworker idlewarning. If the hosts can't be reinstalled that day, useSBX_MAX_LIFETIME_DAYS=off. Cohort users should upgrademocactlbefore using--lifetimeabove the default.docs(spec): idle lifetime review nits on rossoctl#847 (rossoctl#770)
fix(deploy/sbx): name the live maximum when it, not the bundles, keep…
docs: SBX0 idle lifetime is implemented; the lost-.generated lowering…
Merge pull request #847 from pdettori/docs/sbx-idle-lifetime-followups
docs(api): a sandbox's expiresAt slides with activity since 1.25.0