Skip to content

feat(control-plane,sbx,mocactl): pace cold starts per host, and an idle grace for workers - #784

Merged
webchang merged 35 commits into
rossoctl:mainfrom
webchang:pr/i22-start-pacing
Nov 14, 2026
Merged

webchang merged 35 commits into
rossoctl:mainfrom
webchang:pr/i22-start-pacing

Conversation

@webchang

@webchang webchang commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Closes #745. On main (3efcf9a): #776 (placement by host memory), which this branch stacked on, is merged. Its own change is 6 commits (review range 82ea4597..caa21707), plus merges of main.

What it does: a host paces its cold starts, placement accounts for starts in progress, and an idle worker can stay attached for a grace period. Six signed-off commits:

  1. The host agent:
    • SBX_START_CONCURRENCY (default 4) and SBX_START_WINDOW_S (300). The host keeps a start book and reports start seconds, startSeconds and startConcurrency in its limits, and a starting list. A start is never waited on;
    • SBX_IDLE_GRACE_S (0–86,400) becomes idleGraceSeconds, with a graced list.
  2. The control plane:
    • start lines, and start-aware placement, which prefers the host already running the worker even without memory figures (noted in the CHANGELOG);
    • the idle grace in place(), with displacement re-checked under the activation lock (now src/activation-lock.ts);
    • readiness queued with queuePosition, and graced with gracedUntil. Retry-After comes from the start line;
    • deactivate's stopNow;
    • openapi 1.13.0.
  3. mocactl: activate --wait sizes its default wait from the start line (1,800 s to 4 h), and deactivate --stop-now. hosts and show say queued, starting or graced.
  4. The docs, in three commits: the lifecycle spec's §6.5, the RUNBOOK's pacing and idle-grace sections, the configuration rows, and the wanted-state handler's comment.

Notes for review:

Tests on the tip:

  • typecheck passes, and so does the control-plane suite;
  • mocactl passes, run serially;
  • host-agent, setup, overlay and status pass on bash 5 and 3.2;
  • shellcheck adds no findings, and prettier passes.

17 files, +2,047 / -146, counted over the review range.

Assisted-By: Claude Code

Each attached template worker maps and locks its snapshot's whole memory
file at start, so the cost of a host is mostly its attached workers times
their guest size, and the host agent reported nothing about memory.

Every inventory (the build poll's and each --wanted-only run's) now
carries an optional `memory` object:

- memTotalMib and memAvailableMib from /proc/meminfo, and memFloorMib,
  the effective floor (SBX_MEM_FLOOR_MIB, else 10% of MemTotal, at least
  4096). Without MemTotal and MemAvailable no figures are sent (an error
  line), and the control plane places the host by its active limit alone;
- memPressureFull10, memory PSI `full avg10` (left out with no
  /proc/pressure, which is no brake; the summary says "psi":"absent"),
  and memPressureLimit (SBX_MEM_PRESSURE_LIMIT, default 10);
- runningWorkers, the held builds' workers whose sbx-worker unit is
  active, and vmCommittedMib per running worker: its slice's memory.stat
  anon + shmem + kernel (kernel_stack + pagetables + slab without the
  kernel line), never memory.current, which also counts the page cache
  its VMs' files fill. A slice that cannot be read, or has no anon line,
  is left out and named in the summary (sliceUnread);
- memfileMismatch, the held builds whose memory file is not exactly
  guest_ram_mb x 1 MiB (or is missing): an error line each, a summary
  count, and the agent refuses to start them (reported `refused`)
  whatever the control plane asks.

Both settings are validated with the agent's others (exit 2 before any
call) and live in host-agent.env. SBX_SYS_ROOT is the test seam for
/proc and /sys/fs/cgroup.

Refs rossoctl#744

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

place() gains a memory test on hosts whose agent reports memory figures;
an inventory without them is placed by activeLimit alone, as before:

