Skip to content

feat(sbx): lease mode plan 4 — the clients (mocactl, MCP server, Go client) and plan 2–3 carry-overs - #808

Merged
pdettori merged 34 commits into
rossoctl:mainfrom
pdettori:feat/sbx-lease-clients
Nov 14, 2026
Merged

pdettori merged 34 commits into
rossoctl:mainfrom
pdettori:feat/sbx-lease-clients

Conversation

@pdettori

@pdettori pdettori commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Summary

SBX0.3 lease mode, plan 4 of 5: the clients. Plan 3 (#802) put lease mode on the wire. This PR makes it usable from mocactl, the MCP server and the static Go client, and closes the carry-overs from plans 2 and 3. Lease mode stays off by default: SH_SANDBOX_MODES_ALLOWED is still per-exec.

Spec: docs/specs/2026-11-08-sbx-lease-mode-design.md, sections 4, 5, 8, 11 and 13. Plan 3: #802.

Live status (plan Task 12):

What it adds

  • mocactl
    • sbx create --mode <per-exec|lease|lease+processes> --idle-timeout <s>. A lease create is followed by set_mode; if the worker cannot be reached, the create still succeeds and warns that the mode is pending.
    • New sbx mode, sbx reset and sbx get. get re-sends set_mode when the worker reports an unknown epoch.
    • An upgrade needs a terminal: a lease mode without a TTY on stdin is exit 2. This is a speed bump, not a security boundary (spec §11 residual).
    • Unseen lease notices are printed once, from <state>/sbx/notices.json, and run prints the notices it receives.
    • ls gets a MODE column.
    • rm sends sandbox_deleted, bounded at 15 s.
    • Ctrl-C cancels a long set_mode or reset (exit 130; the change is reported as pending).
    • sbx up writes mode-aware agent instructions.
  • MCP server (@moca/sandbox-client, wired by mocactl sbx mcp)
    • Notice lines on tool results, deduplicated, and placed before the error text on a failure.
    • A reset tool.
    • Lease fields in sandbox_info.
    • Mode-aware rules and tool descriptions.
    • A keepalive every 30 s while the latest token's mode is a lease mode.
  • sandbox-client
    • Lease events on ExecResult and on ExecMachineryError.
    • leaseControl and leaseKeepalive, each retried once with a fresh token after a token refusal.
    • An Exec refused with stale_mode is retried once with a fresh token.
    • LeaseControlError codes for the relay's statuses.
    • leaseNotice / noticeLines / NoticeDedupe, holding the exact notice copy from spec §5.
  • Static Go client (cmd/sbx): prints lease notices on stderr; stale_mode: and lease_unsupported: exit 125.
  • Proto (additive): LeaseEvent.ends_by_unix_ms (field 8) and LEASE_OP_SANDBOX_DELETED (4).
  • Worker
    • The expiring event carries its deadline.
    • The sandbox_deleted op ends the lease with that reason.
    • STATUS calls are capped at 32 per session.
    • SH_LEASE_GRACE_S above 1800 s is refused at boot, because the relay times out at 31 min.
    • The .lease-state/.boot marker sets root_wrote after a boot with lease off.
    • A state file the janitor removed is not recreated.
  • Relay: the sandbox_deleted op, and keepalives coalesced to at most one per workspace per second.
  • Janitor: removes the .lease-state file of a deleted sandbox, symlink-safe.
  • Deploy: SBX_MODES_ALLOWED (default per-exec) and SBX_IDLE_CEILING_S (default 1800, minimum 300), through setup.sh, the ocp-sbx overlay and the worker bundle (SH_LEASE_IDLE_CEILING_S).
  • Docs
    • Live-smoke step 8 for lease mode, with an offline test.
    • A draft "Lease mode, level 1" section in docs/sbx/security-review.md, which needs the security owner's sign-off.
    • "As built" notes in the spec, plus the direct-client page and RUNBOOK §13.

Tests

Suite Result
sandbox-client 196 passed, 2 skipped
sandbox-relay (Redis) 269 passed
mocactl, the sbx test files all pass alone; the full suite's 8 to 10 timeouts are load-related and the same set as on main
remote-worker go test ./..., and -race on session and vmpool ok
deploy shell tests (setup, install-host, overlay, janitor, smoke) all pass, under bash 5 and bash 3.2
make typecheck ok
KVM gates (AWS metal rig, tree 57cedca) 28/29, plus TestGateLeaseExecCaps fixed in a32bb73 (a test bug already on main)

The KVM gates were not run.

Each of the 11 tasks had a spec and quality review. A final whole-branch review found one Important issue: stale_mode was not retried with a fresh token after a mode change. It is fixed and re-reviewed.

Left for later

  • The live run on SBX0 (Task 12).
  • The security-review sign-off.
  • Flipping the default to per-exec,lease: a separate decision after both of the above.
  • Plan 5 (level 2).

Assisted-By: Claude Code

…(additive)

LeaseEvent gains ends_by_unix_ms (field 8, int64): on "expiring" only, the
hard end (when the lease became expiring plus grace_limit); zero otherwise.

LeaseOp gains LEASE_OP_SANDBOX_DELETED = 4, which ends the lease with reason
"sandbox_deleted" and takes no mode or mode_epoch.

Both changes are additive; buf breaking against upstream/main passes.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
…p; status cap; bounded grace

- The expiring lease event now carries reason max_duration, the lease's
  mode and age, at_unix_ms (when the lease passed its maximum duration,
  computed from its start so repeats dedupe) and ends_by_unix_ms (that
  plus LeaseGraceLimit, the deadline the sweep enforces).
- Runner.LeaseControl answers LEASE_OP_SANDBOX_DELETED by ending the
  lease with reason sandbox_deleted; it takes no epoch.
- The session bounds status calls at 32 in flight (leaseStatusCap),
  apart from the mutating caps, refusing busy past it without blocking.
- SH_LEASE_GRACE_S above 1800 is refused at boot: the relay times reset
  and set_mode out at 31 min (M6).

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
…o recreate, lease-off boot marker

- janitor.sh: after reclaim frees <root>/<wsk>, remove <root>/.lease-state/<wsk>.json; also the
  state file of a sandbox terminated past the wait whose workspace is already gone (the worker's
  idle reclaim keeps it, PR rossoctl#763 F3). Only a regular file in a real .lease-state directory; a
  symlinked directory or file is refused as an error.
- retireLeaseState writes a kept state back only while its file exists: a file the janitor
  removed is not recreated (the timing argument is in the comment).
- New writes .lease-state/.boot = lease=on|lease=off. A lease-on boot after lease=off, or with
  no marker, sets root_wrote on every known state before serving: a lease-off worker records no
  per-Exec root writes. Failure fails New.
- saveLeaseState's temp/fsync/rename/dir-fsync is factored into writeDurably, shared with the
  marker. BenchmarkSaveLeaseState measures one save.
- TestGateReclamationCannotDeleteALiveWorkspace ignores .lease-state (the boot marker's dir).

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
…r workspace

The relay names LEASE_OP_SANDBOX_DELETED `sandbox_deleted` instead of
refusing it as unspecified. It is a mutate op: the 31-minute timeout, the
same in-flight cap, audited as `sandbox_lease_control` like reset, and no
mode or epoch (a set-mode token sent with it is ignored).

routeKeepalive writes at most one keepalive frame per workspace key per
LEASE_KEEPALIVE_COALESCE_MS (1000 ms) on each parked worker. The caller
is answered OK either way; a coalesced keepalive writes nothing. The
window state lives on the parked session, opens only on a frame actually
written, and is pruned as it goes stale. RelayDeps gains a test-only
clock seam `now` (ruling P4-R1), defaulting to monotonic performance.now.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
…ixMs

Since 71b0dd15 the decoder fills LeaseEvent.endsByUnixMs (0 when unset),
so the exec-mode lease-event assertion, a literal without it, no longer
toEquals the event the caller receives. It failed at 38ac8c83 too; only
the fixture changes.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
…alive, the notice formatter

The shared lease layer of plan 4 (task 5) that the MCP server and mocactl build on:

- ExecResult.lease carries every lease event an Exec's response carried, in order;
  ExecMachineryError.lease carries those that arrived before a failure (spec §5: the
  worker sends them before an error too, so a lease_ended Exec still reports the end).
- ExecConnOptions.keepalive sets Exec.keepalive (default false).
- stale_mode: and lease_unsupported: are refusals before the start (not run);
  lease_ended( stays may-have-run.
- SandboxExecConn.leaseControl(op, setModeToken?) and leaseKeepalive(), under the
  sandbox token, requests built with fromPartial, never retried. A non-OK status is a
  LeaseControlError whose code maps the spec §8.3 table; FAILED_PRECONDITION is
  `failed` with the worker's wire string.
- src/lease.ts: SandboxModeName, LeaseStatusView, leaseNotice (the spec §5 copy) and
  NoticeDedupe (on at_unix_ms; an expiring event is never deduped).

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
… copy per P4-R8

- leaseControl (every op; set_mode resends the same set-mode token) and leaseKeepalive
  retry UNAUTHENTICATED once with a forced fresh token, as exec does (ruling P4-R7); a
  second refusal is LeaseControlError `unauthenticated`. Any other refusal is not retried.
- An expiring event with no deadline (ends_by_unix_ms <= 0, a worker before it) reads
  "[sandbox] guest restarts soon (max_duration)", and the expiring copy always names
  max_duration rather than the event's reason (ruling P4-R8).

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
…nd keepalive

- Each tool result is prefixed with the notice lines of the lease events its
  Execs carried (a failed Exec's included, P4-R5), deduped per server; a start
  shows only when no end is shown in the same result.
- New `reset` tool: status first, then LeaseControl reset.
- sandbox_info appends mode, lease state, age, idle timeout, last end and
  tracked processes from LeaseControl status; a failed status shows
  `lease: unknown (<code>)`.
- In a lease mode the tool descriptions, server rules and sandbox_info say
  calls may share one guest instead of "every call is a fresh VM".
- `mocactl sbx mcp` reads each minted token's mode claim: while it is a lease
  mode, Execs set keepalive and a 30 s interval sends LeaseKeepalive; a
  per-exec mint stops it and the server's close clears it (P4-R6 widens
  ExecConnOptions.keepalive to a function read per Exec).

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
…d single-expiring notices

- sandbox_info follows the re-fetched record's mode for every lease field; a
  per-exec record prints `lease: none (per-exec)` with no status call (P4-R9).
- reset on a per-exec sandbox answers `no lease to reset` with no lease call.
- A cancelled call's lease events are held and shown on the next result.
- A result keeps only its last expiring event.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
…n's mode

The record read at start may be stale: an owner who upgrades mid-session got
"no lease to reset" while a lease existed. The latest minted sandbox token's
mode claim (tracked by `sbx mcp`'s onToken) now decides whether reset and
sandbox_info ask the lease, falling back to the record before the first mint.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
…ncludes held ends

- Before any sandbox token is minted, reset re-reads the sandbox record (one
  GET, through the server's info source) instead of trusting the record read
  at start, so a sandbox upgraded since start is reset.
- sandbox_info folds a cancelled call's held events into `last end` before
  building its text, so it agrees with the notice line the same result shows.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
…se create

- SandboxApiClient: setSandboxMode (PUT /v1/sandboxes/{id}/mode) and
  mintSandboxModeToken (POST .../mode-token); SbxSandbox's mode, idleTimeoutS
  and modeEpoch are required, filled in (per-exec, 0, 0) for a control plane
  from before modes
- mode.ts: sendSetMode (one fresh mode token on PERMISSION_DENIED, R11;
  UNAVAILABLE/DEADLINE_EXCEEDED is pending), modeRank
- sbx create --mode M [--idle-timeout S]: a lease mode needs a terminal
  (exit 2); after a lease create, a mode token is minted and set_mode sent
  before any seed; pending warns and exits 0
- ExecFactory's lease calls are required (P4-R10); the test fakes share
  fakeLease/NO_LEASE

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
… the lease

- `sbx mode <mode> [ID] [--idle-timeout S]`: GET first (an upgrade needs a
  TTY, exit 2), PUT keeping the record's idle timeout, then set_mode with the
  PUT's token; pending (unavailable/timeout) is exit 0, Ctrl-C exit 130.
- `sbx reset [ID]`: status then reset; `no lease` when none (per-exec: no call).
- `sbx get [ID] [--json]`: mode, epoch, idle timeout and lease state; a lease
  record whose epoch the worker does not know gets set_mode re-sent.
- notices.ts: `<state dir>/sbx/notices.json` keeps the last seen at_unix_ms per
  sandbox; get, mode, reset and run print each unseen lease event on stderr.
- `ls` shows MODE; `rm` sends sandbox_deleted (best-effort) before the DELETE.
- create --json carries setMode {outcome, code?}; Ctrl-C on its set_mode is
  pending, exit 130 (P4-R12).
- sandbox-client: leaseControl takes an AbortSignal; an abort cancels the call
  (LeaseControlError cancelled).
- `sbx up` writes the CLAUDE.md/AGENTS.md rules for the sandbox's mode (P4-R11).

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
The notice-shaping rules (a start hidden beside an end, only the last
expiring event, then leaseNotice) move to lease.ts as a pure, exported
noticeLines(fresh, nowMs); each caller keeps its own dedupe.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
- rm waits at most 15 s on sandbox_deleted, then deletes; Ctrl-C during it
  deletes nothing ("nothing was deleted", exit 130).
- notices.ts uses sandbox-client's noticeLines; reset and a downgrading mode
  mark their own end seen without a notice line (P4-R17).
- mode retries once without a carried idle timeout the deployment's ceiling
  refuses (400 invalid_request), and says so (P4-R18).
- rm forgets seen notices on the "already gone" path too; the store's doc
  notes the per-sandbox newest-at caveat.
- Tests: corrupt notices.json, no PUT on a refused upgrade, a longer
  timeout for the lease-rules up test.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
…ts text

reset and a downgrading mode now mark seen, without a line, only the
pending event they report (its at_unix_ms). Another unseen end with the
same reason and minute still prints.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
…e refusals

sbx run prints each lease event to stderr as one line, with the copy of leaseNotice in packages/sandbox-client/src/lease.ts (notice.go is the Go port). A start is shown only without an end in the same result, only the last expiring event is shown, and an at_unix_ms is printed once per run. Refusals stale_mode and lease_unsupported exit 125 with the wire string, and are never retried.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
… the overlay and the worker bundle

setup.sh takes the lease policy as two inputs, SBX_MODES_ALLOWED (default
per-exec, so lease stays off) and SBX_IDLE_CEILING_S (default 1800), and
writes them to sbx-settings as SH_SANDBOX_MODES_ALLOWED and
SH_SANDBOX_IDLE_CEILING_S, which the ocp-sbx overlay maps into the control
plane as optional keys. The ceiling also goes into every worker bundle as
SH_LEASE_IDLE_CEILING_S; install-host.sh checks it and writes it into the
worker env, so the control plane and the workers clamp alike.

The ceiling's floor is 300 s, not the control plane's 30: the same value
is the worker's ceiling, and microvm-worker refuses to start with a
ceiling below its default idle timeout (300 s).

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
…aft; client docs

- deploy/sbx/smoke.sh step 8 (in the default steps): sbx create --mode lease
  --idle-timeout 30 --json on a pseudo-terminal (util-linux `script -qec` or
  the BSD `script -q`, told apart by `script -V`), its set_mode applied; sbx get
  --json shows the epoch known and no lease; a /tmp file is there for the next
  command; after 45 s idle it is gone with the `guest restarted (idle,` notice
  on stderr; reset prints `lease ended (reset)` and, after one more command,
  mode per-exec prints `lease ended (mode_change)` (stdout, P4-R15). A create
  refused as not allowed (403 mode_not_allowed) is `# SKIP lease not allowed`.
- deploy/sbx/tests/smoke.test.sh: a fake script (both flavors) and lease
  emulation in the fake mocactl; the pass case under both flavors, the skip,
  and three failures (no kept guest, no idle end, a pending set_mode).
- docs/sbx/security-review.md §6: a DRAFT "Lease mode, level 1" section from
  spec §11 and §9, marked as needing the security owner's sign-off. The
  default stays per-exec.
- Spec v0.4: as-built notes for plan 4 in §5, §8.2 and §8.3. The direct-client
  guide: ends_by_unix_ms, LEASE_OP_SANDBOX_DELETED, the worker's status cap,
  keepalive coalescing. RUNBOOK §13: step 8. The control-plane API did not
  change, so docs/api/CHANGELOG.md is untouched.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
A long-lived connection (the MCP server) held its token across a mode
change, so the worker refused each file tool's Exec with stale_mode for
up to ~13 minutes. stale_mode is a refusal before the start, so the
Exec is now retried once under a forced fresh token and a new req_id
(the worker's req_id cache fingerprints the epoch), like a token
refusal. A second stale_mode surfaces as before; the first refusal's
lease events ride on the retry's result or error. lease_unsupported is
still not retried (ruling P4-R21, final review I1).

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
The first bearer() mint moves above the try, so a token source that
throws (even a LeaseControlError 'unauthenticated') propagates at once
instead of triggering the forced-mint retry (Task 5 parked minor).

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
LeaseCall takes an optional {signal}; the reset tool passes its call's
cancel signal to both lease calls, and mocactl's MCP server forwards it
to leaseControl (P4-R12's signal). A reset held behind another client's
Exec (up to grace_limit) no longer holds the server's queue past its
cancel (final review M1).

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
With --seed, "created, but its mode was not sent" now ends with
"; the seed was not run" (Task 7 parked minor m4).

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
@pdettori
pdettori force-pushed the feat/sbx-lease-clients branch from 3d22a56 to 8670fa3 Compare November 13, 2026 21:39
@pdettori pdettori added the ready-for-ai-review Request automated AI code review from clawgenti label Nov 13, 2026

@ingpaolodettori-dev ingpaolodettori-dev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Summary

Plan 4 makes lease mode usable from mocactl, the MCP server and the static Go client, and closes the plan 2–3 carry-overs. It is well structured and thoroughly tested. There is one must-fix: on the real client, a cancelled MCP call loses the lease events its Exec already carried, and the test that covers this path fakes the error shape. The rest are suggestions and nits, mostly about lease notices being dropped or repeated on edge paths, plus the janitor/ceiling timing assumptions.

Author: pdettori (MEMBER — maintainer)
Areas reviewed: TypeScript (sandbox-client, sandbox-relay, mocactl), Go (remote-worker, cmd/sbx), proto/gen, Shell (deploy/sbx + tests), Docs
Agent/IDE config (.claude/.vscode): none
Commits: 23 commits, all signed-off: yes
CI status: passing (17/17)

Checked and fine: the generated TS/Go code matches the proto (+field 8, +enum 4); keepalive coalescing is keyed on the token's wsk, so it doesn't cross tenants; leaseCall retries only the relay's UNAUTHENTICATED; the janitor's .lease-state removal is symlink-safe and tested; ceiling validation has no octal pitfall; the status cap and EndsBy arithmetic are correct; the TTY gate runs before any network call; and notices.json is 0600 in a 0700 directory.

Not run live yet (plan Task 12, KVM gates); noted, not blocking this review.

if (extra.signal.aborted) return refuse(CANCELLED);
return refuse(oneLine(describe(err, o.expiresAt)));
if (extra.signal.aborted) {
held.push(...events);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

must-fix: The real client never triggers the held-events path for a cancelled call. On abort, SandboxExecConn.once rejects with abortReason(signal) (exec-conn.ts onAbort, ~L568), which is the signal's reason or a DOMException. It is never an ExecMachineryError. So counted drops the lease events the response had already carried, and held.push(...events) pushes nothing. The worker acks an event once it is queued (spec §5), so a start or end delivered on a cancelled Exec is lost for good, and neither the next result nor sandbox_info shows it. The test "a cancelled call's lease events ride the next result" passes only because its fake rejects with an ExecMachineryError carrying lease. Please attach the collected lease to the abort rejection in onAbort, or wrap it in an error type that counted reads, and add a transport-level test (fake relay sends a lease event, then the client aborts).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in fc94a20.

  • The fix: once's onAbort now rejects through fail(...) with a new ExecAbortedError. It keeps the name AbortError, its cause is the signal's reason, and it carries the lease events received so far. The two aborts before a send throw it too, with lease: []. counted reads lease from it.
  • Abort detection still works: every caller detects an abort through signal.aborted (mocactl run, execFailed, the lease commands, call-record); none uses instanceof DOMException.
  • Tests:
    • New, at transport level: "a cancelled call's lease events ride the next result, over the real client". A real SandboxExecConn runs against fakeExecRelay; the relay sends an end, then hangs, and the client aborts. The next MCP result opens with the notice, and the one after has none.
    • New, at exec-conn transport level: the abort carries its events, and an abort during the stale_mode retry carries both attempts' events.
    • The two older tests now reject with the real error shape.
    • Reverting the fix in a temp copy makes the new test fail.

const r = await attempt(true);
return carried.length > 0 ? { ...r, lease: [...carried, ...r.lease] } : r;
} catch (err) {
if (err instanceof NotStarted) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: Suppose the first attempt fails stale_mode: while carrying, say, a lease_ended event, and the forced-fresh retry then gets UNAUTHENTICATED. This branch throws a new ExecRefusedError and drops carried, so the end notice is lost even though the worker already acked it. The message also says "after one token refresh" when the first failure was stale_mode. Carry carried on this error too, and have counted in mcp-server.ts read lease from ExecRefusedError.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done in fc94a20. ExecRefusedError now carries lease (default []). When the forced-fresh retry after a stale_mode: refusal is refused UNAUTHENTICATED, the error carries the first attempt's events, and counted reads them. The message now says "(after a stale_mode refusal and a fresh token)"; "(after one token refresh)" stays for a plain token refusal. There are transport and MCP tests for both.

const r: ToolResult = await tool.run(args, counted, extra.signal);
record(!r.isError);
return r as CallToolResult;
return noticed(r as CallToolResult);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: The success path doesn't check extra.signal.aborted. If tool.run resolves just as the cancel arrives, noticed() runs the events through NoticeDedupe and marks them seen, and then the SDK discards the response because the request was aborted (protocol.js: if (abortController.signal.aborted) return). Those notices are never shown. Handle it the way the catch does: held.push(...events) when extra.signal.aborted is true after run resolves.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done in fc94a20. When tool.run resolves with extra.signal.aborted already set, the events go to held instead of through noticed(), so the next result shows them. Test: "a call whose run resolves after its cancel holds its events for the next result".

Comment thread packages/sandbox-client/src/tools.ts Outdated
if ((await lease('status', { signal })).state === 'none') return ok(RESET_NONE_TEXT);
// The worker holds a reset behind another client's running Exec: a cancelled call stops
// waiting, so it does not hold the MCP server's call queue past its cancel.
await lease('reset', { signal });

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: The MCP reset tool throws away what lease('reset') returns. The worker keeps that end pending until the next lease Exec carries it, so the next tool result opens with [sandbox] guest restarted (reset, …) right after this call already said lease ended (reset). mocactl sbx reset suppresses exactly this via ownEnd(after.pending, 'reset') (P4-R17). Mark the reset's own pending end as seen in the server's deduper. Related, a nit: status then reset is check-then-act. If the lease ends between the two calls, this still answers lease ended (reset), so choose the text from the reset's returned view.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done in fc94a20, and tightened in 870b2f9.

  • No status call any more. The text comes from what lease('reset') returns: lease ended (reset): … only for a returned pending end with reason reset that the server claims, and no lease to reset otherwise. That removes the check-then-act.
  • No repeat notice. NoticeDedupe.claim(ev) marks that end seen without printing it, mirroring mocactl's P4-R17, so the next result doesn't repeat it.
  • The follow-up: a second review spotted your #4569829034 race inside reset, so the end is now claimed only after a reply that was not cancelled. When the cancel wins, the end stays deliverable as a notice.

Tests:

  • "reset's text comes from its own answer, and its end is not noticed again";
  • "reset answers no lease for a pending reset end it has already seen";
  • the cancelled-reply case.

export class NoticeDedupe {
private readonly seen = new Set<number>();

take(evs: LeaseEvent[]): LeaseEvent[] {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: NoticeDedupe keys only on atUnixMs, so an end and the next lease's start in the same millisecond collapse into one. Keying on ${state}:${atUnixMs} costs nothing.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done. The key is now ${state}:${atUnixMs} in the TS NoticeDedupe (fc94a20), and the Go static client's dedupe uses the same key (04f70d1). Tests on both sides check that an end and the next start in the same millisecond are both shown.

uint64 age_ms = 6; // the lease's age at the event
repeated string processes = 7; // processes that were running; filled from plan 5 on
// On "expiring" only: the hard end, i.e. when the lease became expiring plus grace_limit
// (unix ms). Zero on every other state.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: Expiring events now carry reason: "max_duration" (runner.go deliverLeaseEvents), but field 3's comment still says "empty unless state is "end"", and spec §5 says the same ("set only on an end"). Please update both, so third-party clients don't treat a reason on an expiring event as malformed.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 9ca83d6. The proto comment for field 3 and spec §5 now say a reason is set on end, and on expiring as max_duration. The regenerated output changes in comments only.

// take returns the events not printed before, marking them printed.
func (d noticeDedupe) take(evs []*pb.LeaseEvent) []*pb.LeaseEvent {
var out []*pb.LeaseEvent
for _, ev := range evs {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: take never dedupes expiring events, and call prints notices on every attempt. So a run retried after a busy refusal prints guest restarts within N min twice. Spec §5 says the static client prints each at_unix_ms once per run, so dedupe expiring events per run as well.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 04f70d1. The static client now dedupes expiring events per run as well, keyed on state:at_unix_ms. That is exact, because an expiring event's at is constant for a lease: the expiry instant. A busy-retried run prints the line once (test included). The MCP server deliberately keeps showing it on every result while the lease is expiring, as spec §5 says.

// 60 s, and a reset or a set_mode downgrade blocks for up to the grace limit plus the cut
// Exec's unwind. A longer grace would let the relay fail a call the worker is still
// running, and the client would then report an op that later lands.
const maxLeaseGraceS = 1800

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: maxLeaseGraceS = 1800 is derived by hand from the relay's LEASE_MUTATE_TIMEOUT_MS = 31 * 60_000 (sandbox-caller.ts). Add a pointer comment on the TS side, or a contract test, so one can't be raised without the other.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done in 9ca83d6. Pointer comments on both sides name the other constant. There is also a cheap contract test on each side that reads the other file's literal, so raising one without the other fails a test.

Comment thread deploy/sbx/setup.sh Outdated
die 'SBX_MODES_ALLOWED must be a comma list of per-exec, lease and lease+processes, no spaces'
# The control plane's floor is 30 s, but the same value is the workers' SH_LEASE_IDLE_CEILING_S, and
# a worker refuses to start with a ceiling below its default idle timeout, 300 s.
[[ "$SBX_IDLE_CEILING_S" =~ $COUNT6_RE ]] && ((SBX_IDLE_CEILING_S >= 300)) ||

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: SBX_IDLE_CEILING_S now accepts up to 999999 s (~11.5 days). The janitor/worker timing argument (retireLeaseState doc: "at most the idle ceiling, 30 min") and the SBX_JANITOR_AGE > TTL+30 rule assume 30 min. With a large ceiling, a token minted before a delete (valid TTL+30 s) can keep a lease live past the janitor's reclaim. The janitor then unlinks workspace.img under a running guest, and the lease end writes the state file back, because the end path in lease.go has no existence check, unlike retireLeaseState. Cap the ceiling (e.g. 86400), or require SBX_JANITOR_WAIT_MINUTES*60 > TTL+30+SBX_IDLE_CEILING_S when lease is allowed.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done in 1828af4, plus 57cedca, which applies the same cap in install-host.sh.

  • The cap: SBX_IDLE_CEILING_S is capped at 86400, in setup.sh and in install-host.sh for the bundle value.
  • The janitor rule: when SBX_MODES_ALLOWED names a lease mode, setup.sh refuses unless the janitor wait in seconds is greater than the token TTL in seconds, plus 30, plus the ceiling. The refusal names the minimum. The defaults pass: 900 + 30 + 1800 = 2730 < 3600.
  • No recreate at lease end: in lease.go, a lease end no longer recreates a Known state file whose file the janitor removed, matching retireLeaseState. F3 still holds, because a worker-side reclaim rewrites the file through retireLeaseState. The retireLeaseState doc now names the ceiling rule.
  • Tests: setup.test.sh covers the cap and the rule, and a vmpool test covers the no-recreate check.

Comment thread docs/sbx/security-review.md Outdated
with the user's `mocactl` login. The rule is a guard against accidents, not a boundary.
- **That every delete ends the lease at once.** A `DELETE /v1/sandboxes/{id}` from another client,
or an `rm` whose `sandbox_deleted` failed or took over 15 s, leaves the lease to end by its idle
timeout (at most the operator's ceiling). No new token can be minted after the delete. A token

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit (sign-off text): "leaves the lease to end by its idle timeout (at most the operator's ceiling)" leaves out that a still-valid token (TTL+30 s) can keep restarting the idle clock after the delete. The full bound is delete + token lifetime + 30 s + Exec duration + idle timeout. Since this is what the security owner signs off on, please state it in full.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done in 1828af4. The section now states the full bound: delete, plus the token lifetime, plus 30 s, plus the duration of an Exec in flight, plus the idle timeout. It also says the new setup.sh rule keeps the janitor's wait above that bound.

@pdettori
pdettori marked this pull request as ready for review November 13, 2026 23:30
@pdettori
pdettori requested a review from cwiklik as a code owner November 13, 2026 23:30

@clawgenti clawgenti left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Clawgenti Code Review

Reviewed the plan-4 lease-mode client/deploy work across mocactl, sandbox-client, the MCP server, sandbox-relay, the Go worker, and the deploy scripts. The overall structure is solid: the notice copy parity between Go and TS is pinned by tests, the janitor's deletions are carefully guarded, the TTY gate is honest about its limits, and the security review draft is upfront about the gates that have not been re-run. No secrets, no CI changes, no agent/IDE config paths in the diff. Findings below are suggestions and nits — nothing blocking from my side.

Author: pdettori (MEMBER — maintainer)
Areas reviewed: Go, TypeScript, Shell, Helm/K8s, Docs
Agent/IDE config (.claude/.vscode): none
Commits: 23 commits, all signed-off: yes
CI status: passing

Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).

Comment thread packages/mocactl/src/sbx/commands.ts Outdated
const x = await openExec(c.api, id, factory);
const waited = new AbortController();
const settled = new AbortController();
void (c.sleep ?? c.rt.sleep)(RM_LEASE_WAIT_MS, settled.signal).then(() => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion — void (c.sleep ?? c.rt.sleep)(...).then(...) has no .catch. The Ctrl-C path is covered by a test (exit 130, no DELETE), so rt.sleep evidently resolves rather than rejects on abort — but a custom c.sleep seam (or a future change to rt.sleep) that rejects on abort leaves an unhandled rejection that can crash rm right when the user interrupts it. A .catch(() => {}) (the outcome is best-effort anyway) would make the contract explicit.

return connFailed(c, err);
}
try {
if (jwtMode(x.token.token) === 'per-exec') {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion — cmdReset decides "no lease" from jwtMode(x.token.token), the unverified token claim, rather than the record/epoch. A sandbox upgraded to lease mode after this token was minted (e.g. a set_mode applied by another client or terminal) makes reset print "no lease" without ever asking the worker. The same token-claim gate drives the MCP keepalive loop and the reset tool, so a mid-session mode change silently stops keepalives until a re-mint (up to one token TTL, ~15 min). If spec §8.2's epoch machinery is the intended source of truth, consider consulting status (or the epoch) before concluding there is no lease.

return SBX_EXIT.usage;
}
const carried = o.idleTimeoutS === undefined && cur.idleTimeoutS > 0;
const idle = o.idleTimeoutS ?? (carried ? cur.idleTimeoutS : undefined);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion — the idle-timeout carry (P4-R18 retry) exists only client-side in mocactl, and setSandboxMode documents that an omitted idleTimeoutS is stored as 0, not kept. That means any other client — the MCP path in particular — that PUTs a mode without idleTimeoutS silently resets the owner's idle timeout to the worker default. Worth confirming the control-plane contract really wants omitted-means-zero; if owners' settings should survive mode changes made by other clients, the carry belongs server-side.

* The block body for a sandbox in `mode` (ruling P4-R11): a lease sandbox's agent is told what a
* lease keeps, not that every call is a fresh VM. `up` writes the one for the sandbox's mode.
*/
export const rulesFor = (mode: SandboxModeName): string =>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion — rulesFor(mode) blocks are written by up and never rewritten by sbx mode, and doctor's check deliberately accepts any mode's block (ALL_RULES). So after sbx mode lease (or a downgrade), the sandbox keeps telling the agent the wrong persistence model until the next up. Consider having sbx mode warn about the stale rules block, or having doctor flag a mode mismatch when the bound sandbox's mode is known.

return {
...s,
mode: s.mode === 'lease' || s.mode === 'lease+processes' ? s.mode : 'per-exec',
idleTimeoutS: s.idleTimeoutS ?? 0,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit — an unknown wire mode is silently coerced to per-exec (same pattern in mcp.ts recordMode and exec.ts jwtMode). A future control plane returning a new mode would read as per-exec and then trip cmdCreate's "the control plane did not take the mode" false alarm, and make reset/keepalive misbehave. An explicit unknown-mode error would surface the mismatch instead of hiding it.

// again at the next boot, which changes nothing. Any failure fails New: a lost root_wrote
// would let a lease skip normalising a tree root has written, and a lease-off boot whose
// lease=off cannot be written would leave lease=on for the next lease-on boot to trust.
func markLeaseBoot(root string, leaseOn bool) error {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion — markLeaseBoot failing (unwritable or full WorkspaceRoot) fails pool.New entirely, even for lease-off deployments — and it writes .lease-state/ into every root regardless of mode. A worker that previously booted fine on a read-only-ish root now refuses to start. Consider making the lease-off marker best-effort (log and continue), or only failing hard when lease mode is actually on.

@clawgenti clawgenti left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

noticeDedupe keys on state and at_unix_ms, as the TS NoticeDedupe now
does, so an end and the next lease's start in one millisecond both
print. It dedupes expiring events too: their at_unix_ms is constant per
lease (P4-R2), so a run retried after a busy refusal prints the
countdown once. The TS deduper keeps showing expiring on every MCP
result (spec §5).

Review #4569829041, #4569829081.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
The proto comment on LeaseEvent.reason and spec §5 say a reason is set
on an end, and on an expiring event as max_duration; the generated stubs
change in comments only. Spec §5 also records the MCP server's dedupe
key, its reset claim and the static client's per-run rule.

maxLeaseGraceS (microvm-worker) and the relay's LEASE_MUTATE_TIMEOUT_MS
name each other, and a contract test on each side reads the other's
literal, so neither can be raised alone.

Review #4569829078, #4569829088.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
A keepalive whose write throws is retried by the next one within 1 s;
only a written frame starts the window that coalesces the rest.

Review #4569829045.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
…le lease step

- doctor checks the CLAUDE.md / AGENTS.md rules block against
  rulesFor(record.mode), from the sandbox it already fetches, and names
  a block another mode's up wrote (fix: mocactl sbx up). sbx mode, in a
  repository bound to the sandbox, says on stderr to run sbx up when the
  agent rules change.
- rm starts its 15 s RM_LEASE_WAIT_MS bound before the record read, and
  passes the combined signal to getSandbox and openExec (the token mint
  and the expiry lookup; both take an optional signal now). Ctrl-C still
  deletes nothing, exit 130.
- get --json emits setMode: {error} when the re-sent set_mode fails
  hard, as create --json does, and its pending line is create's
  pendingText.

Spec §8 says each.

Review #4569829055, #4569829061, #4569829068.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
… is bounded by the janitor

- install-host.sh deletes <workspace root>/.lease-state/.boot at every
  worker install, before the restart (a symlinked marker goes as the
  link; a symlinked .lease-state is refused before anything is
  written), so a rollback past the marker followed by a forward install
  boots with no marker and marks every known state root_wrote. RUNBOOK
  §2 and spec §8.2 say why a rollback then a forward install is safe.
  sweep.go's comment no longer says a per-Exec-only worker does no
  lease-state I/O: New writes the marker.
- setup.sh caps SBX_IDLE_CEILING_S at 86400 s and, when
  SBX_MODES_ALLOWED names a lease mode, refuses a janitor wait that does
  not exceed the token lifetime plus 30 s plus the ceiling.
- vmpool's lease end does not write back a known state file the
  janitor removed (the existence check retireLeaseState uses), and its
  cache follows the disk; retireLeaseState's timing argument names the
  setup.sh rule.
- security-review §6.3 states the full bound after a delete: token
  lifetime + 30 s + the Exec's duration + the idle timeout.

Review #4569829075, #4569829097, #4569829101.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
A worker bundle's SH_LEASE_IDLE_CEILING_S above 86400 s is refused
before anything is written, with the 300-86400 range named, as setup.sh
refuses SBX_IDLE_CEILING_S: the janitor-wait rule assumes that cap.

Review #4569829097.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
…ts every carried notice

- The MCP reset tool's own end is claimed in the server's deduper only
  once run resolves with no abort. A reply that lands as the call is
  cancelled is discarded by the SDK, so its end stays deliverable as a
  notice on the next result. NoticeDedupe gains claimable(), which asks
  without marking.
- mocactl sbx run prints the lease notices carried on ExecAbortedError
  and ExecRefusedError, as it did for ExecMachineryError.

Re-review New-1, New-2.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
… can write

Since /var became an overlay over the image's root-owned /var
(691c1a0), the Exec user cannot create /var/fill, so the gate's fill
step failed before the tmpfs OOM case it sets up. It writes the /var
share to /var/tmp instead, which is world-writable and lands in the same
tmpfs-backed /var. The bug predates this branch (the gate is from
2700f11); the gate passed on the AWS rig with this change, beside the
other 28.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
@pdettori

Copy link
Copy Markdown
Member Author

Review 5899498816 is addressed in fc94a205..a32bb73c (9 commits, pushed), with a reply in each thread. Every code fix has a test that failed on the old code. A second, independent review confirmed all 15 items, and three small Low items it raised are fixed too (870b2f9): reset claims its end only after a reply that wasn't cancelled, run prints the notices carried on abort and refusal errors, and install-host.sh caps the idle ceiling at 86400 (57cedca).

  • Must-fix: an abort now rejects with an ExecAbortedError (still named AbortError) that carries the lease events already received. A transport-level test runs a real SandboxExecConn against the fake relay.
  • Janitor timing: SBX_IDLE_CEILING_S is capped at 86400. When lease is allowed, setup.sh refuses a janitor wait shorter than the token TTL plus 30 s plus the ceiling. A lease end no longer recreates a state file the janitor removed. The security review states the full bound.

KVM gates and the fsync measurement, on the AWS metal rig (tree 57cedca, fresh snapshot with lease-v1 and balloon-fpr-v1, 256 MiB guests):

  • guest-agent root tests: 40/40 pass;
  • KVM gates: 28/29 pass, TestGateCredentialNeverInGuest included. The one failure, TestGateLeaseExecCaps, is a test bug that is already on main: it fills /var/fill, but since 691c1a0 /var is an overlay over the image's root-owned /var. a32bb73 moves the fill to /var/tmp, and with that change the gate passes on the rig;
  • saveLeaseState on the rig's XFS volume: mean 2.8 ms, p99 3.0–3.2 ms, under the 10 ms bar.

Still waiting on a network outage: the SBX0 host upgrade and the live smoke (plan Task 12).

Assisted-By: Claude Code

@clawgenti clawgenti left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Automated review pass (comments only — severity-tagged inline).

Author: pdettori (MEMBER — maintainer)
Areas reviewed: deploy/sbx shell scripts + tests, k8s overlay, mocactl (exec/commands/notices/lease-commands/mcp/mode/doctor + tests), sandbox-client (exec-conn, lease, mcp-server, tools + tests), sandbox-relay (lease ops, keepalive coalescing + tests), proto + generated TS/Go, remote-worker (session, vmpool lease state/sweep/runner + tests), docs/spec parity
Agent/IDE config (.claude/.vscode): none
Commits: 32 commits, all signed-off
CI status: passing

Feature-gate parity verified: setup.sh writes SH_SANDBOX_MODES_ALLOWED/SH_SANDBOX_IDLE_CEILING_S to sbx-settings, the overlay injects exactly those keys, install-host.sh re-injects the same names into the worker env, and the 300–86400 s range is enforced identically in setup.sh and install-host.sh — no cross-file drift. Docs match the implemented behavior. No must-fix findings; 6 suggestions and 1 nit inline.

Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).

(pending ??= api.mintSandboxToken(id).then(
(t) => ((pending = undefined), (cur = t)),
const mint = (signal?: AbortSignal) =>
(pending ??= api.mintSandboxToken(id, signal ? { signal } : {}).then(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion — because pending is shared, the first caller's AbortSignal is baked into the in-flight mint for every subsequent caller on the same connection: if that caller aborts (Ctrl-C during endLease's bounded step), the shared mint rejects for everyone, and a caller that arrives already-aborted still receives the pending mint. Today only first() passes a signal and the retry uses token({force:true}) without one, so the blast radius is small, but the seam is easy to misuse. Suggested fix: aggregate interested signals with AbortSignal.any while the mint is shared (register on pending, unregister on settle), or document that only first()'s signal aborts the mint.

async function endLease(c: SbxCtx, id: string, factory: ExecFactory | undefined): Promise<void> {
const waited = new AbortController();
const settled = new AbortController();
void (c.sleep ?? c.rt.sleep)(RM_LEASE_WAIT_MS, settled.signal).then(() => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion — the 15 s timer promise here has no .catch. The finally { settled.abort(); } fires while this sleep is still pending whenever endLease finishes first (the normal case). If rt.sleep rejects on abort (a common sleep(ms, signal) contract), the rejection is unhandled: an unhandled-rejection warning, and with --unhandled-rejections=strict a process exit 1 after the delete already succeeded. The if (!settled.signal.aborted) guard inside .then suggests the author expects resolve-on-abort, but nothing enforces it. Suggested fix: append .catch(() => {}), or make the sleep always resolve.

const at = new Set<number>();
const fresh = events.filter((ev) => {
if (ev.state === 'expiring') return true;
if (ev.atUnixMs <= last || at.has(ev.atUnixMs)) return false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion — the in-batch dedupe keys on atUnixMs alone, dropping an event that shares another's millisecond. sandbox-client's NoticeDedupe deliberately keys on ${state}:${atUnixMs} with the comment "so an end and the next lease's start in the same millisecond are both shown", and the Go port follows suit — here the start of the next lease would be silently swallowed. Suggested fix: key on ${state}:${atUnixMs} like NoticeDedupe (the persisted last max is unaffected).

removeLeaseState(root, key)
return
}
if leaseStateFileGone(root, key) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion — the "the janitor's next run removes it" claim for the stat/save race only holds while the control-plane list still reports the sandbox: sweep_lease_states requires the workspace to be in the reclaim map, and after the retention window purges the record (SBX_RETENTION_DAYS, default 14) a file written by the race is never matched again — a small permanent leak per occurrence. Suggested fix: also remove .lease-state/<wsk>.json for unknown keys whose workspace is long gone (age from the file's mtime, as the janitor already does for .reclaiming-* fallbacks), or re-check leaseStateFileGone immediately before the rename in writeDurably for these paths.

// Only max_duration expires a lease, so the copy names it whatever `reason` says (P4-R8).
// A worker that predates ends_by_unix_ms sends 0: no deadline to count down to.
if (ev.endsByUnixMs <= 0) return '[sandbox] guest restarts soon (max_duration)';
const min = Math.max(1, Math.ceil((ev.endsByUnixMs - nowMs) / 60_000));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion — when the grace deadline is already behind (a client that reconnects after ends_by_unix_ms, or a result delivered late), Math.max(1, ...) still prints "guest restarts within 1 min", understating an already-overdue hard end. The Go twin (cmd/sbx/notice.go) behaves the same, so at least the two agree. Suggested fix: when endsByUnixMs <= nowMs, print e.g. "guest restart overdue (max_duration)" instead.

carried &&
err instanceof ApiError &&
err.status === 400 &&
err.code === 'invalid_request'

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion — the fallback catches any 400 invalid_request when an idle timeout was carried, re-sends setSandboxMode without it, and prints "idle timeout reset to the worker default…". A 400 for a different field (a mode the control plane rejects, a malformed id) would be retried once without the idle timeout and the user told the idle timeout was reset even though that was never the problem. Suggested fix: match the ceiling-refusal error specifically (a distinguishable code or message), or verify the retry succeeded before printing the idle-reset explanation.

let leased = false;
let beat: ReturnType<typeof setInterval> | undefined;
let closed = false;
let warned = false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit — warned is set on the first leaseKeepalive failure and never cleared, so after one transient failure (say, a worker restart) later failures are never logged even though the comment only promises "further failures are not logged" per failure episode. The lease-end notice still reaches the user, so impact is cosmetic. Reset warned = false after a subsequent successful keepalive.

@clawgenti clawgenti left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Conflicts resolved, keeping both sides:
- mocactl cli.ts help: main's templates activate/deactivate lines, then the
  lease create line with --mode and --idle-timeout.
- mocactl commands.ts create: the lease flow (set_mode after a lease create,
  the ignored-mode warning, pending and failure paths) now creates through
  main's createWaitingForActivation.
- mocactl contract.test.ts: both sides added two routes, so 25 replies.
- deploy/sbx/install-host.sh: validate_worker runs check_lease_state and
  check_template_record, and sets W_IDLE_CEILING beside W_RECORD/W_TEMPLATE.
- install-host.test.sh: main's template-record checks, and the pass message
  names the idle ceiling too.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>

@ingpaolodettori-dev ingpaolodettori-dev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Follow-up review at 27fa79a (a32bb73..27fa79a: one merge of main ec0f840)

This replaces our unsent a32bb73 draft and clears our CHANGES_REQUESTED from 8670fa3. All 15 items from that review were verified as fixed at a32bb73. This head only merges main ec0f840 (#769/#771/#772/#773/#775/#782).

The five hand resolutions are correct. They were checked with git show --remerge-diff, and nothing from either side was dropped:

  • install-host.sh validate_worker runs both check_lease_state and check_template_record, and still sets W_IDLE_CEILING next to main's record/template vars. The comment names all of them.
  • install-host.test.sh keeps main's SH_TEMPLATE_RECORD, SANDBOX_TEMPLATE and verify-cache assertions, and the pass message names the idle ceiling.
  • mocactl cli.ts help: main's templates activate/deactivate lines come before the lease-aware create line.
  • mocactl commands.ts cmdCreate now creates through main's createWaitingForActivation, so the lease flow (set_mode, ignored-mode warning, pending/failed paths) runs after an activation wait. sbx up's findOrCreate picks up the same helper from main.
  • contract.test.ts: there are 25 scripted replies for the 22 client calls, and the reply carries sandbox: {} for setSandboxMode.

One nit is inline. createWaitingForActivation still types its body without mode/idleTimeoutS. Our setup.sh nit from a32bb73 still applies (it is now at :184).

Before merging: the PR is dirty again. Main moved on to 82a4249 (#776, #784), and packages/mocactl/src/sbx/cli.ts conflicts in the templates activate/deactivate help, where #784 added --stop-now and sbx hosts. Because of that, only DCO has run on this head. Please merge main again, and let ci/k8s-kind-e2e go green.

clawgenti's 8670fa3 suggestions that were still open at a32bb73 are unchanged. They are non-blocking.

Author: pdettori (MEMBER — maintainer)
Areas reviewed: merge resolutions (Shell: install-host.sh + test; TypeScript: mocactl cli.ts, commands.ts, sync.ts, contract.test.ts)
Agent/IDE config (.claude/.vscode): none
Commits: 1 new merge commit, signed off: yes
CI status: only DCO ran (pass); mergeable_state: dirty (conflict with main 82a4249 in mocactl sbx/cli.ts)

Comment thread deploy/sbx/setup.sh
# a lease still running: its wait must exceed all three (vmpool's retireLeaseState relies on it).
if [[ "$SBX_MODES_ALLOWED" == *lease* ]]; then
local lease_live_s=$((TOKEN_TTL_S + 30 + SBX_IDLE_CEILING_S))
((JANITOR_AGE_S > lease_live_s)) ||

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit (carried over from our unsent a32bb73 draft): when a lease mode is allowed, the default janitor wait fails this check whenever SBX_TOKEN_TTL_MINUTES >= 30 at the default 1800 s ceiling. For example, TTL 30 gives a default wait of 60 min = 3600 s against 3630 s. TTL 60 gives 3900 s against 5430 s, which setup.test.sh pins as a refusal. The message says what to set, so nothing fails silently, but the default could be derived instead: when SBX_MODES_ALLOWED names a lease mode, take wait_default as max(60, TTL + 5, (TOKEN_TTL_S + 30 + SBX_IDLE_CEILING_S)/60 + 1). Then only an explicitly set wait is refused. It would also be worth one line in the README's knob table.

o: { seed?: boolean; factory?: ExecFactory } = {},
): Promise<number> {
try {
const s = await createWaitingForActivation(c, body);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: createWaitingForActivation (:322, from main) types body as { template; name?; labels? }, so mode/idleTimeoutS only reach createSandbox because TypeScript accepts the wider object here. If someone later rebuilds the body inside the helper, the mode would be dropped with no type error. Typing the helper's parameter as SbxSandboxCreate (and its return as SbxCreated) keeps the lease fields checked. A retry test that asserts the second POST still carries mode would pin it.

@clawgenti clawgenti left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Clawgenti Code Review

Follow-up pass on the new head (27fa79a, the upstream merge and the fixes since my last review at 633c311–era head). Re-checked the retry rules, the dual-mode config wiring end-to-end, the worker boot path, and the deploy scripts. The spec's as-built notes now match the code where I could verify it: the TS exec client retries only a stale_mode: refusal (StaleMode at exec-conn.ts:247/311) — lease_unsupported: sits in NOT_STARTED for ran/not-ran classification only and is not retried, matching §8.3; the SBX_IDLE_CEILING_S 300–86400 floor in setup.sh is deliberate (a worker's ceiling must cover its default idle) and is threaded consistently into the worker bundle as SH_LEASE_IDLE_CEILING_S. Shellcheck is clean on the four changed scripts; no secrets, no CI changes, no agent/IDE config paths. Two suggestions and one nit below — nothing blocking from my side.

Author: pdettori (MEMBER — maintainer)
Areas reviewed: Go, TypeScript, Shell, Helm/K8s, Docs
Agent/IDE config (.claude/.vscode): none
Commits: 33 commits, all signed-off: yes
CI status: passing (DCO)

Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).

// snapshot cannot back would put lease Execs on a guest without plan 1's half.
cfg.LeaseEnabled = LeaseSupported(cfg)
// Before anything is served, and before endLeasesOpenAtStart reads the state files.
if err := markLeaseBoot(cfg.WorkspaceRoot, cfg.LeaseEnabled); err != nil {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion — New now fails the whole pool when markLeaseBoot cannot write .lease-state/.boot, and markLeaseBoot (lease_state.go:209) always writes the marker, even on a lease-off boot. A worker whose workspace root has gone read-only or full — which ran fine before lease mode, since it did no lease-state I/O — now refuses to boot. If that fail-fast is intended (state divergence is worse than downtime), a word in the spec or install-host.sh docs saying a lease-off worker still requires a writable workspace root would help operators diagnose the new failure mode. Relatedly, a marker read error on a lease-on boot is logged and treated as a lease-off boot, which silently re-normalizes root_wrote for every lease after e.g. a transient read error — conservative, but worth a comment acknowledging the cost.

return connFailed(c, err);
}
try {
if (jwtMode(x.token.token) === 'per-exec') {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion — cmdReset (and sandbox_info) decide "no lease" from the token's mode claim, read without verification (exec.ts:79), and skip the leaseControl('status') call entirely. That matches P4-R9, but the claim is only as good as the CP that minted the token: a token minted without a mode claim (or a stale per-exec token in the local record after a set_mode that was applied later) makes reset print no lease for a sandbox that genuinely holds one, with no wire round-trip to catch it. The record's mode is already available (cmdGet uses it) — falling back to the status call when the token and record disagree (or simply when the claim is absent) would close the gap cheaply.

chmodSync(dir, 0o700);
const tmp = `${file}.${process.pid}.tmp`;
writeFileSync(tmp, JSON.stringify(store) + '\n', { mode: 0o600 });
renameSync(tmp, file);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit — the store is load → update one id → save-the-whole-store. Two concurrent mocactl processes (an agent's sbx run while the user runs sbx get) can interleave and lose one side's lastSeenAtUnixMs, so a notice prints twice. The module's comment accepts that worst case, and the per-pid tmp file keeps the rename atomic — just noting the window is real, not theoretical, once MCP-driven runs and interactive use overlap.

@clawgenti clawgenti left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

One conflict, the mocactl sbx help text: main's templates activate wording,
deactivate --stop-now and the new hosts command, then the lease create line
with --mode and --idle-timeout. The contract test keeps 25 replies (main's
count did not change).

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
@pdettori
pdettori merged commit 9e31f53 into rossoctl:main Nov 14, 2026
23 of 24 checks passed
webchang added a commit to webchang/moca that referenced this pull request Nov 14, 2026
Brings rossoctl#808 (sbx lease clients: mocactl create --mode, get, reset,
and rm's lease step).

Conflicts:
- packages/mocactl/src/sbx/api.ts: this branch's sandboxEgress and
  sandboxEgressNdjson, then main's mintSandboxToken (with its abort
  signal), setSandboxMode and mintSandboxModeToken. This branch's older
  mintSandboxToken is dropped for main's.
- packages/mocactl/src/sbx/cli.ts: TAKES_ID_ARG holds main's get and reset
  and this branch's egress.
- packages/mocactl/src/sbx/commands.ts: this branch's cmdEgress,
  verifyEgress, num and sealedText, beside main's RM_LEASE_WAIT_MS and
  endLease.
- packages/mocactl/test/contract.test.ts: both sides' routes, calls and
  method names.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
webchang added a commit to webchang/moca that referenced this pull request Nov 14, 2026
Brings pr/i26-retire at upstream main d227d41 (through rossoctl#790, with rossoctl#789's
combined plane and pinned-session holds, rossoctl#791/rossoctl#792 egress, rossoctl#784 pacing,
rossoctl#776 memory placement and rossoctl#808), and i26's retire at API 1.18.0. This
branch's quotas and reject section moves to 1.19.0.

Conflicts:
- docs/api/CHANGELOG.md: ## 1.19.0 quotas and reject above i26's
  ## 1.18.0 and main's sections, which are unchanged.
- docs/api/openapi.yaml: info.version 1.19.0. The wanted-state
  description is main's (memory, idle grace, pinned-session hold, start
  order) with this branch's admin-rejected builds in `stop`.
- docs/reference/change-policy.md: main's list, then "template retire",
  then "admin quotas and build reject"; control plane 1.19.0, harness
  1.3.0.
- docs/reference/http-api.md: main's rows (egress records, Retire at
  1.18.0), then the Admin row at 1.19.0.
- docs/specs/2026-11-03-template-lifecycle-and-provenance-design.md:
  the status line names both main's §6.2/§6.5 parts and this branch's
  quotas and reject.
- packages/control-plane/src/activation.ts: main's buildOfWorker and
  running-worker maps, with endedWithWorker (retired or admin-rejected)
  where main tests for a retired build with a worker.
- packages/control-plane/src/host-handlers.ts: main's file (wantedAnswer,
  egress, start limit, grace), with this branch's rejectedByAdmin in the
  wanted state's ended branch, liveSnapshots skipping rejected builds,
  and `detached` taken for an admin-rejected build.
- packages/control-plane/src/sandbox-handlers.ts: activationLock is
  main's import from activation-lock.ts (its local copy dropped, so no
  duplicate); this branch's templateUseLock stays. Imports carry both
  rejectedByAdmin and main's readinessReasonOf, startQueue,
  startRetryAfterS; identity.js is imported once.
- packages/control-plane/test/activation.test.ts: both new placement
  cases.
- packages/control-plane/test/openapi-contract.test.ts: 31 enrollable
  routes (28 + this branch's 2 + main's 1).
- packages/mocactl/src/sbx/api.ts, commands.ts, cli.ts: both sides'
  types, imports, usage, flags and dispatch (quota and --stop-now).
- packages/mocactl/test/contract.test.ts: 28 replies (25 + 1 + 2), with
  main's reply shape.

Also: activation-lock.ts's comment says, as this branch's code does,
that a reject takes the activation lock and a sandbox create takes only
its template's use lock; http-api.md's "admin routes came with API
1.19.0"; the reject test reads main's wanted answer (starting,
egressSids).

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
webchang added a commit to webchang/moca that referenced this pull request Nov 14, 2026
Brings pr/i26-retire at upstream main d227d41 (through rossoctl#790, with rossoctl#789's
combined plane and pinned-session holds, rossoctl#791/rossoctl#792 egress, rossoctl#784 pacing,
rossoctl#776 memory placement and rossoctl#808), and i26's retire at API 1.18.0. This
branch's removal section moves to 1.19.0.

Conflicts:
- docs/api/CHANGELOG.md: ## 1.19.0 removal above i26's ## 1.18.0 and
  main's sections, which are unchanged. The `remove` bullet names a
  pinned session's hold beside a live sandbox.
- docs/api/openapi.yaml: info.version 1.19.0. The wanted-state
  description is main's (memory, idle grace, pinned-session hold, start
  order), with "in no list", `remove` (since 1.19.0; not under a live
  sandbox or a session's hold) and the shared-build rule; the response
  keeps main's `starting`, `graced` and `egressSids` and adds `remove`.
- docs/reference/change-policy.md: main's list, then "template retire",
  then "retired build removal"; control plane 1.19.0, harness 1.3.0.
- packages/control-plane/src/host-handlers.ts: main moved the wanted
  state into wantedAnswer; `remove` is built there, in the retired
  branch, under main's busyWorkers (a live sandbox or a pinned session's
  hold), and returned beside main's run, stop, starting and graced;
  hostWanted adds egressSids as main does. hostWorkerReport takes
  `removed` on main's version of it (st.running and refused kept); the
  host's holds drop the build on st. The header, liveSnapshots and
  T.unique texts are this branch's.
- packages/control-plane/test/activation.test.ts: the wanted answers
  carry both `remove` and main's `starting`/`egressSids`.
- packages/mocactl/src/sbx/cli.ts: main's usage (sbx hosts, create
  --mode/--idle-timeout) with this branch's retire --wait text.
- deploy/sbx/host-agent.sh: main's header and run loop (run.tsv, start
  limit, grace), then this branch's removal() before the lock is let go;
  REMOVED beside main's counters; summary keeps "removed" before
  "errors" and main's egress, memory, start and grace fields after it.
- deploy/sbx/tests/host-agent.test.sh: both mocks (install-host,
  journalctl) and both settings; main's sections 13-26, then this
  branch's removal section as 27, on a clean srv with well-formed
  snapshots (snapfiles), so main's memory report raises no error.
- deploy/sbx/RUNBOOK.md: main's summary text with "removed".
- docs/specs/2026-11-03-template-lifecycle-and-provenance-design.md:
  main's records table with this branch's `event: removed`; step 7 names
  a pinned session's hold.

Also moved to 1.19.0: http-api.md's "Since API 1.19.0" and
host-agent.sh's "older than API 1.19.0" comment. activation.test.ts's
live-sandbox removal case reads the answer with toMatchObject: the
wanted state now also carries egressSids, which list the sandbox.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
webchang added a commit to webchang/moca that referenced this pull request Nov 16, 2026
…te lifecycle stack

Upstream main 0dc3d01 (API 1.21.0) carries the reviewed, final form of
the features this branch held in early, integrated versions, through the
PRs filed from this fork (rossoctl#755-rossoctl#776, rossoctl#781, rossoctl#782, rossoctl#784-rossoctl#786, rossoctl#789-rossoctl#794,
rossoctl#798-rossoctl#800) and the maintainer's lease mode, grants and lease clients
(rossoctl#763, rossoctl#802, rossoctl#807, rossoctl#808, rossoctl#810, rossoctl#812, rossoctl#814). Where upstream has a feature,
upstream's version wins: its code, tests, openapi, CHANGELOG (byte
identical), docs and specs.

The fork was 736 commits behind and 390 ahead (merge base dd0ce71).

Conflict resolution (148 files, 82 both-modified, 66 both-added): every
conflicted file is upstream's side as is (byte identical to 0dc3d01).
No conflicted file differs from 0dc3d01 in this commit.

One file merged without a conflict and was set back to upstream's:
- packages/mocactl/src/sbx/push.ts: the auto-merge added the fork's
  baselineAtHead a second time beside upstream's own (fb28e06's
  function, already upstream); upstream's file as is.

With that, this commit's tree is 0dc3d01's plus the 18 files only the
fork has (below). Every other file the fork changed is upstream's.

Conflicted files, all resolved to upstream's side (0dc3d01):
- deploy/k8s/overlays/ocp-combined/kustomization.yaml (AA)
- deploy/k8s/overlays/ocp-combined/patch-addressing.yaml (AA)
- deploy/k8s/overlays/ocp-combined/patch-relay.yaml (AA)
- deploy/microvm/P4-ON-P6.md (UU)
- deploy/microvm/build-rootfs.sh (UU)
- deploy/microvm/build-snapshot.sh (UU)
- deploy/microvm/setup-microvm.sh (UU)
- deploy/microvm/tests/build-rootfs.test.sh (UU)
- deploy/microvm/tests/build-snapshot.test.sh (UU)
- deploy/microvm/tests/setup-microvm.test.sh (UU)
- deploy/sbx/README.md (UU)
- deploy/sbx/RUNBOOK.md (UU)
- deploy/sbx/host-agent.sh (AA)
- deploy/sbx/install-host.sh (UU)
- deploy/sbx/sbx-host-agent-wanted.service (AA)
- deploy/sbx/sbx-host-agent-wanted.timer (AA)
- deploy/sbx/sbx-host-agent.service (AA)
- deploy/sbx/[email protected] (UU)
- deploy/sbx/setup.sh (UU)
- deploy/sbx/template-onboarding/GUIDE.md (AA)
- deploy/sbx/template-onboarding/ONBOARDING.md (AA)
- deploy/sbx/template-onboarding/README.md (AA)
- deploy/sbx/template-onboarding/examples/django__django-11133.gate-record.json (AA)
- deploy/sbx/template-onboarding/examples/django__django-11133.json (AA)
- deploy/sbx/template-onboarding/governance/GATING-RULES.md (AA)
- deploy/sbx/template-onboarding/governance/PROCESS.md (AA)
- deploy/sbx/template-onboarding/governance/README.md (AA)
- deploy/sbx/template-onboarding/template-build.sh (AA)
- deploy/sbx/template-onboarding/template-register.sh (AA)
- deploy/sbx/template-onboarding/tests/examples.test.sh (AA)
- deploy/sbx/template-onboarding/tests/template-build.test.sh (AA)
- deploy/sbx/template-onboarding/tests/template-register.test.sh (AA)
- deploy/sbx/template-onboarding/verify-provenance.py (AA)
- deploy/sbx/templates-check.sh (AA)
- deploy/sbx/tests/host-agent.test.sh (AA)
- deploy/sbx/tests/install-host.test.sh (UU)
- deploy/sbx/tests/overlay-combined.test.sh (AA)
- deploy/sbx/tests/setup.test.sh (UU)
- deploy/sbx/tests/templates-check.test.sh (AA)
- deploy/vm/tests/setup-vm.test.sh (UU)
- docs/api/CHANGELOG.md (UU)
- docs/api/harness-openapi.yaml (UU)
- docs/api/openapi.yaml (UU)
- docs/concepts/sandboxes-and-tiers.md (UU)
- docs/reference/change-policy.md (UU)
- docs/reference/cli-mocactl.md (UU)
- docs/reference/configuration.md (UU)
- docs/reference/http-api.md (UU)
- docs/sbx/user-guide.md (UU)
- docs/specs/2026-10-15-sbx0-internal-sandbox-service-design.md (UU)
- docs/specs/2026-10-30-session-sandbox-templates-design.md (AA)
- docs/specs/2026-11-03-template-lifecycle-and-provenance-design.md (AA)
- docs/specs/2026-11-05-combined-control-plane-design.md (AA)
- docs/specs/2026-11-08-enrollment-and-roles-api-design.md (AA)
- docs/specs/2026-11-08-sandbox-egress-records-design.md (AA)
- docs/specs/2026-11-08-subject-trust-gate-records-design.md (AA)
- docs/specs/README.md (UU)
- harness/src/run-turn.ts (UU)
- harness/src/sandbox-affinity.ts (UU)
- harness/src/select-sandbox.ts (UU)
- harness/test/select-sandbox-templates.test.ts (AA)
- harness/test/turn-seed.test.ts (AA)
- harness/test/turn-stream.test.ts (UU)
- packages/control-plane/src/activation-lock.ts (AA)
- packages/control-plane/src/activation.ts (AA)
- packages/control-plane/src/egress-handlers.ts (UU)
- packages/control-plane/src/egress-log.ts (AA)
- packages/control-plane/src/errors.ts (UU)
- packages/control-plane/src/exchange.ts (UU)
- packages/control-plane/src/handler-util.ts (UU)
- packages/control-plane/src/handlers.ts (UU)
- packages/control-plane/src/host-handlers.ts (AA)
- packages/control-plane/src/identity.ts (UU)
- packages/control-plane/src/index.ts (UU)
- packages/control-plane/src/main.ts (UU)
- packages/control-plane/src/member-handlers.ts (AA)
- packages/control-plane/src/members.ts (AA)
- packages/control-plane/src/ownership.ts (UU)
- packages/control-plane/src/provenance.ts (AA)
- packages/control-plane/src/routes.ts (UU)
- packages/control-plane/src/sandbox-config.ts (UU)
- packages/control-plane/src/sandbox-handlers.ts (UU)
- packages/control-plane/src/server.ts (UU)
- packages/control-plane/src/template-catalog.ts (AA)
- packages/control-plane/src/template-policy.ts (AA)
- packages/control-plane/src/token.ts (UU)
- packages/control-plane/test/activation.test.ts (AA)
- packages/control-plane/test/egress-redis.test.ts (AA)
- packages/control-plane/test/errors.test.ts (UU)
- packages/control-plane/test/host-flow.test.ts (AA)
- packages/control-plane/test/members.test.ts (AA)
- packages/control-plane/test/openapi-contract.test.ts (UU)
- packages/control-plane/test/provenance.test.ts (AA)
- packages/control-plane/test/repository-allowlist.test.ts (AA)
- packages/control-plane/test/route-authz-enumeration.test.ts (UU)
- packages/control-plane/test/route-profile.test.ts (UU)
- packages/control-plane/test/routes.test.ts (UU)
- packages/control-plane/test/sandbox-egress.test.ts (AA)
- packages/control-plane/test/sandbox-handlers.test.ts (UU)
- packages/control-plane/test/session-templates.test.ts (AA)
- packages/control-plane/test/subject-trust.test.ts (AA)
- packages/control-plane/test/template-admin.test.ts (AA)
- packages/control-plane/test/template-catalog.test.ts (AA)
- packages/control-plane/test/template-create.test.ts (AA)
- packages/knative-server/src/server.ts (UU)
- packages/knative-server/src/turn-auth.ts (UU)
- packages/knative-server/test/turn-auth.test.ts (UU)
- packages/mocactl/src/api/errors.ts (UU)
- packages/mocactl/src/api/frames.ts (UU)
- packages/mocactl/src/cli.ts (UU)
- packages/mocactl/src/core/session-manager.ts (UU)
- packages/mocactl/src/core/session-options.ts (UU)
- packages/mocactl/src/headless.ts (UU)
- packages/mocactl/src/sbx/api.ts (UU)
- packages/mocactl/src/sbx/call-record.ts (AA)
- packages/mocactl/src/sbx/cli.ts (UU)
- packages/mocactl/src/sbx/commands.ts (UU)
- packages/mocactl/src/sbx/dry-run.ts (AA)
- packages/mocactl/src/sbx/exec.ts (UU)
- packages/mocactl/src/sbx/run.ts (UU)
- packages/mocactl/src/sbx/templates.ts (AA)
- packages/mocactl/test/contract.test.ts (UU)
- packages/mocactl/test/harness.test.ts (UU)
- packages/mocactl/test/headless.test.ts (UU)
- packages/mocactl/test/helpers/sbx.ts (UU)
- packages/mocactl/test/run-record.test.ts (AA)
- packages/mocactl/test/sbx-admin-subjects.test.ts (AA)
- packages/mocactl/test/sbx-cli.test.ts (UU)
- packages/mocactl/test/sbx-egress.test.ts (AA)
- packages/mocactl/test/sbx-exec.test.ts (UU)
- packages/mocactl/test/sbx-templates.test.ts (AA)
- packages/mocactl/test/session-manager.test.ts (UU)
- packages/mocactl/test/session-options.test.ts (UU)
- remote-worker/cmd/microvm-worker/main.go (UU)
- remote-worker/cmd/microvm-worker/template_record.go (AA)
- remote-worker/cmd/microvm-worker/template_record_test.go (AA)
- remote-worker/cmd/microvm-worker/verify_cache.go (AA)
- remote-worker/cmd/microvm-worker/verify_cache_test.go (AA)
- remote-worker/internal/egress/audit_test.go (UU)
- remote-worker/internal/session/labels.go (UU)
- remote-worker/internal/vmpool/errors.go (UU)
- remote-worker/internal/vmpool/guestconn.go (UU)
- remote-worker/internal/vmpool/guestconn_test.go (UU)
- remote-worker/internal/vmpool/launcher_firecracker.go (UU)
- remote-worker/internal/vmpool/launcher_firecracker_egress_unix_test.go (UU)
- remote-worker/internal/vmpool/snapshot.go (UU)
- remote-worker/internal/vmpool/snapshot_test.go (UU)
- remote-worker/internal/vmpool/verifycache.go (AA)

Fork-only files, kept as they are (upstream has no such file):
- deploy/sbx/mint-login.sh, deploy/sbx/tests/mint-login.test.sh: a test
  login minted with the deployment's signing key. Checked against
  upstream: makeSigner/mint, SANDBOX_API_ISSUER, the moca-mu1 Secret and
  its label, the env keys it reads and mocactl's sbx-auth.json shape are
  all still upstream's.
- deploy/sbx/template-onboarding/deck/ (README, requirements, the two
  generators, deck_kit.py, the two PDFs, .gitignore): the fork's decks.
- deploy/sbx/template-onboarding/GUIDE.pdf: regenerated from upstream's
  GUIDE.md in a later commit.
- deploy/sbx/template-onboarding/governance/GAPS-AND-ASSUMPTIONS.md and
  INVENTORY-2026-11-02.md: the fork's register and inventory.
- docs/specs/2026-11-09-cold-start-pacing-design.md,
  2026-11-09-memory-aware-placement-design.md and
  2026-11-10-mocactl-template-commands-design.md: the fork's design
  notes; upstream folded their content into its lifecycle spec
  (§6.4 memory, §6.5 pacing) and the user guide (mocactl).
- docs/tools/gen_pdf.py, docs/tools/gen_toc.py: the PDF and TOC tools.

Fork-only behaviour, decided one by one (from git log 0dc3d01..f125c02
--no-merges, checked against 0dc3d01):

Ported onto upstream's code, each in its own commit after this one:
- The pinned-session retire guard (c571226): a retire is refused
  (409 build_in_use) while an active Moca Pi session is pinned to the
  build. Upstream's buildsInUse checks live sandboxes only and its
  comment says pinned sessions are still to be checked.
- Reuse only while a host holds the snapshot (G29, 521efe5): upstream
  reuses any registered build with the same inputs; its own lifecycle
  spec (§4, Reuse) says a registered build is reused only while a host
  reports holding its snapshot.
- install-host.sh --uninstall-shared and the mounted legacy jail guard
  (5e66397): upstream has neither.
- GUIDE §4b.4's base example without skip_git_identity_check
  (f125c02): upstream applies X12 under every profile, so its example
  create would be refused.
- Links from upstream's READMEs to the fork-only files above.

Dropped, because upstream's design replaces them on purpose:
- Removal of admin-rejected builds: upstream stops them and never
  removes them (the user's decision in rossoctl#786).
- The harness-profile catalog's fallback to SH_SESSION_TEMPLATES
  (902255b): upstream serves the harness profile the store's templates
  only (its test was renamed so); a combined plane is unaffected.
- The fork's register ids (G-numbers), window dates and results
  pointers inside the documents upstream now has (RUNBOOK, README,
  GUIDE, ONBOARDING, PROCESS, GATING-RULES, P4-ON-P6, the specs):
  upstream's text wins; the fork's own documents above keep them.
- The fork's image-builder-specific wording in GATING-RULES.md:
  upstream's generic wording (the image builder) is taken as is.

Dropped, could be re-proposed (no upstream equivalent, but the port is
an API change or its intent upstream is unclear):
- TurnPlacement.template, a turn result naming the session's sandbox
  template (9d6004d): a harness API field; upstream's CHANGELOG is kept
  byte identical.
- An imported build's catalog entry and create record carrying the
  declared seed (20d0995): sessions are seeded the same (upstream falls
  back to the declared seed); only the field in the catalog API goes.
- mocactl: sbx create --seed checking the seeded HEAD against the spec's
  baseline_commit; activate --wait stopping at once on not_held or
  memfile_mismatch; ApiError's readiness, readinessReason and
  queuePosition in refusals; an admin write refused when the control
  plane URL came only from the login; the admin-write issuer check for
  the combined profile; the dry run's X1.offline check and its guest_mb
  and git-less advice; the quota, policy and build lines' extra fields
  (quotaSource, selfAttest, allowedRepositories, heldBy, attestation).
  Upstream's reviewed client (rossoctl#767, rossoctl#768) left them out; the server
  still enforces every rule.

Already upstream (not lost): build reuse (G21), the verify cache, the
host agent's --keep-shared removals, read-ahead, the hash_version 2
check in the microVM worker, M7, G39, G42, G43, G48, G49, G50, mocactl
--record, --version, the minted login's own control plane, activate
--wait sizing, and every other fork feature listed in the task.

The relay's per-client tokens: not on this branch (the fork's
sandbox-relay main.ts is older upstream code), so nothing to resolve.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
pdettori added a commit to pdettori/moca that referenced this pull request Nov 16, 2026
Sixteen ADRs still said Proposed although their decisions are in code
on main. Each status line now names the merged PRs that implemented it
and the date the core landed (format of ADR-0042), and notes what is
still owed where only part is built:

- 0028 (rossoctl#170, rossoctl#201, rossoctl#340; its KEDA transport removed by ADR-0041)
- 0029 (rossoctl#171), 0030 (rossoctl#214), 0031 (rossoctl#214, rossoctl#225)
- 0032 (rossoctl#249, rossoctl#350, as amended by MI1)
- 0035 (rossoctl#251; ADR-0048 adds lease mode beside it)
- 0036 (rossoctl#347), 0038 (rossoctl#458), 0039 (rossoctl#467), 0040 (rossoctl#481)
- 0043 (rossoctl#560, rossoctl#588, rossoctl#600, rossoctl#615), 0044 (rossoctl#563), 0045 (rossoctl#620)
- 0046 (phase 1: rossoctl#630, rossoctl#641, rossoctl#646; phase 2 owed)
- 0047 (M1 and M3: rossoctl#704, rossoctl#713, rossoctl#717, rossoctl#765; M2 owed)
- 0048 (rossoctl#706, rossoctl#763, rossoctl#802, rossoctl#808, rossoctl#814; off by default until the
  security review's lease sections are signed off)

The README index follows, and its 0033 row, which still said Proposed
after rossoctl#249 accepted the ADR, is corrected.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
@pdettori pdettori added this to the v0.11.0 milestone Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-ai-review Request automated AI code review from clawgenti

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants