Skip to content

feat(control-plane,mocactl): template tags, edits and owner transfer - #774

Merged
webchang merged 15 commits into
rossoctl:mainfrom
webchang:pr/i24-template-admin
Nov 13, 2026
Merged

webchang merged 15 commits into
rossoctl:mainfrom
webchang:pr/i24-template-admin

Conversation

@webchang

@webchang webchang commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Closes #747. On main (d4babb8): #766, which this branch used to stack on, is merged. Its own change is the commits on top of main (template tags, edits and owner transfer, their review fixes, and merges of main).

What it does: a template's owner, or an admin, can tag it, edit it and hand it over, through the API and mocactl. Three signed-off commits:

  1. MEMBER_SUBJECT_RE, the member subject grammar. It's carried here byte-identical to its source, so feat(control-plane): enroll subjects and grant the admin role through the API #762 and Let admins set template quotas per subject, and reject a registered build after the fact #748 merge onto it cleanly.
  2. The control plane:
    • POST and DELETE /v1/templates/{id}/tags;
    • PATCH /v1/templates/{id} (visibility, description);
    • PUT /v1/templates/{id}/owner (admin only);
    • each writes a tag, visibility or owner provenance record;
    • openapi 1.7.0 → 1.8.0, with a CHANGELOG entry.
  3. mocactl: sbx templates tag | untag | edit | transfer.

Limits:

Coordination: #759, #762, #769 and this PR each take openapi 1.8.0 from main's 1.7.0, so whichever merge later renumber.

Tests on the tip:

  • typecheck passes;
  • the control-plane and mocactl suites pass, including the new test/template-admin.test.ts (auth, 404 when hidden, tag targets, edit validation, transfer);
  • prettier passes. No shell script changed.

17 files, +1,418 / -18, counted against #766's tip.

Assisted-By: Claude Code

A route that names another subject (a template's new owner here; the
members and quota routes later) takes 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.

The same hunk is carried by the enrollment and admin-quota changes:
whichever lands first brings it, and the others merge onto it as is.

Refs rossoctl#747

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

What changes after a template is created was only changeable by editing
the store. Each change is now an API call and a provenance record (rossoctl#730)
naming the new value and the one before (template lifecycle spec
§5.1-§5.2):

- POST /v1/templates/{id}/tags {tags, build} (the owner, or an admin)
  moves 1-16 tags onto a registered build, by build id or handle, and
  DELETE /v1/templates/{id}/tags/{tag} removes one; `default` is moved,
  never removed, and a removed tag's build stays. A `tag` record
  {tag, buildId (null when removed), before} per tag that changes.
  Sandboxes and sessions created earlier keep the build they were given.
- PATCH /v1/templates/{id} {description?, visibility?} (the owner, or an
  admin): a `visibility` record {field, value, before} per field changed.
- PUT /v1/templates/{id}/owner {owner} (an admin): the new owner takes
  the subject grammar (`github:<id>` or `oidc:<sub>`, never `test:<n>`)
  and must be enrolled. A template the deployment declared (owner null)
  can be handed over the same way, `before: null`: its id no longer
  blocks its new owner's builds, and a restart does not undo it.

Every owner action is open to admins, on any template. The checks and
the writes run under the catalog's per-template lock, so a tag is only
ever moved onto a build that is registered at that moment. A change to
the value already set writes no record.

The API version goes 1.5.0 -> 1.6.0 (additive). The changelog, the
HTTP reference and the lifecycle design's §5 say so.

Refs rossoctl#747

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
The client side of the template admin routes (template lifecycle spec
§5.1-§5.2):

- `sbx templates tag ID TAG... --build BUILD` moves tags onto a build
  and prints each tag's new build and what it named before (new,
  unchanged, or the old build);
- `sbx templates untag ID TAG` removes a tag; its build stays;
- `sbx templates edit ID [--visibility private|deployment]
  [--description TEXT]` prints which fields changed;
- `sbx templates transfer ID SUBJECT` (admins) prints the new owner and
  the one before.

Each takes --json. Argument and flag misuse (a missing --build, an edit
with nothing to change, a visibility other than the two, --description
or --visibility outside edit) is a usage error before any request. The
contract test pins the four routes and the fields the client sends and
reads against openapi.yaml.

Refs rossoctl#747

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

@clawgenti clawgenti left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Summary

This PR is stacked on #772 (it carries #772's commits up to be419cd), so this review covers only the increment be419cd...1d100d1: MEMBER_SUBJECT_RE, the tag, edit and owner-transfer routes, and the mocactl subcommands. The authorization gates are right: transfer is admin-only, the new owner must match the member grammar and be enrolled, and the other three routes return 404 to a caller who cannot see the template and 403 to one who is neither owner nor admin. One must-fix: tags are looked up on a plain object, so the tag name constructor passes TEMPLATE_ID_RE, the catalog write goes through, and then the provenance append throws. The result is a 500 and a tag change with no record. A description holding a lone surrogate fails the same way, and the ownership check runs outside the per-template lock that the commit message says covers 'the checks and the writes'.

