Repository navigation
feat(control-plane,mocactl): admin quotas, and rejecting a registered build after the fact - #786
Conversation
The quota route names another subject: a person's login from either real provider, `github:<numeric id>` or `oidc:<provider sub>` (rossoctl#701), and never a synthetic `test:<n>` user. MEMBER_SUBJECT_RE is built from the same OIDC_SUB_PATTERN as SUBJECT_RE, so the two cannot drift, and MEMBER_SUBJECT_FORMS is the grammar as a refusal states it. This is the same hunk the template admin and enrollment changes carry, byte for byte: whichever lands first brings it, and the others merge onto it as is. Refs rossoctl#748 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
Template lifecycle spec §5.2 and §6.2. Until now the template quotas
(templates, buildsQueued, active) were one deployment-wide value: an admin
could not give one subject more than another without changing everyone's.
- PUT /v1/quota/default and PUT /v1/quota/{subject} (admins): the
deployment default, or one subject's override (`github:<numeric id>` or
`oidc:<provider sub>`, MEMBER_SUBJECT_RE); a body of null removes an
override. Overrides live in the policy (`quotaBySubject`), so each
change is a new `policy` record naming the admin, whose digest the
answer carries, with the quota before. Enforced at once on creates,
queued builds and activations (quotaFor: the override, else the
default).
- GET /v1/quota shows the limits that apply to the caller and
`quotaSource` (`subject` or `default`).
- The policy check refuses a quotaBySubject key that is not a subject,
and a malformed override, as it does a malformed default.
- openapi.yaml: Quota in the policy (quotaBySubject), quotaSource, the
new route.
Refs rossoctl#748
Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
Template lifecycle spec §5.2. A build that passed policy at registration
but later turns out wrong (a rule found broken, a bad image) could not be
withdrawn: it stayed usable until its owner retired it.
- POST /v1/templates/{id}/builds/{build}/reject {reason}: admin only, a
reason required, a registered build only (by build id or handle). The
build becomes `rejected` with reason.rule `admin`, its activation
leases go, and a create naming it answers 400 unknown_template, as for
a build policy rejected at registration.
- It takes retire's path (retireBuilds, in a `reject` mode): refused
409 build_in_use under a live sandbox, idempotent (an already rejected
build is answered with record null), and a `reject` record names the
admin, `from`, the reason and `buildRecord`, the digest of the build's
`build` record (buildRecordOf), as a retire record does.
- A host holding it is told to stop its worker (the wanted state's
`stop`), as for a retired build, and its `detached` report is taken.
- openapi.yaml: the route, and `admin` as a rejection's rule.
Refs rossoctl#748
Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
The client part of per-subject quotas (template lifecycle spec §5.2):
`mocactl sbx templates quota TARGET --templates N --builds-queued N
--active N` sets a subject's quota (TARGET `github:<numeric id>` or
`oidc:<provider sub>`) or the default (TARGET `default`); `--clear`
removes a subject's override. Flags are checked before any request: all
three limits as whole numbers, or --clear alone, and never --clear on the
default.
Like the other admin writes it names the control plane it writes to,
and refuses a login issued for another control plane or by another
deployment's issuer before any read or write (loginMismatch). It then
reads the value (`GET /v1/policy`), writes (`PUT /v1/quota/{target}`)
and compares the answer's `before` with its read: it prints old -> new
with the policy's digest and record, and exits 1 loudly when the value
changed between its read and its write.
loginMismatch and raced are the same code the enrollment change's
`sbx admin subjects` carries, byte for byte, so the two merge onto one
copy.
Refs rossoctl#748
Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
- openapi.yaml's version goes to 1.9.0 (additive: the quota write, the policy's quotaBySubject, GET /v1/quota's quotaSource, the reject route), and the API changelog says what each change is. - http-api.md lists the two admin routes and what they do. - The template lifecycle spec gains §5.2, the admin's actions: per-subject quotas kept in the policy, reject after the fact on retire's path, mocactl's read-write-compare quota write, and the known limits; §6.2 says a subject's quota may be an admin's override. Refs rossoctl#748 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
…tract
The contract test lists every call SandboxApiClient makes and checks it
against openapi.yaml: `sbx templates quota` added two, GET /v1/policy
(read before the write) and PUT /v1/quota/{subject}, with the fields the
command reads from each.
Refs rossoctl#748
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
This PR is stacked on #781, and this review covers only what it adds on top (the last 6 commits, d7d994e..7459997). The admin checks are correct: only an admin can call PUT /v1/quota or reject a build (the owner gets 403 on reject), subjects are checked against MEMBER_SUBJECT_RE in the handler and in policyProblems, and the host stop/detached handling for admin-rejected builds matches what retire does. There are two race defects. PUT /v1/quota/{subject} reads and writes the policy in two separate steps, so concurrent admin writes silently lose each other's overrides, and the mocactl before/read check cannot see this when the two writes target different subjects. A reject can also lose a race with a concurrent activation, which then writes a live lease onto the rejected build that counts against the subject's active quota. A smaller TOCTOU remains: in-use is checked before the catalog update, so a sandbox created in that gap can still land on the build. It is the same gap retire already has, so it is not flagged inline.
Author: webchang (MEMBER — maintainer)
Areas reviewed: control-plane quota handlers and policy validation, reject-after-the-fact (retireBuilds reject mode), host wanted-state/worker report, activation lease path, mocactl sbx templates quota, openapi/CHANGELOG/http-api/spec §5.2 docs, tests, commit conventions/DCO
Agent/IDE config (.claude/.vscode): none
Commits: 6 commits, all signed-off: yes
CI status: passing (all 17 checks green, incl. DCO, CodeQL, deploy-scripts, k8s-kind-e2e)
1 must-fix, 1 suggestions, 0 nits.
Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).
| 'invalid_request', | ||
| `the quota's target is 'default' or a subject, ${MEMBER_SUBJECT_FORMS}`, | ||
| ); | ||
| const { policy: cur } = await store.current(); |
There was a problem hiding this comment.
must-fix: Concurrent admin writes can silently lose updates. putQuota calls store.current() here and store.set(next, ...) at L1332. FilePolicyStore serializes each call on its own (template-policy-store.ts serial()), but not the read and the write together. Take two admins setting quotas for github:1 and github:2 at the same time: both read the same cur, each builds next from it with only its own key added, and the second set wins. The first subject's override is gone, with a valid policy record and a 200 to both callers. A concurrent PUT /v1/policy loses the same way. The mocactl race check (canonical(r.before) !== canonical(read) in commands.ts) does not catch this: each target's before matches its own read, so both clients exit 0. The PR body and spec §5.2 promise that a value changed in between is reported. Suggested fix: add update(fn: (cur: Policy) => Policy, subject) to PolicyStore and run the whole read-modify-write inside FilePolicyStore.serial(). putQuota should then compute before and next inside that callback. Add a test that fires two putQuota calls for different subjects with Promise.all and checks that both overrides survive.
| ...(reason === 'first_use' ? { reason } : {}), | ||
| }, | ||
| }); | ||
| await cat.update(d0.id, async (cur) => ({ |
There was a problem hiding this comment.
suggestion: A reject can lose a race with a concurrent activation. activate resolves target from d0 (L793, read before any lock), and takeLeaseLocked writes the lease here without re-checking cur's build status. Reject's catalog update (retireBuilds, L1066 on) runs on the catalog's per-id queue and does not take activationLock. If the reject lands between activate's read and this update, the newly rejected build gets a live lease: activate answers 200, writes an activate record, and leasedBy (L772, which does not filter by status) counts the lease against the subject's active quota for up to leaseSeconds (at most a day). The first-use path through requireActive behaves the same way. Retire already had this gap; reject adds a second path into it. Suggested fix: run the catalog update in retireBuilds under activationLock(cat), so leases and reject/retire serialize. Also, or instead, re-check target's status from docs before the record, and in this cat.update callback throw template_unavailable when the build is no longer registered. Separately, leasedBy could count only registered builds.
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Summary
The range adds MEMBER_SUBJECT_RE (verified byte-identical to #774's commit 21de03f: the identity.ts and identity.test.ts hunks are the same and the blobs match), admin-only PUT /v1/quota/{subject|default} with per-subject overrides kept in the policy, admin-only reject-after-the-fact for registered builds on retire's code path, the mocactl sbx templates quota command, openapi 1.9.0 docs and contract tests. Authz is right (both routes check isAdmin, and the owner cannot reject), and the new quotas are applied wherever the old default was read (createBuild templates/buildsQueued, takeLeaseLocked active, getQuota). The main problems are concurrency: the quota write is a read-modify-write of the whole policy with no compare-and-set, so concurrent writes lose updates, and the client's 'exit 1 if it changed' check runs only after the write has already landed. A reject can also race with a concurrent activation or sandbox create.
Author: webchang (MEMBER — maintainer)
Areas reviewed: TypeScript, OpenAPI, CLI
Agent/IDE config (.claude/.vscode): none
Commits: all signed-off: yes
CI status: 16 pass, one check pending
Inline: 1 must-fix, 2 suggestion, 1 nit. The head 7e14d98 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 d7d994ed..74599971, as the body asks.
AI-assisted review, approved by a maintainer before posting.
| 'invalid_request', | ||
| `the quota's target is 'default' or a subject, ${MEMBER_SUBJECT_FORMS}`, | ||
| ); | ||
| const { policy: cur } = await store.current(); |
There was a problem hiding this comment.
must-fix: Lost update: putQuota reads the whole policy (store.current()), builds next from it, then writes the whole policy with store.set(next, …). FilePolicyStore serializes current() and set() separately, not as one unit, and there are awaits in between. So two concurrent writes, such as admin A's PUT /v1/quota/github:1 and admin B's PUT /v1/quota/github:2 (or a PUT /v1/policy), both start from the same cur, and the second set silently drops the first one's change. The before each one answers looks correct, so mocactl's check does not catch it either: it compares only its own target's value. Suggested fix: add an update(mutate) (or set(policy, subject, {expectRecord})) to PolicyStore that runs the read, mutate, validate and write inside one serial() step, and use it from putQuota (and putPolicy). Add a test that runs two putQuota calls for different subjects together and expects both overrides to survive.
| return SBX_EXIT.failed; | ||
| } | ||
| c.io.err(`sbx: admin write to ${sanitizeRemote(c.url)}`); | ||
| const pol = (await c.api.getPolicy()).policy; |
There was a problem hiding this comment.
suggestion: This is detection after the write, not compare-and-set: by the time canonical(r.before) !== canonical(read) finds a difference, the PUT has already replaced the other writer's value, and the command exits 1 with the new value in force. The help text ('exit 1 if it changed between the read and the write') and the PR body suggest the write is guarded. Either make it a real CAS (have the server take an expected value or the policy record digest, e.g. If-Match: <policy record> or {quota, expect}, and answer 409 on a mismatch, with nothing written), or say plainly in the help and the error message that the other admin's value was overwritten and has to be restored by hand. The error text already prints read / before / now, which helps, but 'write again if need be' undersells the fact that someone's change was just discarded.
| ...x, | ||
| status: 'rejected' as const, | ||
| leases: [], | ||
| reason: { message: String(reason), rule: 'admin', step: 'rejected' }, |
There was a problem hiding this comment.
suggestion: Reject (like retire, whose path it reuses) can race with an activation or a sandbox create. (1) takeLeaseLocked runs under activationLock, but retireBuilds does not take that lock, and the lease write cat.update(d0.id, cur => …withLease…) does not re-check cur's target status. An activation that read the build as registered therefore still appends an activate record and writes a lease onto the now-rejected build after the reject cleared leases: []. place() skips non-registered builds, so the activation then answers 200 with host: null, and the stray lease counts against the subject's active quota (leasedBy does not filter on status) until it expires. (2) buildsInUse is read before the catalog update, and createSandbox resolves the build before store.create. So a sandbox created in that window ends up live on a rejected build, which the documented 409 build_in_use is meant to rule out. For an admin action meant to stop a build found broken, both are worth closing. Suggestions: in the lease's cat.update, throw template_unavailable if the target in cur is no longer registered, and take activationLock in retireBuilds for the reject and retire modes. For sandboxes, re-check buildsInUse after the catalog write and report it, or re-check the build's status in createSandbox after store.create.
| ) | ||
| out.push('trustedGateRecords must be sha256 digests'); | ||
| const q = o.quota; | ||
| const quotaOk = (x: unknown): boolean => { |
There was a problem hiding this comment.
nit: quotaOk checks only that the three counters are present, but putQuota stores the request body as is (next.quotaBySubject[subject] = body, next.quota = body). A body like {templates:1,buildsQueued:1,active:1,note:"…"} (any extra keys, up to the body cap) is accepted and kept in policy.json and in every later policy record. Store a normalized {templates, buildsQueued, active} in putQuota, or reject unknown keys here.
clawgenti
left a comment
There was a problem hiding this comment.
Summary
Re-review of the push since my last review (7459997..7e14d98, review 5883318729). 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/i26-retire into pr/i25-quotas-reject", 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 must-fix, 1 suggestion still apply: none of the files they cite changed in this push. The earlier must-fix is still open: no file it cites changed.
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 pr/i26-retire's reviewed head: the per-subject quota lock and the owner charged for an admin's build, slots only for live builds, sticky placement and hostManaged, retire under the activation lock with the status re-check in takeLeaseLocked, build_in_use by build id, and a retired build's draining worker keeping its host slot. Conflicts and resolutions: - packages/control-plane/src/sandbox-handlers.ts (create): this side's quotaFor(pol, p.sub) against the other's pol.quota with normalizeSpec. Kept normalizeSpec and the reuse key from the built spec; the quota is now quotaFor(pol, charged), the template owner's override or the default, read for the owner whose quotaLock covers the check and write. - packages/control-plane/src/sandbox-handlers.ts (retireBuilds): this side's reject mode (ended(), the registered-only check, the rejected status with reason.rule admin) inside the other side's activation lock and build-id in-use check. The lock comments name the reject too; the re-check in takeLeaseLocked already refuses a rejected build (template_unavailable, as any build no longer registered). - packages/control-plane/src/host-handlers.ts: hostWanted stops an admin-rejected build as a retired one, and clears its repeated-refusal memory too; hostManaged gates both; the report doc names both the admin-rejected detach and the repeated refusal. - docs/api/openapi.yaml: getQuota, hostWanted and hostWorkerReport descriptions carry both sides (quotaSource and the counted builds; sticky placement, the draining slot, imported builds and the reject; the repeated refusal and the reject's detach). Beyond the conflicts: rejectedByAdmin moves to activation.ts with endedWithWorker, so place() counts an admin-rejected build's draining worker against its host's activeLimit like a retired one's; the spec's reject bullet says it runs under the activation lock and keeps that slot. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
…e policy store
PUT /v1/quota/{target} read the whole policy and wrote it back in two
separate steps of the policy store, so two admin writes made together
(two subjects' overrides, or a quota and a PUT /v1/policy) could start
from the same policy, and the second dropped the first's change while
both answered 200.
PolicyStore gains update(mutate, subject): FilePolicyStore runs the
read, the change, the validation and the write in one serial step.
putQuota computes `before` and the new policy inside it. Test: two
quota writes for different subjects run together both survive.
Refs rossoctl#748
Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
putQuota stored the request body as it came, so a quota carrying any other key was accepted and kept in policy.json and in every later policy record. It now refuses a key beyond templates, buildsQueued and active (400 invalid_request) and stores a new object of those three; policyProblems refuses an override with another key too, so a PUT /v1/policy cannot keep one either. Test: a quota with another key is refused by both routes, with no policy record written, and a stored override holds the three alone. Refs rossoctl#748 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
sbx templates quota compared the answer's `before` with its own read
only after the write had landed, so a value another admin wrote in
between was already overwritten when the command reported it.
PUT /v1/quota/{target} takes an optional `?expect=` (JSON: the quota
the client read, null for no override): inside the policy store's one
read-change-write step, a target whose quota is not that value now is
refused 409 quota_changed (a new error code) with nothing written.
mocactl sends the value it read; on quota_changed it reads again and
reports the value now, exit 1, nothing written. Its help, the spec,
openapi, http-api and the API changelog say so.
Tests: the write with a matching, a stale and a malformed expect, for
a subject and the default (control plane); the command's 409 path, its
query, and an expect of no override (mocactl).
Refs rossoctl#748
Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
…fter its create resolved it The review found that a reject, like the retire whose path it takes, could race a sandbox create: the create resolves the build before it stores the sandbox, and the reject's in-use check reads the sandboxes before its catalog write, so a sandbox created in between was left live on the rejected build. A sandbox create now re-reads its build's status and stores the sandbox under the activation lock (createUnlessEnded), which a retire and a reject hold around their in-use check and their write: either the sandbox is stored first and the retire or reject answers 409 build_in_use, or the build ended first and the create is refused with nothing stored (410 template_retired, or 400 unknown_template for a rejected build). leasedBy counts only a registered build's leases. The activation side of the same race (a lease written onto a build rejected meanwhile) is closed by the merge of the retire branch: a reject runs under the activation lock and takeLeaseLocked re-reads the build's status under it. Tests: a reject waits for an activation taking its lease, then drops it (the active quota shows none used); a create that resolved the build before a reject, and before a retire, stores nothing. Refs rossoctl#748 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
…its host slot The merge of the retire branch made place() count the worker of a build an admin rejected after the fact, while it drains a live sandbox, against its host's activeLimit, as a retired build's is counted. This tests it: the slot is held while a sandbox runs on the worker and free once none does. Refs rossoctl#748 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
… retire or reject createUnlessEnded took the deployment-wide activation lock, so every sandbox create waited on every other create and on every activation. It now takes a lock keyed by template id (templateUseLock, a SubjectQueue). A retire or a reject takes that template's key inside the activation lock it already holds, always in that order (activation, then template), and a create takes only the template's key, holding no other lock meanwhile: no lock cycle. The create-versus-retire/reject race stays closed per template, and creates on different templates run in parallel. Test: with one template's create held inside its store write, a create on another template completes, and a retire of the first waits for its create and answers build_in_use. The existing race tests still pass. Refs rossoctl#748 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
openapi, http-api and the client's putQuota and sbx templates quota docs say how `?expect=` is sent: the quota read, as JSON, percent- encoded as a query value (an example given), or `null` for a subject with no override; key order and spacing do not matter. Test: the control plane takes the raw percent-encoded forms. Refs rossoctl#748 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
|
Merged #781's reviewed head into this branch. A build's quota is now charged to the template's owner, and reject runs under the same guards as retire. Start tip: 90a41d5 (the merge of pr/i26-retire, #781's reviewed head, into this branch). New tip: 79d8582. Maintainer threads1.
|
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Follow-up to our 7e14d98 review. I compared the old and new heads: 7e14d98 is an ancestor of the new head. The range adds the merge 90a41d5 (#781's reviewed head 508baff) plus 7 signed-off TS/docs commits from this PR (dabfd19 → 79d8582). All 4 earlier items are fixed and tested: (1) PolicyStore.update() runs the read, mutate, validate and write in one serial() step, and putQuota computes before inside it. (2) ?expect= is a real compare-and-set, answering 409 quota_changed with nothing written, and the old after-the-write check is gone from mocactl. (3) retireBuilds takes activationLock → templateUseLock(id), takeLeaseLocked re-reads the status, leasedBy counts only registered builds, and createUnlessEnded re-reads the build and stores the sandbox under the per-template lock (consistent lock order, so no cycle). (4) quotaBody refuses extra keys and stores only the three counters, and policyProblems refuses extra keys in quotaBySubject entries.
Author: webchang (MEMBER — maintainer)
Areas reviewed: TypeScript (control-plane, mocactl), OpenAPI/docs
Agent/IDE config (.claude/.vscode): none
Commits: 7 new non-merge commits in this PR's range, all signed-off: yes
CI status: deploy-scripts is FAILING ("Run deploy shell tests", exit 2 after 5m03s, so it's not the old 5-min cancel, since ci.yml is now 10 min). Everything else passes, including check, lint, and k8s-kind-e2e.
CI: the red deploy-scripts comes from #766, not this PR. This PR's own commits touch no shell. Every branch stacked on #766 has failed "Run deploy shell tests" since a187e99, while main, #757 and #771 are green. The cause is deploy/sbx/template-onboarding/tests/examples.test.sh:22: jq parses A and B as $g | … as (A and B) as $g | …, so $g is bound to a boolean and every sample spec fails the check. Parenthesising the right side of the and fixes it (reproduced with jq 1.8.2). It is already raised as a must-fix on #766: #766 (comment). Please don't merge this PR until that fix has cascaded up the stack and deploy-scripts is green here.
AI-assisted review, approved by a maintainer before posting.
clawgenti
left a comment
There was a problem hiding this comment.
Summary
This PR is stacked on #781, so this review covers only its own increment, 508baffc..79d8582a (23 files, +1528/−102; the full diff is over GitHub's 20k-line limit). It adds admin quotas (PUT /v1/quota/{default|subject}, an atomic policy-store update, and a compare-and-set through ?expect=), an admin-only reject of a registered build after the fact, and mocactl sbx templates quota. The authz is correct: both handlers check isAdmin, and the subject grammar is enforced in the route and in policyProblems. One must-fix: the retire/reject in-use check reads a template doc fetched before the locks are taken, which reopens the create-vs-reject race that 4b2768d/086f3dc6 set out to close. There is also one suggestion and one nit, both inline.
PR body (nit): it still says d7d994ed..74599971 with 19 files, +1,034/−49. It does not mention dabfd19, 5ab19eb, fe20f4a (the server-side CAS and the new 409 quota_changed), 4b2768d, 086f3dc or 2d3df2e.
Author: webchang (MEMBER — maintainer)
Areas reviewed: TypeScript (control-plane quota/reject handlers, policy store, locks; mocactl quota command), OpenAPI 1.9.0/CHANGELOG/http-api/spec, tests
Agent/IDE config (.claude/.vscode): none
Commits: 116 commits, all signed-off: yes
CI status: failing. deploy-scripts ("Run deploy shell tests", exit 2) fails, and #781 at the base of this stack fails the same way. The other checks pass.
Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).
| await activationLock(cat).run('activation', () => | ||
| templateUseLock(cat).run(d0.id, async () => { | ||
| // Read before the catalog update, so no store lookup runs inside it. | ||
| const inUse = await buildsInUse(deps, d0.builds.filter(which), seconds(deps)); |
There was a problem hiding this comment.
must-fix: inUse is computed from d0.builds, but d0 was read by visibleTemplate at the top of retireBuilds, before activationLock and templateUseLock were taken, and the wait for the activation lock can be long. The cat.update callback then checks cur!.builds.filter(which) against an inUse map keyed by the stale builds' buildId. Here is how it goes wrong: a build is still building when d0 is read (no sha256: buildId, no worker yet) and registers before the lock is granted. A sandbox created in that window isn't counted, so the reject or retire goes through with a live sandbox on the build. That breaks the invariant in the comment above ("either is stored before the in-use check or sees the build ended").
Suggested fix: inside the template use lock, re-read the doc (const cur0 = await cat.get(d0.id)) and compute buildsInUse from cur0.builds.filter(which). Alternatively, have the update callback check that each target's buildId matches one that inUse was computed for, and refuse or retry if it doesn't. A test that registers the build between the read and the lock would pin this down.
| } | ||
| c.io.err(`sbx: admin write to ${sanitizeRemote(c.url)}`); | ||
| const pol = (await c.api.getPolicy()).policy; | ||
| const read = target === 'default' ? pol.quota : (pol.quotaBySubject?.[target] ?? null); |
There was a problem hiding this comment.
suggestion: read is sent verbatim as ?expect=, and on the server quotaBody(v) refuses any key beyond the three counters with 400 invalid_request. But policyProblems refuses extra keys only in quotaBySubject overrides, not in the default quota. So a default quota with an extra key, set through PUT /v1/policy or already in an older policy.json, makes every later mocactl sbx templates quota default … fail with 400. That also contradicts openapi's "the three counters are compared".
Suggested fix: send only {templates, buildsQueued, active} picked from read, and/or have the server compare only those three counters when it parses expect. Tightening policyProblems on the default isn't a good fix on its own, because FilePolicyStore.read() validates with it and would stop loading existing files.
| buildsQueued: { $ref: '#/components/schemas/LimitUse' } | ||
| active: { $ref: '#/components/schemas/LimitUse' } | ||
| sandboxes: { $ref: '#/components/schemas/LimitUse' } | ||
| quotaSource: |
There was a problem hiding this comment.
nit: getQuota always emits quotaSource, but it isn't in this response's required: [subject, templates, buildsQueued, active], so generated clients will type it as optional. Add it to required if that fits the contract-test conventions.
Signed-off-by: Rong Chang <[email protected]>
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Summary
Follow-up at 772ac04 (79d8582..772ac04, merge-only: #766's jq fix up the stack; this PR's own files are unchanged). deploy-scripts is green now.
After our approval at 79d8582, clawgenti posted a must-fix that is still open at this head, and I +1 it: inUse is computed from the stale d0.builds (sandbox-handlers.ts:1204). d0 is read by visibleTemplate before activationLock and templateUseLock are taken. A build that is still building at that read registers and gets its sha256: buildId while retire or reject waits for the lock. A sandbox created in that window carries the new buildId, which inUse (keyed by the stale ids) never sees. The reject then goes through with a live sandbox on the build, which breaks the invariant in the comment above it. Fix: re-read the template inside the use lock and compute buildsInUse from that. A test that registers the build between the read and the lock would cover it. The same stale read starts in #781 (:1155).
Still open, not blocking: clawgenti's suggestion on ?expect= keys (commands.ts:470) and their nit on quotaSource in openapi required (openapi.yaml:2450).
Author: webchang (MEMBER — maintainer)
Agent/IDE config (.claude/.vscode): none
Commits: new own commits signed off: yes
CI status: 9 pass, 7 pending; deploy-scripts green.
AI-assisted review, approved by a maintainer before posting.
clawgenti
left a comment
There was a problem hiding this comment.
Summary
Follow-up at 772ac04. The range 79d8582a..772ac047 is merges only. They bring #766's jq fix (cbec01ca) up the stack and change just deploy/sbx/template-onboarding/tests/examples.test.sh (+3/−2). The fix is correct: the parentheses end the guest_mb check and its $g binding before the vcpus clauses. This PR's own files are unchanged, and nothing new is found. deploy-scripts is green now.
The items from the previous review (79d8582) are all still open at this head:
- must-fix: the retire/reject in-use check reads stale
d0.builds(packages/control-plane/src/sandbox-handlers.ts:1204).d0comes fromvisibleTemplateat :1177, beforeactivationLock/templateUseLockare taken. SobuildsInUsenever sees a build that registers in that window, and a reject can go through with a live sandbox on it. Fix: re-read the template inside the use lock and buildinUsefrom that read. The same stale read starts in #781.
The rest are a suggestion and nits:
- suggestion:
?expect=sends the policy view as it was read (packages/mocactl/src/sbx/commands.ts:470). The server'squotaBodyrefuses any key outside the three counters. Project the view to{templates, buildsQueued, active}first. - nit:
quotaSourceis not in the getQuota 200requiredlist (docs/api/openapi.yaml:2450). - nit: the PR body still gives the range as
d7d994ed..74599971(19 files, +1,034/−49). Over508baffc..772ac047(#781's head..this head) it is 23 files, +1528/−102.
Author: webchang (MEMBER — maintainer)
Areas reviewed: TypeScript (control-plane, mocactl), OpenAPI/docs, Shell (the delta's examples.test.sh)
Agent/IDE config (.claude/.vscode): none
Commits: 121 commits, all signed-off: yes
CI status: passing
Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).
clawgenti
left a comment
There was a problem hiding this comment.
Clawgenti Code Review
PR #786 — feat(control-plane,mocactl): admin quotas, and rejecting a registered build after the fact
All checks pass. Ready for human review.
Summary
Reviewed the PR's own change (the quota/reject range, not the stacked #781/#784 content): the PUT /v1/quota/{subject|default} and POST /v1/templates/{id}/builds/{build}/reject handlers, the quota CAS (?expect=) path, the mocactl sbx templates quota command, and the openapi/docs updates, all read at the head SHA.
- Both new write routes are admin-gated (
isAdmin) before any store access; the quota body is allowlisted to the four counters (quotaBodyrejects extra keys, so nothing else in the request reaches the policy), and the reject reason is length-capped. - The quota write runs as one read-change-write step of the policy store, and the
?expect=compare-and-set throwsquota_changed(409) inside the update with nothing written — verified the error maps to 409 inerrors.ts. - Reject takes retire's path under the activation + template use locks, with the in-use check against a fresh read,
build_in_usewhile a live sandbox runs on the build, and lease-drop on the build record. The body's claims (idempotent second reject,400 unknown_templateon create viacreateUnlessEnded, openapi at 1.11.0 with the disclosed renumbering coordination on #784/#785) all check out against the code at head. - Extensive new test coverage (activation, sandbox-handlers, grant/CAS cases, mocactl quota CLI) and full CI green including CodeQL, Trivy, and shellcheck.
No must-fix, suggestion, or nit findings — the one known gap (the openapi subject path parameter having no pattern) is already disclosed in the PR body as a possible follow-up.
Author: webchang (MEMBER — maintainer)
Areas reviewed: TypeScript (control-plane, mocactl), OpenAPI/docs, security
Agent/IDE config (.claude/.vscode): none
Commits: 100 commits, all signed-off: yes (DCO check passing)
CI status: passing (all checks green; one transient pending check job on a duplicated run)
Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).
…r their locks, and no lease or sandbox lands on an ended build - An activation that resolved a build before a retire or an admin's reject could write its lease and `activate` record onto the build just ended: a retire and a reject now run under the activation lock, and takeLeaseLocked re-reads the build's status under it before any record (retired: 410 template_retired; rejected or otherwise not registered: 409 template_unavailable). - A sandbox create that resolved the build before a retire or reject could store its sandbox on it: the create now stores under a per-template use lock (createUnlessEnded) after one last read of the build's status (410 template_retired; 400 unknown_template for a build no longer registered). A retire or reject takes that lock inside the activation lock, always in that order; a create takes only its template's, so creates on different templates never wait on each other. - The in-use check was made from the request's first read: a build that registered and got a sandbox meanwhile could be retired under it. It is now made on the template read again under both locks, as is the active-session check this tree has. - build_in_use was decided by worker id: a sandbox on one build blocked retiring another build that shares its worker. A live sandbox now counts for the build it resolved to (buildsInUse); a record without a build id still counts for every build on its worker. - Each retire or reject record was appended after the catalog write, outside the locks: it is now appended inside the update, so a record that cannot be written leaves the build as it was, and a retry ends it with its record. - buildRecordOf matches a build's `build` record by its handle when it has one, so a build built and then rejected (its buildId stays its handle) cites its record; the host's removal report passes the build too. The API changelog says so. The activation tests' `registered` helper also builds another build of an existing template, through a shared reportBuilt. Tests (each fails with the fix reverted): judges build_in_use by build: a sandbox on another build of one worker does not block; a sandbox create that resolved the build before a retire is refused 410; a sandbox create waits for a retire judging use, then is refused 410; retires nothing when its retire record cannot be written; a retry retires it; cites the build record of a build built and then rejected; an activation that resolved the build before a retire writes no lease onto it; a retire (and a reject) waits for an activation taking its lease, then drops that lease; a sandbox create that resolved the build before a reject (or a retire) stores nothing. Also: judges build_in_use by worker for a sandbox record without a build id; on the template as read under the lock; creates on two templates do not wait on each other. (cherry picked from commit c33982a) (cherry picked from commit cf059b7) (cherry picked from commit bb42101) (cherry picked from commit b7ec347) (cherry picked from commit d5953e2) (cherry picked from commit 4b2768d) (cherry picked from commit 086f3dc) (cherry picked from commit 7022377) Ports rossoctl#781 and rossoctl#786 review fixes Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
…a live build shares is neither stopped nor removed Two builds can share a snapshot (the same manifest hash in two templates, or built again) or a worker id (two builds of one template from one image). The wanted state's `remove` was keyed only on the build being retired, so retiring one had the host agent uninstall a worker and delete a snapshot that a build still registered needed. - liveSnapshots(docs): the build ids and workers of every build whose use has not ended. A retired or admin-rejected build that shares either is left out of `stop` and `remove` (that build's own entries decide), a host's `removed` report of it is refused 409 build_in_use (so the live build keeps the host in heldBy), and its TemplateBuild reports `shared: true`. A rejected build is not live, so an admin's reject does not count as sharing with itself (the upstream branches' merge follow-up). Sharing is judged across the whole catalog, as the wanted state judges it. - One worker id is never listed in `run` for one build and in `stop` for another that shares it. - A retired or admin-rejected build's worker still draining a live sandbox counts against its host's activeLimit, as a registered one's does. - heldBy lists every host as last reported, stale ones too: it is the snapshot inventory, not placement, and a silent host still holds what it last reported. - A T.unique rejection naming a retired build says it is the same snapshot, and to change the spec or create again after the snapshot is removed. - mocactl's `templates retire --wait` is done at once for a `shared` build, and says why. openapi (TemplateBuild `shared`, heldBy) and the API changelog say so. (This tree's retire waits for removal through heldBy and reports no capacity for a retired build, so the upstream capacity changes for retired builds do not apply.) Tests (each fails with the fix reverted): never stops or removes a retired build whose snapshot or worker a build not retired shares; never lists one worker in run and stop for two registered builds that share it; keeps a silent host in heldBy; counts a retired (and an admin-rejected) build's worker draining a live sandbox against its host; says how to rebuild when the same snapshot belongs to a retired build; mocactl: is done at once for a shared build. (cherry picked from commit 52fd121) (cherry picked from commit 668d831) (cherry picked from commit 15e6655) (cherry picked from commit 6688bf1) (cherry picked from commit 508baff) (cherry picked from commit 2d3df2e) (cherry picked from commit 6e24cdb) (cherry picked from commit e895379) Ports rossoctl#781, rossoctl#785 and rossoctl#786 review fixes Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
…e policy store
PUT /v1/quota/{subject} read the whole policy and wrote it back in two
separate steps of the policy store, so two admin writes made together
could start from the same policy and the second drop the first's change
while both answered 200. PolicyStore gains update(mutate, subject):
FilePolicyStore runs the read, the change, the validation and the write
in one serial step; putQuota computes `before` and the new policy inside
it. The spec hunk is not ported (the fork's spec has no such section);
the change is in the API changelog instead.
activation.test.ts: two quota writes for different subjects made
together both survive (fails with the fix reverted).
(cherry picked from commit dabfd19)
Ports rossoctl#786 review fixes
Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
putQuota stored the request body as it came, so a quota carrying any other key was accepted and kept in policy.json and in every later policy record. It now refuses a key beyond templates, buildsQueued and active (400 invalid_request) and stores a new object of those three; policyProblems refuses an override with another key too, so PUT /v1/policy cannot keep one either. Upgrade note: a stored override with another key now fails the policy read (fail closed). activation.test.ts: a quota with another key is refused by both routes with no policy record written, and a stored override holds the three alone (fails with the fix reverted). (cherry picked from commit 5ab19eb) Ports rossoctl#786 review fixes Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
sbx templates quota compared the answer's `before` with its own read
only after the write had landed, so a value another admin wrote in
between was already overwritten when the command reported it.
PUT /v1/quota/{subject} takes an optional `?expect=` (JSON: the quota
the client read, null for no override): inside the policy store's one
read-change-write step, a target whose quota is not that value now is
refused 409 quota_changed (a new error code) with nothing written.
mocactl sends the value it read; on quota_changed it reads again and
reports the value now, exit 1, nothing written. The help, the mocactl
design spec §3.6, openapi, http-api and the API changelog say so.
Tests: a matching, a stale and a malformed expect, for a subject and
the default (control plane); the command's 409 path and its query, and
an expect of no override (mocactl). They fail with the fix reverted.
(cherry picked from commit fe20f4a)
Ports rossoctl#786 review fixes
Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
`sbx templates quota` sent the quota it read as `?expect=` as is. The control plane refuses an expect with a key beyond the three counters, and a deployment-wide quota stored through PUT /v1/policy may carry one (policyProblems checks only the overrides' keys), so every later write of the default would fail with 400. The command now sends only templates, buildsQueued and active (upstream also sends `owned`, a counter the fork does not have). openapi and the client's docs say how `?expect=` is sent: the quota read as JSON, percent-encoded (an example given), or `null`; key order and spacing do not matter. Tests: the control plane takes the raw percent-encoded forms; the command expects only the counters when the stored default carries another key (fails with the fix reverted). (cherry picked from commit 79d8582) (cherry picked from commit 852ee5a) Ports rossoctl#786 review fixes Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
GET /v1/quota always answers quotaSource (an override for the caller, or the default), and mocactl reads it; openapi now lists it in the answer's required fields. Upstream also lists ownedSource, a field of the owned quota the fork does not have. (cherry picked from commit 392a9ce) Ports rossoctl#786 review fixes Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Follow-up at a3ace50 (b5c28fd..a3ace50). This push has no commits of this PR's own. It merges main 1016d26 (#800, #768). The PR's net diff against main is byte-identical to the one at b5c28fd. I checked the hand resolution with git show --remerge-diff and a dropped-lines check against both parents. The conflict was in sbx/cli.ts. It keeps #768's NO_RECORD set beside this PR's TEMPLATE_SUBS/TAKES_BUILD/TAKES_TIMEOUT, each declared once. No conflict markers are left.
Still open from our review at e895379: clawgenti's spec:371. putPolicy (sandbox-handlers.ts:1681) still calls store.set(ctx.body, …) outside store.update, so a stale PUT /v1/policy drops a concurrent PUT /v1/quota/{subject}.
Author: webchang (MEMBER — maintainer)
Agent/IDE config (.claude/.vscode): none
Commits: no new own commits; one merge of upstream main 1016d26 (#800 worker-stop VM reaping, #768 --record / sbx token --renew-every); DCO pass
CI status: green (one check run still pending at drafting time)
AI-assisted review, approved by a maintainer before posting.
Brings in upstream main through ec0f840 (template tags, edits and owner transfer at API 1.8.0, subject trust for gate records at 1.9.0, the worker stop's VM reap, SBX_WORKER_AT_BOOT, setup.sh's Redis image guard; the host agent at 1.10.0 and activation at 1.11.0, merged) and retire at 1.12.0, by pr/i26-retire. Conflicts: - docs/api/CHANGELOG.md: this branch's quotas and reject section, renumbered 1.13.0, above retire's 1.12.0 and below. - docs/api/openapi.yaml: info.version 1.13.0; a build's reason.rule keeps this branch's `admin` note, beside main's attestation and gate floor fields. - 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, template retire, and admin quotas and build reject. - docs/reference/http-api.md: main's template admin row and the stack's rows, then this branch's admin row (API 1.13.0). - docs/specs/2026-11-03-template-lifecycle-and-provenance-design.md: §5.2 is main's admin text, then this branch's quotas and reject block; the status line names rossoctl#748. - packages/control-plane/src/template-policy.ts: PolicyStore keeps main's set(policy, subject, extra) and this branch's update(). - packages/control-plane/src/sandbox-handlers.ts: - createBuild takes main's owner-transfer retry and self-attestation checks, with the quota read per attempt for the owner charged (quotaFor) and `owned` from it; - retireBuilds takes main's ownTemplate for a retire, and for a reject a new adminTemplate (an admin only, on a template it can see); its catalog update checks the owner again under the template's lock (own), as main's other owner actions do; - createUnlessEnded beside main's ownTemplate, ownerCheck and the tag, edit and transfer handlers; the identity.js import once. - packages/control-plane/test/openapi-contract.test.ts: 30 enrollable routes (28 plus the quota and reject routes). - packages/mocactl/src/sbx/cli.ts: both sides' imports; main's TEMPLATE_ADMIN_SUBS and TEMPLATE_ONE_ID, with quota in TEMPLATE_SUBS and TEMPLATE_ONE_ID, where the one-argument refusal names a TARGET for quota. - packages/mocactl/test/contract.test.ts: 26 replies; both the /TAG and /SUBJ path rewrites. API version: this branch's quotas and reject move from 1.11.0 to 1.13.0 (openapi info.version, the changelog, change-policy and the two "API 1.11.0" mentions in docs/reference/http-api.md). Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
The merge of pr/i26-retire left a second import of MEMBER_SUBJECT_FORMS and MEMBER_SUBJECT_RE (TS2300, duplicate identifier); the first, beside the provenance import, stays. Refs rossoctl#748 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
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]>
|
#781's newest head (219d83f, with main d227d41) merged in. Besides resolving the conflicts, one change: The openapi version is 1.19.0 here. #785 also claims it (both stack on #781), so whichever merges later renumbers. Assisted-By: Claude Code |
Main brings retired build removal (API 1.19.0) and enrollment and the admin role through the API (API 1.20.0). This branch's admin quotas and build reject section becomes API 1.21.0. Conflicts: - docs/api/CHANGELOG.md: this branch's section on top as 1.21.0, then main's 1.20.0 and 1.19.0 as main has them; the reject bullet says an admin-rejected build is in `stop` but never in `remove`. - docs/api/openapi.yaml: info.version 1.21.0; hostWanted and hostWorkerReport keep main's `remove` and `removed` text and this branch's admin-rejected builds, which are stopped and take `detached` but are never in `remove` and take no `removed`. - docs/reference/change-policy.md: main's list, then "admin quotas and build reject"; control plane 1.21.0 in both places. - docs/reference/http-api.md: main's Subjects row, then this branch's Admin row (API 1.21.0); the 409 list keeps main's codes and adds quota_changed. This branch's "came with API" note moves to 1.21.0. - packages/control-plane/src/host-handlers.ts: main's `remove` and `removed` kept for retired builds; this branch's rejectedByAdmin builds are stopped as retired ones are and take `detached`, but are left out of `remove` (the push now checks for a retired build) and a `removed` for one is refused not_found. Doc comments describe both. - packages/mocactl/src/sbx/api.ts: both SbxQuota and SbxSubject. - packages/mocactl/src/sbx/cli.ts: both sides' imports; main's retire --wait text, then this branch's quota usage, then main's admin subjects usage. - packages/mocactl/src/sbx/commands.ts: both sides' imports; this branch's quotaText, quotaCounters and cmdSetQuota, then main's raced, subjectLine, cmdSubjects and cmdSubjectChange. - packages/mocactl/test/contract.test.ts: both sides' routes, calls and method names; the scripted replies are main's 32 plus putQuota, 33. Beyond the markers: the reject test's wanted answer gains main's `remove: []` and checks that a `removed` for the rejected build is refused. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
PUT /v1/policy reads the policy, checks it for a widening and writes it
under its own lock, as separate policy store calls. A quota write
(PUT /v1/quota/{subject}) ran as one store update but outside that lock,
so it could land between the PUT's read and its write, and the PUT's
policy then replaced the quota unseen. The quota write now takes the
same lock around its update.
Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
…ired one's removal Since main's removal, a retired build whose snapshot or worker only a rejected build (by policy or by an admin) shares is removed as any retired build is: liveSnapshots counts a rejected build as needing the snapshot no more than a retired one. The rejected build itself is only stopped, never in `remove`. liveSnapshots' comment, the removal refusal message, openapi's hostWanted and hostWorkerReport text and the changelog now say so, and a test pins the behaviour. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
|
Main (e921272) merged in (#781, #785 and #762 landed). Besides resolving the conflicts, the merge makes three changes that this PR's own diff doesn't show:
The openapi version moves to 1.21.0, above #762's 1.20.0. Assisted-By: Claude Code |
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Follow-up at 69d12b8 (b23d327..69d12b8). This push has two of this PR's own commits plus a merge of main:
- 56d1b66 merges main e921272 (#743 retired-build removal at API 1.19.0, and #762 enrollment and admin role at 1.20.0). This branch moves to 1.21.0. I checked it with
git show --remerge-diff, and every conflict keeps both sides.wantedAnswerstops admin-rejected builds the same way as retired ones but pushes onlystatus === 'retired'toremove.hostWorkerReporttakesremovedfor retired builds only anddetachedfor retired or admin-rejected ones. In mocactl,cmdSetQuotaand main'sraced/cmdSubjects/cmdSubjectChangesit side by side, and the imports and usage text come from both sides. The info.version, the CHANGELOG, change-policy and http-api all say 1.21.0. No conflict markers are left. - 69d12b8 documents that
liveSnapshotsalready treats a rejected build like a retired one, and adds a test for that: a retired build whose snapshot only an admin-rejected build shares gets removed, and the rejected build is only stopped. This looks right. - 08352e6 makes
putQuotatakepolicyLock, which addresses spec:371. It only partly closes it (see the inline comment). It fixes the in-process race, where a quota write lands betweenputPolicy'sstore.current()and itsstore.set(). It does not fix the stale read on the client, which is the sequence the thread describes: admin A runsGET /v1/policy, admin B runsPUT /v1/quota/{subject}, then A sendsPUT /v1/policywith what A read.putPolicystill storesctx.bodyas sent, so B's override is dropped with no 409. The spec's "a quota and aPUT /v1/policynever drop each other's change" (spec §5.2) is still not true.
nit (lines outside the diff): after 69d12b8, shared is false for a retired build whose snapshot only a rejected build shares. Some text still describes shared and the retire --wait as "a build that is not retired": openapi.yaml:648/664, http-api.md:264, sandbox-handlers.ts:558/656/669, and the cli.ts retire --wait usage. It should say "neither retired nor rejected", as hostWanted now does.
Author: webchang (MEMBER — maintainer)
Areas reviewed: TypeScript (control-plane, mocactl), OpenAPI/docs, merge resolutions
Agent/IDE config (.claude/.vscode): none
Commits: 2 new own commits (signed off) plus 1 merge; DCO pass
CI status: all checks green, k8s-kind-e2e included
AI-assisted review, approved by a maintainer before posting.
| // It also takes PUT /v1/policy's lock (policyLock): that PUT reads, checks and writes as | ||
| // separate store calls, and a quota written between its read and its write would be replaced, | ||
| // unseen, by the policy it sends. | ||
| const { record } = await policyLock(store).run('policy', () => store.update(change, p.sub)); |
There was a problem hiding this comment.
must-fix: this lock closes the server-side interleaving, but the lost update in spec:371 is still there. That lost update comes from a stale client read, not from the race this lock covers.
putPolicy (sandbox-handlers.ts:2539) still calls store.set(ctx.body, …) and stores the body as sent, quotaBySubject included. So if a client runs GET /v1/policy, another admin then runs PUT /v1/quota/github:42, and the first client sends PUT /v1/policy with its earlier read, the override is gone and no 409 comes back. A client built against the pre-1.21 Policy schema has no quotaBySubject and wipes every override on each write. The new test only covers a read that runs inside the PUT. It doesn't cover a read the client made earlier.
Here are two options, either of which fixes it:
- Inside the existing
policyLockstep, haveputPolicykeepbefore.quotaBySubject(andquota, if/v1/quota/defaultowns it) whenever the body omits the key. This makes/v1/quota/*the only writer of overrides. - Give
PUT /v1/policya compare-and-set (?expect=<policy digest>→409 policy_changed).
If you keep the current behaviour, correct spec §5.2 ("…or a quota and a PUT /v1/policy never drop each other's change"), and correct the putPolicy/quotaBySubject descriptions in openapi.yaml, to say that a policy write replaces the overrides.
Refs rossoctl#748 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
…on the policy digest
A PUT /v1/policy stores the whole policy as sent, quota overrides
included. An admin who read the policy, then sent it back after another
admin's PUT /v1/quota/{subject}, dropped that override with no error:
the shared lock only orders the two writes inside one process, it does
not tell the second writer that its read is stale.
PUT /v1/policy now takes an optional ?expect=, the `digest` GET
/v1/policy answers. Inside the policy lock, the write reads the current
policy and compares its digest; if they differ it answers the new code
409 policy_changed, writes and records nothing, and names the current
digest in the error body so the client can read again. An expect that is
not sha256:<64 lowercase hex> is 400 invalid_request. Without expect the
policy is stored as sent, as before (last writer wins); the precondition
is opt-in, as the quota write's is.
- errors.ts and its test: policy_changed, 409;
- openapi: the error enum, PUT /v1/policy's expect parameter, its 409
and its description, and quotaBySubject's description;
- http-api.md: the 409 list and the policy write;
- spec 5.2: a quota write and a policy write that sends expect never
drop each other's change; one without expect replaces the policy as
sent, overrides included;
- RUNBOOK 5: the documented policy write reads the digest and sends it,
and says what to do on a 409; the governance README points there;
- CHANGELOG 1.21.0 (the version stays 1.21.0).
The new test runs the two-admin sequence: A reads, B writes a quota,
A's PUT with the old digest is refused and B's override survives, then
A reads again and the PUT with the new digest succeeds; it fails
without the fix. It also covers a PUT without expect and malformed
expect values.
Refs rossoctl#748
Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
…rejected Since a rejected build keeps no snapshot or worker for a retired one, `shared` is true only when a build that is neither retired nor rejected shares the retired build's snapshot or worker. Say so where the text still read "a build that is not retired": openapi's capacity and shared, http-api.md, the template lifecycle spec, the handler comments, mocactl's api type, the retire --wait usage text and its message (and its test). The spec's known limits gain one line: holds are keyed by build id, so a retired build's `removed` report also drops a rejected twin's hold (the same manifest hash in another template) until the host's next inventory, and for that one poll egress shipping for the twin's draining sandboxes is refused. Refs rossoctl#748 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
Reply to the review of #786 (round 3)Upstream main (#793) is merged in 2c607c0. The merge was clean. sandbox-handlers.ts:2637: a PUT /v1/policy built from an older read drops a quota written sinceFixed in 94266e7. The precondition is opt-in by design, the same as for quota writes. The documented path uses it: The new error code is in The new test runs your sequence. A reads the policy and its digest. B writes a quota override. Spec §5.2 (line 371 thread): "a quota and a PUT /v1/policy never drop each other's change"Fixed in 94266e7. §5.2 now says that a quota write and a policy write that sends Nit: "a build that is not retired" now means "neither retired nor rejected"Fixed in 2627f79. The wording is now "a build neither retired nor rejected" in:
The spec's known limits gain one line. Holds are keyed by build id, so a retired build's A possible follow-upThe RUNBOOK's example writes the policy with curl and leaves the admin's session token as a placeholder, because mocactl has no policy-write command yet. A New tip: 2627f79 Assisted-By: Claude Code |
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Follow-up at 2627f79 (69d12b8..2627f79). This push brings two of the PR's own commits and a merge of main.
- 2c607c0 merges main 2f992db (#793, the onboarding guide, docs only). I checked it with
git merge-tree: it is a clean merge with no hand-resolved conflicts. - 94266e7 fixes the open must-fix (sandbox-handlers.ts:2655, spec:371).
PUT /v1/policynow takes?expect=<digest from GET /v1/policy>. The digest is compared insidepolicyLockagainstpolicyDigest(before), which is the same functiongetPolicyanswers with. When they differ, the write gets409 policy_changedand the currentdigestcomes back in the body. Nothing is written or recorded. A malformedexpectgets a 400 before any read. The new test runs the two-admin stale-read sequence (A reads, B writes a quota, A's PUT is refused, B's override survives, then A re-reads and the write goes through). Spec §5.2, openapi, http-api.md, RUNBOOK §5 and the CHANGELOG now say the opt-in precondition is what protects the overrides, and that a write withoutexpectreplaces them. That resolves the item. - 2627f79 fixes the
shared/retire --waitwording nit. It now reads "neither retired nor rejected" everywhere we listed (openapi, http-api.md, the handler comments, mocactl api.ts, cli.ts usage, templates.ts and its test). It also adds a known limit to the spec, about the rejected twin's hold.
Every item from our 69d12b8 review is closed.
Author: webchang (MEMBER — maintainer)
Areas reviewed: TypeScript (control-plane, mocactl), OpenAPI/docs, merge resolution
Agent/IDE config (.claude/.vscode): none
Commits: 2 new own commits (signed off) plus 1 merge; DCO pass
CI status: all green except k8s-kind-e2e, which is still pending at drafting time
AI-assisted review, approved by a maintainer before posting.
…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]>
Closes #748. On main (2f992db): #781 (retire), which this branch stacked on, is merged. Its own change is the first review's 6 commits (
d7d994ed..74599971), the review-fix commits since, and merges of #781 and main.What it does: admins set quotas (the default, and per subject) and reject a registered build after the fact. Six signed-off commits:
MEMBER_SUBJECT_RE, byte-identical to feat(control-plane,mocactl): template tags, edits and owner transfer #774's copy, so either merge order works.PUT /v1/quota/{subject|default}, admin only. A null body removes a subject's override; the default can't be removed;policyrecord withbefore. The new values apply at once to creates, queued builds and activations;GET /v1/quotagainsquotaSource.POST /v1/templates/{id}/builds/{build}/reject {reason}, admin only, with a required reason, for registered builds only (a retired one is a 400);rejected(ruleadmin), its leases are dropped, and arejectrecord is written (from, reason, buildRecord);409 build_in_usewhile a sandbox is live on it; a second reject is a no-op;400 unknown_template, and an activation gets409 template_unavailable;stop, anddetachedis accepted for it.sbx templates quota TARGET --templates N --builds-queued N --active N | --clear. It refuses another deployment's login, prints old → new, and exits 1 if the value changed in between. Its helpers are byte-identical to feat(control-plane): enroll subjects and grant the admin role through the API #762's copy, so whichever merges second keeps one.http-api.md, and the spec's §5.2 and §6.2.Commits since the first review (all signed off): dabfd19, 5ab19eb and fe20f4a (the quota write is one serial step that keeps only the counters, and can be a compare-and-set answering
409 quota_changed); 4b2768d, 086f3dc and 2d3df2e (no sandbox lands on a build retired or rejected after its create resolved it; a create waits only on its own template; a rejected build's draining worker keeps its slot); 79d8582; 6df5758, 5eadcd4 and 4cb981b (ownedas the fourth per-subject counter, shown bysbx quotaandsbx policy); 7022377 (retire and reject judge live use on the template read under their locks); 852ee5a, 392a9ce and f4e7951.Limits:
quotaFor(pol, charged)for that attempt'scharged, not once outside the loop, so a transfer checks the new owner's usage against the new owner's limits. The two PRs aren't stacked on each other, so this falls to whichever merges second.remove.PUT /v1/quota/defaultwith a null body is refused explicitly;subjectpath parameter has no pattern; the server checks it. A pattern for generated clients is a possible follow-up.Coordination: #785 (1.19.0) and #762 (1.20.0) are merged; this PR takes 1.21.0.
Tests on the tip:
25 files, +1,837 / -156, counted over
15e66557..e8953799.Assisted-By: Claude Code