- a build costs its guest RAM (the registered spec's guest_mb, else the
  create's guest_mb or guest_ram_mb, else 4096) plus 128 MiB for the
  worker and its VMM;
- used = the cost of the host's running workers (the agent's
  runningWorkers, any build's, wanted or draining) + their VMs'
  vmCommittedMib + the builds placed there in this pass and not started;
  headroom = min(total - floor - used, available - floor - pending); a
  build fits if cost <= headroom and the host is under activeLimit; a
  host already running the build's worker keeps it (nothing is evicted)
  and is preferred;
- no new start on a host whose inventory is over 60 s old or whose PSI
  full avg10 is above its limit; a build in a host's memfileMismatch is
  never placed there.

Placement's unplaced reasons gain `memory` and `memfile_mismatch`. A
409 no_active_slot for memory carries reason: memory (Retry-After as
before; at the active limit it answers as before, with no reason); every
holder reporting a wrong memory file is 409 template_unavailable with
reason: memfile_mismatch; template_not_active with readiness unavailable
carries the reason. Templates and builds gain readinessReason, present
only with readiness unavailable, and GET /v1/templates' hosts gain
`memory` (the figures, the effective floor, used, headroom, the brake).
The inventory route parses `memory` field by field (parseHostMemory),
dropping what is malformed. The check runs under the activation lock, so
two activations cannot see the same headroom.

openapi 1.8.0 (ReadinessReason, the inventory's memory, the hosts
block's memory, the refusals' reason) with a CHANGELOG entry.

Refs rossoctl#744

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
The client part of placement by host memory:

- `mocactl sbx hosts [--json]` prints each KVM host from GET
  /v1/templates' hosts block: its active slots, its memory headroom, total
  and effective floor with a brake and any memory-file mismatches (from
  an agent that reports memory), and its disk; "no host has reported
  yet" when the block is empty. It takes no argument.
- `templates show` names a build's readinessReason beside `unavailable`
  (`unavailable (memory)`), on the template and on each build.
- `templates activate --wait` says when it waits for memory: a 409
  no_active_slot with reason: memory, and a build unavailable for memory,
  each read as "no host holding it has the memory for its worker now";
  the other reasons have their own words.

Refs rossoctl#744

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

- The template lifecycle spec's §6.2 gains the memory rule: why a fixed
  active limit is not enough (an attached worker locks its guest's whole
  memory file), the inventory's memory, a build's cost and the
  memory-file check, what vmCommittedMib counts (memory.stat, never the
  page cache), the headroom, the brakes, the settings, what a client
  sees, compatibility both ways, and the limits, with how the floor
  relates to the sandbox lease mode's reclaim; §6.3's refusals name the
  memory reasons.
- The RUNBOOK's host agent section lists SBX_MEM_FLOOR_MIB and
  SBX_MEM_PRESSURE_LIMIT in host-agent.env, the summary's memory notes,
  SBX_ACTIVE_LIMIT as an upper bound, and a "Memory-aware placement"
  part: what the agent reports, the settings, the cost and headroom, the
  brakes, the memory-file check, what a client sees (with `mocactl sbx
  hosts`), lease mode, and version skew; keep /srv/sbx off tmpfs.
- docs/reference/configuration.md gains the two settings' rows.

Refs rossoctl#744

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

A cold template worker reads and pins its whole memory file before it
attaches, and workers started together share the host's disk. The host
agent now starts at most SBX_START_CONCURRENCY (default 4; 0 or anything
but a positive whole number is refused at the settings check) less those
still starting, per run, in the wanted answer's order (oldest lease
first); the rest wait for the next run and are counted in the summary
(startQueued). activation() never waits on a start.

"Starting" is the wanted answer's new `starting` list (builds placed here
whose worker is not attached to the relay). With a control plane that
sends none, the agent counts its own starts of the last
SBX_START_WINDOW_S (default 300), so the limit holds with an older
control plane too. The agent keeps its starts in $SBX_SRV/start-times
(0600) and reports startConcurrency and, once a start is done,
startSeconds (the mean of the last 10, to within the 15 s poll) in the
inventory's limits.

SBX_IDLE_GRACE_S (default 0, off; at most 86400) is reported as
limits.idleGraceSeconds; the control plane decides the grace. A build in
the wanted answer's new `graced` list is kept running and never started
(a grace keeps a worker, it never starts one), counted in the summary
("graced"), and a stop that ends a grace is logged as such.

Tests: the limit and its order, the queue count, startSeconds, an older
control plane, a start never waited on, the settings' refusals, and the
grace's cases; all on the existing mocks and time seams, with no sleeps.

Refs rossoctl#745

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
…ment and the idle grace

The control plane's side of pacing template workers' cold starts:

- GET /v1/hosts/{host}/wanted gains `starting`: the builds of `run`
  whose worker is not attached to the relay (its presence, as readiness
  reads it), and `run` is in the wanted order, first leased first, the
  order the agent starts them in. Absent when the presence is unreadable.
- The inventory's limits take startConcurrency and startSeconds. On a
  host that reports them, a placed, wanted build not attached has a
  1-based place in the host's start line; beyond startConcurrency it is
  `activating` with queued: true. Builds show queued and queuePosition.
- 409 template_not_active's Retry-After is
  ceil(ceil(position / concurrency) x startSeconds) when both are known,
  else 30 s as before.
- place() prefers a holder already running the build's worker
  (runningWorkers), with or without memory figures.
- The hosts block shows start: {concurrency, seconds, starting, queued}.

The idle grace, on a host whose agent reports idleGraceSeconds > 0
(SBX_IDLE_GRACE_S): a registered build whose last lease has ended keeps
its running worker for that long, in a slot of activeLimit and within
the memory headroom, unless it has a live sandbox (it drains as before).
place() computes the graced builds; a wanted build that needs the slot
or the memory displaces the soonest-ending ones, as few as fit it, and
the wanted answer re-checks each displaced build for a lease under the
activation lock before listing it in `stop`. Graced builds stay in
`run`, after the wanted ones, and are listed in `graced`.