Author: webchang (MEMBER — maintainer)
Areas reviewed: control-plane handlers (authorization, catalog locking, provenance writes), routes, identity grammar, OpenAPI/CHANGELOG/http-api/lifecycle spec docs, mocactl CLI/API client, tests, commit conventions/DCO, .claude/.vscode gate
Agent/IDE config (.claude/.vscode): none
Commits: 15 commits, all signed-off: yes
CI status: passing (all 17 checks green, incl. CodeQL, DCO, lint, k8s-kind-e2e)

1 must-fix, 2 suggestions, 0 nits.

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

const meta = { ...(cur!.tagsMeta ?? {}) };
for (const t of tags as string[]) {
if (next[t] === buildId) continue;
moved.push({ tag: t, from: next[t] ?? null });

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

must-fix: tags is a JSON-parsed plain object, so next[t] reads inherited properties. constructor matches TEMPLATE_ID_RE (/^[a-z0-9][a-z0-9-]{0,30}$/). For POST .../tags {tags:["constructor"]}, next['constructor'] is Object, so from is a function. cat.update writes the tag, and then prov.append (line 754) throws: canonicalJson refuses a function (provenance.ts:122). The caller gets a 500, the tag has moved, and no tag record exists, which breaks the 'every change is a record' invariant. DELETE .../tags/constructor (line 796) on a template without that tag does the same: b is Object, not undefined, so it returns 500 where it should return 404. Fix: use Object.hasOwn(cur!.tags, t) ? cur!.tags[t] : undefined in both places (or keep tags in a Map or Object.create(null)), validate ctx.params.tag against TEMPLATE_ID_RE in removeTemplateTag, and add a test with constructor.

throw new CpError('invalid_request', "visibility must be 'private' or 'deployment'");
if (
b.description !== undefined &&
(typeof b.description !== 'string' || b.description.length > 1024)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: The description is checked only for type and length. A JSON body can carry a lone surrogate ("\ud800" parses into one), and canonicalJson refuses that (provenance.ts:103). The catalog write at line 845 succeeds, and then prov.append at line 859 throws: a 500, with the description changed and no visibility record. Reject lone surrogates here with the same regex canonicalJson uses (or call canonicalJson(b.description) in a try block) and answer 400 invalid_request. More generally, the handlers would be sturdier if the record body went through canonicalJson before cat.update wrote anything.

const p = requireEnrolled(ctx, deps);
const w = writable(deps);
const d0 = await visibleTemplate(deps, p, ctx.params.id ?? '');
if (d0.owner !== p.sub && !isAdmin(p))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: ownTemplate checks ownership on d0, which is read before the lock. The cat.update mutators in the tag, untag and edit handlers do not check again. If an admin's PUT .../owner moves the template from A to B in between, A's tag move or edit still lands after the transfer. That contradicts the commit message ('The checks and the writes run under the catalog's per-template lock') and spec §5.2 (the new owner gets the owner actions, and by implication the old one loses them). Fix: inside each mutator, repeat if (cur!.owner !== p.sub && !isAdmin(p)) throw new CpError('forbidden', ...), and repeat the visibility check too, for example with a shared helper that ownTemplate and the mutators both call.

@ingpaolodettori-dev ingpaolodettori-dev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Summary

The range adds MEMBER_SUBJECT_RE, four control-plane routes (POST/DELETE template tags, PATCH template, admin-only PUT owner), each writing a provenance record, with openapi 1.6.0 docs and the mocactl sbx templates tag|untag|edit|transfer commands. Route table, openapi, route-profile tests and the mocactl client agree, and mocactl's human output passes every remote string through sanitizeRemote. The real problems are in the handlers. Tag names are looked up on plain objects, so constructor reads Object.prototype. Provenance records are appended after the catalog write rather than inside it, so a failed append leaves a change with no record, and no record is ever written later. The owner check is also done outside the write lock.

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

Inline: 1 must-fix, 3 suggestion, 0 nit.

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

Overlap with clawgenti (same head): clawgenti's review already covers the constructor tag lookup (sandbox-handlers.ts:746), the provenance append that runs after the catalog write / lone-surrogate description (:845), and the owner check made outside the lock (:703). We agree with all three, so we have not repeated them inline. They are why this review requests changes. The one inline comment below covers what that review leaves out: the DELETE path, where the raw tag path parameter is never validated.

);
let before = '';
await cat.update(d0.id, async (cur) => {
const b = cur!.tags[tag];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: Same problem on the DELETE path, and here tag is a raw path parameter with no validation. For DELETE .../tags/constructor (or toString, __proto__, hasOwnProperty), cur!.tags[tag] is an inherited value, not undefined. The handler doesn't answer 404: it writes the unchanged document, then prov.append throws on a function or a non-plain object in before, and the caller gets a 500. Check Object.hasOwn(cur!.tags, tag), and validate tag against TEMPLATE_ID_RE before taking the lock.

The merged create now refuses a spec naming both guest_ram_mb and its
alias guest_mb, so the tags, edit and transfer tests' fixture sends the
worked example's spec as it is.

Refs rossoctl#747

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

Tags are a JSON-parsed plain object, so a lookup by name read
Object.prototype: moving the tag `constructor` (it matches the tag
grammar) saw a function as the build before it, wrote the tag and then
failed to record it (500), and removing it from a template without it
did the same instead of 404. Moving, removing, resolving `id:tag` and
listing a tag's assignment now look at own properties only.

DELETE .../tags/{tag} validates the path parameter against the tag
grammar before the lock is taken (400 invalid_request), so names like
`toString` or `__proto__` never reach the catalog. A test moves, serves
and removes `constructor` and refuses the inherited names.

Refs rossoctl#747

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

The tag, untag, edit and transfer routes (and cancel) wrote the catalog
first and appended their provenance records after it, so a failed append
answered 500 with the change stored and no record of it, never written
later. They now append inside the catalog's write, as create does: every
record body is checked as canonical JSON before the first append, and
the document is written only after the appends succeed.

PATCH .../templates/{id} refuses a description holding a lone surrogate
(400 invalid_request), which a JSON body can carry and a record cannot.
LONE_SURROGATE_RE is the check canonicalJson itself uses.

Tests: a lone-surrogate description changes nothing; with appends
failing, no move, removal, edit, transfer or cancel is stored.

Refs rossoctl#747

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

The tag, untag and edit routes (and cancel) checked ownership on the
document read before the lock, and their writes did not check again: an
admin's owner transfer in between let the old owner's change land after
it. ownerCheck now runs on the document as read, for an early answer,
and again inside each write on the document under the lock (404 for a
template the caller can no longer see, 403 for one no longer theirs).
The transfer's write refuses a template gone meanwhile.

The create path read the owner it charges the quota to before the lock,
on the ground that an owner never changes; with transfers it can. The
write now compares that owner with the one under the lock and, if a
transfer moved it, writes nothing and runs again under the new owner's
lock (refused with internal_error after three tries).

Tests: with a stale read, the old owner's move, removal, edit and cancel
are refused and nothing is written; an admin's build after a transfer is
charged to the owner found under the lock.

Refs rossoctl#747

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

Copy link
Copy Markdown
Member Author

This PR also changes #766's create path. #766 assumed a template's owner never changes, and this PR's transfer makes that false. So create now re-checks the owner under the lock and retries; after three retries it answers 500 internal_error. A 503 with Retry-After is an option if you'd prefer it.

Base for these fixes: a5f062a (which merged #766's reviewed fixes). The first new commit, 29be5d7, makes the template
admin tests send the guest size once: the merged create now refuses guest_ram_mb together with its alias guest_mb,
and the old fixture sent both.

packages/control-plane/src/sandbox-handlers.ts:796 (DELETE path, raw tag parameter)

"Same problem on the DELETE path, and here tag is a raw path parameter with no validation ... Check Object.hasOwn(cur!.tags, tag), and validate tag against TEMPLATE_ID_RE before taking the lock."

Fixed in 340c073: removeTemplateTag now checks the path parameter against TEMPLATE_ID_RE before taking the lock
(400 invalid_request), and the lookup inside the write uses Object.hasOwn. The same own-property lookup applies to
moving tags, to resolving id:tag (resolveBuild) and to the tag list's assignedAt/assignedBy. The OpenAPI 400 and the
1.6.0 changelog list the refused tag name. Test: takes a tag named as an Object.prototype property as any other tag
(constructor gets 404 before it is moved, then is moved, served and removed with its records; toString,
__proto__, hasOwnProperty and other non-grammar names get 400).

packages/control-plane/src/sandbox-handlers.ts:746 (must-fix: constructor tag on a plain object)

"tags is a JSON-parsed plain object, so next[t] reads inherited properties ... use Object.hasOwn(cur!.tags, t) ? cur!.tags[t] : undefined in both places ... validate ctx.params.tag ... and add a test with constructor."

Fixed in 340c073: as above. Both lookups (POST and DELETE) use own properties only, ctx.params.tag is validated, and
the test moves and removes constructor. Separately, 966b81d moves every record append inside the catalog's write
(next reply), so a record that cannot be written now refuses the change instead of leaving it with no record.

packages/control-plane/src/sandbox-handlers.ts:839 (lone surrogate in the description; records after the write)

"Reject lone surrogates here ... and answer 400 invalid_request. More generally, the handlers would be sturdier if the record body went through canonicalJson before cat.update wrote anything."

Fixed in 966b81d: PATCH refuses a description holding a lone surrogate with 400 invalid_request. The check is
LONE_SURROGATE_RE, which canonicalJson now uses too, so the two cannot drift apart. On the general point: tag, untag,
edit, transfer and cancel now append their records inside the catalog's write, as create does. A shared appendRecords
checks every body with canonicalJson before the first append, and the document is written only after the appends
succeed, so no change is stored without its record. The one order left is a write that fails after its appends: that
leaves a record of a change that was not stored, never a stored change with no record. The OpenAPI and changelog say so.
Tests: refuses a description holding a lone surrogate, before anything is written and
writes no change whose record fails to append (with appends failing, no move, removal, edit, transfer or cancel is
stored).

packages/control-plane/src/sandbox-handlers.ts:703 (owner check outside the lock)

"inside each mutator, repeat if (cur!.owner !== p.sub && !isAdmin(p)) throw new CpError('forbidden', ...), and repeat the visibility check too, for example with a shared helper that ownTemplate and the mutators both call."

Fixed in eed9e30: a shared ownerCheck (visibility: 404, ownership: 403) runs in ownTemplate on the document as
read, and again inside each write (tag, untag, edit and cancel) on the document under the template's lock. The
transfer's write refuses a template that is gone by then. Transfers also break an assumption in create, whose comment
said "a template's owner never changes": create reads the owner it charges the quota to before the lock. Its write now
compares that owner with the one under the lock. If a transfer moved it, the write stores nothing and runs again under
the new owner's lock, and after three tries it gives up with internal_error. Tests:
checks the owner again under the lock: a transfer meanwhile refuses the old owner's change and
charges an admin's new build to the owner it finds under the lock.

New tip: eed9e30

Assisted-By: Claude Code

@clawgenti clawgenti left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Summary

Re-review of the push since my last review (1d100d1..eed9e30, review 5883320884). This PR's own increment adds four fix commits (29be5d7, 340c073, 966b81d, eed9e30), and the merge a5f062a brings in #766's new fixes, which are reviewed there. All three earlier findings are resolved:

  • Tags are looked up as own properties. Object.hasOwn is now used in the move, removal, id:tag resolution (template-catalog.ts:108) and the tags listing. DELETE validates {tag} against TEMPLATE_ID_RE before taking the lock.
  • Records go on the chain before the write. appendRecords checks every body as canonical JSON, then appends, all inside cat.update. A lone-surrogate description is refused with 400 using the same LONE_SURROGATE_RE that canonicalJson uses.
  • The owner is checked again under the lock. The tag, untag, edit and cancel writes run ownerCheck again. Create retries under the new owner's quota lock (at most 3 attempts) when a transfer moves the owner.

Each fix has a test in template-admin.test.ts or template-create.test.ts. No new findings in this increment. One inherited problem: the deploy-scripts failure comes from #766's examples.test.sh jq change. See the inline comment, which repeats the #766 finding so the red check on this PR is explained.

Author: webchang (MEMBER — maintainer)
Areas reviewed: control-plane handler fixes (sandbox-handlers.ts, template-catalog.ts, provenance.ts), their tests, the merge a5f062a (no conflicts), commits/DCO, CI, agent-config gate
Agent/IDE config (.claude/.vscode): none
Commits: 31 commits, all signed-off: yes
CI status: failing: deploy-scripts (step "Run deploy shell tests"), inherited from #766. The other 16 checks pass.

0 new must-fix of its own (1 inherited from #766), 0 suggestions, 0 nits.

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

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

must-fix (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.

@clawgenti clawgenti left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Summary

Re-review of the push since my last review (eed9e30..70f40c8, review 5884462890). The only content change is the shared jq fix from #766, merged in (2 commits, 1 file, +3/−2).

passing (dependency-review still pending)

Author: webchang (MEMBER — maintainer)
Areas reviewed: examples.test.sh M7 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-scripts now passes on this head, so the inherited failure is resolved. No new findings, and there are no open findings from me on this PR.
Agent/IDE config (.claude/.vscode): none
Commits: 33 commits, all signed-off: yes
CI status: Shell (template-onboarding tests)

Verified by: 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 ingpaolodettori-dev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Summary

Follow-up at 70f40c8. The push since eed9e30 only merges #766's jq fix (cbec01c), so this PR's own code is the same as at eed9e30, which I reviewed in full:

Every item from the 1d100d1 review is fixed. That includes clawgenti's and ours, which I checked in the code:

  • Tag lookups now check own properties everywhere: POST move (sandbox-handlers.ts:842), DELETE (:898, and the tag name is validated against TEMPLATE_ID_RE before the lock), id:tag resolution (template-catalog.ts:108), and the tag list's tagsMeta (:1059).
  • A description with a lone surrogate is refused up front (:947, the shared LONE_SURROGATE_RE that canonicalJson uses). Every record goes through the canonical-JSON check before the first append.
  • Tag, untag, edit, transfer and cancel each append their records inside the cat.update closure. The catalog write happens only after that, and there is a test for a failing append.
  • The owner is checked again under the template's lock. Create's OWNER_MOVED retry is bounded at 3 and writes nothing on a failed attempt, so it can't livelock.

On your 500-vs-503 question: 503 with Retry-After would describe that case more accurately. Reaching it takes three admin transfers inside one create, though, so 500 is fine and doesn't block this.

Minor, not blocking: if the append succeeds and the catalog write then fails, the chain records a change the catalog never stored. Create already behaves this way, and the trade-off is documented. A retry converges, but if no client retries, verify-provenance.py won't notice the mismatch.

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-scripts is green.

Author: webchang (MEMBER — maintainer) · Agent/IDE config: none · DCO: all signed off.
CI status: 17/17 pass.

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

Takes the self-serve create's second round: the templates quota checked
whenever a template holds no slot, the examples check's M1 grammar, and
the owned quota (template ids a subject owns in any status, checked for
new ids only).

Conflict in packages/control-plane/src/sandbox-handlers.ts (createBuild),
resolved by keeping both sides:
- this branch's owner re-check under the template's lock, with the
  create retried under the new owner's quota lock when an owner
  transfer lands between the read and the write;
- the other branch's quota checks (templates for a template holding no
  slot, owned for a new id), placed inside the retried step, so a retry
  after an owner change runs them again against the new owner's usage
  under the new owner's lock;
- the other branch's comment that a template's owner never changes is
  dropped: owner transfer makes it untrue, and the retry covers it.
appendRecords inside the write and ownerCheck merged without conflict.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
…ked against the new owner's templates quota

The merged create runs the templates quota for any template holding no
slot. A transfer that lands between the owner's read and the write
makes the write run again under the new owner's lock; the test shows
that run counts the new owner's usage: a transferred template whose
builds all failed gets no new build when the new owner's one slot is
taken, though the stale owner holds none, and nothing is written.

Refs rossoctl#747

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

Copy link
Copy Markdown
Member Author

Second round. Base: 70f40c8 merged with #766's second round as b91ccfb (the templates quota checked whenever a
template holds no slot, the examples check's M1 grammar, and the new owned quota). The merge's one conflict was
in createBuild: it keeps this PR's owner re-check under the template's lock, with the retry under the new owner's
quota lock, and puts #766's new quota checks inside the retried step. A create that a transfer interrupts therefore
runs them again against the new owner's usage. The owned check applies to new ids only, and a new id has no owner
to transfer. #766's comment saying "a template's owner never changes" is dropped.

packages/control-plane/src/sandbox-handlers.ts:796 (DELETE path, raw tag parameter)

"Check Object.hasOwn(cur!.tags, tag), and validate tag against TEMPLATE_ID_RE before taking the lock."

Fixed in 340c073 (earlier round): removeTemplateTag checks the path parameter against TEMPLATE_ID_RE before
it takes the lock (400 invalid_request), and the lookup inside the write uses Object.hasOwn. Test:
takes a tag named as an Object.prototype property as any other tag.

packages/control-plane/src/sandbox-handlers.ts:746 (must-fix: constructor tag on a plain object)

"use Object.hasOwn(cur!.tags, t) ? cur!.tags[t] : undefined in both places ... and add a test with constructor."

Fixed in 340c073 (earlier round): moving tags, removing them, resolving id:tag and the tag list all look up
own properties only. Same test as above.

packages/control-plane/src/sandbox-handlers.ts:943 (lone surrogate in the description)

"Reject lone surrogates here with the same regex canonicalJson uses ... and answer 400 invalid_request."

Fixed in 966b81d (earlier round): PATCH refuses a description holding a lone surrogate with 400 invalid_request,
using LONE_SURROGATE_RE, which canonicalJson uses as well. Every record is appended inside the catalog's write,
after appendRecords checks each body as canonical JSON. Tests: refuses a description holding a lone surrogate, before anything is written and writes no change whose record fails to append. The thread is not marked outdated
only because the line it points to did not change; the check is at the top of updateTemplate on the current tip.

packages/control-plane/src/sandbox-handlers.ts:703 (owner check outside the lock)

"inside each mutator, repeat if (cur!.owner !== p.sub && !isAdmin(p)) throw new CpError('forbidden', ...)"

Fixed in eed9e30 (earlier round): the shared ownerCheck runs again inside each write. Create retries under the
new owner's lock. Added in e7d4d50, after the merge with #766: the retry also applies #766's templates quota to
the new owner. Take a transferred template whose builds all failed, and a new owner whose one slot is taken: it
gets no new build, even though the stale owner holds no slot, and nothing is written. Test: checks the new owner's templates quota again when a transfer lands before the write (it fails if the check goes back to new ids only).

deploy/sbx/template-onboarding/tests/examples.test.sh:22 (inherited jq precedence)

"In jq, A and B as $g | C parses as (A and B) as $g | C ... Suggested fix: parenthesise as shown, in #766."

Fixed in cbec01c (earlier round, from #766). After the merge, the suite passes on bash 5 and bash 3.2.

Re-review (2026-11-13T03:06Z, on 70f40c8)

No new findings, so nothing to change. The head since then holds the merge above and one test commit.

New tip: e7d4d50

Assisted-By: Claude Code

@ingpaolodettori-dev ingpaolodettori-dev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Follow-up at e7d4d50. The merge with #766 (b91ccfb) keeps the owner re-check under the template's lock and the bounded OWNER_MOVED retry. #766's new checks (templates quota whenever the template holds no slot; owned for new ids only) run inside the retried closure and use usage() read under the new owner's lock, so a create interrupted by a transfer is re-checked against the new owner, which e7d4d50's test covers. owned cannot be dodged by a transfer, since it applies only to new ids. policyProblems, /v1/quota, openapi, CHANGELOG and spec are consistent. One nit inline (inherited from #766's examples check).

Author: webchang (MEMBER — maintainer) · Agent/IDE config: none · DCO: all signed off.

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

# distribution reference grammar, an optional host[:port]/ (a first component with a `.` or a `:`,
# or localhost), lowercase path components, no tag, pinned by digest, at most 255 characters before
# the `@`.
M1_JQ='(split("@")[0] | length) <= 255 and test("^(?:(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?)(?:\\.(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?))+(?::[0-9]+)?|(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?):[0-9]+|localhost(?::[0-9]+)?)/)?[a-z0-9]+(?:(?:[._]|__|-+)[a-z0-9]+)*(?:/[a-z0-9]+(?:(?:[._]|__|-+)[a-z0-9]+)*)*@sha256:[0-9a-f]{64}$")'

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: the host group here is optional, so a first component that is not a valid domain falls through to the path rule: my_reg.io/x@sha256:<64 hex> and a__b.c/x@sha256:<64 hex> pass this filter (jq 1.8.2), but isPinnedImage refuses them (splitHost takes the first component as a host when it has a ., and DOMAIN_RE has no _). Adding one of them to the bad list would catch it; the fix is to require the host branch when the first component holds a . or :.

Conflicts and resolutions (upstream/main brings sbx templates create, build,
follow, cancel, quota and policy; this branch brings templates tag, untag,
edit and transfer):

- packages/mocactl/src/sbx/api.ts: both sides' types and client methods kept.
- packages/mocactl/src/sbx/cli.ts: the usage lists both sides' commands; one
  TEMPLATE_SUBS list holds both sides' subcommands, with TEMPLATE_ADMIN_SUBS
  (tag, untag, edit, transfer: no empty argument) and TEMPLATE_ONE_ID (build,
  show, follow, cancel, edit). --build applies to show, follow, cancel and tag;
  --visibility to templates create and edit (its value checked locally for
  edit, as before); --description to edit only. The duplicate visibility
  option is dropped. Both sides' argument checks are kept with their messages.
- packages/mocactl/test/contract.test.ts: both sides' routes and calls kept;
  the scripted reply count is 21.
- packages/mocactl/test/sbx-cli.test.ts (no textual conflict): the --build
  misuse message now lists show, follow, cancel, tag.

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

Copy link
Copy Markdown
Member Author

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

Main's #767 brought sbx templates create, build, follow, cancel, and sbx quota and sbx policy. This PR's commands now sit beside them in one sbx templates list.

Assisted-By: Claude Code

Upstream main (f60db30) adds the sandbox lease wire (rossoctl#802) as API
1.6.0, which this branch also claimed, and session grants (rossoctl#807) as
API 1.7.0; this branch's section moves to 1.8.0.

Conflicted:
- docs/api/CHANGELOG.md: main's 1.7.0 (grants) and 1.6.0 (sandbox
  modes) kept as main has them; this branch's template-admin section
  is now 1.8.0, above them.
- docs/api/openapi.yaml: info.version 1.8.0 (this branch said 1.6.0,
  main 1.7.0).
- packages/control-plane/src/sandbox-handlers.ts: the imports are the
  union (this branch's provenance, identity and isEnrolled imports,
  and main's MIN_IDLE_TIMEOUT_S).
- packages/control-plane/test/openapi-contract.test.ts: the enrollable
  route count is 24: the base's 18, this branch's four template admin
  routes and main's two sandbox mode routes.

Also changed in the merge:
- docs/reference/http-api.md: the template admin routes say API 1.8.0.

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

Copy link
Copy Markdown
Member

there are still merge conflicts

Conflicts:
- packages/mocactl/src/sbx/cli.ts: main's NO_RECORD (the commands
  `--record` is refused on) is kept, followed by this branch's template
  subcommand lists (TEMPLATE_ADMIN_SUBS, TEMPLATE_SUBS, TEMPLATE_ONE_ID).

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
@webchang
webchang merged commit 33a29d6 into rossoctl:main Nov 13, 2026
17 checks passed
webchang added a commit to webchang/moca that referenced this pull request Nov 13, 2026
… as guest_ram_mb

The size envelope could be bypassed through the guest-size alias: the policy read
`guest_mb ?? guest_ram_mb`, the build tool reads only `guest_ram_mb`, so a spec with a small
guest_mb and a large guest_ram_mb passed M7 and the envelope and then built the large guest.

A spec with both keys is now refused as M7.guest, even when the two are equal. When the alias
guest_mb comes alone, it is renamed to guest_ram_mb (normalizeSpec) before the spec is recorded in
the create record, kept as request.spec or used in the reuse key, so the policy and the build
always read one number. openapi, the API changelog, GATING-RULES M7 and the lifecycle spec say so.
The tests' fixtures that sent both keys now send the guest size once.

Tests (fail with the fix reverted): refuses both guest-size keys (differing, and equal) with 422
policy_refused M7.guest; stores the guest_mb alias as guest_ram_mb, the key the build reads, and
reuses across the two.

(cherry picked from commit a187e99)
(cherry picked from commit 29be5d7)

Ports rossoctl#766 and rossoctl#774 review fixes

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

A template's `tags` is a JSON-parsed plain object, so `tags[t]` read inherited properties: a tag
named `constructor` (or `toString`, `__proto__`, ...) read Object.prototype's member, so a move
recorded a function as the tag's `before`, a removal of a tag that was never set went through, and
`id:constructor` could resolve. Moving tags, removing one, resolving `id:tag` (resolveBuild) and the
tag list's assignedAt/assignedBy now look up own properties only, and DELETE …/tags/{tag} checks
its path parameter against the tag grammar first (400 invalid_request). openapi's 400 and the API
changelog say so.

Test: template-admin.test.ts, the tag, untag, edit and transfer tests (this tree had none for these
routes), with takes a tag named as an Object.prototype property as any other tag (`constructor`
gets 404 before it is moved, then is moved, served and removed with its records; `toString`,
`__proto__`, `hasOwnProperty` and other non-grammar names get 400). It fails with the fix reverted.

(cherry picked from commit 340c073)

Ports rossoctl#774 review fixes

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
webchang added a commit to webchang/moca that referenced this pull request Nov 13, 2026
… are on the chain, and its owner is checked again under the lock

- Tag, untag, edit, transfer and cancel wrote the catalog first and appended their records after:
  a record that failed to append left a stored change with no record. They now append their
  records inside the catalog's write, as create does: a shared appendRecords checks every body as
  canonical JSON before the first append, and the document is written only after the appends
  succeed. The one order left is a write that fails after its appends: a record of a change not
  stored, never a stored change with no record.
- PATCH refuses a description holding a lone surrogate with 400 invalid_request, before anything
  is written (LONE_SURROGATE_RE, which canonicalJson now uses too).
- The owner's check (visibility: 404, ownership: 403) ran on the request's read only, so an owner
  transfer between the read and the write let the old owner's change through. A shared ownerCheck
  runs in ownTemplate on the document as read, and again inside each write (tag, untag, edit,
  cancel) on the document under the template's lock; the transfer's write refuses a template gone
  by then. Tag moves now check their target build under the lock too.
- A create read the owner it charges before the lock, assuming an owner never changes. Its write
  compares that owner with the one under the lock; if a transfer moved it, it stores nothing and
  runs again under the new owner's lock, against the new owner's quota and usage, giving up with
  internal_error after three tries.

openapi and the API changelog say so.

Tests (each fails with the fix reverted): refuses a description holding a lone surrogate, before
anything is written; writes no change whose record fails to append; checks the owner again under
the lock: a transfer meanwhile refuses the old owner's change; charges an admin's new build to the
owner it finds under the lock; checks the new owner's templates quota again when a transfer lands
before the write.

(cherry picked from commit 966b81d)
(cherry picked from commit eed9e30)
(cherry picked from commit e7d4d50)

Ports rossoctl#774 review fixes

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
webchang added a commit to webchang/moca that referenced this pull request Nov 13, 2026
Upstream main (949dc5f) adds template tags, edits and owner transfer
(rossoctl#774) as API 1.8.0, so this branch's section moves to 1.9.0.

Conflicted:
- docs/api/CHANGELOG.md: main's 1.8.0 (template tags, edits and owner
  transfer), 1.7.0 and 1.6.0 kept as main has them; this branch's
  session-templates section is now 1.9.0, above them.
- docs/reference/change-policy.md: main's list kept, with this
  branch's "then session sandbox templates" after it; both version
  mentions say 1.9.0.

Also changed in the merge:
- docs/api/openapi.yaml: info.version 1.9.0.
- packages/mocactl/test/run-record.test.ts (from rossoctl#768): mocactl run
  now reads discovery twice before it creates the session, once for
  the sandbox tier and once for this branch's sandbox template field,
  so the recorded call list gains a line and the later indices and
  sequence numbers move by one.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
webchang added a commit to webchang/moca that referenced this pull request Nov 13, 2026
Upstream main (949dc5f) adds template tags, edits and owner transfer
(rossoctl#774) as API 1.8.0, so this branch's section moves to 1.9.0.

Conflicted:
- docs/api/CHANGELOG.md: main's 1.8.0, 1.7.0 and 1.6.0 kept as main
  has them; this branch's enrollment section is now 1.9.0, above them.
- docs/reference/change-policy.md: main's list kept, with this
  branch's "then enrollment and the admin role" after it; both version
  mentions say 1.9.0.
- docs/reference/http-api.md: main's Template admin row and paragraph
  kept; this branch's Subjects row and enrollment paragraph after
  them, now API 1.9.0.
- packages/control-plane/src/identity.ts: main's MEMBER_SUBJECT_RE
  comment (members, owner and quota routes) taken; the code was the
  same on both sides.
- packages/mocactl/src/sbx/cli.ts: both sides' imports, and main's
  templates tag/untag/edit/transfer usage lines then this branch's
  admin subjects ones.
- packages/mocactl/test/contract.test.ts: the scripted replies are 23,
  the sum of both sides' calls; both path placeholders (TAG, SUBJ)
  are replaced.

Also changed in the merge:
- docs/api/openapi.yaml: info.version 1.9.0.
- packages/control-plane/src/sandbox-handlers.ts: main's owner
  transfer checks the new owner's enrollment as a request of theirs
  would be, with this branch's membershipNow (the settings, an admin
  role, or the members store), and its refusal names /v1/subjects
  beside SH_ALLOWED_SUBJECTS. template-admin.test.ts tests a subject
  enrolled through /v1/subjects, refused before and accepted after.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
webchang added a commit to webchang/moca that referenced this pull request Nov 13, 2026
Upstream main (949dc5f) adds template tags, edits and owner transfer
(rossoctl#774) as API 1.8.0, so this branch's section moves to 1.9.0.

Conflicted:
- docs/api/CHANGELOG.md: main's 1.8.0, 1.7.0 and 1.6.0 kept as main
  has them; this branch's subject-trust section is now 1.9.0, above
  them.
- docs/reference/change-policy.md: main's list kept, with this
  branch's "then subject trust for gate records" after it; both
  version mentions say 1.9.0.
- packages/control-plane/src/sandbox-handlers.ts (admitBuild): main's
  retry when an owner transfer moves the template between the read and
  the write kept; this branch's self-attested refusals (a
  deployment-visible template, an owner other than the attester), its
  gate record body (source self, scope) and its build fields
  (selfAttested, selfAttestProfile, gateFloor, private visibility) put
  into it. The comment that a template's owner never changes is gone.

Also changed in the merge:
- docs/api/openapi.yaml: info.version 1.9.0; PATCH /v1/templates/{id}
  declares 409 self_attested.
- sandbox-handlers.ts: the owner's check on main's tag, edit and
  transfer routes reads the effective visibility (canSee with the
  trusted set), as every other read does on this branch. PATCH
  /v1/templates/{id} refuses `visibility: deployment` with 409
  self_attested while a build is self-attested (registered, or on its
  way there), the refusal this branch's spec deferred until the edit
  route was in.
- The CHANGELOG's 1.9.0 section and the subject-trust spec (§6, §8)
  say so; subject-trust.test.ts tests it.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
webchang added a commit to webchang/moca that referenced this pull request Nov 13, 2026
Upstream main (949dc5f) adds SBX_WORKER_AT_BOOT (rossoctl#799), the worker
stop's VM reap (rossoctl#800), and template tags, edits and owner transfer
(rossoctl#774). This branch claims no API version.

Conflicted:
- deploy/sbx/install-host.sh (main): both checks kept, this branch's
  SBX_READ_AHEAD_KB refusal and then main's SBX_WORKER_AT_BOOT one,
  each before the host is touched.

Also changed in the merge:
- install-host.sh's header, the README and the RUNBOOK's read-ahead
  section say sbx-read-ahead.service is enabled whatever
  SBX_WORKER_AT_BOOT says, so a host agent's later worker starts read
  ahead too; install-host.test.sh checks it (a worker installed with
  SBX_WORKER_AT_BOOT=0 still enables the read-ahead, not the worker).
- deploy/sbx/README.md: a blank line after the read-ahead paragraph,
  which ran into the next one.
- [email protected] (auto-merged): main's ExecStopPost and this
  branch's After=sbx-read-ahead.service both kept.

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

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Manage template tags, description, visibility and owner through the API

4 participants