Repository navigation
feat(mocactl): sbx templates create, build, follow and cancel, with --dry-run; sbx quota and policy - #767
Conversation
…fiable offline Add an append-only provenance store to the control plane: one hash chain per stream (`policy`, `template/<id>`), kept in a directory on the control plane's persistent volume, exportable as one JSON document and verifiable offline with the Python standard library alone. - provenance.ts: ProvenanceStore (one file per record named by the sha256 of its canonical JSON, one head per stream, cited documents under blobs/; a record is written before its head moves, appends to a stream are serialized, the directory is checked writable at start), canonicalJson, export() (moca-provenance-export/1) and verifyExport. Record kinds: policy, create, gate, build, check, activate, deactivate, tag, visibility, owner, retire, reject, use, sandbox, session. - sandbox-handlers.ts: with deps.provenance set, a sandbox's create, its delete, and its expiry (once, from the janitor's sweep) are recorded as `sandbox` records on its template's chain. Without a store nothing is recorded and no behavior changes; main.ts does not open a store yet (that comes with the template store, rossoctl#736, which shares the directory). - deploy/sbx/template-onboarding/verify-provenance.py: the same checks as verifyExport, plus --head to compare a head kept elsewhere. redact-provenance.py: rewrites one stream from its first match, moves the head and logs counts only; dry run by default. - Tests run the Python verifier on the same exports as verifyExport, cover tampering, concurrent appends, restart continuity and redaction, and the sandbox span on its template's chain. - Docs: the provenance section (§7) of the template lifecycle design. Refs rossoctl#730 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
…-read race CodeQL's file-system race rule flagged writeOnce(): after an exclusive open failed with EEXIST, it read the existing file by path to compare the bytes. writeOnce now writes the bytes to a temp file in the same directory (exclusive create, fsync), puts it at the record's name with link(2), which is atomic and fails with EEXIST, and on EEXIST reads the existing file through its own handle (O_RDONLY | O_NOFOLLOW) to compare, never by a second lookup of the path. The temp file is always removed. As a side effect a crash mid-write can no longer leave a torn file under a record's name. Test: a file under a blob's name with other bytes is refused and left as it is, and no temp file is left behind in blobs/ or records/. Refs rossoctl#730 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
…adiness and a read API
Templates were a fixed SH_SANDBOX_TEMPLATES list, read on the sandbox
profile only, each id mapped straight to one worker. They now live in a
catalog the control plane owns (template-catalog.ts, template lifecycle
spec §3-§4):
- A template is a name over immutable builds, with tags naming builds;
`default` is what a bare id names. An env-list entry is one registered
build, `imported:<12 hex>` (stable per worker, never the worker id),
owned by no one (`owner: null`).
- With SH_PROVENANCE_DIR set, the provenance store and a file catalog
open together on that directory (templateCatalogFromEnv). The env list
is imported once into an empty catalog, a provenance `create` record
per template, and ignored after that, with a warning when it differs.
Unset, templates come from the env list at every start, as before.
- A sandbox names `id`, `id:tag` or `id@<build id>`. The reference is
resolved to one registered build at create and kept for the sandbox's
life: the record and the Sandbox carry `buildId` and
`templateManifestHash` (null for an imported build), and the sandbox's
provenance records name its build. An unknown reference stays
`400 unknown_template`. A sandbox keeps its worker when its template
moves to a new one.
- Readiness comes from facts: a registered build is `active` while the
relay holds its worker's presence record (with its capacity and live
sandboxes), `inactive` without one, `unknown` when presence cannot be
read.
- GET /v1/templates keeps its first three fields and adds owner,
visibility, onboarding, readiness, tags, builds and a `hosts` block
(empty until a host agent reports). New GET /v1/templates/{id},
/builds, /builds/{build} (each build with its spec) and /tags. All
mount on both route profiles. A private template is visible to its
owner and admins only; anyone else gets 404 template_not_found, as for
an unknown template or build.
API 1.4.0 (additive), with its changelog entry, the HTTP and
configuration references, and §1-§4 of the template lifecycle design.
Refs rossoctl#736
Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
…olume SBX_TEMPLATE_STORE=1 adds the overlay component ocp-sbx/template-store to the control plane: - a 1 GiB RWO PVC, moca-sbx-templates, mounted as SH_PROVENANCE_DIR, for the template catalog and the provenance records; SBX_TEMPLATES_FILE is imported into it once, at the first start; - the Recreate strategy, since an RWO volume cannot attach to a surge pod. Unset or 0 renders exactly as before. Turning it off leaves the PVC and its records in place. Any other value is refused before anything is applied. setup.test.sh covers on, off, a re-run, egress together, and the refusals; overlay.test.sh renders the component. Refs rossoctl#736 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
The client part of the template store's read API: - `sbx templates` shows each template's readiness and tags when the control plane sends them; an older one's list prints as before. - `sbx templates show ID [--build BUILD] [--json]`: a template and its builds (status, readiness with capacity, tags), or one build with its spec. - `sbx create --template ID[:TAG|@build]` passes the reference through. With `--seed`, the build the create was served (its `buildId`, never the newest) has its seed run as the sandbox's first command, and /workspace is checked for a clean tree. Its HEAD becomes the sbx baseline, so `pull` returns only later changes and `rm` needs no `--force`. A failed seed, a dirty tree or a build with no seed is exit 1, with the sandbox kept and named. - A 404 template_not_found is reported as itself, not as a control plane without sandbox routes. The contract test covers the two new calls and the fields they read. Refs rossoctl#736 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
The import of SH_SANDBOX_TEMPLATES into an empty catalog skipped itself whenever the catalog held any document, so a crash after the first document lost the rest for good, and a crash between a template's `create` record and its document re-imported it with a second `create` on its stream. The import now writes a marker (`catalog/.imported`) last; a start without it resumes: it writes only the templates not yet in the catalog, and reuses a template's `create` record from the env list when its stream already ends in one. With the marker present the catalog holds the templates and a differing env list is only warned about, as before. Test: a crash after the first document (the second document and the marker missing) resumes to both templates, with exactly one `create` per stream and the reused record named by the document. Refs rossoctl#736 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
…h quotas
An enrolled client creates a sandbox template from an image pinned by digest, and a policy, not a
person, admits or refuses it before anything is queued. All routes mount on both route profiles and
need SH_PROVENANCE_DIR:
- POST /v1/templates {id, image, spec, gateRecord?, profile?, visibility?} answers 202 {templateId,
buildId: null, build, status: queued}, the build addressed by a b-<26 hex> handle; POST
/v1/templates/{id}/builds adds a build to the caller's own template; POST
/v1/templates/{id}/builds/{build}/cancel withdraws a queued, building or probing build (failed,
step cancelled, a build record naming who).
- The policy (moca-template-policy/1, template-policy.ts, stored by template-policy-store.ts beside
the template store): profiles (base, benchmark) with their rules and size envelope, allowed
registries, trusted gate records by sha256, quotas. GET /v1/policy for any enrolled client; PUT
/v1/policy for an admin, each change a policy record naming who. GET /v1/quota shows the caller's
limits and use, and on the sandbox profile the live-sandbox cap.
- Rules carry the gating-rule ids (M1, M7 field by field with M7.spec_id and M7.spec_image, M8, M9,
the registry allowlist, the envelope; for benchmark X1 and X1.trusted, X10, X11, X12, X14, X15). A
refusal is 422 policy_refused {rule, message} and a check record; over quota is 429
quota_exceeded naming which; another subject's id is 409 template_exists (404 when private).
- An admitted create writes create, gate and check provenance records. A create with the same image,
spec, profile and gate record sha256 on the caller's own template answers that build with
reused: true (200 registered, 202 on its way); a failed or rejected build is never reused.
The examples (deploy/sbx/template-onboarding/examples/: the default sandbox image's spec, and a
SWE-bench instance's spec and gate record, kept byte for byte) are what the tests create. TemplateBuild
adds handle and reason, and a build is found by its handle. The catalog gains a
serialized update(). API 1.5.0, with a changelog entry.
Tests: template-create.test.ts (the worked examples admitted, each rule's refusal and its check
record, ids unique per deployment, reuse, quotas, cancel, the policy and quota routes); the route
tables, the error taxonomy and the OpenAPI contract.
Refs rossoctl#737
Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
…e lifecycle design The rules a template create is refused by are named in a gating-rules document: deploy/sbx/template-onboarding/governance/GATING-RULES.md, §1 the image (Moca's M1-M6, the image builder's X1-X9), §2.1-§2.2 the template (M7-M17, X10-X16) and §3 the provenance each rule's evidence lives in. Where the create-time policy enforces a rule (X1, X11, X14, X15 on the benchmark profile), its status says so. deploy/sbx/template-onboarding/tests/examples.test.sh checks the samples in examples/: each a well-formed template spec (M1, M7, M8, M9, field by field with jq), none naming a private registry, an account id or a token, and a gate record beside a sample being the one its spec names, passed, and backing its skipped identity check (X1, X10, X12). make test-deploy runs it. The template lifecycle design gains §4's create, reuse and cancel as built, and §8, policy: the profiles, the checks at create, registration once a host agent reports, trusted gate records by sha256, and the benchmark id rule (not enforced yet). The HTTP API reference lists the self-serve routes. Refs rossoctl#737 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
… caller may write A policy refusal of any well-formed id appended a `check` record to `template/<id>`, so any enrolled subject could grow another owner's stream without bound by sending refused creates for that id. A refusal is now recorded only when no template holds the id yet, the template is the caller's own, or an admin is adding a build; on another subject's id it is only answered (the same 422, so no existence oracle). The design says so, and that refusals on the caller's own and new ids are bounded only by the request rate. Test: another subject's refused create writes nothing to the owner's stream; the owner's own refusal, and a refusal on a new id, are recorded. Refs rossoctl#737 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
One conflict, docs/reference/configuration.md's control-plane table: main's rows kept, with this stack's SH_PROVENANCE_DIR and SH_SANDBOX_TEMPLATES rows (merged row by row; none changed on both sides). Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
…o pr/i14a-self-serve-create One conflict, docs/reference/configuration.md's control-plane table: merged row by row; this PR's SH_PROVENANCE_DIR wording kept beside main's rows. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
An image builder's review of the rules for outside builders: §1.2 says which X rules a general gate record (a self-serve user's, rossoctl#738) proves and that X2 and X3 do not apply to it; M3 states the rule without its history; X8's container user is the image's own; X9 says what the hosts file must map; §3's fields table notes the general record's null recipe and base digest, and that G must be published where `gate_record.commit` points for an offline check. Refs rossoctl#737 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
…; sbx quota, policy
The authoring client for self-serve template create (the server is the parent change):
- `mocactl sbx templates create --spec F [--spec F ...] [--id ID] [--image REF] [--profile P]
[--visibility V] [--gate-record F] [--dry-run] [--timeout S]`: one POST /v1/templates per spec,
in order. F is a spec or a gate record whose `template` block is the spec; the id and image
default to the spec's own and must equal it (M7.spec_id, M7.spec_image, checked before any
request). The gate record is sent byte for byte (its sha256 is what the policy trusts). At
`429 quota_exceeded {quota: buildsQueued}` a create waits for a queue slot (Retry-After, else
30 s) up to --timeout (default 3600 s); one refused spec does not stop the next. A
`409 template_exists` names the owner; an id already the caller's is followed to its newest
build instead. A reused build (`reused: true`) is said so.
- `templates build ID --spec F`: POST /v1/templates/{id}/builds.
- `templates follow ID [--build B] [--timeout S]`: polls the build (default the newest) through
5xx and unreachable moments until registered (exit 0), failed, rejected or cancelled (exit 1,
with its reason); past --timeout, exit 5.
- `templates cancel ID --build B`: POST .../builds/{build}/cancel.
- `templates show` prints a build's handle beside its build id, and why it failed.
- `--dry-run` (src/sbx/dry-run.ts): the policy's create-time rules that need only the inputs and
the policy's profiles (GET /v1/policy), with the server's rule ids and order; not the gate
record's trust, the registries or the quotas, which only the server decides. It checks no gate
record schema, as the server does not.
- `sbx quota` (GET /v1/quota) and `sbx policy` (GET /v1/policy).
- ApiError keeps a refusal's `rule` and `quota`; a refusal prints "refused by policy rule R: ..."
or "over your Q quota: ...". Exit 5 is a wait that timed out.
Tests: sbx-templates.test.ts (create, build, follow, cancel, the queue-slot wait, dry-run rule by
rule and over the onboarding examples), contract.test.ts (the new routes, the Error and Policy
fields), helpers/sbx.ts (response headers, the default policy).
Refs rossoctl#737
Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
A new section 8: what a client may do (sbx quota, sbx policy), create and follow a build, the dry run and what only the server decides, waiting for a queue slot, reuse, cancel and build. The troubleshooting list gains "refused by policy rule", "over your quota" and exit 5. Later sections renumbered (no link names them by number). Refs rossoctl#737 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
clawgenti
left a comment
There was a problem hiding this comment.
Summary
This PR adds mocactl's authoring client for self-serve templates: sbx templates create/build/follow/cancel, --dry-run, sbx quota and sbx policy, with the user-guide section. It is stacked on #766, so this review covers its own two commits (mocactl and docs); #766's content is reviewed on #766. No must-fix issues. dry-run.ts matches the server's checkCreate rule for rule and in the same order, and a probe that ran both on the same inputs found no divergence. One suggestion: the client's 409 template_exists "already yours" branch cannot be reached against this server, and the help text describes it as if it could. One nit is inline.
Author: webchang (MEMBER — maintainer)
Areas reviewed: TypeScript (mocactl sbx CLI, API client, dry-run), Docs
Agent/IDE config (.claude/.vscode): none
Commits: 15 commits, all signed-off: yes
CI status: passing (17/17 checks green)
Verified by: vitest run test/sbx-templates.test.ts test/contract.test.ts (101 passed), tsc --noEmit (clean), and a throwaway parity probe that ran dryRun and the server's checkCreate on the same inputs: valid spec, probe as an array, empty gate record (base and benchmark), uppercase id. Each case failed on the same rule on both sides. The probe and the worktree have been deleted.
Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).
| return SBX_EXIT.failed; | ||
| } | ||
| const me = c.rt.auth?.subject; | ||
| if (t.owner !== null && t.owner === me) { |
There was a problem hiding this comment.
suggestion: This "already yours" branch cannot be reached against this PR's control plane. In packages/control-plane/src/sandbox-handlers.ts (cat.update), template_exists is thrown only when cur.owner !== p.sub, with the message "belongs to another subject". For the caller's own id the server goes on to reuse a matching build or queue a new one, and answers 2xx. So the help text in cli.ts ("An id already yours: its newest build is followed") describes behaviour the server never triggers. The test at sbx-templates.test.ts:559 only passes because its mock returns a 409 the real server would not send. If the branch ever did fire, it would also report reused: true for a build that has nothing to do with the posted inputs.
Suggested fix: remove the owner branch (keep the "belongs to X / declared by the deployment" message) and correct the help line. Or, if a 409 for one's own id is planned server-side, note that here and in the openapi template_exists description.
| Math.min(Math.max(1, err.retryAfterS ?? QUEUE_SLOT_WAIT_MS / 1000) * 1000, left), | ||
| c.signal, | ||
| ); | ||
| if (c.signal?.aborted) throw err; |
There was a problem hiding this comment.
nit: On abort during the queue-slot wait this rethrows the 429 ApiError, so a Ctrl-C prints "quota exceeded" and exits failed. pollBuild throws new Error('interrupted') for the same situation. Use the same here so the two report an interruption the same way.
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
This adds sbx templates create/build/follow/cancel (with --dry-run), sbx quota and sbx policy to mocactl. It also carries the server's rule/quota on API errors and adds exit 5 for a wait that times out. The routes, field names and status codes match the control plane and openapi from #766, and the dry run follows checkCreate rule for rule (registry and X1.trusted are deliberately left to the server). One blocker: a Ctrl-C during the queue-slot wait still POSTs the remaining specs' creates.
- Author: webchang (MEMBER — maintainer)
- Areas reviewed: mocactl sbx templates create/build/follow/cancel/show, dry-run, quota, policy, ApiError rule/quota, exit codes, user guide §8/§10
- Agent/IDE config: none
- Commits: 2 (+1 merge), all signed-off: yes
- CI status: passing
| Math.min(Math.max(1, err.retryAfterS ?? QUEUE_SLOT_WAIT_MS / 1000) * 1000, left), | ||
| c.signal, | ||
| ); | ||
| if (c.signal?.aborted) throw err; |
There was a problem hiding this comment.
must-fix: Ctrl-C during the queue-slot wait does not stop the create loop, and the next spec's create is still POSTed.
When the signal aborts, sleep returns at once and this line rethrows the 429 ApiError. cmdCreateTemplates (line 430) passes it to failed(). That prints "over your buildsQueued quota" (wrong: the user interrupted), gets SBX_EXIT.failed, and goes on to the next input. For that input createOne sends a new POST /v1/templates without checking the signal. The request carries no signal, so it goes out. If a slot has freed by then, a template the user meant to cancel gets created and queued. Failure case: templates create --spec a.json --spec b.json --spec c.json, queue full, Ctrl-C while waiting on a. b and c are each POSTed once more after the interrupt.
Fix: check c.signal?.aborted before each POST in createOne and at the top of each loop pass in cmdCreateTemplates. On abort, throw or return a distinct "interrupted" result and leave with 130, as sync.ts/exec.ts do, not 1. Add a test that aborts during the wait and asserts no further POST.
| const left = end - now(); | ||
| if (left <= 0) return 'timeout'; | ||
| await sleep(Math.min(POLL_MS, left), c.signal); | ||
| if (c.signal?.aborted) throw new Error('interrupted'); |
There was a problem hiding this comment.
suggestion: Ctrl-C during templates follow exits 1 with "sbx: interrupted". mocactl's other sbx waits return 130 on abort (execFailed, checkBeforeRm in sync.ts). A script that runs follow and branches on its exit code then can't tell "build failed" (1) apart from "user interrupted". Return 130 here, for example by catching c.signal?.aborted in cmdFollowTemplate before failed(), and document it next to exit 5.
| return SBX_EXIT.failed; | ||
| } | ||
| const me = c.rt.auth?.subject; | ||
| if (t.owner !== null && t.owner === me) { |
There was a problem hiding this comment.
suggestion: this branch can't be reached against the control plane in #766. createBuild only throws template_exists when cur.owner !== p.sub (sandbox-handlers.ts). The caller's own id on POST /v1/templates queues a new build, or answers reused, and never 409s. So "is already yours: following its newest build" never shows. It also makes up a reused: true answer that the server never sent. The usage text ("An id already yours: its newest build is followed", cli.ts) and the test "409 template_exists: follows your own newest build" describe behaviour the server doesn't have. Worse, they hide the real behaviour: creating your own id again with a changed spec queues a new build. Drop the own-template branch, or make it defensive only (no synthesized reused). Correct the usage line to say a create on your own id is a new build of it.
| for (const n of r.notes) c.io.err(`sbx: ${sanitizeRemote(body.id)}: ${n}`); | ||
| if (r.failed) { | ||
| c.io.err( | ||
| `sbx: ${sanitizeRemote(body.id)} (${sanitizeRemote(file)}): would be refused by policy rule ${r.failed.rule}: ${r.failed.message}`, |
There was a problem hiding this comment.
suggestion: r.failed.message goes to the terminal unsanitized. Several messages embed remote text from GET /v1/policy. no policy profile '${profileName}' is user input. But spec is outside the ${profileName} profile's envelope (guest <= ${env.maxGuestMb} …) and the X rules interpolate the profile name, and the envelope numbers come from the server's JSON unchecked: a hostile or misconfigured control plane can send a string there. M9 interpolates String(s.probe_status) from the spec file. By the moca convention, remote strings reaching a terminal go through sanitizeRemote. Wrap r.failed.message (and n in the notes loop above) in sanitizeRemote, as cmdPolicy already does for its own output.
| if (o.gateRecord !== undefined) { | ||
| let raw: Buffer; | ||
| try { | ||
| raw = readFileSync(o.gateRecord); |
There was a problem hiding this comment.
nit: readFileSync(o.gateRecord) has no size cap and runs before any request. Pointing --gate-record at the wrong file (an image tarball, say) reads all of it into memory. The UTF-8 round-trip check then makes a second full copy, only for the server to answer 413 (the create routes cap the body at 1 MiB, routes.ts). Check statSync(...).size first and refuse anything over 1 MiB as a usage error, with a message naming the limit. Related: with several --spec, the same gate record is attached to every create. That is right for a template block taken from that record but almost certainly wrong for unrelated specs. Consider refusing --gate-record with more than one --spec, as --id/--image already are.
| are the spec's own (`--id`, `--image` must equal them). `--profile P` names a policy profile, | ||
| `--gate-record F` sends its gate record byte for byte (the `benchmark` profile needs one), | ||
| `--visibility private` keeps a new template to yourself. | ||
| - `--dry-run` sends nothing: it names the policy rule a create would fail (`M7.id`, `M1`, `X10`, …). |
There was a problem hiding this comment.
nit: "--dry-run sends nothing" is accurate about mutation but not about the network. The dry run needs a login and a reachable control plane, since it reads GET /v1/policy (cmdDryRun), and it fails with exit 3/4 otherwise. Suggest: "--dry-run creates nothing: it reads the policy (sbx policy) and names the rule a create would fail …".
…per-subject lock The review found the quota check was not atomic: the catalog serializes per template id, but the quotas count across every id a subject owns, so concurrent creates for different ids all read the same use and all passed. The quota read and the build's write now run under one lock per subject (a SubjectQueue per catalog), taken outside the catalog's id lock. A test fires parallel creates under templates: 1 and parallel new builds under buildsQueued, and expects exactly one admitted. Refs rossoctl#737 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
…ged to the owner The review asked for three changes to how a subject's use is counted: - a template counts only while a build is registered or on its way there, so a template whose builds all failed or were cancelled no longer holds a slot that nothing could free; - buildsQueued counts probing builds too, the host work still in flight; - a build an admin adds to another subject's template is charged to the template's owner, under the owner's lock, not to the admin. The policy type, openapi's Quota and GET /v1/quota, the changelog and the lifecycle design say so. Tests cover the freed slot, a probing build and an admin-added build. Refs rossoctl#737 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
… as guest_ram_mb The review found the size envelope (and X15) could be bypassed: the policy read guest_mb before guest_ram_mb, while the build tool reads only guest_ram_mb, so a spec with guest_mb inside the envelope and a larger guest_ram_mb passed the policy and built the larger guest. A spec with both keys is now refused as M7.guest (even when equal), and the alias guest_mb alone is stored as guest_ram_mb before the spec is recorded, kept for the build or compared for reuse (normalizeSpec). The examples' test refuses a sample with both; openapi, GATING-RULES M7 and the lifecycle design say so. Refs rossoctl#737 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
…ign says The review found the gate rules the design applies whatever the profile were only partly checked outside benchmark: a spec naming a gate record on base was admitted when that record's gate failed or was for another image, and a skip of the git identity check with no gate record added no X12 result at all, so neither the control plane nor the build host checked it. Now, under any profile, a spec that names a gate record (or a create that sends one) also passes X1 (the gate passed) and X1.image (the record is for this image); only X1.trusted stays the profile's. And X12 refuses any skip no gate record backs. Tests cover the three cases on base; GATING-RULES X10/X12 and the lifecycle design §8.1 say so. Refs rossoctl#737 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
…hosts compare case-insensitively The review found the image check accepted any non-space, non-@ text as the repository (Images/X, -x, a//b, ../x, control characters, name:tag@digest), which the build host then refuses after spending its time, and a leading `-` would reach the host's podman calls as an option. M1 now takes the distribution reference grammar: an optional host[:port]/ (a first component with a `.` or `:`, or localhost), lowercase path components, then @sha256:<64 hex>, at most 255 characters before the `@`, and no tag beside the digest (so the reuse key never sees two spellings of one image). registryOf lowercases the host, and allowedRegistries compares case-insensitively, so GHCR.io matches ghcr.io. Tests list accepted and refused references; openapi and GATING-RULES M1 say so. Refs rossoctl#737 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
…s on, and a whole-number exact envelope
The review noted that `requires` took any string, so `['X13']` or
`['x11']` was accepted and enforced nothing, and that `envelope.exact`
was unchecked, so `{guestMb: "4096"}` made X15 refuse every create.
policyProblems now refuses a rule id outside PROFILE_RULES (exported: the
ids checkCreate acts on, X1, X10, X11, X12, X14, X15) and an `exact` that
is not two positive whole numbers. openapi's Policy says the same.
Refs rossoctl#737
Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
…ate's codes As the review asked, the list in http-api.md now has `template_exists` under 409, `policy_refused` as 422 and `quota_exceeded` under 429, as in errors.ts and the paragraph above it. Refs rossoctl#737 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
…ly answered The review noted that a refused create on a new id still wrote a `check` record to `template/<id>`, for any id a caller picks, so any enrolled subject could open provenance streams without bound, which no quota counts. A refusal is now recorded only on the stream of a template that exists and whose stream the caller may write (its own, or an admin adding a build); on a new id, as on another subject's, it is only answered with the 422. Tests, openapi and the lifecycle design say so. Refs rossoctl#737 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
…; the changelog notes the policy's tightenings A refused create on an id no template holds, which since the previous commit writes no provenance record, now writes one line to the capped audit stream (template_create_refused) through the best-effort audit helper, naming the subject, the template id and the failed rule ids (new optional audit fields templateId and rules). A test checks that one such refusal leaves one audit entry and no provenance stream. The changelog's 1.5.0 notes say that X12 now applies on base too (an unbacked skip_git_identity_check is refused; send a gate record showing commits refused, or drop the skip and let the build host's git identity check run), and that a stored policy naming an unknown rule id, or an exact envelope not of whole numbers, fails closed when read until an admin sets a valid one, which a new test shows. openapi and the lifecycle design name the audit line. Refs rossoctl#737 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
clawgenti
left a comment
There was a problem hiding this comment.
Summary
Re-review of the push since my last review (a8c399a..7880b3c, review 5883064191). This PR's own increment adds seven fix commits (c9e7666..7880b3c), and the merge a6df6de brings in #766's fixes, which are reviewed there. Every earlier finding from both reviews is addressed:
- Ctrl-C while waiting for a queue slot throws
Interrupted. The loop andcreateOnecheck the signal before every POST, and the exit code is 130. followexits 130 on Ctrl-C.- The unreachable "already yours" 409 branch is gone, and the usage text now describes a create on your own id as a new build.
- Dry-run output passes
notes,ruleandmessagethroughsanitizeRemote. --gate-recordis size-checked before it is read and goes with one--speconly.- The user-guide wording for
--dry-runis fixed.
The dry run now matches #766's tightened server checks. Its isPinnedImage is equivalent to template-policy.ts's isPinnedImage/splitHost (same regexes, same host rule). A spec with both guest-size keys is refused. X10, X1 and X12 apply under every profile when a record is named or sent. One new suggestion: the size check leaves a stat-then-read race, and CodeQL flags it as the failing CodeQL check (inline). The deploy-scripts failure is inherited from #766's examples.test.sh jq change (inline).
Author: webchang (MEMBER — maintainer)
Areas reviewed: mocactl fixes (templates.ts, dry-run.ts, cli.ts, commands.ts) and their tests, dry-run/server parity for M1, M7.guest, X1, X10 and X12, user-guide.md, the merge a6df6de (no conflicts), commits/DCO, CI, agent-config gate
Agent/IDE config (.claude/.vscode): none
Commits: 34 commits, all signed-off: yes
CI status: failing: CodeQL (1 high alert, templates.ts:295, this PR) and deploy-scripts (inherited from #766). The other 15 checks pass.
0 new must-fix of its own (1 inherited from #766), 1 suggestion, 0 nits.
Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).
| const size = statSync(o.gateRecord).size; | ||
| if (size > GATE_RECORD_MAX_BYTES) | ||
| return `--gate-record ${o.gateRecord} is ${size} bytes: a gate record is at most 1 MiB (the create's body limit)`; | ||
| raw = readFileSync(o.gateRecord); |
There was a problem hiding this comment.
suggestion: this is the line behind the red CodeQL check (code-scanning alert #124, "Potential file system race condition"). The size comes from statSync(path) at line 292 and the bytes from a second open at line 295, so a file that grows in between gets past the 1 MiB cap, which is the reason line 292 was added. For a CLI reading its user's own file, the impact is small. Still, the check is red, and the fix is cheap. Suggested fix: open once and work from the descriptor, const fd = openSync(o.gateRecord, 'r'); try { const size = fstatSync(fd).size; if (size > GATE_RECORD_MAX_BYTES) return ...; raw = readFileSync(fd); } finally { closeSync(fd); }. Or read at most GATE_RECORD_MAX_BYTES + 1 bytes and refuse when the read fills that. Either way the cap holds for the bytes actually sent.
| 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 |
There was a problem hiding this comment.
must-fix (inherited from #766, commit a187e99; already reported there: #766 (comment)): this filter is false for every spec, and that is why deploy-scripts is red on this head. In jq, A and B as $g | C parses as (A and B) as $g | C, so $g is bound to the boolean and ($g | type) == "number" never holds. With jq 1.8.2 on this head's default.json (guest_ram_mb: 256, vcpus: 1) the expression gives false. With the binding parenthesised, ((has("guest_mb") and has("guest_ram_mb")) | not) and ((.guest_mb // .guest_ram_mb) as $g | ...), it gives true, and it still refuses {"guest_mb":256,"guest_ram_mb":256}. Suggested fix: parenthesise as shown, in #766. This PR picks it up on its next merge from #766.
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Follow-up at 7880b3c. Every item from our a8c399a review and both of clawgenti's are fixed in code, and new tests cover each one:
- Ctrl-C stops a create loop before any further POST and exits 130 in both waits.
- The made-up
reusedpath is gone. A 409 on your own id now prints the server's refusal as sent. - The dry-run output is sanitized.
--gate-recordis size-capped and goes with one--spec.- The
--dry-rundocs are corrected.
The dry run in 7880b3c matches #766's tightened checkCreate rule for rule, apart from the registry and X1.trusted checks, which are documented. The #766 merge a6df6de has an empty remerge-diff.
Two nits are inline, none blocking. (+1 to clawgenti's templates.ts:295 suggestion on the stat-then-read race behind the CodeQL alert; a bounded read on one fd would also cap pipes and FIFOs such as /dev/stdin.)
sbx policyprints the envelope and quota values unsanitized.--dry-rundisagrees with the server on an uppercase--idand on an invalid--visibility.
Author: webchang (MEMBER, maintainer) · Agent/IDE config: none · DCO: all new commits signed off.
| const e = pr.envelope; | ||
| c.io.out( | ||
| `${sanitizeRemote(name).padEnd(16)}${name === p.defaultProfile ? ' (default)' : ''} ` + | ||
| `guest <= ${e.maxGuestMb} MiB, vcpus <= ${e.maxVcpus}, workspace <= ${e.maxWorkspaceMb} MiB` + |
There was a problem hiding this comment.
nit: cmdPolicy sanitizes the profile names, registries, rules and digest, but interpolates the envelope and quota values from GET /v1/policy raw: e.maxGuestMb, e.maxVcpus, e.maxWorkspaceMb, e.exact.* (lines 90-91) and p.quota.* (95-96). They are typed number, but they arrive as unchecked JSON. A misconfigured or hostile control plane can send "maxGuestMb": "\u001b]52;c;…\u0007", and mocactl sbx policy writes it to the terminal as is (OSC 52 clipboard write, title change, and so on). 5ff17fb closed this for the dry run's envelope message but not here. Wrap each value as sanitizeRemote(String(e.maxGuestMb)), or check Number.isSafeInteger and print ? otherwise.
| ); | ||
| rule( | ||
| 'M7.id', | ||
| TEMPLATE_ID_RE.test(input.id), |
There was a problem hiding this comment.
nit: two drifts from the control plane's create checks at this head, where --dry-run and the real create give different answers:
- id case.
POST /v1/templateslowercases the id beforecheckCreate(b.id.toLowerCase(), sandbox-handlers.ts:450). The dry run testsinput.idas given.templates create --spec s.json --id My-Python --dry-run(spec without an id) reports "would be refused by policy rule M7.id". The real create accepts it asmy-python. Lowercaseinput.idhere for the create path (not forbuild ID, whose route uses the path id as is). Or havereadCreateInputslowercase--id, so the client and server agree on the id they compare againstspec.id. - visibility. The server answers
400 invalid_requestfor anyvisibilityother thanprivateordeployment(sandbox-handlers.ts:462). No client check or dry-run check exists.--visibility public --dry-runprints "passes the local checks", and the create then fails. A usage check in cli.ts next to the existing--visibilityflag check would cover both paths.
Everything else in 7880b3c matches checkCreate, compared rule by rule:
isPinnedImageand its regexes are the same.M7.guestrefusesguest_mbandguest_ram_mbtogether, with the same messages.X10andX10.recordapply when named.X1andX1.imageapply when the profile requires them, the record is named, or one is sent.X12applies under every profile.X14andX15are unchanged.
Only the server's registry and X1.trusted checks are left out, which is documented. The extra typeof probe === 'object' changes no outcome.
Dismissing our approval until clawgenti's must-fix on deploy/sbx/template-onboarding/tests/examples.test.sh:22, a jq precedence bug inherited from #766 (a187e99), makes the required deploy-scripts check fail on this head (#767 (comment)).
… 1.8 jq 1.8 parses `a and b as $g | c` differently from 1.6 and 1.7, so the M7 guest-size check read default.json as failing on runners with jq 1.8 (it passes on 1.7). Every clause is parenthesized; the check passes on jq 1.7.1 and 1.8.1. Refs rossoctl#737 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
CodeQL's file-system race rule: the size was taken with statSync and the file then read by path, so the file checked may not be the file read. It is now opened once, sized with fstat and read from the same handle. Refs rossoctl#737 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
clawgenti
left a comment
There was a problem hiding this comment.
Summary
Re-review of the push since my last review (7880b3c..085c98e, review 5884463244). New: 61a69353 (--gate-record is sized and read through one handle) and the merge of #766's jq fix (2 files, +15/−8).
passing
Author: webchang (MEMBER — maintainer)
Areas reviewed: Both earlier open items are resolved:
--gate-recordstat-then-read race.readCreateInputsnow opens the file once, sizes it withfstatSync(fd), reads from the same fd and closes infinally. Open errors still land in the existingcannot read --gate-recordcatch. CodeQL now passes.- Inherited
deploy-scriptsfailure.examples.test.shM7 guest-size jq is now fully parenthesized (cbec01ca). I confirmed the fix on jq 1.8.2: the suite passes at head, and with the old line restored,default.json: guest size or vcpus (M7)fails again (positive control).deploy-scriptspasses on this head.
No new findings, and all checks pass. Ready for human review.
Agent/IDE config (.claude/.vscode): none
Commits: 37 commits, all signed-off: yes
CI status: TypeScript (mocactl sbx/templates.ts), Shell (template-onboarding tests)
Verified by: mocactl test/sbx-templates.test.ts 63 of 63 passed and tsc --noEmit is clean on head (the temporary worktree was removed afterwards); examples.test.sh on head under jq 1.8.2 (pass), plus the old-line positive control (fail)
Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Summary
Follow-up at 085c98e (7880b3c..085c98e). Our approval at 7880b3c was dismissed only because of the inherited jq bug from #766. Both open items are now fixed:
- examples.test.sh (inherited from #766): merged in through cbec01c. The merged change is cbec01c (#766's jq fix in examples.test.sh, +3/−2), byte-identical in every PR of the stack. I checked it on jq 1.8.2: both shipped examples (
default.json,django__django-11133.json) pass, and so do the edge cases (both aliases, missing, <128, string, vcpus 0/33), which fail as they should.deploy-scriptsis green. --gate-recordstat-then-read (clawgenti's CodeQL suggestion, which we +1'd): 61a6935 opens the file once, sizes it withfstatSync(fd), readsreadFileSync(fd)from the same descriptor and closes it infinally(templates.ts:293-301). An open error still lands in thecannot read --gate-recordcatch. CodeQL is green. A FIFO or pipe path now blocks inreadFileSyncand is no longer refused by size, but that is the user's own path and not worth a change.
Our two nits are still open and don't block this: envelope and quota values from GET /v1/policy are printed without sanitizing (templates.ts:90), and the dry-run differs from the create on id case and visibility (dry-run.ts:79).
Author: webchang (MEMBER — maintainer)
Agent/IDE config (.claude/.vscode): none
Commits: new own commits signed off: yes
CI status: 17/17 pass.
AI-assisted review, approved by a maintainer before posting.
…hecked against the templates quota
A template whose builds all failed, were cancelled or were retired holds
no templates slot, but the templates quota was checked only for a new
id. A subject could bring such templates back with
POST /v1/templates/{id}/builds, or a create on its own id, and go past
quota.templates. The check now applies whenever the template does not
hold a slot yet. Test: checks the templates quota when a template that
holds no slot gets a new build.
Refs rossoctl#737
Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
…ammar The examples test still matched images with the old pattern (any non-space, non-@ text, then a digest), so a sample the policy refuses, such as Images/x@sha256:..., passed it. The check now uses the distribution reference grammar as the policy's isPinnedImage does (an optional host[:port]/, lowercase path components, no tag, at most 255 characters before the @), and the test runs the filter on references the policy accepts and refuses. Refs rossoctl#737 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
… owns in any status Since a failed or cancelled-only template holds no templates slot, a create-then-cancel loop freed both templates and buildsQueued every time, so nothing bounded the template ids, catalog documents and provenance streams one subject opens. A new per-subject quota, owned, counts the ids a subject owns in any status and is checked for a new id only, so the subject's own ids still take new builds. A policy that does not set it gets 200 (DEFAULT_OWNED); a stored policy without the field stays valid. GET /v1/quota shows it, and quota_exceeded names it. Tests: bounds the template ids a subject owns in any status, applies the default owned quota to a policy that does not set one, and the policy check refuses a malformed owned. Refs rossoctl#737 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
It counts template ids in any status, retired ones included, and a retired id is spent for good; so a user who retires as they go reaches it in time, and only an admin raises it. The CHANGELOG and design §4 say so. Refs rossoctl#737 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Summary
Follow-up at 6c08f5d (085c98e..6c08f5d). The only change is a merge of #766's tip (ef65b8a). Its diff is byte-identical to #766's own 4 new commits (cbec01c..ef65b8a): the templates quota is now checked for a no-slot template's new build, a new owned per-subject quota (default 200), and the examples test's M1 check now uses the reference grammar. No mocactl files changed in this push.
One suggestion, inline: sbx quota and sbx policy don't show the new owned quota yet.
Our two earlier nits are still open and don't block: the GET /v1/policy envelope and quota values are printed without sanitizing (templates.ts:90), and the dry run differs from the server on id case and visibility (dry-run.ts:79).
Author: webchang (MEMBER — maintainer)
Agent/IDE config (.claude/.vscode): none
Commits: 5 new (4 from #766 + merge), all signed off: yes
CI status: all checks pass.
AI-assisted review, approved by a maintainer before posting.
| limitLine('templates', q.templates) + | ||
| limitLine('buildsQueued', q.buildsQueued) + | ||
| limitLine('active', q.active) + | ||
| limitLine('sandboxes', q.sandboxes), |
There was a problem hiding this comment.
suggestion: #766 (merged here in 6c08f5d) adds a fourth template quota, owned. It is required in GET /v1/quota and appears as quota.owned in the policy, and it is in effect a lifetime cap per subject. sbx quota prints only templates, buildsQueued, active and sandboxes, and sbx policy (line 99) prints only templates, builds queued and active. So a user refused with 429 quota_exceeded {quota: owned} can't see owned 200 of 200 without --json. Consider adding limitLine('owned', q.owned) here, owned to SbxQuotaView and the policy quota type in api.ts (optional on the policy, since a stored policy may omit it, so print the default 200 or default), and the value to the sbx policy line.
…xit 130, and posts nothing more
- Ctrl-C during the wait for a queue slot did not stop the create loop: the wait rethrew the 429,
and the next spec's create was still POSTed. createOne checks the signal before each POST and
after its wait and throws a distinct Interrupted (not the 429); cmdCreateTemplates checks it at
the top of each pass and on any failure, and ends with exit 130 ("sbx: interrupted (exit
130)"), as sbx run and sbx rm do. No later spec is posted.
- Ctrl-C during `templates follow` exited 1 as a failed build: pollBuild throws the same
Interrupted, and follow returns 130 for it (the build goes on; `templates cancel` withdraws it).
SBX_EXIT gains interrupted: 130; the usage and the user guide (an "Exit 130" entry beside "Exit 5")
say so.
Tests (fail with the fix reverted): many creates: Ctrl-C during the wait for a queue slot is exit
130, and posts nothing more (one POST only, no quota message; an abort before the first POST sends
none); follow: Ctrl-C is exit 130, not a failed build.
(cherry picked from commit c9e7666)
(cherry picked from commit 67796c4)
Ports rossoctl#767 review fixes
Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
…ur own id is a new build The client's "already yours" branch could not be reached against the control plane, which answers a create on the caller's own id as a new build of it (or the build of the same inputs, `reused`), never 409; and when it did run it made up an answer (`reused: true` for the newest build) that no server sent. The branch is gone: a 409 template_exists is always a refusal (exit 1). It names the other owner, or says the deployment declared the id and an admin can hand it over; and if the template ever reads as the caller's own, it prints the server's refusal as sent. The usage line and the user guide say that a create on your own id is a new build of it. Test (fails with the fix reverted): 409 template_exists on an id read as your own: the refusal as sent, no answer made up (replaces the test that followed your own newest build). (cherry picked from commit 98b0a1e) Ports rossoctl#767 review fixes Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
…es the terminal The dry run printed the failed rule, its message and each note straight to the terminal; they carry the policy's text (a profile name, an envelope value), which comes from the control plane, and the spec's. The profile, the rule, the message and each note now go through sanitizeRemote. The user guide and the usage line also stop saying `--dry-run` sends nothing: it creates nothing, but reads the policy (`mocactl sbx policy`), so it needs the login and the control plane (exit 3 or 4 without them). Test (fails with the fix reverted): sanitizes the policy's text (a profile name, an envelope value) in what it prints (control sequences in the default profile's name and an envelope value; none reaches stderr). (cherry picked from commit 5ff17fb) (cherry picked from commit 0f48868) Ports rossoctl#767 review fixes Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
…andle, and goes with one --spec readFileSync(--gate-record) had no size cap and ran before any request, so a wrong file (an image tarball) was loaded whole. The file is now opened once, sized with fstat on that handle, refused as a usage error naming the limit when over 1 MiB (the create routes' body limit, exit 2), and read through the same handle, so the size checked is the file read. --gate-record with more than one --spec is a usage error too, as --id and --image are: a gate record is one image's. The usage and the user guide say both. Test (fails with the fix reverted): refuses bad usage locally, before any request (a gate record with two specs; a file of 1 MiB + 1 byte; no request sent). (cherry picked from commit 9ce5ee9) (cherry picked from commit 61a6935) Ports rossoctl#767 review fixes Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
…checks The dry run is meant to fail on the rule the server would refuse, and the server's create checks were tightened by the ported policy fixes. The dry run now does the same: M1 takes the distribution reference grammar (optional host[:port]/, lowercase path, no tag); M7.guest refuses guest_ram_mb and guest_mb together; a gate record sent or named is checked (X1, X1.image) under every profile; X12 applies under every profile. A gate record sent with a profile that requires none (base) is no longer reported as a refusal (`gate.profile`): the server checks and admits it, untrusted, so the dry run says so in a note. Tests (fail with the fix reverted): checks a gate record sent or named, and X12, under every profile; new M1 and M7.guest cases in "refuses %s"; the base case of the self-profile test. (cherry picked from commit 7880b3c) Ports rossoctl#767 review fixes Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
…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]>
Part of #737. Stacked on #766 (self-serve create, gated by policy): this branch contains that PR's commits, and its own change is the last 2 commits (plus one merge of its tip). Once it merges, only those remain.
What it does: mocactl becomes the authoring client for self-serve templates. Two signed-off commits:
sbx templates create(with--dry-run, and--gate-recordsent byte for byte),build,follow,cancel, and a fullershow;sbx quotaandsbx policy;ruleandquota, and a wait that times out exits 5.Notes for review:
--dry-run(dry-run.ts) mirrors the server's create checks in the same rule order, without the registry, trusted-record and quota checks, which only the server can answer. The two need to stay in step.Tests on the tip:
10 files, +1,771 / -39, counted against the stacked PR's tip.
Assisted-By: Claude Code