A build records lastLeaseEnd when its leases are dropped; deactivate
takes `stopNow: true`, which skips the grace (stopNowAt) and is said in
the `deactivate` record. Builds show graced and gracedUntil; the hosts
block shows idleGraceSeconds and the graced count; a create on a graced
build is served at once. The activation lock moves to its own module
(src/activation-lock.ts) so the wanted answer and activation share it;
no call to a host runs under it.

An agent that reports none of the new limits changes nothing. openapi
1.9.0, with its CHANGELOG entry.

Refs rossoctl#745

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
…t line; deactivate --stop-now

The client part of pacing template workers' cold starts:

- `sbx templates activate --wait` with no --timeout sizes its limit from
  the host's start line once the build reads queued:
  (ceil(queuePosition / concurrency) + 1) x startSeconds x 1.25, at
  least 1800 s, capped at 4 h (saying so, with "pass --timeout for
  longer"); it says the size it waits for, and while queued it says
  "activating: queued at N in its host's start line". --timeout always
  wins, and then the hosts block is not read.
- `sbx templates deactivate ID --stop-now` releases with stopNow: true,
  skipping the host's idle grace, and says so; --stop-now elsewhere is a
  usage error.
- `sbx hosts` shows each host's start line (starting, queued, the limit
  and the measured start time) and its idle grace (length and graced
  count), from an agent that reports them.
- `sbx templates show` says "queued at N" (or "starting") for a build in
  its host's start line, and "graced until ..." for one in its idle
  grace.

Refs rossoctl#745

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

- The template lifecycle spec gains §6.5, pacing cold starts: why a
  cold start is slow (the whole memory file is read and pinned before a
  worker attaches, and starts at once share the disk), the measured
  figures with their conditions, the host agent's start limit and its
  fallback for an older control plane, the measured start time, the
  control plane's start lines and Retry-After, start-aware placement,
  the optional idle grace (when it ends early: stopNow, a wanted build
  that needs the slot, re-checked under the activation lock), the shared
  lock module, compatibility both ways, and the limits. §6.4's
  Retry-After names the start line.
- The RUNBOOK's host agent section lists SBX_START_CONCURRENCY,
  SBX_START_WINDOW_S and SBX_IDLE_GRACE_S in host-agent.env, the
  summary's startQueued and graced, and gains "Cold-start pacing" and
  "The idle grace": what each caps or keeps, the settings, what the
  agent reports, what a client sees (with mocactl sbx hosts, templates
  show, activate --wait and deactivate --stop-now), what a grace costs,
  the change on upgrade, and the rollout order (the control plane
  before the grace setting).
- docs/reference/configuration.md gains the three settings' rows.

Refs rossoctl#745

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

Refs rossoctl#745

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
…verage, one at a time)

Refs rossoctl#745

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 #776, and the review covers only its increment (82ea459..caa2170): the host agent's start limit, start-line readiness and Retry-After, start-aware placement, the idle grace with stopNow, and the mocactl and doc changes that go with them. Placement, the grace's displacement re-check under the activation lock, and deactivate's lastLeaseEnd/stopNowAt bookkeeping read correctly, and each has tests. One suggestion: when the control plane sends starting, a worker whose unit stays active but never attaches holds a start slot with no time limit, so a few such workers can stop every start on a host. One nit: the openapi text for the re-check says the build stays in run, but the code leaves it out of both lists.

Author: webchang (MEMBER — maintainer)
Areas reviewed: host agent shell (deploy/sbx/host-agent.sh), control-plane placement/activation/wanted answer/deactivate, activation lock module, mocactl activate --wait sizing and deactivate --stop-now, openapi 1.9.0 and CHANGELOG, RUNBOOK/spec/configuration docs, tests (host-agent.test.sh, activation.test.ts, sbx-templates.test.ts), commit conventions/DCO
Agent/IDE config (.claude/.vscode): none
Commits: 6 commits, all signed-off: yes
CI status: passing (all 17 checks, including DCO, deploy-scripts, deploy-scripts-bash32, k8s-kind-e2e, shellcheck)

0 must-fix, 1 suggestions, 1 nits.

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

