Repository navigation
docs(spec,adr): SBX0 idle lifetime - a sandbox's lifetime counts idle time (#770) - #820
Conversation
… time (rossoctl#770) A sandbox now ends after its idle lifetime with no activity mint, instead of 7 days after creation. The owner picks idleLifetimeS at create (default 7 days, at most 30), there is no hard maximum age, mints that run no command say activity: false, and the worker's idle reclaim follows the maximum. Adds the design, a 2026-11-16 revision of ADR-0042, the SBX0 spec pointers and the milestone registry row. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
clawgenti
left a comment
There was a problem hiding this comment.
Reviewed the SBX0 idle-lifetime design docs (new spec, ADR-0042 revision, SBX0 spec pointers, registry row).
Verified against origin/main: the current-state claims in §1.1 all check out — KEEPALIVE_MS = 30_000 and the 60 s token requirement (mcp.ts), the set-mode token routes and setModeTokenFor (routes.ts, sandbox-handlers.ts), setup.sh's SBX_LIFETIME_DAYS × 24 + 48 (216 h) formula and the SBX_ACK_HOSTS refusal, MAX_SANDBOX_TOKEN_TTL_S = 3600, and the ref commit fb9d839b. The arithmetic in the doc is internally consistent (768 h = 30 d + 48 h; the §7 gap of (max − L) + 48 h ≈ 25 d at the 7-day default and 2 d at the maximum; the §5.2 "21 days after create" = 7 d lifetime + 14 d retention).
The design holds together well: the mint as the single activity choke point (so older clients slide too), the activity: false hint closing the idle-MCP-window hole, the atomic TOUCH moving every expiry-bearing key together, and the honest §7 accounting of the one accepted gap. One suggestion below on status wording.
Author: pdettori (MEMBER — maintainer)
Areas reviewed: Docs (design/ADR/spec), consistency against code on main
Agent/IDE config (.claude/.vscode): none
Commits: 1, signed-off: yes
CI status: passing (deploy-scripts-bash32 pending)
Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).
| although the sandbox was never idle (rossoctl/moca#770). The absolute lifetime is right | ||
| for an abandoned sandbox and wrong for one in use. | ||
|
|
||
| **Decided** (design: [`../specs/2026-11-16-sbx-idle-lifetime-design.md`](../specs/2026-11-16-sbx-idle-lifetime-design.md)): |
There was a problem hiding this comment.
suggestion — The revision opens with "Decided" while the design doc it points to says "Status: Design. Not approved. Not built." and the registry row says "design — draft". ADR-0035's revisions record decisions already made; this one records a decision still out for review. Consider wording it as provisional (e.g. "Decided, pending design approval") or updating the ADR only when the design is accepted, so a reader of the ADR alone doesn't take the idle lifetime as settled. Everything else in the revision is consistent with the draft's content.
Suggested fix: soften the one word (or gate the ADR edit on design acceptance); no content change needed.
There was a problem hiding this comment.
Fixed in 01c4b5b, the other way round: the design was approved on 2026-11-16, so the spec's status line now reads "Approved (2026-11-16). Not built.", the registry row reads "design — approved (2026-11-16)", and the ADR's "Decided" names the approval date. The ADR and the design now agree that this is settled.
clawgenti
left a comment
There was a problem hiding this comment.
Review tracking marker for the automation queue (review 5923112538 posted above, at 864848c).
Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Summary
A clear, well-scoped design for #770. It makes SBX0's lifetime idle-based: activity mints slide expiresAt forward, never back, and never revive a sandbox. idleLifetimeS is chosen at create, there's no hard max age, and SH_WORKSPACE_IDLE follows the deployment maximum. I checked the claims about current state against main @ 032c8f6: expiresAt = now + cfg.lifetimeS at create, notAfter: rec.expiresAt in both mint paths, MAX_SANDBOX_TOKEN_TTL_S = 3600, KEEPALIVE_MS = 30_000, the record EXPIREAT / name PXAT in sandbox-redis.ts, egress-log EXPIREAT, setup.sh's SBX_LIFETIME_DAYS*24+48 and the SBX_ACK_HOSTS refusal, vmpool keepalive setting lastKeepalive, not lastExec, and exec-conn's learn() using sandboxExpiresAt. All accurate. The activity: false hint and the "no-activity token never runs a command" rule close the idle-MCP-window hole neatly. No blockers; the suggestions below tighten the invariant argument and two places where the spec leaves a builder's choice that matters.
Author: pdettori (MEMBER — maintainer)
Areas reviewed: Docs (spec, ADR revision, specs registry). Claims verified against main code (control-plane, sandbox-client, mocactl, remote-worker vmpool, deploy/sbx)
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, all signed-off: yes
CI status: all green except deploy-scripts-bash32, which failed with no steps run ("The job was not acquired by Runner of type hosted even after multiple attempts": macOS arm64 capacity). That's infra, not this docs-only change; re-run before merge.
|
|
||
| - the worker reclaims a workspace after `max + 48 h` with no Exec on it; | ||
| - the control plane ends a sandbox after `L ≤ max` with no mint; | ||
| - every Exec is preceded, within one token lifetime (≤ 1 h), by a mint. |
There was a problem hiding this comment.
suggestion: §6.2's "every Exec is preceded by a mint" holds per token, but the worker's idle clock is per workspace, and lease-path activity resets it too. On main, rp.lastExec is set by acquire (pool.go:634) and by runLease at its start and its end (lease.go:743, :792), and also by lease end (lease.go:909: "idle clocks run from the lease's end"). Lease end includes keepalive_lost and the idle timeout. So with an MCP window open, a lease that times out moves the worker's clock forward with no activity mint. That's harmless: it only makes the worker more conservative, and the inequality still holds. But the argument as written ("both clocks are idle clocks") reads as if they reset on the same events. Consider one sentence: the worker's clock resets on Exec start/end and lease end, all of which come after a mint or are later than one, so the worker's last reset is never earlier than the last Exec, and the bound still holds.
There was a problem hiding this comment.
Fixed in 01c4b5b. §6.2 now lists the worker's actual resets: Exec start (acquire, pool.go), a lease run's start and end, and lease end (lease.go, which includes keepalive_lost and the lease idle timeout). It also says that each of these happens during or after an Exec, so the worker's last reset is never earlier than the last Exec's start. A lease end with no mint only moves the worker's clock later, which is the conservative direction, so the bound still holds.
|
|
||
| In `mintSandboxToken`, after `requireLive` and `underPolicy`, before the token is minted (and in | ||
| the same place in the two set-mode token handlers, before `setModeTokenFor`), unless the body says | ||
| `activity: false` (which `PUT …/mode` does not accept): |
There was a problem hiding this comment.
suggestion: PUT …/mode with a stray activity field. "(which PUT …/mode does not accept)" is ambiguous. Today's handlers ignore unknown body fields (create's asRecord(ctx.body) reads only named keys), so a client sending {mode, activity:false} to PUT would get a silent extension, not a refusal. Say which you mean: ignored (and still counts), or 400 invalid_request. Add the test to §12's Hint line either way.
There was a problem hiding this comment.
Fixed in 01c4b5b: refused. PUT …/mode returns 400 invalid_request for a body naming activity, so a client sending it there learns it has no effect instead of getting a silent extension (§3.1, and §4.2 points to it). §12's Hint line now tests it.
| events, from the deadline as it was then. The egress records design promises the log lives "as long | ||
| as the sandbox record: its end plus the sandbox retention". So a touch that moves the deadline also | ||
| moves those keys' `EXPIREAT` and their index score (`ZADD XX`), when they exist, and leaves a sealed | ||
| log alone (a sealed log belongs to an ended sandbox, which a touch refuses). Preferably inside |
There was a problem hiding this comment.
suggestion: Leaving the egress-log move to the builder ("preferably inside TOUCH … a second write is acceptable") is weaker than it reads. The repair argument ("the next mint or append repairs a crash") needs another mint after the crash, and the last mint before a sandbox goes idle may be the crashed one. Then the egress log expires at the old end + retention while the record lives to the new one. That breaks the egress-records promise that this section quotes. The window is small, but the call is cheap to make: require it inside TOUCH (pass stream/meta/index in KEYS. Same-slot isn't a concern unless Redis Cluster is planned, and nothing in sandbox-redis.ts uses hash tags), or state the accepted divergence explicitly.
There was a problem hiding this comment.
Agreed, fixed in 01c4b5b. §5.2 now requires the egress move inside TOUCH, with the stream, meta and index keys passed in KEYS, and gives your reason for not using a second write: the crashed write can be the last mint before the sandbox goes idle, and nothing would repair it. It also records that no key in either module is hash-tagged and SBX0 runs no Redis Cluster, so one script can touch both prefixes.
| - `POST /v1/sandboxes/{id}/token` and `POST /v1/sandboxes/{id}/mode-token` with | ||
| `{ "activity": false }` mint as today and do not touch the deadline. Anything but a boolean is | ||
| `400 invalid_request`. `PUT /v1/sandboxes/{id}/mode` (an owner's mode change) always counts. | ||
| - **Default `true`**, so an older `mocactl` and developers' own code (SBX0 §7) still extend. An older |
There was a problem hiding this comment.
nit: "An older client cannot ask for more than the 7-day default (it has no --lifetime)" is true of mocactl, but §3.1 also names developers' own code (SBX0 §7), and that code can send idleLifetimeS to POST /v1/sandboxes without the hint. Then its keepalive-style mints count at up to 30 days, and the margin is 2 days, not 25. §7 covers "a client of its own … without the hint", so maybe just drop "25-day" here or point to §7's 30-day figure.
There was a problem hiding this comment.
Fixed in 01c4b5b. The 25-day margin now applies only to an older mocactl. The text adds that developers' own code can send idleLifetimeS up to the maximum without the hint, which leaves it with §7's margin: as low as 2 days at 30 days.
| ## 8. Clients | ||
|
|
||
| - `mocactl sbx create` and `mocactl sbx up` take `--lifetime DURATION` (`36h`, `14d`, or seconds), | ||
| sent as `idleLifetimeS`. The control plane holds the range; the client checks only the syntax, as |
There was a problem hiding this comment.
nit: --lifetime bounds: the control plane refuses below 3600 s, so mocactl sbx create --lifetime 30m reaches the server and gets a 400. That's fine if the 400 names the range (§4.1 says it does). Consider stating that up passes --lifetime and ignores it on an existing sandbox (or warns), since "cannot be changed later" (§2) plus a silently dropped flag is a likely support question.
There was a problem hiding this comment.
Fixed in 01c4b5b. §8 now says --lifetime 30m reaches the server and gets the 400 that names the range (§4.1). When up binds an existing sandbox, it warns that the sandbox keeps its own lifetime because --lifetime applies only to a new sandbox, and carries on, without an error. §12 tests the warning.
- Status: the design is approved (2026-11-16); the ADR revision and the registry row say so. - §6.2: the worker's lastExec resets on Exec start, lease-run start/end and lease end; the bound still holds, a lease end only makes it later. - §3.1, §4.2: PUT /mode refuses a body naming activity with 400. - §5.2: the egress log's keys move inside TOUCH, not in a second write. - §3.1: developers' own code may set idleLifetimeS without the hint; its margin is §7's. - §8: up warns, and goes on, when --lifetime meets an existing sandbox; --lifetime 30m gets the server's range error. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Takes upstream main at 1a7f41e (19 merges since 032c8f6): the sandbox idle lifetime across docs, control plane, clients and deploy (rossoctl#820, rossoctl#837, rossoctl#842, rossoctl#843), grant redemption (rossoctl#822), the lease-check log line (rossoctl#824), egress fixes (rossoctl#829, rossoctl#834), the mock wait (rossoctl#828), the deadline timer (rossoctl#835), the create rollback (rossoctl#832), multi refusals and the rossoctl#363 leftovers (rossoctl#833, rossoctl#838), the identity near-miss check (rossoctl#827), mocactl login errors (rossoctl#836), the ghostunnel probes (rossoctl#830), refusal-burst deferral (rossoctl#831), a sandbox-worker change (rossoctl#841) and the v0.11 doc truth (rossoctl#821). Conflicts (one): - deploy/sbx/README.md, the "Optional inputs" table. Upstream (rossoctl#843) rewrote the SBX_LIFETIME_DAYS row (the default idle lifetime, at most SBX_MAX_LIFETIME_DAYS) and added the SBX_MAX_LIFETIME_DAYS and SBX_LOWER_WORKSPACE_IDLE rows, which widened the table; the fork had added an SBX_GATE_RECORD_SCHEMA row at its end. Resolved by taking upstream's table whole and appending the fork's SBX_GATE_RECORD_SCHEMA row after SBX_PROFILE, then re-padding the table with prettier. The fork's env-file example line for SBX_GATE_RECORD_SCHEMA merged cleanly. Merged without markers, checked: setup.sh keeps the fork's SBX_GATE_RECORD_SCHEMA validation and its sbx-settings write (so it stays in the settings hash) beside upstream's SH_SANDBOX_MAX_LIFETIME_SECONDS; both ocp-sbx and ocp-combined patch-control-plane.yaml keep the optional SH_GATE_RECORD_SCHEMA from sbx-settings beside the new optional SH_SANDBOX_MAX_LIFETIME_SECONDS; setup.test.sh keeps the fork's cases beside upstream's. The fork's RUNBOOK, README and template-onboarding docs say nothing about sandbox lifetime, refusal bursts, login errors or the create rollback, so none needed a correction; GUIDE.md is unchanged and GUIDE.pdf is not regenerated. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
Summary
Design for #770: a SBX0 sandbox's lifetime counts idle time, not time since creation, so a user working in a sandbox daily never loses it at the 7-day mark.
expiresAttomax(expiresAt, now + idleLifetimeS); it never moves backwards and an ended sandbox is never revived. Expiry stays computed, never scheduled.idleLifetimeS(mocactl sbx create|up --lifetime), 1 h toSH_SANDBOX_MAX_LIFETIME_SECONDS(30 d); defaultSH_SANDBOX_LIFETIME_SECONDS(7 d).SH_WORKSPACE_IDLEfollows the maximum (+48 h = 768 h).activity: falsehint on the mint routes for mints that run no command (MCP lease keepalive,sbx get's lease status), so an open idle MCP window neither keeps a sandbox alive forever nor opens a silent-reset window; a command never runs on a no-activity token.TOUCHmoves the record field, thelivescore, the record hash'sEXPIREAT, the name key'sPXATand the egress log's expiry together.sandboxExpiresAt, which long-lived clients (the MCP server,exec-conn) follow.Files
docs/specs/2026-11-16-sbx-idle-lifetime-design.md(new)docs/adrs/0042-sbx0-sandbox-service-on-sandbox-v1.md: 2026-11-16 revisiondocs/specs/2026-10-15-sbx0-internal-sandbox-service-design.md: §5.1, §5.2, §5.4, §5.5 pointersdocs/specs/README.md: registry rowDocs only; the implementation plan follows.
Refs #770
Assisted-By: Claude Code