Repository navigation
feat(mocactl,sandbox-client): SBX0 idle lifetime - the activity hint and --lifetime (#770) - #842
Conversation
…; the sandbox end follows each grant (#770) Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…y token; sandboxExpiresAt (#770) Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…o feat/sbx-idle-lifetime-clients Signed-off-by: Paolo Dettori <[email protected]> Assisted-By: Claude (Anthropic AI) <[email protected]>
…user guide (#770) Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…ent (#770) Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…he MCP server follows the deadline (#770) Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
leaseControl takes opts.activity (default: every op but status); sendSetMode passes it to the call and to its denied re-mint; get passes false. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
… number (#770) Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…ndbox (#770) Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Summary
This is plan 2 of #770 (clients). Every mint that runs no command now sends {"activity":false}: the sbx mcp keepalive and its relay-refusal re-mint, lease status, all of sbx get's mints (including the set_mode re-send and the denied re-mint), and sbx env. That closes the keepalive-counts-as-activity gap from #837's review. Exec, process calls, reset, create/mode, token, doctor, rm, up and push still count as activity. The base branch's control plane reads the same field: parseActivity(...activity) in sandbox-handlers.ts:301, used for /token and /mode-token, and it is in the openapi. The client sends a body only for activity === false, so older control planes are unaffected.
I also checked these, and they look right:
sandboxExpiresAtadoption- the "did not take --lifetime" path
- the lifetime suffixes in ls/get/doctor
- the rewritten user-guide §7
sanitizeRemoteon remote text
I have three suggestions. None of them block.
Author: pdettori (MEMBER, maintainer)
Areas reviewed: TypeScript (mocactl, sandbox-client), Docs, Tests
Agent/IDE config (.claude/.vscode): none
Commits: 14 commits (one is a merge of the base branch), all signed-off: yes
CI status: passing (DCO, check, k8s-kind-e2e, which is all that runs for a PR based on a non-main branch)
| worker's) | ||
| worker's); | ||
| --lifetime: the sandbox ends after DURATION (36h, | ||
| 14d, 30m or seconds) without use (default: the |
There was a problem hiding this comment.
suggestion: The 30m example can never succeed. The control plane's floor is MIN_SANDBOX_LIFETIME_S = 3600 (base branch sandbox-config.ts:109), and parseLifetime (sandbox-handlers.ts:205-217) refuses anything lower with 400 invalid_request. The same example appears at cli.ts:289 and docs/sbx/user-guide.md:91, and the guide never mentions the 1 h minimum. I'd change the example (e.g. 90m) and say "at least 1 h". You could also refuse values under 3600 on the client with a clear message, as parseIdleTimeout does for its range.
There was a problem hiding this comment.
Fixed in 86536f0. The examples now use 90m, and the usage text and user guide say "at least 1 h, at most the deployment's maximum". The client still checks syntax only, so the control plane remains the one place that enforces the range.
| fix: | ||
| 'pull its work before then (mocactl sbx pull --apply); for a fresh sandbox, ' + | ||
| `mocactl sbx rm, then ${UP}`, | ||
| `it ends after ${validLifetime(s.idleLifetimeS) ? lifetimeText(s.idleLifetimeS) : 'its lifetime'} ` + |
There was a problem hiding this comment.
suggestion: This fix text is also printed when the record has no idleLifetimeS (the 'its lifetime' fallback). On a control plane from before idle lifetimes, the lifetime is absolute, so "any command extends it" is wrong there. The old advice (pull, then sbx rm + up) is the right one in that case. Suggest keeping the old text when !validLifetime(s.idleLifetimeS). (#837 with SH_SANDBOX_MAX_LIFETIME_SECONDS unset also reports idleLifetimeS without sliding, but plan 3 closes that.)
There was a problem hiding this comment.
Fixed in 989c711. When the record has no valid idleLifetimeS (a control plane from before idle lifetimes), doctor gives the old advice: pull its work, then mocactl sbx rm and mocactl sbx up. It says "any command extends it" only when the lifetime is valid. Both cases are tested.
| // A no-activity mint in flight is not joined by an activity ask: wait it out, then mint. | ||
| while (pending && activity && !pending.activity) await pending.p.catch(() => undefined); | ||
| // An ask aborted during that wait starts nothing, and publishes no mint for others to join. | ||
| signal?.throwIfAborted(); |
There was a problem hiding this comment.
suggestion: With mintShared now async and calling throwIfAborted(), an ask whose signal is already aborted always yields a rejected inner promise. mint wraps it in untilAborted(...), and for an aborted signal that returns Promise.reject(signal.reason) straight away (:196) without ever observing the inner promise. The inner rejection is therefore unhandled, and under Node's default --unhandled-rejections=throw it can kill a long-lived sbx mcp. It can happen through remint(signal) → t.force(signal) from refreshMode(extra.signal) on an already-cancelled tool call. Main had a milder form of this (a pending fetch with an aborted signal); throwIfAborted makes it certain. A fix is to check signal?.aborted in mint before calling mintShared, or to add p.catch(() => {}) in untilAborted. A test with a pre-aborted force(signal) would pin it.
There was a problem hiding this comment.
Fixed in ed8cbd9. mint now returns Promise.reject(signal.reason) for an already-aborted signal without calling mintShared, so no mint starts. untilAborted also attaches a no-op catch to the inner promise on its early return, as a defence for any future caller. A new test calls force(aborted) and first(aborted) and asserts the abort reason, that no mintSandboxToken call is made, and that no unhandledRejection fires.
…ection (#770) Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…te (#770) Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
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]>
… caveat (#770) The idle-lifetime spec moves to v0.2, implemented in #837, #842 and #843 and shipping in v0.11.0, and records what the build decided (sliding only once the maximum is configured, doctor and sbx env, SBX_MAX_LIFETIME_DAYS=off, a lowered maximum keeping the workers' idle). The registry row reads implemented. The deploy README says to keep deploy/sbx/.generated/workers until a lowered maximum's old value has passed: the kept idle lives only in those bundles. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Summary
Plan 2 of 3 for #770 (spec:
docs/specs/2026-11-16-sbx-idle-lifetime-design.md). Stacked on #837; review only the commits after6efafbc6(the merge commitc3565119only brings in #837's review fixes).The clients side of idle lifetimes:
@moca/sandbox-clientreset,set_mode,sandbox_deleted) ask with activity. The lease keepalive and the leasestatusask without it.sandboxExpiresAt, so a session that outlives the sandbox's original deadline keeps running. Without the field, behaviour is as today.mocactltoken source{"activity":false}only for a no-activity mint, and no body otherwise (older control planes).sbx get(status, set-mode re-send, itsdeniedretry), thesbx mcplease keepalive, andsbx envmint withactivity:false.sbx tokenand--renew-everykeep counting, because a direct client's Execs run on them; the docs say so.--lifetime DURATIONoncreateandup(36h,14d,30m, or seconds).upwarns and carries on when it reuses a sandbox.create,up,doctor,get,ls(andls --all, with aligned columns) showafter 7 d without usewhen the record carriesidleLifetimeS. Nothing extra is shown otherwise.doctor's <24 h warning says any command extends the sandbox.--lifetime, the §7 margins (25 d / 2 d), an oldermcpdriving a long-lifetime sandbox, and token pumps.doctorline is corrected.Test evidence
packages/mocactl: 2065 passed in the full run. Two failures:app.test.tsx(the TUI baseline failure on the base) and onesbx-templatestest that times out under full-suite load and passes alone (94/94).sbx-up,sbx-pushandsbx-templateseach pass alone. A focused rerun of contract, sbx-mode, sbx-exec, sbx-cli and sbx-lifetime at head gives 289 passed.tscand prettier are clean.packages/sandbox-client: 260 passed.pi-schema-contract.test.tsdoesn't load locally (pi-fork unbuilt), as on the base.Rollout
Ship with #837 and plan 3 (deploy). With #837 alone, idle lifetimes stay off. Plan 3's
setup.shturns them on together with the workers' longer cleanup timer. Users should upgrademocactlbefore using--lifetimeabove the default, because an oldersbx mcpkeepalive counts as use.Part of #770.
Assisted-By: Claude Code