Comment thread deploy/sbx/host-agent.sh Outdated
# The control plane's list, whoever started the unit: a listed build whose unit is active.
while IFS=$'\t' read -r w b; do
if ! [[ "$w" =~ $WORKER_RE ]] || ! grep -qxF -- "$b" "$WORK/starting.ids"; then continue; fi
if systemctl is-active --quiet "sbx-worker@$w.service"; then INFLIGHT=$((INFLIGHT + 1)); fi

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 has == 1 (a 1.9.0 control plane that can read presence), a worker counts as in flight whenever its build is in starting and its unit is active, and nothing limits how long that lasts. The SBX_START_WINDOW_S bound only applies in the has == 0 branch. A worker that stays active but never attaches stays in starting for as long as its lease lasts. Examples: a stale or rotated relay token, or a relay it cannot reach while the control plane's presence still reads fine; microvm-worker keeps retrying with nextBackoff, and Type=simple keeps the unit active. Each such worker permanently uses one of SBX_START_CONCURRENCY, so 4 of them (the default) stop every other start on the host, and the summary only shows startQueued growing. Suggested fix: also limit the count by the start book's age. For example, count a listed build as in flight only when the agent has no record of starting it, or started it less than some multiple of SBX_START_WINDOW_S ago. Emit an error line (for example worker <id> started <n> s ago, not attached) for the ones over that age, so an operator sees the stuck worker rather than a growing queue. Add a host-agent test: starting lists 4 active units whose start-times are past the window, and a 5th wanted build still starts.

Comment thread docs/api/openapi.yaml Outdated
them in, at most its start limit at once). On a host with an idle grace the graced builds
follow the wanted ones in `run`, soonest grace end first, and are listed in `graced`. A
graced worker displaced for a wanted build is re-checked for a lease when the answer is
made: a build leased since stays in `run`.

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: "a build leased since stays in run" does not match wantedAnswer (packages/control-plane/src/host-handlers.ts). A displaced entry that the re-check finds leased is not added to stop, and it is never added to run or graced either, so it is in none of the lists. The agent then leaves the unit running, which is the intended effect (the spec's §6.5 and the RUNBOOK say it correctly: "keeps its worker running"). But an agent or client that reads this text would expect the build in run. Suggested wording: "a build leased since is left out of stop (its worker keeps running; it is in run from the next answer)".

@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 cold-start pacing for KVM hosts. The host agent gets a start limit (SBX_START_CONCURRENCY), a start book that measures start time (startSeconds), and an SBX_IDLE_GRACE_S setting. The control plane gets start lines with queued/queuePosition readiness and a Retry-After from the line, start-aware placement, an idle grace in place() with displacement re-checked under the activation lock, and deactivate stopNow. mocactl sizes its --wait default from the line and gains --stop-now. Openapi, RUNBOOK and spec are updated. The logic is careful and well tested, and the settings validation and the openapi/CHANGELOG/mocactl contract agree with the code. The main gap is that a worker that never attaches holds a start slot for as long as it stays wanted, with no timeout.

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

Inline: 0 must-fix, 1 suggestion, 1 nit. The head 9e577e8 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 82ea4597..caa21707, as the body asks.

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

Comment thread deploy/sbx/host-agent.sh Outdated
# The control plane's list, whoever started the unit: a listed build whose unit is active.
while IFS=$'\t' read -r w b; do
if ! [[ "$w" =~ $WORKER_RE ]] || ! grep -qxF -- "$b" "$WORK/starting.ids"; then continue; fi
if systemctl is-active --quiet "sbx-worker@$w.service"; then INFLIGHT=$((INFLIGHT + 1)); fi

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: When the control plane sends starting, a start slot is held by any wanted build whose unit is active and which the relay does not show attached. Nothing times this out. [email protected] is Restart=on-failure with RestartSec=5s, so a worker that crash-loops before it attaches (bad snapshot, failed probe restore) or hangs reads as active almost all the time and keeps its slot for its whole lease (up to 86400 s, renewable). With the default of 4, four such builds stop every other cold start on the host, and the control plane meanwhile shows the builds behind them as queued with a Retry-After that keeps repeating. The SBX_START_WINDOW_S fallback has a time bound, but this path has none. A suggested fix: stop counting a start-book entry (and an unlisted active unit) as in flight once now - t passes some multiple of SBX_START_WINDOW_S, and emit an error/stuck line naming the worker, so the operator sees it and the line moves. Section 19 of host-agent.test.sh currently asserts that the slot is held across runs; one more case with a time past the window would pin down the bound.

Comment thread deploy/sbx/RUNBOOK.md Outdated
not that host reports its memory.
- **The one change on upgrade:** a host whose agent is upgraded, with no new settings and whatever
its control plane, now starts at most 4 workers per run instead of every wanted one at once; a
wide activation takes several 15 s runs to start everything, and a client's first Retry-After is

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: "a wide activation takes several 15 s runs to start everything" understates the change. Against a 1.9.0 control plane, a slot frees only when a worker attaches, not on each run. With the 78 s single start measured in this same section (and 3-4 minutes per wave of four), 28 builds take about 7 waves, i.e. many minutes. The sentence is accurate only with an older control plane, where the SBX_START_WINDOW_S fallback releases a slot after 300 s, and that is slower still. Suggest saying that the starts proceed in waves of SBX_START_CONCURRENCY, each about one start time long.

@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 (caa2170..9e577e8, review 5883319441). 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/i21-memory-placement into pr/i22-start-pacing", 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, 1 nit 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: 57 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).

Brings in the parent's reviewed fixes (sticky placement, running
workers counted against activeLimit, silent hosts left out of
placement, imported templates never host-managed, Retry-After from
placed builds, refusal dedupe, host-agent.sh's running flags and
stops before starts). Both sides' rules now hold in place().

