Skip to content

feat(control-plane,mocactl): retire a template, or one build of it - #781

Merged
webchang merged 32 commits into
rossoctl:mainfrom
webchang:pr/i26-retire
Nov 14, 2026
Merged

webchang merged 32 commits into
rossoctl:mainfrom
webchang:pr/i26-retire

Conversation

@webchang

@webchang webchang commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Closes #749. On main (d227d41): #775 (activation leases and placement), which this branch stacked on, is merged. Its own change is 4 commits (review range b35b8c77..d7d994ed), plus merges of main.

What it does: a template's owner, or an admin, retires a template or one of its builds through the API, and the host stops its worker. Four signed-off commits:

  1. The control plane:
    • POST /v1/templates/{id}/retire {reason?} and DELETE /v1/templates/{id}/builds/{build}, for the owner or an admin, 404 when the template is hidden;
    • the builds become retired and their leases end. Each build gets one retire record (caller, from, buildRecord, reason). A second retire answers record: null and writes nothing;
    • 409 build_in_use while a sandbox is live on the build;
    • 410 template_retired for a create, tag or activation that names a retired build;
    • readiness retired, and builds gain heldBy;
    • the wanted state's stop lists a held retired build with no live sandbox, and detached is accepted for it;
    • openapi 1.18.0.
  2. mocactl: sbx templates retire ID [--build B] [--reason T] [--wait [--timeout S]]. Any 410 is explained in words.
  3. A fix: --wait waits for the worker's stop (capacity null after the wanted stop), not for the snapshot's removal. Without host agents, it returns at once.
  4. A fix: when a retired build's presence can't be read, it reports running: null, and --wait keeps waiting rather than taking it as stopped.

Limits and notes for review:

Tests on the tip:

  • typecheck passes, and so does the full control-plane suite;
  • mocactl passes, run serially;
  • prettier passes.

20 files, +1,127 / -61, counted over the review range.

Assisted-By: Claude Code

…he API

Template lifecycle spec §5.1. Nothing withdrew a template or a build: every
build stayed usable for ever, and retiring meant editing the env list and
redeploying, which left no trace of what the template was.