Conflicts and resolutions:

- packages/control-plane/src/activation.ts: HostView keeps at,
  memory (this branch) and running (the parent). Placement returns
  both used (the activeLimit counts) and memory. place() starts each
  host's count from the workers that stay running, takes busy, skips
  holders reporting the build's memfile wrong, then keeps a build on
  a holder already running it (sticky: past its limit, its brake and
  its headroom, as both sides say a running worker is never evicted);
  any other build needs a holder under its limit with memory for it.
  "Running" is the union of the held builds marked running and the
  inventory's runningWorkers. A worker running only by an attached
  report newer than the inventory is counted in pending too, since
  that inventory's MemAvailable cannot show it yet. The parent's
  sticky rule replaces this branch's "prefer the running host" sort
  key; a memfile mismatch overrides stickiness.
- packages/control-plane/src/host-handlers.ts: HOST_STALE_S and
  freshHosts kept; hostViewsOf passes at, running and memory; the
  inventory stores running, refused and memory; hostWanted stops a
  copy this host runs (by either report) while placement keeps it
  elsewhere.
- packages/control-plane/src/sandbox-handlers.ts: both imports; the
  hosts block lists fresh hosts with placement's used and the memory
  object; activation keeps the displaced build's reason, the
  memfile_mismatch refusal, and the parent's Retry-After from the
  holders' placed builds, now for no_slot and memory alike.
- packages/control-plane/test/activation.test.ts: inventory() takes
  running then memory; the memory tests pass [] for running. A new
  test pins sticky placement with the memory rule.
- deploy/sbx/host-agent.sh: memory_report kept; inventory() sends the
  per-build running flags and the memory object.
- docs/api/openapi.yaml: both texts in the hosts block, activate,
  inventory and wanted descriptions; the version stays 1.8.0.
- docs/reference/configuration.md, deploy/sbx/RUNBOOK.md, the
  template lifecycle spec: both texts; the spec's memory rule now
  says a running build stays (sticky) instead of being preferred.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
After about 60 s without an inventory the memory brake already stops
new starts on a host that reports its memory, keeping what it runs; at
360 s the host leaves placement entirely. Each constant now says so.

Refs rossoctl#744

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

Two holders: h1 sorts first and has fewer builds; the worker runs on
h2. The build stays on h2, and h2 counts it once (running, not
pending) beside the build placed there in the same pass.

Refs rossoctl#744

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
Brings in the memory-placement branch's reviewed fixes (sticky placement,
the running union, draining workers' slots, stale hosts, hostManaged,
refusal dedupe, holders' Retry-After, host-agent.sh's running flag and
stops before starts), kept together with cold-start pacing and the idle
grace.

Conflicts and resolutions:

- activation.ts place(): one placement with both rule sets. Each host's
  count starts at its running wanted builds and its draining (busy)
  ones; a build already running on a sound holder stays there (sticky),
  which covers a graced build leased again. Grace candidates are the
  running, unleased, not-busy builds; they take slots beside the count
  and are the only workers a wanted build may displace, never a leased
  one or one under a live sandbox. A displaced candidate's memory comes
  back on the bound it is counted in (MemAvailable for one in the
  inventory, pending for one started since). Placement returns used,
  memory, graced and displaced; used counts graced builds apart. The
  signature takes busy positionally (always read now, since draining
  workers hold slots); PlaceOptions is gone. hostManaged and the grace
  helpers are both kept.
- host-handlers.ts: busyWorkers and freshHosts replace graceBusy. The
  wanted answer keeps start order, starting, graced and the displaced
  re-check under the activation lock, and gains the other side's stop
  of a leased build that runs here while placed on another host, and
  the refusal cleanup for a build out of run. The inventory keeps both
  running/refused and start/idleGraceSeconds.
- sandbox-handlers.ts: imports both; readiness facts and takeLease pass
  busyWorkers to place(); the hosts block shows placement's used beside
  start and graced, for fresh hosts only; deploymentRun kept, the
  activation lock stays in activation-lock.ts; requireActive skips
  imported builds and keeps the start-line Retry-After.
- host-agent.sh: inventory reports running per held build with the
  start limit, start seconds and idle grace; activation() reads the
  answer, stops first (logging a graced stop), then books starts and
  starts within the start limit.
- openapi.yaml, configuration.md, the lifecycle spec: both texts. The
  version stays 1.9.0. CHANGELOG 1.9.0, the spec's section 6.5 and the
  RUNBOOK now say a running build stays where it runs (1.8.0's sticky
  placement) instead of "is preferred", and that graced builds take
  slots beside the counted ones and a draining worker is never graced.
- test/activation.test.ts: both import sets. Two tests adjusted for the
  merge: an exact wanted body gains starting: [], and the grace test
  re-sends its inventory before its 599 s check (a host silent for over
  HOST_STALE_S leaves placement). A pure test covers sticky, draining
  and displacement together.

Refs rossoctl#745

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

With the wanted answer's `starting`, a listed worker whose unit was
active counted as starting with no time bound. A worker that
crash-loops (Restart=on-failure), hangs, or cannot reach the relay
before it attaches reads as active, so it held its start slot for its
whole lease, and SBX_START_CONCURRENCY such workers stopped every
other cold start on the host.

A listed start now counts for SBX_START_WINDOW_S at most (default 300),
as the agent's own starts already did with a control plane that sends
no `starting`. Past it the worker is stuck: each run says so in an
error line naming it, and it holds no slot, so the line moves. A
listed active unit the start book does not hold (started by hand, or
before the agent kept a book) is entered as first seen (`seen`) and
timed from then; its attach, and that of a start done only after it
was stuck, gives no start time. host-agent.test.sh section 19b covers
three stuck starts beside one within the window (the next two start),
and a first-seen unit. The header, the RUNBOOK, the spec section 6.5,
the configuration reference, the OpenAPI text and the changelog say
so.

Refs rossoctl#745

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
…ld is left out of stop

The RUNBOOK's upgrade note said a wide activation takes several 15 s
runs to start everything. A slot frees when a worker attaches (with a
control plane older than 1.9.0, after SBX_START_WINDOW_S), not on each
run: the starts go in waves of SBX_START_CONCURRENCY, each about one
start time long, so 28 builds at the default take about seven waves.

The OpenAPI text for the wanted answer said a displaced graced build
found leased at the re-check stays in `run`. The answer leaves it out
of `stop` only (its worker keeps running); it is in `run` from the next
answer. The text now says so, as the spec and the RUNBOOK do.

Refs rossoctl#745

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

Copy link
Copy Markdown
Member Author

Merge note (conversation comment)

The branch now merges #776's head again (c7622a7), which carries #775's reviewed fixes with #776's memory model: sticky placement, the union of the running reports, draining workers counted against activeLimit, stale hosts left out, hostManaged, refusal dedupe, the holders' Retry-After for no_active_slot, and host-agent.sh's per-build running flag with stops before starts. The resolution keeps both sides' rules in one place(). A host's count starts with its running wanted builds and its draining ones. A build already running on a holder stays there, and that includes a graced build leased again. Grace candidates (running, no lease, no live sandbox) take slots beside that count, and they are the only workers a wanted build may displace: never a leased one, never one under a live sandbox. used counts graced builds apart. The two Retry-After rules answer different refusals: 409 no_active_slot takes the holders' wait, and 409 template_not_active takes the start line's wait (else 30 s). No single answer has both waits, so neither formula changed. The OpenAPI version stays 1.9.0. Two tests changed for the merge: an exact wanted body gains starting: [], and the grace test re-sends its inventory inside HOST_STALE_S. A new pure test checks sticky placement, draining and displacement together. The merge commit's message lists each conflict and how it was resolved.

Thread: deploy/sbx/host-agent.sh:456 (maintainer review, suggestion)

Fixed in b4068a4. With starting, a listed worker now counts as starting for SBX_START_WINDOW_S at most (default 300), the bound the agent already applied to its own starts with an older control plane. A worker that is still not attached after that is stuck: every run reports it in an error line (worker <id> started <n> s ago and is not attached: it no longer holds a start slot), and it no longer holds a start slot, so the line moves. A listed active unit missing from the start book (started by hand, or before the agent kept a book) goes into the book as first seen (seen) and is timed from that moment. Neither its attach nor that of a start completed only after it was stuck counts toward startSeconds. host-agent.test.sh section 19b has three stuck starts beside one still within the window: the next two builds start. It also covers a first-seen unit. The header, the RUNBOOK, spec §6.5, the configuration reference, the OpenAPI text and the changelog document the bound. The RUNBOOK also says to keep SBX_START_WINDOW_S above the host's slowest start in a full wave.

Thread: deploy/sbx/host-agent.sh:456 (bot review, suggestion)

Fixed in b4068a4, as in the thread above. A listed worker counts as starting only if its start, or the moment it was first seen, is less than SBX_START_WINDOW_S old. Past that, an error line names the worker each run and it holds no slot. Section 19b is the test you suggested: four active units are listed in starting, three of them past the window, and the queued builds behind them start.

Thread: deploy/sbx/RUNBOOK.md:774 (maintainer review, nit)

Fixed in 864d6b9. The upgrade note now says a wide activation starts in waves of SBX_START_CONCURRENCY, each about one start time long. A slot frees when a worker attaches, or after SBX_START_WINDOW_S with a control plane older than 1.9.0, so 28 builds at the default take about seven waves.