- POST /v1/templates/{id}/retire {reason?} and DELETE
  /v1/templates/{id}/builds/{build} (the owner, or an admin): every build
  not yet retired, or the one named by build id or handle, becomes
  `retired` and its activation leases go. Each writes a `retire` record
  naming the caller, `from` (the status before), `buildRecord` (the digest
  of the build's `build` record, null for one never built) and the reason;
  earlier records stay. The answer lists each build with its id, readiness
  and the record's digest; an already retired build is listed with
  `record: null` and no second record.
- Never cuts off running work: refused `409 build_in_use` while a live
  sandbox runs on a build it names. The in-use check is one function
  (buildsInUse), where sessions pinned to a build join the live sandboxes
  once sessions name builds.
- Use is refused as gone: a sandbox create or an activation naming a
  retired build, a tag of one, or a template whose every build is retired,
  answers `410 template_retired`.
- Readiness reads `retired`; each build lists `heldBy`, the hosts whose
  last inventory holds its snapshot (null without host agents).
- The wanted state lists a retired build a host holds, with no live
  sandbox, in `stop`, and the worker report takes `detached` for it.
  Removing the worker and the snapshot from the host is not part of this
  change.
- openapi 1.8.0 (the two routes, RetiredBuild, the codes, `heldBy`, the
  readiness value), its changelog, the HTTP API reference and the
  lifecycle spec's §5.1.

Refs rossoctl#749

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
The client part of retire (template lifecycle spec §5.1).

- `mocactl sbx templates retire ID [--build B] [--reason TEXT] [--wait
  [--timeout S]]` retires the template (every build of it) or build B,
  and prints each build retired, saying when one was already retired.
  --reason is kept in the record of a whole template's retire; with
  --build (a DELETE, which takes no body) it is refused as a usage error.
- --wait then reads each build until it is `retired` and no host holds
  its snapshot (`heldBy` empty; null, or absent from an older control
  plane, means no host agents), saying once who still holds it. Past
  --timeout (default 300 s) it exits 5, as `activate --wait` does.
- Any sbx command refused `410 template_retired` says that a retired
  template or build is never served again, and where to look instead.

SandboxApiClient gains retireTemplate, SbxBuild `heldBy` and `handle`,
and the contract test checks both routes against the OpenAPI document.

Refs rossoctl#749

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
…'s removal

`templates retire --wait` waited for `heldBy` to empty, which only the
host's removal step does, so on a deployment with host agents it always
ran to its timeout. It now waits for what this change does deliver: the
build reads `retired` and its worker no longer runs.

- control-plane: a retired build whose worker still holds a presence
  record reports `capacity` {running, inUse}, as an active one does;
  null once its host has stopped it. openapi's TemplateBuild.capacity
  and the 1.8.0 changelog say so; a test covers both cases.
- mocactl: `retire --wait` is done when each build is `retired` with
  `capacity` null, or at once without host agents (`heldBy` null). While
  waiting it says once per change that the worker still runs, with its
  sandboxes in use; the timeout names the worker's stop. The usage text,
  the spec's §5.1 and the HTTP API reference say that waiting for the
  removal from every host comes with rossoctl#743.
- The spec's §5.1 known limits add that `build_in_use` is judged from a
  read before the catalog update, so a create racing the retire can land
  on the build; the wanted state never stops a worker with a live
  sandbox, so that sandbox runs. A follow-up note: retiring the build
  `default` points to could move `default` to the newest registered one.

Refs rossoctl#749

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
…opped worker

With the relay's presence unreadable, a retired build's capacity read as
null, which retire --wait takes as "its worker stopped". Such a build now
reports `capacity: {running: null, inUse}`, so a null capacity means only
"read, and not attached", and --wait keeps waiting on it, saying the
worker's state cannot be read.

Tests: the control plane reports running null with presence unreadable;
--wait waits it out and says so once.

Refs rossoctl#749

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
@pdettori pdettori added the ready-for-ai-review Request automated AI code review from clawgenti label Nov 12, 2026

@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.

Summary

This PR is stacked on #775, and the review covers only its own four commits (git diff refs/prr/775...refs/prr/781). They add retire to the control plane (POST /retire, DELETE /builds/{build}, 410 template_retired, 409 build_in_use, the wanted state's stop for retired builds, heldBy and capacity on retired builds) and sbx templates retire [--wait] to mocactl. I checked these against the spec §5.1 text, the openapi 1.8.0 changes and the host agent's stop loop, and found no correctness or security defects. One suggestion: a build retired before it was ever built has no worker, but while presence cannot be read it still reports capacity.running: null, so retire --wait runs until its timeout for nothing.

Author: webchang (MEMBER — maintainer)
Areas reviewed: control-plane retire handlers, wanted state and worker report, readiness/capacity/heldBy, provenance retire record, routes and errors, mocactl retire CLI and --wait loop, openapi/changelog/http-api/spec docs, tests, commit conventions/DCO, agent-config supply-chain gate
Agent/IDE config (.claude/.vscode): none
Commits: 4 commits, all signed-off: yes
CI status: passing (all 17 checks green, including DCO, CodeQL, lint, k8s-kind-e2e)

0 must-fix, 1 suggestions, 0 nits.

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

// only "read, and not attached".
capacity:
readiness === 'active' ||
(b.status === 'retired' && (f.attached === null || f.attached.has(b.worker)))

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: Take the f.attached === null branch only for a build that has a worker. A build retired before it registered (status queued/building/probing, then retired) has worker: '', so it has no worker to stop. When presence is unreadable, this condition still gives it capacity: {running: null, ...}. cmdRetire --wait (packages/mocactl/src/sbx/templates.ts:280-295) reads that as "its worker's state cannot be read; still waiting" and polls until the timeout, then exits 5, although nothing can ever stop. heldBy gives no way out either: on a deployment with host agents it is [], not null, so noAgents is false. Suggested fix: (b.status === 'retired' && b.worker !== '' && (f.attached === null || f.attached.has(b.worker))). Then a worker-less retired build reports capacity: null and --wait finishes at once. Add a case for it beside the existing "running null with presence unreadable" test in activation.test.ts.

@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

The range adds POST /v1/templates/{id}/retire and DELETE /v1/templates/{id}/builds/{build} (owner or admin, 404 when hidden), marks builds retired and drops their leases, refuses 409 build_in_use while a live sandbox runs on the worker, answers 410 template_retired on create and activate, puts retired held builds in the wanted state's stop, and adds heldBy and openapi 1.8.0. mocactl gains sbx templates retire [--build] [--reason] [--wait]. Authz and the openapi, routes and mocactl contract agree. The main problem is that --wait can never finish for a retired build that no host agent holds, such as an imported env-list template. There are also smaller issues: an activation that races a retire can leave a quota-counting lease on the retired build, build_in_use checks by worker, and buildRecord comes back null for rejected builds.

Author: webchang (MEMBER — maintainer)
Areas reviewed: TypeScript, OpenAPI, CLI
Agent/IDE config (.claude/.vscode): none
Commits: all signed-off: yes
CI status: 16 pass, deploy-scripts pending

Inline: 1 must-fix, 2 suggestion, 1 nit. The head ba1c8e2 is a merge-only cascade of #757 up the stack (empty remerge-diff, no new non-merge commits); the review covers this PR's own range b35b8c77..d7d994ed, as the body asks.

AI-assisted review, approved by a maintainer before posting.

Comment thread packages/mocactl/src/sbx/templates.ts Outdated
} catch (err) {
if (!transient(err)) throw err;
}
const noAgents = b !== undefined && (b.heldBy === null || b.heldBy === 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.

must-fix: --wait cannot finish when host agents exist but no host holds the build. heldBy is [] there, not null, so noAgents is false, and the loop needs capacity === null. The server keeps capacity non-null for a retired build as long as its worker has a presence record (sandbox-handlers.ts buildBody). hostWanted only lists in stop the builds that mine.holds[b.buildId] covers, so no host will ever stop that worker. A concrete case: an imported env-list template (buildId imported:..., never in a host inventory, retirable by an admin) whose operator-run worker is attached. mocactl sbx templates retire ID --wait then always prints 'its worker still runs' and exits 5 at the timeout. Suggested fix: treat heldBy empty like null (no host agent will stop it, so nothing to wait for), or say plainly that the worker isn't host-managed and return. Add a test with heldBy: [] and a non-null capacity.

return {
...cur!,
builds: cur!.builds.map((x) =>
done.includes(x) ? { ...x, status: 'retired' as const, leases: [] } : x,

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: Retire takes no activation lock, and takeLeaseLocked doesn't re-check status inside its own cat.update. So an activate that resolved target as registered just before this update still writes withLease(x, rec.digest) onto the now-retired build, and returns 200 with a lease and an activate record. The PR body calls this harmless because only registered builds are wanted. But leasedBy (the active quota in takeLease and GET /v1/quota) doesn't filter by status, so the stale lease counts against the caller's active quota until it expires, which can be up to 86400 s. Suggested fix: in takeLeaseLocked's update, throw template_retired when cur's build is no longer registered. Alternatively, have leasedBy count only registered builds. Either way, take the activation lock here.

const busy = new Set<string>();
for (const r of await deps.sandboxes.listAll(nowS)) if (isLive(r, nowS)) busy.add(r.worker);
for (const x of builds) {
if (x.worker && busy.has(x.worker)) out.set(x.buildId, 'still serves a live sandbox');

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: build_in_use is decided by worker id, not by build. template-build.sh names the worker sbx_<id>_<image digest 12>, so two builds of one template from the same image with different specs (vcpus, guest_mb, ...) share a worker id. A live sandbox on the newer build then blocks retiring the older one with a misleading 409. Since SandboxRecord carries buildId, match on r.buildId === x.buildId when it is set, and fall back to the worker only for records without it.

body: {
build: x.handle ?? x.buildId,
...(x.status === 'registered' ? { buildId: x.buildId } : {}),
buildRecord: await buildRecordOf(prov, d0.id, x.buildId),

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: buildRecordOf(prov, d0.id, x.buildId) matches the build record's manifest_hash against x.buildId. A rejected build keeps its handle as buildId (hostBuildReport sets buildId: manifestHash only on registration), so its retire record gets buildRecord: null even though an outcome: built record exists for it. That contradicts the documented 'null for one never built'. Match on body.handle === x.handle as well, or instead.

@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.

Summary

Re-review of the push since my last review (d7d994e..ba1c8e2, review 5883319992). This PR's own commits are unchanged: git range-diff shows every earlier commit as equal. The push only merges the parent branches again ("Merge pr/i19-activation into pr/i26-retire", and the merges below it), and so brings in #757's five new fixes (381d7c4 too-large command closes its connection, b1beba6 lease keeps its VM on that refusal, ace1c43 build-snapshot.sh no writes through a symlink, ab347c1 install-host.sh removes the old jail path, 5181204 http-api doc). Those belong to #757 and are reviewed there. I checked the two conflicted merges on the way down (3ee0acf upstream/main into i10, d4445a2 i10 into i17) against their recorded resolutions. errors.go, guestconn.go, build-snapshot.sh, microvm-worker main.go and snapshot_test.go keep both sides, as the commit messages say, and main.go's single LoadManifest now feeds both ManifestFeatures and VerifyWith. No new findings. The earlier 1 suggestion still apply: none of the files they cite changed in this push.

Author: webchang (MEMBER — maintainer)
Areas reviewed: range-diff of this PR's own commits, the incoming #757 commits (scope only), the conflict resolutions in the two upstream merges, commits/DCO, CI, agent-config gate
Agent/IDE config (.claude/.vscode): none
Commits: 50 commits, all signed-off: yes
CI status: passing (all 17 checks green)

0 new must-fix, 0 new suggestions, 0 new nits.

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

Conflicts in docs only, both sides kept: openapi's getQuota description
(rossoctl#766's template and build counting, and this branch's activation
leases) and http-api.md's error-code list (rossoctl#766's template_exists,
policy_refused and quota_exceeded, and this branch's no_active_slot,
template_unavailable and template_not_active).

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
Conflict in docs/reference/http-api.md's error-code list, both sides
kept: rossoctl#766's template_exists, policy_refused and quota_exceeded, and
this branch's build_in_use and template_retired.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
rossoctl#775's merge was redone without a duplicate import; this takes it. The
error-code list keeps the resolution already made here.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
A retired build's worker is stopped only by a host agent that holds the
build: the wanted state's `stop` lists only the builds a host holds. With
host agents present but none holding the build (`heldBy` empty, such as an
imported template whose worker an operator runs), the server still reports
the attached worker's capacity, so --wait could only time out and exit 5.

--wait now treats `heldBy` empty like null: nothing to wait for. When the
worker still runs, it says that the worker is not host-managed and is to be
stopped where it runs, instead of saying it stopped. The spec, the HTTP API
reference and the usage text say so; a test covers `heldBy: []` with a
non-null capacity (running known and unknown).

Refs rossoctl#749
Assisted-By: Claude (Anthropic AI) <[email protected]>

Signed-off-by: Rong Chang <[email protected]>
…apacity

A build retired while queued, building or probing has no worker, so there
is nothing to stop. While presence could not be read it still reported
`capacity: {running: null, ...}`, which `sbx templates retire --wait`
waits out until its timeout. Only a retired build with a worker now
reports capacity; one without reports null, presence read or not. The
openapi description says so; an activation test covers it.

Refs rossoctl#749
Assisted-By: Claude (Anthropic AI) <[email protected]>

Signed-off-by: Rong Chang <[email protected]>
A retire's build_in_use check matched live sandboxes by worker id. Two
builds of one template from the same image with other specs share a
worker id (template-build.sh names the worker from the template id and
the image digest), so a live sandbox on the newer build blocked retiring
the older one with a misleading 409.

A sandbox record names the build it resolved to (`buildId`); it now
counts for that build only. A record without `buildId`, from before
builds were traced, still counts for every build on its worker. The
spec says so; activation tests cover both.

Refs rossoctl#749
Assisted-By: Claude (Anthropic AI) <[email protected]>

Signed-off-by: Rong Chang <[email protected]>
…cord

A retire record's `buildRecord` was found by matching the `build`
record's manifest_hash against the build's id. A build that was built and
then rejected keeps its handle as its id (only registration sets the id to
the manifest hash), so its retire record said `buildRecord: null`, though
an `outcome: built` record exists for it, against the documented "null
for one never built".

buildRecordOf now matches the build record by the build's handle when it
has one, and by the manifest hash only for a build without a handle. An
activation test retires a built-then-rejected build and checks the
record it cites.

Refs rossoctl#749
Assisted-By: Claude (Anthropic AI) <[email protected]>

Signed-off-by: Rong Chang <[email protected]>
…the retired build

A retire took no activation lock, and the lease-taking step did not
re-check the build's status. An activation that resolved its build as
registered just before a retire still wrote its lease onto the retired
build and answered 200; the `active` quota counts leases whatever the
build's status, so that stale lease counted against the caller until it
expired.

A retire now runs its in-use read and catalog update under the activation
lock, and the lease-taking step re-reads the build's status under that
lock: a build retired since is refused 410 template_retired, with no lease
and no activate record. The spec says so; two activation tests drive the
race both ways (the retire between resolve and lock, and the retire
arriving during the lease write).

Refs rossoctl#749
Assisted-By: Claude (Anthropic AI) <[email protected]>

Signed-off-by: Rong Chang <[email protected]>
Refs rossoctl#749
Assisted-By: Claude (Anthropic AI) <[email protected]>

Signed-off-by: Rong Chang <[email protected]>
@webchang

Copy link
Copy Markdown
Member Author

packages/mocactl/src/sbx/templates.ts:280 (must-fix)

"--wait cannot finish when host agents exist but no host holds the build."

Fixed in 84ed479: --wait now treats heldBy empty like null, since only a host agent that holds the build stops its worker (the wanted state's stop lists only held builds). It returns at once; when the worker still runs, it says that the worker is not host-managed and is to be stopped where it runs (no longer "its worker stopped"). The spec, the HTTP API reference and the usage text say so. Test: sbx-templates.test.ts "--wait: done at once when no host holds the build (heldBy empty, worker attached)", with heldBy: [] and a non-null capacity (running known and unknown); the heldBy null test now checks the message too.

packages/control-plane/src/sandbox-handlers.ts:1058

"Retire takes no activation lock, and takeLeaseLocked doesn't re-check status inside its own cat.update."

Fixed in cf059b7 (spec rewrap in d5bca89): a retire now runs its in-use read and catalog update under the activation lock, and takeLeaseLocked re-reads the build's status from its catalog read under that lock, before the activate record and the lease: a build retired since is refused 410 template_retired (no lease, no activate record). The check sits before the record rather than inside cat.update, so no activate record is ever written without its lease. leasedBy is unchanged: with both under the lock and the retire clearing leases, no lease is left on a retired build. Tests: activation.test.ts "an activation that resolved the build before a retire writes no lease onto it" (the retire runs between resolve and lock; active.used stays 0) and "a retire waits for an activation taking its lease, then drops that lease" (the retire arrives during the lease write). Each fails with its half of the fix removed.

packages/control-plane/src/sandbox-handlers.ts:1005

"build_in_use is decided by worker id, not by build."

Fixed in c33982a: a live sandbox counts for the build it resolved to (r.buildId) only; a record without buildId (from before builds were traced) still counts for every build on its worker. The spec says so. Tests: activation.test.ts "judges build_in_use by build: a sandbox on another build of one worker does not block" (two builds sharing a worker; the idle one retires, the busy one is refused) and "judges build_in_use by worker for a sandbox record without a build id".

packages/control-plane/src/sandbox-handlers.ts:1071 (nit)

"buildRecordOf(prov, d0.id, x.buildId) matches the build record's manifest_hash against x.buildId."

Fixed in bb42101: buildRecordOf takes the build and matches the build record by its handle when the build has one, and by the manifest hash only for a build without a handle. A built-then-rejected build's retire record now cites its outcome: built record. Test: activation.test.ts "cites the build record of a build built and then rejected".

packages/control-plane/src/sandbox-handlers.ts:338 (bot)

"Take the f.attached === null branch only for a build that has a worker."

Fixed in 32c64ff: a retired build reports capacity only when it has a worker (worker !== ''); one retired before it registered reports capacity: null, presence read or not, so retire --wait finishes at once. The openapi capacity description says so. Test: activation.test.ts "reports null capacity for a build retired before it registered, presence unreadable too".

New tip: d5bca89

Also: leasedBy counting only registered builds, the alternative you mentioned, isn't done here; the status re-check under the activation lock closes the race either way.

Assisted-By: Claude Code

Takes the activation branch's reviewed fixes (the default lease from the
holders' idle limit, imported templates never host-managed, stale hosts
left out of placement, sticky placement from the hosts' running workers,
Retry-After from the builds placed on the holders, no renewal on a
first-use retry, a repeated refusal recorded once, and the host agent's
fixes) beside this branch's retire. Conflicts and their resolutions:

- packages/control-plane/src/sandbox-handlers.ts: imports only. Both
  sides kept: buildRecordOf and the HostView type from this branch;
  hostManaged, busyWorkers and freshHosts from the activation branch.
  takeLeaseLocked merged cleanly and keeps both: the clamped default
  lease, busy-aware placement and the holders' Retry-After, and the
  status re-check under the activation lock (template_retired, or
  template_unavailable, before the quota check, placement and the
  activate record).
- packages/control-plane/src/host-handlers.ts: hostWanted keeps the
  retired branch (a held retired build's idle worker is in stop, never
  in run) and the activation branch's sticky stop (a leased build this
  host runs while placement keeps it elsewhere) and refusal clearing,
  also cleared for a retired build. A build that is not hostManaged (an
  imported one) is skipped whatever its status. hostWorkerReport keeps
  detached for a retired build and the running list and refusal dedupe.
  Both doc comments merged.
- docs/api/openapi.yaml: activate's description keeps the Retry-After
  wording and 410 template_retired; hostWanted's keeps sticky placement,
  the draining count and retired builds in stop, and says an imported
  build is in neither list; hostWorkerReport's keeps detached for a
  retired build and the refusal dedupe. info.version stays 1.8.0 (the
  activation branch's changes stay under 1.7.0, retire is 1.8.0).
- docs/specs/2026-11-03-template-lifecycle-and-provenance-design.md: the
  wanted-state bullet joins both texts: sticky stop, retired builds in
  stop, imported builds in neither list, stop-then-start order, and
  detached taken for a retired build.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
…slot

Placement counted a worker still draining a live sandbox against its
host's activeLimit only when its build was registered. A build retired
while a sandbox still ran on its worker freed the slot at once, though
the worker kept running until the sandbox ended, so placement could put
another build on that host over its limit. A retired build with a worker
now counts the same way while its worker is busy. The spec says so; a
placement test retires a build with a live sandbox on its worker and
sees the slot taken until the sandbox ends.

The in-use check's local set of workers with untraced sandboxes is
renamed, so it no longer shadows the imported busyWorkers.

Refs rossoctl#749
Assisted-By: Claude (Anthropic AI) <[email protected]>

Signed-off-by: Rong Chang <[email protected]>
@webchang

Copy link
Copy Markdown
Member Author

Merged #775's reviewed head into this branch. The conflicts were in four files, and both sides are kept: retire's guard under the activation lock; imported builds never in run or stop; and retired builds marked detached, kept beside the running and refusal updates.

The merge surfaced one gap, fixed in 508baff: a worker still draining a live sandbox after its build was retired keeps its host's activeLimit slot until the sandbox ends. A test shows placement answering no_slot while it drains. New head: 508baff.

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.

Summary

Re-review of the push since my last review (ba1c8e2..d5bca89, review 5883637563). This PR's own range has 5 fixes and a docs rewrap, one fix for each open finding: mine (32c64ff: a build retired before it registered has no worker, so it reports null capacity) and ingpaolodettori-dev's four (84ed479 --wait returns when no host holds the build, c33982a build_in_use is judged by the sandbox's buildId, bb42101 the retire record finds a rejected build's build record by its handle, cf059b7 retire takes the activation lock and takeLeaseLocked re-reads the build's status under it). I read each fix against its finding, and each one holds. The merges 9f28420 and c12b6a8 only bring in #775's earlier heads.

New: 1 must-fix, the same red deploy-scripts as on #775 (examples.test.sh under jq 1.8, from #772's a187e99). Details and a fix are inline.

Note: d5bca89 does not yet contain #775's head dbd2973. A trial merge conflicts in openapi.yaml, the lifecycle design, host-handlers.ts and sandbox-handlers.ts. A push after this review was queued (d7a1933 "Merge pr/i19-activation into pr/i26-retire", then 508baff) appears to bring it in. The next cycle reviews that push.

Author: webchang (MEMBER — maintainer)
Areas reviewed: TypeScript (retire, activation lock, provenance, mocactl retire --wait), docs/openapi deltas, commits/DCO, CI, agent-config gate
Agent/IDE config (.claude/.vscode): none
Commits: 86 commits, all signed-off: yes
CI status: failing. deploy-scripts fails at "Run deploy shell tests" (exit 2). The other 16 checks pass.

Verified by: control-plane tsc --noEmit (clean) and vitest run test/activation.test.ts (36/36 pass); mocactl tsc --noEmit (clean) and vitest run test/sbx-templates.test.ts --no-file-parallelism (25/25 pass), all on d5bca89; examples.test.sh fails on jq 1.8.2; the trial merge of dbd2973 was aborted.

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

jq -e '.id | test("^[a-z0-9][a-z0-9-]{0,30}$")' "$spec" >/dev/null || fail "$name: id (M7)"
jq -e '.image | test("^[^\\s@]+@sha256:[0-9a-f]{64}$")' "$spec" >/dev/null ||
fail "$name: image not pinned by digest (M1)"
jq -e '(has("guest_mb") and has("guest_ram_mb") | not) and

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: deploy-scripts is red because this check is always false under jq 1.8, so examples.test.sh fails default.json: guest size or vcpus (M7) on a good spec. jq 1.8 parses A and B as $g | body as (A and B) as $g | body, so $g is the boolean true, not the size. Probe on this head, with default.json:

  • jq 'true and (.guest_ram_mb) as $g | ($g|type) == "number"' gives false on jq 1.8.2 and true on jq 1.7.1;
  • bash deploy/sbx/template-onboarding/tests/examples.test.sh fails on jq 1.8.2 and passes all 5 checks on jq 1.7.1.

The line came in with a187e99 (#772's stack). The red deploy-scripts follows that commit: #766, #772, #774, #775 and #781 contain it and fail; #757 and #776 lack it and pass. I could not read the CI log itself (the log host timed out from here), so this is reproduced locally, not read from the run.

Suggested fix: put the binding in parentheses, which gives true for default.json on both 1.7.1 and 1.8.2:

jq -e '(has("guest_mb") and has("guest_ram_mb") | not) and
    ((.guest_mb // .guest_ram_mb) as $g | ($g | type) == "number" and $g >= 128 and
    (.vcpus | type) == "number" and .vcpus >= 1 and .vcpus <= 32)'

It matters now: every PR stacked on #772 stays red until this lands there.

@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

Summary

Adds retiring a template, or one build of it (control-plane routes, wanted-state stop, mocactl sbx templates retire [--wait]), stacked on the build-tooling / host-agent / activation work. Auth, locking and the wanted-state logic look correct: owner-or-admin is checked after a 404-on-hidden lookup, and retire, activation lease writes and sandbox creates all serialize on the activation lock with a fresh re-read. The main defect is that the documented recovery — "a new build is the way back" — doesn't hold: after a whole-template retire, default stays on the retired build so the bare id answers 410 forever (must-fix), and rebuilding the same inputs is rejected by T.unique against the retired twin (suggestion).

Author: webchang (MEMBER — maintainer)
Areas reviewed: TypeScript (control-plane retire/activation/host handlers, routes, errors; mocactl retire CLI), Shell (host-agent.sh stop/detached path), Docs (openapi 1.8.0, CHANGELOG, http-api.md, spec §5.1)
Agent/IDE config (.claude/.vscode): none
Commits: 76 commits, all signed-off: yes
CI status: passing

Verified by: aube install --frozen-lockfile; full control-plane vitest suite (1337 pass, 9 fail, all Redis-dependent suites with no Redis in the review sandbox — none in activation/retire); two throwaway probes in test/activation.test.ts (retire → rebuild same image+spec → rejected; whole-template retire + new registered build → tags stay {default: <retired build>}, activate t1 and createSandbox t1 → template_retired). Probes deleted afterwards.

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

worker: String(t.worker ?? ''),
});
// A first registered build of a template takes `default` (§3.2); later ones are tagged by the owner.
return !failed && c.tags.default === 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.

must-fix — After a whole-template retire, the 'way back' never serves the bare id again. A first registered build takes default only when c.tags.default === undefined. After POST /v1/templates/{id}/retire, default still names the retired build, so a new build registers untagged. The template's tags are fixed at that point, and the PR adds no route to set them. So t1 / t1:default answer 410 template_retired for good, and activate t1 does too.

This contradicts the PR's own docs:

  • openapi retireTemplate: "a new build of the template (POST /v1/templates/{id}/builds) is the way back"
  • CHANGELOG 1.8.0, http-api.md and spec §5.1 ("Not reversible. A new build ... is the way back")

The 'Known limits' note covers retiring one build that default points to. It does not cover the whole-template case, where the documented recovery path is the problem.

Probe: register t1, retire t1, then register another build of t1 (vcpus 4). doc.tags is {"default":"sha256:1111…"} (the retired build), statuses are registered,retired, and activateTemplate and createSandbox {template:'t1'} both throw template_retired.

Suggested fix: move default when it is unset or names a build that is no longer registered, e.g.

const def = c.builds.find((x) => x.buildId === c.tags.default);
const takeDefault = !failed && (def === undefined || def.status === 'retired');

Record the move in tagsMeta. Alternatively, have the whole-template retire drop the tags that point at the builds it retires. Then add a test: retire, new build, bare id serves.

// A build id names one build of a template: a second build of the same snapshot (the same
// image and spec, created again with another gate record or profile) is not registered
// beside the first.
const twin = c.builds.find((x) => x !== y && x.buildId === manifestHash);

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 — A retired build blocks re-registering the same snapshot. twin matches any other build with this manifest hash, whatever its status, a retired one included. So the obvious way back after a retire (rebuild the same image and spec, e.g. the build was retired by mistake, or retired along with the whole template) is always rejected with T.unique. The retired build still holds that buildId.

This happens in practice: the host still holds the snapshot (heldBy, removal is #743), so template-build.sh answers "already built" with the same manifest hash. The reuse check in createBuild skips retired builds (REUSABLE has no retired), so the create is queued, built and then rejected at registration.

Probe: register t1 with hash('1'), retire t1, then create another build of t1 with the same image and spec and report built with hash('1'). The result is rejected, not registered.

This also conflicts with the openapi/spec 'way back' wording.

Suggested fix: either document that a retired snapshot can never be registered again in that template (so the way back needs different inputs), and refuse at create time with a clear error instead of a wasted build, or exclude retired builds from twin. If you take the second route, buildId uniqueness inside builds[] (used by resolveBuild / @build refs and getTemplateBuild) needs a decision: for example, make the retired entry's id distinct, or have lookups prefer the non-retired build.

Comment thread packages/mocactl/src/sbx/templates.ts Outdated
* build, cancel it, and `create --seed`, which runs the served build's own seed. Every command has
* `--json` (the API's answer, never a token); a wait that runs out of time exits 5.
* build, cancel it, and `create --seed`, which runs the served build's own seed; activation (§6.3):
* take or renew a lease, wait for the build to be active, release it; and retire (§5.1), waiting

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 module doc says retire is "waiting until no host holds the build". But this PR's fix commit (4623a1e) and cmdRetire's own doc say --wait waits for the worker's stop (capacity null), not for heldBy to empty; that comes with #743. Suggested fix: "…and retire (§5.1), waiting until its worker has stopped."

@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 at 15e6655 (4c6524f..15e6655). Requesting changes for one open must-fix, clawgenti's host-handlers.ts:627, which I checked at this head and +1. After POST /v1/templates/{id}/retire, tags.default still names the retired build. Registration moves default only when it is undefined (host-handlers.ts:627), and this branch has no route that sets tags (only GET /tags). So a new build registers untagged, and t1/t1:default stay 410 template_retired for good. That breaks the "a new build is the way back" promise in openapi retireTemplate, CHANGELOG, http-api.md:243 and spec §5.1:325. The activation test at :985 stops at queued and never checks the bare id after the new build registers. Fix: let a registered build take default when the current one is retired (or have the whole-template retire drop the tags it orphans), record the move in tagsMeta, and extend that test through registration. I also +1 clawgenti's twin suggestion (:591; we noted the same on #772:402): a retired build with the same manifest hash makes the obvious rebuild come back rejected by T.unique.

Everything else open from our 1f9d488 review and the bot threads is fixed, and I verified each against the code:

  1. A retired build sharing a worker was put in stop (host-handlers.ts:271): fixed in 668d831. liveSnapshots is judged across the whole catalog. 15e6655 also never lists a worker in both run and stop when two registered builds share it.
  2. retire --wait never finished for a shared build: fixed in 668d831. The build now reports shared: true and capacity: null, and cmdRetire checks shared first.
  3. heldBy dropped silent hosts: fixed in 6688bf1 (deps.hosts.all()). Placement still reads fresh hosts only.
  4. Stale d0.builds read for inUse: fixed in b7ec347. The template is read again under the activation lock, and the retire records are written inside cat.update.
  5. A create racing a retire: fixed in d5953e2 (notRetired under the activation lock). #786 replaces this with its per-template createUnlessEnded, which is fine.

One nit inline, on the wording of the --wait message.

Author: webchang (MEMBER — maintainer)
Agent/IDE config (.claude/.vscode): none
Commits: 5 new, all signed off
CI status: all checks green at this head, including k8s-kind-e2e.

AI-assisted review, approved by a maintainer before posting.

if (b && b.status === 'retired' && b.shared === true) {
c.io.err(
`${sanitizeRemote(r.templateId)} ${sanitizeRemote(build)}: retired; its worker also ` +
'serves a build that is not retired, so it keeps running for that build',

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: "keeps running for that build" holds only while that build is wanted. If the build sharing the worker has no live lease, hostWanted still puts the worker in stop through that build's own entry, so the message can be wrong. Suggest: "its worker also serves a build that is not retired; that build's state decides whether it runs".

Brings in upstream main (lease modes, API 1.6.0) through pr/i19-activation.

Conflicts:
- docs/api/CHANGELOG.md: this branch's retire section, renumbered 1.9.0, above
  pr/i19-activation's 1.8.0, pr/i18-host-agent's 1.7.0 and main's 1.6.0.
- docs/api/openapi.yaml: the Error code list keeps this branch's template_retired and
  build_in_use, then main's mode_not_allowed.
- docs/reference/http-api.md: the host agents (1.7.0) and activation (1.8.0) rows as
  pr/i19-activation has them, then this branch's retire row.
- packages/control-plane/src/errors.ts, test/errors.test.ts: both sides' new codes and statuses.
- packages/control-plane/src/sandbox-handlers.ts: this branch's imports (buildRecordOf, HostView,
  liveSnapshots) with main's MIN_IDLE_TIMEOUT_S.

Beyond the markers:
- packages/control-plane/test/openapi-contract.test.ts: the enrollment-checked route count is 24
  (pr/i19-activation's 22 plus this branch's retire and build delete; each side had raised 20 to 22).
- packages/control-plane/test/activation.test.ts: the untraced sandbox record carries main's
  mode, idleTimeoutS and modeEpoch, now required fields of SandboxRecord.

API version: this branch's retire moves from 1.8.0 to 1.9.0 (openapi info.version, the changelog,
and the two "API 1.8.0" mentions in docs/reference/http-api.md).

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
Brings in upstream main through f60db30 (turn grants, API 1.7.0) by pr/i19-activation.

Conflicts:
- docs/api/CHANGELOG.md: this branch's retire section, renumbered 1.10.0, above
  pr/i19-activation's 1.9.0, pr/i18-host-agent's 1.8.0 and main's 1.7.0 and 1.6.0.
- docs/reference/http-api.md: the host agents (1.8.0) and activation (1.9.0) rows as
  pr/i19-activation has them, then this branch's retire row.

API version: this branch's retire moves from 1.9.0 to 1.10.0 (openapi info.version, the
changelog, and the two "API 1.9.0" mentions in docs/reference/http-api.md).

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

@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 of #781 (retire a template or one build of it).

The retire slice itself is solid: routes, statuses (410 template_retired, 409 build_in_use), idempotent second retire, lease drops, wanted-state stop/detached, openapi 1.10.0 and the mocactl client all match the PR body's claims, and test coverage of the retire features is broad. DCO passes; CI green except codeql still pending at review time. No secrets, no agent/IDE config changes, no new containers. The rest are suggestions and nits.

Author: webchang (MEMBER — maintainer)
Areas reviewed: TypeScript (control-plane, mocactl), Shell, Go, systemd units, K8s YAML, Docs/OpenAPI
Agent/IDE config (.claude/.vscode): none
Commits: 86 commits, all signed-off: yes
CI status: passing (codeql pending at review time)

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

return { status: 200, body: { builds: claimed } };
},

hostBlob: async (ctx, deps) => {

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 — hostBlob serves any stored gate record to any host in SH_TEMPLATE_HOSTS, not only records cited by builds that host claimed, although the route is described as "a gate record a claimed build cites". Digests are sha256 and the data is policy evidence rather than secret, so risk is low — but the code does not enforce the tie the comment promises. Suggested fix: either enforce the claimed-build citation or adjust the comment so the broader contract is documented.

* `retire` record naming the caller, the status before (`from`) and the build's `build` record
* (`buildRecord`). Idempotent: an already retired build is answered with `record: null`.
*/
async function retireBuilds(

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 — retireBuilds re-reads the template's entire provenance chain once per retired build (buildRecordOf(prov, ...) inside the per-build loop of the cat.update callback) while holding the deployment-wide activation lock. A template with many builds and a long chain makes retire slow and blocks every concurrent activation/create for the scan. Suggested fix: read the chain once before the loop. It matters now because retire is an admin-facing operation likely to be used on exactly the old, many-build templates.

# A SWE-bench build with its probe takes minutes; one poll must not outlive a few of them.
TimeoutStartSec=2h
Nice=5
NoNewPrivileges=no

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 service that runs template-build.sh (podman pull/export of an untrusted image, go build, a VMM) runs unbounded as root: NoNewPrivileges=no and no MemoryMax/CPUQuota. The spec records that hardening the export of a hostile image is a known limit — but even a coarse MemoryMax/CPUQuota on this oneshot would contain a runaway build (the RUNBOOK's only sizing guidance today is disk floor and concurrency).

Comment thread deploy/sbx/host-agent.sh
: "${SBX_HOST_TOKEN_FILE:=$SBX_ENV_DIR/host-agent.token}"
[[ -f "$SBX_HOST_TOKEN_FILE" && -r "$SBX_HOST_TOKEN_FILE" ]] || refuse 'SBX_HOST_TOKEN_FILE must name a readable file'
local mode
mode="$(stat -c '%a %u' "$SBX_HOST_TOKEN_FILE" 2>/dev/null || stat -f '%Lp %u' "$SBX_HOST_TOKEN_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 BSD stat fallback prints %u as the user name on macOS while id -u returns a number, so the [[ "$mode" == "600 $(id -u)" ]] check always refuses on a Mac even though the script otherwise goes out of its way for bash-3.2/macOS portability (${a[@]+"${a[@]}"}, shasum fallbacks). Linux-only in practice (CI runs deploy-scripts-bash32 on Linux), hence nit.

return { status: 200, body: { recorded: event } };
},

hostInventory: async (ctx, deps) => {

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 — hostInventory regex-checks each holds entry per manifestHash but puts no cap on entry count or template string length, so a misbehaving (authenticated) host can grow in-memory HostState without limit. Trusted-party input, so nit — but a simple max-entries guard would make it a non-issue.

@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.

webchang added a commit to webchang/moca that referenced this pull request Nov 13, 2026
…r their locks, and no lease or sandbox lands on an ended build

- An activation that resolved a build before a retire or an admin's reject could write its lease
  and `activate` record onto the build just ended: a retire and a reject now run under the
  activation lock, and takeLeaseLocked re-reads the build's status under it before any record
  (retired: 410 template_retired; rejected or otherwise not registered: 409 template_unavailable).
- A sandbox create that resolved the build before a retire or reject could store its sandbox on
  it: the create now stores under a per-template use lock (createUnlessEnded) after one last read
  of the build's status (410 template_retired; 400 unknown_template for a build no longer
  registered). A retire or reject takes that lock inside the activation lock, always in that order;
  a create takes only its template's, so creates on different templates never wait on each other.
- The in-use check was made from the request's first read: a build that registered and got a
  sandbox meanwhile could be retired under it. It is now made on the template read again under
  both locks, as is the active-session check this tree has.
- build_in_use was decided by worker id: a sandbox on one build blocked retiring another build that
  shares its worker. A live sandbox now counts for the build it resolved to (buildsInUse); a record
  without a build id still counts for every build on its worker.
- Each retire or reject record was appended after the catalog write, outside the locks: it is now
  appended inside the update, so a record that cannot be written leaves the build as it was, and a
  retry ends it with its record.
- buildRecordOf matches a build's `build` record by its handle when it has one, so a build built
  and then rejected (its buildId stays its handle) cites its record; the host's removal report
  passes the build too.

The API changelog says so. The activation tests' `registered` helper also builds another build of
an existing template, through a shared reportBuilt.

Tests (each fails with the fix reverted): judges build_in_use by build: a sandbox on another build
of one worker does not block; a sandbox create that resolved the build before a retire is refused
410; a sandbox create waits for a retire judging use, then is refused 410; retires nothing when its
retire record cannot be written; a retry retires it; cites the build record of a build built and
then rejected; an activation that resolved the build before a retire writes no lease onto it; a
retire (and a reject) waits for an activation taking its lease, then drops that lease; a sandbox
create that resolved the build before a reject (or a retire) stores nothing. Also: judges
build_in_use by worker for a sandbox record without a build id; on the template as read under the
lock; creates on two templates do not wait on each other.

(cherry picked from commit c33982a)
(cherry picked from commit cf059b7)
(cherry picked from commit bb42101)
(cherry picked from commit b7ec347)
(cherry picked from commit d5953e2)
(cherry picked from commit 4b2768d)
(cherry picked from commit 086f3dc)
(cherry picked from commit 7022377)

Ports rossoctl#781 and rossoctl#786 review fixes

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 13, 2026
…a live build shares is neither stopped nor removed

Two builds can share a snapshot (the same manifest hash in two templates, or built again) or a
worker id (two builds of one template from one image). The wanted state's `remove` was keyed only
on the build being retired, so retiring one had the host agent uninstall a worker and delete a
snapshot that a build still registered needed.

- liveSnapshots(docs): the build ids and workers of every build whose use has not ended. A retired
  or admin-rejected build that shares either is left out of `stop` and `remove` (that build's own
  entries decide), a host's `removed` report of it is refused 409 build_in_use (so the live build
  keeps the host in heldBy), and its TemplateBuild reports `shared: true`. A rejected build is not
  live, so an admin's reject does not count as sharing with itself (the upstream branches' merge
  follow-up). Sharing is judged across the whole catalog, as the wanted state judges it.
- One worker id is never listed in `run` for one build and in `stop` for another that shares it.
- A retired or admin-rejected build's worker still draining a live sandbox counts against its
  host's activeLimit, as a registered one's does.
- heldBy lists every host as last reported, stale ones too: it is the snapshot inventory, not
  placement, and a silent host still holds what it last reported.
- A T.unique rejection naming a retired build says it is the same snapshot, and to change the spec
  or create again after the snapshot is removed.
- mocactl's `templates retire --wait` is done at once for a `shared` build, and says why.

openapi (TemplateBuild `shared`, heldBy) and the API changelog say so. (This tree's retire waits for
removal through heldBy and reports no capacity for a retired build, so the upstream capacity
changes for retired builds do not apply.)

Tests (each fails with the fix reverted): never stops or removes a retired build whose snapshot or
worker a build not retired shares; never lists one worker in run and stop for two registered
builds that share it; keeps a silent host in heldBy; counts a retired (and an admin-rejected)
build's worker draining a live sandbox against its host; says how to rebuild when the same
snapshot belongs to a retired build; mocactl: is done at once for a shared build.

(cherry picked from commit 52fd121)
(cherry picked from commit 668d831)
(cherry picked from commit 15e6655)
(cherry picked from commit 6688bf1)
(cherry picked from commit 508baff)
(cherry picked from commit 2d3df2e)
(cherry picked from commit 6e24cdb)
(cherry picked from commit e895379)

Ports rossoctl#781, rossoctl#785 and rossoctl#786 review fixes

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
Brings in upstream main through ab8d10e (template tags, edits and owner transfer at API 1.8.0,
setup.sh's Redis image guard), the host agent at 1.9.0 and activation at 1.10.0, by
pr/i19-activation.

Conflicts:
- docs/api/CHANGELOG.md: this branch's retire section, renumbered 1.11.0, above activation's
  1.10.0, the host agent's 1.9.0 and main's 1.8.0, 1.7.0 and 1.6.0.
- docs/reference/change-policy.md: version 1.11.0; main's list, then the template host agents,
  activation leases and template retire.
- docs/reference/http-api.md: main's template admin row, the host agent and activation rows, then
  this branch's retire row (API 1.11.0).
- docs/specs/2026-11-03-template-lifecycle-and-provenance-design.md: the status line names
  §5.1-§5.2 with retire; §5 is main's, with this branch's retire block (its table without the
  cancel row, which main's table holds) after main's tag paragraph and before §5.2.
- packages/control-plane/src/routes.ts: main's four template admin routes, then retire and the
  build delete, then activation.
- packages/control-plane/src/sandbox-handlers.ts: both sides' imports (main's, with this branch's
  buildRecordOf, HostView and liveSnapshots).
- packages/control-plane/test/routes.test.ts, route-profile.test.ts: main's routes, then retire's.
- packages/control-plane/test/openapi-contract.test.ts: 28 enrollable routes (26 plus retire's
  two).
- packages/mocactl/src/sbx/cli.ts: main's NO_RECORD, TEMPLATE_ADMIN_SUBS and TEMPLATE_ONE_ID, with
  retire in TEMPLATE_SUBS, TEMPLATE_ONE_ID, TAKES_BUILD and TAKES_TIMEOUT.
- packages/mocactl/test/contract.test.ts: 25 replies.

Fitted to main: retireBuilds takes main's ownTemplate and makes the owner's check again under the
template's lock (ownerCheck), as main's other owner actions do, so a retire by an owner the
template was transferred away from meanwhile is refused.

API version: this branch's retire moves from 1.10.0 to 1.11.0 (openapi info.version, the
changelog, change-policy and the two "API 1.10.0" mentions in docs/reference/http-api.md).

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
Brings in upstream main through 01528b6 (subject trust for gate records at API 1.9.0), the host
agent at 1.10.0 and activation at 1.11.0, by pr/i19-activation.

Conflicts:
- docs/api/CHANGELOG.md: this branch's retire section, renumbered 1.12.0, above activation's
  1.11.0, the host agent's 1.10.0 and main's 1.9.0 and below.
- docs/reference/change-policy.md: version 1.12.0; main's list (through subject trust for gate
  records), then the template host agents, activation leases and template retire.
- docs/reference/http-api.md: the host agent (1.10.0) and activation (1.11.0) rows, then this
  branch's retire row (API 1.12.0).
- packages/control-plane/src/sandbox-handlers.ts: ReadinessFacts carries both this branch's hosts
  and shared and main's trusted set; resolveForUse judges visibility once with main's
  canSee(d, p, trusted) and uses it for both the retired refusal and the build.

API version: this branch's retire moves from 1.11.0 to 1.12.0 (openapi info.version, the
changelog, change-policy and the two "API 1.11.0" mentions in docs/reference/http-api.md).

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
Brings in upstream main through ec0f840, whose tree is pr/i19-activation's, already merged here
(its merges of pr/i18-host-agent and pr/i19-activation). No conflicts and no file changes.

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

@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.

Summary

Reviewed the template/build retirement feature across the control plane, mocactl, and the API docs. The implementation is careful and very well tested — 18 new control-plane tests covering races, provenance records, wanted state and capacity, plus 10 mocactl tests and contract updates; the version chain (openapi 1.11.0 → 1.12.0, CHANGELOG, change-policy, http-api) is consistent, and all earlier must-fixes from previous review rounds are verified fixed in this head. One unresolved doc/code mismatch remains (the unqualified "a new build is the way back" promise), detailed inline.

Author: webchang (MEMBER — maintainer)
Areas reviewed: TypeScript (control-plane, mocactl), OpenAPI/docs, security
Agent/IDE config (.claude/.vscode): none
Commits: 37 commits, all signed-off: yes
CI status: passing (DCO)

Comment thread docs/api/openapi.yaml
its earlier records stay. Idempotent: an already retired build is listed with
`record: null` (no second record). Refused `409 build_in_use` while a live sandbox runs on
any of its builds: delete it, then retire. A retire never cuts off running work. It cannot
be undone: a new build of the template (`POST /v1/templates/{id}/builds`) is the way back,

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 retireTemplate description promises "It cannot be undone: a new build of the template (POST /v1/templates/{id}/builds) is the way back", and the same unqualified claim appears in CHANGELOG.md:19, docs/reference/http-api.md:249, the lifecycle spec §5.1, and the mocactl usage text. But the code never moves tags.default off a retired build — retireBuilds only sets status: 'retired', leases: [] — and the spec's own Known limits section admits that id:default still resolves to 410 after the default build is retired even when another build is registered. This is the same issue ingpaolodettori-dev raised in the earlier review round (host-handlers.ts registration moves default only when undefined); the commits since are merges plus one doc commit, so it is not fixed in code. At this head the merge brought in POST /v1/templates/{id}/tags, so the owner can recover by building and manually moving default — but the docs don't say that.

Suggested fix: either implement the move (a registered build takes default when the current one is retired, recorded in tagsMeta; or whole-template retire drops orphaned tags), or qualify every "way back" sentence: after a whole-template retire the bare id and id:default stay 410 until the owner moves default to the new build via POST /v1/templates/{id}/tags. Why it matters now: this ships as the 1.12.0 contract wording, and the docs currently promise behavior the code does not have.

* build, cancel it, and `create --seed`, which runs the served build's own seed; and activation
* (§6.3): take or renew a lease, wait for the build to be active, release it. Every command has
* `--json` (the API's answer, never a token); a wait that runs out of time exits 5.
* build, cancel it, and `create --seed`, which runs the served build's own seed; activation (§6.3):

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 module header says retire waits "until no host holds the build" — stale wording from before commit 4623a1e. cmdRetire's own doc, spec §5.1, the usage text and http-api.md all say --wait waits for the worker's stop (capacity null); waiting for heldBy to empty comes with #743.

Suggested fix: reword to "waiting until its worker has stopped" to match cmdRetire's doc comment.

}
if (b && b.status === 'retired' && b.capacity === null) {
c.io.err(
`${sanitizeRemote(r.templateId)} ${sanitizeRemote(build)}: retired, its worker stopped`,

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 — For a build retired before it registered (no worker, capacity: null by construction in buildBody's b.worker !== '' guard), cmdRetire --wait prints "retired, its worker stopped" — it never had a worker. The control-plane tests cover the null-capacity case but no mocactl test covers this wording.

Suggested fix: say "retired; it never had a worker" when the build was never registered, or accept the current wording as harmless.

@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.

@webchang

Copy link
Copy Markdown
Member Author

Main (ec0f840) merged in. Besides resolving the conflicts, the merge makes two changes that this PR's own diff doesn't show:

  1. retireBuilds uses main's ownTemplate and checks the owner again under the template lock. An owner who has just transferred the template away can no longer retire its builds.
  2. resolveForUse checks visibility once, with the trusted set (feat(control-plane): a subject's own gate record, trusted for its own templates; repositories per registry #769), and uses that one result for both the retired refusal and resolving the build.

The openapi version moves to 1.12.0, above #775's 1.11.0.

Assisted-By: Claude Code

Merges upstream main c812554 (memory placement, start pacing, egress
records and the egress agent, the sbx lease clients). This branch's retire
section moves from API 1.12.0 to 1.15.0, the next number above main's 1.14.0.

Conflicts and their resolutions:
- docs/api/CHANGELOG.md: this branch's section, renamed 1.15.0, above main's
  1.14.0 to 1.12.0 sections; main's sections from 1.14.0 down are main's
  bytes.
- docs/api/openapi.yaml: info.version 1.15.0; Template.readiness keeps
  `retired` and main's readinessReason; TemplateBuild.readiness keeps main's
  memory wording plus `retired`, and main's readinessReason, queued,
  queuePosition, graced and gracedUntil; activateTemplate keeps main's
  memory refusals plus `410 template_retired`; hostWanted keeps main's
  wording (memory headroom, idle grace, the wanted order) plus the retired
  builds in `stop` and the imported-build rule.
- docs/reference/change-policy.md: main's list, then "template retire";
  both version numbers 1.15.0.
- docs/reference/http-api.md: main's egress-records row and paragraph, then
  this branch's retire row and paragraph, now API 1.15.0.
- docs/specs/2026-11-03-template-lifecycle-and-provenance-design.md: main's
  status line plus "and retire (rossoctl#749)"; §6.2 keeps main's memory text plus
  "retired ones (§5.1) included" for `used`.
- packages/control-plane/src/activation.ts: main's place() with its memory
  maps; workerOf also holds a retired build with a worker (this branch), and
  buildOfWorker names a retired build's worker too unless a registered build
  shares it, so a retired worker draining a live sandbox counts against its
  host whether the agent reports it in `running` or in the memory report's
  runningWorkers. The doc comment keeps both.
- packages/control-plane/src/host-handlers.ts: main's imports plus
  hostManaged; main's hostEgress and hostWanted (now wantedAnswer plus
  egressSids). This branch's retire logic moves into wantedAnswer: a held,
  host-managed retired build is in `stop` when its worker has no live
  sandbox, unless a build not retired shares its snapshot or worker
  (liveSnapshots); a retired build is never graced or displaced (graceUntil
  takes registered builds only). The run/stop worker filter runs after the
  graced builds join `run` and after the displaced re-check, so a worker in
  `run` (wanted or graced) is never in `stop`. `starting` and `graced` are
  main's, for the live builds.
- packages/control-plane/src/sandbox-handlers.ts: main's imports plus
  liveSnapshots. ReadinessFacts keeps main's `queue` and `hosts` (the fresh
  host views, for a start line's Retry-After) and this branch's every-host
  views, renamed `holders` (for `heldBy`), and `shared`. readinessFacts
  reads the catalog once for both sharing and placement. buildBody keeps
  `retired` readiness and main's readinessReason, start line and grace
  fields. The activation lock moves to main's activation-lock.ts, whose
  comment gains this branch's retire and sandbox-create sentences.
  retireBuilds keeps ownerCheck under the template lock.
- packages/control-plane/test/activation.test.ts: both sides' place() tests.
- packages/control-plane/test/openapi-contract.test.ts: 29 enrollable routes
  (26 + 2 retire + 1 egress).
- packages/mocactl/src/sbx/api.ts: main's SbxBuild fields, with this
  branch's capacity `running: number | null`.
- packages/mocactl/src/sbx/cli.ts: usage keeps main's activate, deactivate
  --stop-now, hosts and create --mode text, with retire after deactivate;
  both `reason` and `stop-now` options; both dispatches.
- packages/mocactl/src/sbx/templates.ts: header names both; both
  RETIRE_TIMEOUT_S and main's sized activate timeout; readinessText keeps
  `running ?` for a null running and main's reason, queue and grace text.
- packages/mocactl/test/contract.test.ts: 27 calls (main's reply shape).
- packages/mocactl/test/sbx-templates.test.ts: both imports, header and
  test blocks.

Beyond the markers:
- activation.test.ts: this branch's retire tests compare the whole wanted
  answer; they now include main's `starting` and `egressSids`.
- activation.test.ts: new tests for the merged behaviour: a graced build
  retired is stopped at once and never graced; a retired build whose worker
  a graced build shares stays out of `stop`, and the graced build's own
  entry stops the worker once its grace ends; a retired worker draining a
  live sandbox that only the memory report names counts against its host.

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

@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 of #781 (head 4aee09d).

Summary

Clean, additive retire-a-template implementation matching the lifecycle spec §5.1: owner/admin auth with a re-check under the lock, retire records written atomically inside the catalog update (failed record write leaves the build unretired), idempotent second retire (record: null), and the create-vs-retire race closed in both directions (409 build_in_use vs 410 template_retired via notRetired() under the activation lock). No blocking findings; two minor notes inline.

Author: webchang (MEMBER — maintainer)
Areas reviewed: TypeScript (control-plane, mocactl), docs/openapi, tests
Agent/IDE config (.claude/.vscode): none
Commits: 31 commits, all signed-off: yes
CI status: passing (DCO, lint, shellcheck, Trivy; a few checks still pending at review time)

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

Comment thread docs/api/openapi.yaml Outdated
info:
title: MOCA control plane
version: 1.14.0
version: 1.15.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.

suggestion — The PR body (and commit b910daa) still says "openapi 1.12.0" / "1.10.0", but this diff bumps 1.14.0 → 1.15.0 (verified: main is at 1.14.0). Since the body explicitly coordinates version numbers across #759, #762, #776 and #791, updating the stale figures in the body would help whoever merges later renumber.

Suggested fix: edit the PR body's two version mentions to 1.15.0.

const ref = ctx.params.build ?? '';
const r = await retireBuilds(ctx, deps, (x) => x.handle === ref || x.buildId === ref);
return {
status: 200,

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 — r.builds[0] is taken without a bounds check. It is safe today because retireBuilds throws template_not_found when the ref matches no build, so builds is non-empty on success — but the invariant lives in another function, and a future change to the predicate (e.g. skipping already-retired builds silently) would turn this into an undefined spread into the response body.

Suggested fix: a one-line guard (const b = r.builds[0]; if (!b) throw ... or a comment stating the invariant).

@webchang

Copy link
Copy Markdown
Member Author

@pdettori, #781 is ready for your re-review on its new head, 4aee09d (main c812554 merged in). Besides resolving the conflicts, this merge changes the following, none of it visible in the PR's own earlier diff:

  1. Retiring now sits inside main's wantedAnswer. A retired build is never graced or displaced. It goes to stop only when it's idle and doesn't share a worker with a live build. The run/stop worker filter now applies after graced and displaced builds have joined run.
  2. ReadinessFacts: this branch's host list for heldBy is renamed holders, since main's hosts already means the fresh views used for Retry-After. Both are kept.
  3. Three new tests:
    • a graced build that is retired is stopped at once;
    • a retired build whose worker a graced build shares stays out of stop until the grace ends;
    • a draining retired worker still counts against its host's memory.

One point to check: in wantedAnswer, hostManaged also gates registered builds, which main didn't check. That's this branch's existing rule. It has no effect today, since place() already skips builds that aren't host-managed.

The openapi version moves to 1.15.0. #789 also claims it, so whichever merges later renumbers.

Assisted-By: Claude Code

Brings rossoctl#789 (sandbox templates for sessions, the combined control plane;
API 1.15.0 and 1.16.0) and rossoctl#790 (a session's seed, patch and records;
1.17.0). This branch's retire section moves to 1.18.0.

Conflicts:
- docs/api/CHANGELOG.md: ## 1.18.0 retire, above main's ## 1.17.0 to
  1.15.0 and below, which are unchanged.
- docs/api/openapi.yaml: info.version 1.18.0. The wanted-state
  description is main's (with a pinned session's hold), plus the
  retired builds in stop and the imported-build rule.
- docs/reference/change-policy.md: main's list, then "template retire";
  control plane 1.18.0, harness 1.3.0 (main's).
- packages/control-plane/src/sandbox-handlers.ts readinessFacts: this
  branch's fields (holders, shared) on the no-sandbox return, under
  main's condition (no sandbox use on the harness profile only).
- packages/control-plane/test/activation.test.ts: registered() takes this
  branch's options (another, vcpus, sourceDigest, status) plus main's
  spec, as opts.spec; main's one caller passes { spec }.

Also moved to 1.18.0: http-api.md's Retire row and "Retire came with API"
line.

A worker kept by a pinned session's hold counts as busy, as a live
sandbox does, so a retired build's worker drains until the hold ends
before it is stopped.

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

@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 — sbx templates retire (§5.1)

Automated review of b35b8c77..d7d994ed (32 commits on the branch, all DCO-signed; label ready-for-ai-review). Overall this looks solid: the retire path is serialized through the activation lock, provenance records are written inside the catalog update so a failed record write rolls the retire back, the idempotent second retire writes nothing, and the openapi/contract/docs bumps are all in step (1.17.0 → 1.18.0, RetiredBuild schema, template_retired/build_in_use codes, route tables and contract tests updated together). No secrets, no workflow/CI changes, no agent/IDE config files in the diff; all checks pass on the tip.

No must-fix issues. The rest are suggestions/nits.

Author: webchang (MEMBER — maintainer)
Areas reviewed: TypeScript (control-plane, mocactl), OpenAPI/YAML, docs, tests
Agent/IDE config (.claude/.vscode): none
Commits: 32, all signed-off: yes
CI status: all passing (CodeQL, DCO, Trivy, check, k8s-kind-e2e, lint, shellcheck, docs, …)

One note on the PR body: it says "openapi 1.15.0" (twice, including the #789 coordination note), but the diff ships 1.18.0 — worth refreshing the body so the renumbering coordination note is accurate.

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

if (!cat?.update || !deps.provenance) return write();
return activationLock(cat).run('activation', async () => {
const cur = (await cat.get(t.id))?.builds.find((x) => x.buildId === t.buildId);
if (cur?.status === 'retired')

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 locked re-read in notRetired only refuses retired, while takeLeaseLocked's re-read (lines 1463–1465) also refuses a build that is no longer registered. So a sandbox create whose build became rejected (or whose template/build vanished, making cur undefined) between resolution and the locked write still writes its record, while an activation racing the same change is refused template_unavailable. Suggested fix: mirror the two-line check here (cur?.status !== 'registered' → template_unavailable/template_retired as appropriate). Why it matters now: this is the seam #750 (sessions pinned to a build) will build on, so the create-side guard is about to gain more callers. If the asymmetry is deliberate (a create on a rejected build was already checked before the lock and refusing again is redundant), a one-line comment saying so would keep the next reader from "fixing" it.

const r = await retireBuilds(ctx, deps, (x) => x.handle === ref || x.buildId === ref);
return {
status: 200,
body: { templateId: r.templateId, subject: r.subject, ...r.builds[0], status: 'retired' },

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 — ...r.builds[0] is spread unguarded. It is safe today because retireBuilds throws template_not_found when no build matches which, so builds is never empty — but the safety lives two functions away. Suggested fix: const first = r.builds[0]; if (!first) throw new CpError('template_not_found', 'no such build of this template'); — cheap, and it keeps the invariant local.

break;
}
// No host holds it (heldBy null, absent or empty): no host agent will stop its worker.
if (b && b.status === 'retired' && (b.heldBy ?? []).length === 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 — In the --wait loop this heldBy-empty break runs after the capacity === null break (line 868), so a build no host holds whose capacity is already null reports "retired, its worker stopped" instead of "no host agent holds it … stop it where it runs". For such a build (e.g. imported, worker never host-managed) the actionable message is the second one. Suggested fix: swap the two checks (test heldBy emptiness before capacity === null). Cosmetic only — the exit code and termination behavior are the same.

});
});
if (done.length > 0)
await auditBestEffort(deps, 'template_retired', d0.id, {

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 — auditBestEffort('template_retired', …) fires only when done.length > 0, so an idempotent re-retire (by a different admin, say) leaves no audit trace of the attempt — only the original retire's provenance record exists. If "who tried to retire what, when" is worth auditing independently of state changes, drop the if; if not, this is fine as is.

@webchang

Copy link
Copy Markdown
Member Author

Main (d227d41) merged in (#789 and #790). Besides resolving the conflicts, the merge makes one change that this PR's own diff doesn't show:

  • A worker held by a pinned session counts as busy, so a retired build's worker drains until that hold ends, and is stopped only then.

The openapi version moves to 1.18.0, above #790's 1.17.0.

Assisted-By: Claude Code

@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 at 219d83f. This push adds no code of this PR's own. It merges main d227d41, which brings #789 (sessions pinned to a template build, the combined control plane) and #790 (a session's seed, patch and records). I checked the six hand resolutions with git show --remerge-diff and a check for lines dropped from either side:

  • Docs. The CHANGELOG puts ## 1.18.0 retire above main's 1.17.0–1.15.0, which are unchanged. openapi info.version, change-policy (control plane 1.18.0, harness 1.3.0) and http-api.md's Retire row and "Retire came with API" line all agree on 1.18.0. The wanted-state description keeps main's pinned-session hold, then adds the retired builds in stop and the imported-build rule.
  • readinessFacts. This branch's holders/shared fields go on the no-sandbox return, under main's (routeProfile ?? 'harness') === 'harness' condition, so combined reads sandbox use. startQueue still reads all.
  • activation.test.ts. registered() takes this branch's options plus main's spec as opts.spec, and main's one caller is updated.

No conflict markers are left, and no line is dropped other than the superseded version figures and the two signatures that were merged.

New with this merge (suggestion, inline): sessions now pin a build, and the retire path doesn't account for them yet. buildsInUse counts only live sandboxes. holdPinnedWorker (host-handlers.ts:269, main's code) renews a hold from the cached sessionWorker without re-checking the build's status. So a session that keeps taking turns keeps a retired build's worker out of stop indefinitely, and retire --wait times out. The spec's "does not yet name a build" limit is now out of date.

Still open from earlier rounds: the default-after-retire docs and test (spec:369, carried over unchanged).

Author: webchang (MEMBER — maintainer)
Agent/IDE config (.claude/.vscode): none
Commits: no new own code; one merge of main, signed off (DCO pass)
CI status: all 17 checks green, k8s-kind-e2e included

AI-assisted review, approved by a maintainer before posting.

* resolved to (`buildId`), so it counts for that build only: two builds of one template from one
* image can share a worker id, and a sandbox on one must not block retiring the other. A record
* from before builds were traced (no `buildId`) counts for every build on its worker. Sessions
* pinned to a build, once sessions are, are live use too, and are to be checked here.

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: "once sessions are" is now: with main's #789 merged in, a session pins sandboxBuildId, and each of its turns keeps that build's worker through holdPinnedWorker → busyWorkers. Two consequences for retire:

  1. A retire is not refused while a pinned session is mid-use, although it is for a live sandbox (409 build_in_use). That session keeps running turns on the retired build: sessionSeed still returns the build's seed and no exchange path checks retired.
  2. The drain never ends while the session stays active. holdPinnedWorker only requires status === 'registered' on the first turn of a hold. After that it renews from hosts.sessionWorker(build, nowS) (host-handlers.ts:269) without reading the catalog. So every turn inside the hold extends it, wantedAnswer keeps the retired worker out of stop (busy), and mocactl sbx templates retire --wait exits 5 at its timeout.

Either is fine, but pick one deliberately: (a) count builds with a live session hold in buildsInUse (e.g. still serves a pinned session), as for sandboxes, or (b) let a retire end the hold, by clearing sessionUse for the retired builds inside retireBuilds and/or having holdPinnedWorker skip a renewal for a non-registered build. Then refuse or let the session's next turn fail cleanly. A test of retire → pinned turn → wanted state would pin down whichever you choose.


Known limits:

- A tag that points at a retired build still resolves to it, and is refused; so does `default`

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: with main's tag routes (#774) now on this branch, this limit has a documented way out. A new build registers untagged while default still names the retired build (host-handlers.ts:627), but the owner can then POST /v1/templates/{id}/tags {build, tags:["default"]} to move it (moveTemplateTags accepts any registered build). That closes clawgenti's r4561322508. Two things are still missing:

  1. The docs: here, at :347 ("a new build … is the way back") and in http-api.md:250, say that the bare id stays 410 until default is moved onto the new build.
  2. A test for retire whole template → register a new build → bare id still 410 → move default → bare id resolves. That pins the interaction between the two features, which were written on separate branches.

Suggested wording: "…so does default when the default build is retired, even with another registered build, until the owner moves default onto it (POST …/tags)."

when the default build is retired, even with another registered build.
- Removing a retired build's worker and snapshot from its host comes with the host agent's removal
step (#743); until then a retired build stays in `heldBy`.
- A Moca Pi session does not yet name a build, so only live sandboxes count as use; a session

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: this limit is out of date after the merge. A Moca Pi session on the combined plane now names its build (combined control plane spec §3.4), so this should say how a retire treats a pinned session (see the sandbox-handlers.ts:1639 comment). The buildsInUse doc comment needs the same update.

@webchang
webchang merged commit acbb132 into rossoctl:main Nov 14, 2026
18 checks passed
webchang added a commit to webchang/moca that referenced this pull request Nov 14, 2026
Brings rossoctl#781 (template retire, API 1.18.0).

Conflicts:
- docs/api/CHANGELOG.md: this branch's section above main's ## 1.18.0
  and the sections below it, which are unchanged.
- docs/reference/change-policy.md: main's list, then "enrollment and the
  admin role".
- docs/reference/http-api.md: main's Retire row and paragraph, then the
  Subjects row and paragraph. The 409 list holds main's build_in_use
  plus this branch's bootstrap_subject, self_revoke and admin_granted.
- packages/mocactl/test/contract.test.ts: 32 scripted replies (main's
  2 retire calls plus this branch's 5 subject calls).

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 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.

Retire a template, or one build of it, through the API

4 participants