Thread: docs/api/openapi.yaml:2613 (bot review, nit)

Fixed in 864d6b9 with your wording: a build leased since the re-check is left out of stop (its worker keeps running) and is in run from the next answer.

Tip: 864d6b9

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.

Summary

Follow-up to our APPROVE at 9e577e8. The 864d6b9 push fixed both of our items and both of clawgenti's. b4068a4 caps a listed start at SBX_START_WINDOW_S: after that it is reported stuck and no longer holds a slot, and a unit missing from the book is entered as seen. 864d6b9 rewords the RUNBOOK wave text and the openapi "stays in run" text. This head (9c1908c) only merges #766's jq fix up the stack, which clears the inherited red deploy-scripts. proto, which was red at 864d6b9, is green now, so that failure was flaky.

Author: webchang (MEMBER — maintainer)
Agent/IDE config (.claude/.vscode): none
Commits: new own commits signed off: yes
CI status: 9 pass, 6 pending; deploy-scripts and proto green.

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

Brings rossoctl#766's quota changes (the templates quota for a template holding
no slot, and the owned quota) through pr/i19-activation.

Conflicts: none.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
Brings rossoctl#766's quota changes (the templates quota for a template holding
no slot, and the owned quota) through pr/i21-memory-placement.

Conflicts: none.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
pr/i19-activation now carries upstream/main: this brings upstream's sbx
templates create, build, follow, cancel, quota and policy beside this
branch's sbx hosts and its unavailable-reason readiness.

Conflicts and resolutions:

- packages/mocactl/src/sbx/api.ts: both sides' types kept (SbxHost; the
  create, quota and policy types).
- packages/mocactl/src/sbx/cli.ts: the import list holds both sides' commands.
- packages/mocactl/src/sbx/templates.ts: both sides' imports (with
  SbxReadinessReason); the module comment covers both; cmdHosts kept beside
  the follow, cancel and create commands.
- packages/mocactl/test/sbx-templates.test.ts: the header comment covers both;
  both sides' describe blocks kept.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
pr/i21-memory-placement now carries upstream/main: this brings upstream's
sbx templates create, build, follow, cancel, quota and policy beside this
branch's start pacing (sized activate --wait, deactivate --stop-now).

Conflicts and resolutions:

- packages/mocactl/src/sbx/templates.ts: both sides' imports (with SbxHost);
  the module comment covers both; FOLLOW_TIMEOUT_S kept beside this branch's
  ACTIVATE_TIMEOUT_S, ACTIVATE_TIMEOUT_CAP_S and sizedActivateTimeoutS; one
  POLL_MS (5000 on both).
- packages/mocactl/test/sbx-templates.test.ts: both sides' imports kept.

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

Copy link
Copy Markdown
Member Author

Merged main (d4babb8). CI is the full check: local tests ran on the existing node_modules during the hono pin's release-age window.

Assisted-By: Claude Code

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

Conflicts:
- docs/api/CHANGELOG.md: this branch's memory placement 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.

API version: this branch's memory placement moves from 1.8.0 to 1.9.0: openapi info.version and
its "(1.8.0)" field notes, the changelog, and the "openapi 1.8.0" mentions in deploy/sbx/RUNBOOK.md
and deploy/sbx/host-agent.sh.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
Brings in upstream main (lease modes, API 1.6.0) through pr/i21-memory-placement.

Conflicts:
- docs/api/CHANGELOG.md: this branch's start pacing section, renumbered 1.10.0, above
  pr/i21-memory-placement's 1.9.0, 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 hosts description is this branch's (graced builds, start and the idle
  grace), with memory at 1.9.0 and this branch's fields at 1.10.0.

API version: this branch's start pacing moves from 1.9.0 to 1.10.0, and its mentions of the lower
branches' versions move with them (memory placement 1.8.0 to 1.9.0): openapi info.version and its
field notes, the changelog, and the "1.9.0" mentions in deploy/sbx/RUNBOOK.md,
deploy/sbx/host-agent.sh and deploy/sbx/tests/host-agent.test.sh.

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

API version: this branch's memory placement moves from 1.9.0 to 1.10.0: openapi info.version and
its field notes, the changelog, and the "openapi 1.9.0" mentions in deploy/sbx/RUNBOOK.md and
deploy/sbx/host-agent.sh.

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/i21-memory-placement.

Conflicts:
- docs/api/CHANGELOG.md: this branch's start pacing section, renumbered 1.11.0, above
  pr/i21-memory-placement's 1.10.0 and the lower sections.
- docs/api/openapi.yaml: the hosts description is this branch's, with memory at 1.10.0 and this
  branch's fields at 1.11.0.

API version: this branch's start pacing moves from 1.10.0 to 1.11.0, and its mentions of memory
placement from 1.9.0 to 1.10.0: openapi info.version and its field notes, the changelog, and the
mentions in deploy/sbx/RUNBOOK.md, deploy/sbx/host-agent.sh and deploy/sbx/tests/host-agent.test.sh.

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
…ds a start slot

With a control plane that sends `starting`, a listed worker whose unit was active counted as
starting for as long as it was listed: a few workers that crash-loop, hang or cannot reach the
relay held every start slot on the host, and nothing else started. A listed worker now counts as
starting for SBX_START_WINDOW_S at most (default 300), the bound the agent already applied to its
own starts with an older control plane. Past it, it is stuck: every run reports it in an error line
(`worker <id> started <n> s ago and is not attached: it no longer holds a start slot`), and it holds
no start slot. A listed active unit missing from the start book (started by hand, or before the
agent kept a book) goes into the book as first seen (`seen`) and is timed from that moment; neither
its attach nor that of a start completed only after it was stuck counts toward startSeconds. The
header and the RUNBOOK say so, and that SBX_START_WINDOW_S is to stay above the host's slowest
start in a full wave.

Test (host-agent.test.sh, bash 5 and 3.2; fails with the fix reverted): three stuck starts beside
one still within the window: the next two builds start, each stuck worker is said stuck, nothing is
queued; a first-seen unit is entered as `seen` and gives no start time.

Host-side (deploy/sbx/host-agent.sh).

(cherry picked from commit b4068a4)
(cherry picked from commit 864d6b9)

Ports rossoctl#784 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 memory placement 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 memory-aware placement.
- docs/specs/2026-11-03-template-lifecycle-and-provenance-design.md: the status line names
  §5.1-§5.2 and this branch's placement by host memory.
- packages/control-plane/src/sandbox-handlers.ts: main's provenance, identity and sandbox-config
  imports, with this branch's readinessReasonOf from activation.ts.
- packages/mocactl/src/sbx/api.ts: main's SbxTagsMoved and this branch's SbxHost.

API version: this branch's memory placement moves from 1.10.0 to 1.11.0 (openapi info.version
and its four "1.10.0" field notes, the changelog, change-policy, and the "openapi 1.10.0" mentions
in deploy/sbx/RUNBOOK.md and deploy/sbx/host-agent.sh).

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) and memory placement at 1.11.0, by pr/i21-memory-placement.

Conflicts:
- docs/api/CHANGELOG.md: this branch's cold-start pacing section, renumbered 1.12.0, above memory
  placement's 1.11.0, 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; its note on the sticky placement names 1.11.0.
- docs/api/openapi.yaml: the hosts block's note: `memory` (1.11.0), then `start`,
  `idleGraceSeconds` and `graced` (1.12.0).
- docs/reference/change-policy.md: version 1.12.0; main's list, then the template host agents,
  activation leases, memory-aware placement and cold-start pacing.
- docs/specs/2026-11-03-template-lifecycle-and-provenance-design.md: the status line names
  §5.1-§5.2 and this branch's §6.5.

API version: this branch's pacing moves from 1.11.0 to 1.12.0 (openapi info.version and every
"1.11.0" field note it added, the changelog, change-policy, and the "openapi 1.11.0" and
"older than 1.11.0" mentions in deploy/sbx/RUNBOOK.md, deploy/sbx/host-agent.sh and
deploy/sbx/tests/host-agent.test.sh).

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 memory placement 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 memory-aware placement.

API version: this branch's memory placement moves from 1.11.0 to 1.12.0 (openapi info.version
and its four field notes, the changelog, change-policy, and the "openapi 1.11.0" mentions in
deploy/sbx/RUNBOOK.md and deploy/sbx/host-agent.sh).

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]>
Brings in upstream main through ec0f840 (subject trust for gate records at API 1.9.0; the host
agent at 1.10.0 and activation at 1.11.0, merged) and memory placement at 1.12.0, by
pr/i21-memory-placement.

Conflicts:
- docs/api/CHANGELOG.md: this branch's cold-start pacing section, renumbered 1.13.0, above memory
  placement's 1.12.0 and below; its note on the sticky placement names 1.12.0.
- docs/api/openapi.yaml: the hosts block's note: `memory` (1.12.0), then `start`,
  `idleGraceSeconds` and `graced` (1.13.0).
- docs/reference/change-policy.md: version 1.13.0; main's list (through subject trust for gate
  records), then the template host agents, activation leases, memory-aware placement and
  cold-start pacing.
- packages/control-plane/src/sandbox-handlers.ts: readinessFacts returns this branch's queue and
  hosts with main's trusted set.

API version: this branch's pacing moves from 1.12.0 to 1.13.0 (openapi info.version and every
field note it added, the changelog, change-policy, and the "openapi 1.12.0" and "older than
1.12.0" mentions in deploy/sbx/RUNBOOK.md, deploy/sbx/host-agent.sh and
deploy/sbx/tests/host-agent.test.sh).

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
@pdettori 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.

Pace template workers' cold starts: a start limit, visible start lines, and an optional idle grace

4 participants