Skip to content

templates: move default off a retired or rejected build, and let a new build retake it - #943

Merged
pdettori merged 2 commits into
rossoctl:mainfrom
webchang:pr/i909-default-on-retire
Nov 20, 2026
Merged

pdettori merged 2 commits into
rossoctl:mainfrom
webchang:pr/i909-default-on-retire

Conversation

@webchang

Copy link
Copy Markdown
Member

Summary

A bare template id resolves to the template's default tag. Only the first registered build took default, and nothing moved it. So once that build was retired, every bare-id create was refused 410 template_retired while the template had another registered build; and when every build had been retired, a build registered later never took default either (#909). This takes the issue's option 1 for both halves: default follows the build it names when that build ends, and a new build retakes it when it names an ended one.

What changes

  • Retire and reject (retireBuilds, packages/control-plane/src/sandbox-handlers.ts): when a retire or a reject ends the build default names, default moves to the newest registered build left, inside the template's update. "Newest" is by createdAt, with the builds list's newest-first order breaking a tie. It's the newest registered build, not the newest active one: active is derived per request from leases, so default would flap with it. The move writes a tag record ({tag: default, buildId, before}), as an owner's POST …/tags does, sets tagsMeta.default to the caller and writes a template_tags_moved audit line. With no registered build left, default stays. A reject moves it too, because a create naming a rejected build answers 400 unknown_template, which is worse than a 410.
  • Registration (hostBuildReport, packages/control-plane/src/host-handlers.ts): a registering build takes default when the template has none (as before), or when default names a retired or rejected build (buildById), with the same tag record (subject the reporting host), tagsMeta.default (by: null, the deployment) and audit line. A superseding rebuild keeps the twin's id, so its tags already follow, and that path is unchanged.
  • The answers: DELETE /v1/templates/{id}/builds/{build}, POST /v1/templates/{id}/retire and POST …/builds/{build}/reject gain default: {buildId, before, record} when it moved, else null (DefaultTagMove in the OpenAPI document).
  • The 410: a create through a tag that names a retired build is still 410 template_retired; its message now names the tag and the fix ("its 'default' tag names retired build …; tag another build (POST /v1/templates/{id}/tags) or pin one").
  • Docs: API 1.33.0 (openapi, CHANGELOG, change-policy); the lifecycle spec (the registration rule and the known limit), the templates concept page and the reference table say what a retire, a reject and a registration do to default.
  • Not here, a follow-up: mocactl printing the move (a stderr line on templates retire when default moved).

Tests

Five new cases in packages/control-plane/test/activation.test.ts:

  • a retire of the default build with two later builds: default moves to the newest, with a tag record and the answer's default, and a bare id no longer answers 410;
  • a retire of a build default doesn't name: no move, no tag record, default: null;
  • a retire of the only build: default stays, the 410 names the tag (a pinned build's 410 doesn't), and a whole-template retire moves nothing;
  • every build retired, then a new build registers: it takes default, with a tag record from the host, the bare id resolves to it, and a third build doesn't move it;
  • a reject of the default build moves default to the other registered build; a repeat reject moves nothing.

Before the fix (upstream's sandbox-handlers.ts and host-handlers.ts), all five fail. After it, the control-plane suite has 2012 passed (3 skipped), including openapi-contract.test.ts and the existing supersede tests in host-flow.test.ts. The package's tsc is clean, prettier is clean on the changed files, and scripts/check-doc-links.py finds 0 broken links.

Closes #909

Assisted-By: Claude Code

…uild, and a new build retakes it

A bare template id resolves to the template's `default` tag, which only the first
registered build took and which nothing moved, so once that build was retired every
bare-id create answered 410 template_retired while another build was registered, and a
build registered later never took `default` either (rossoctl#909).

- retireBuilds: when a retire or a reject ends the build `default` names, `default`
  moves to the newest registered build left (createdAt, the list's newest-first order
  breaking a tie; registered rather than active, which is per request and would flap),
  with a `tag` record as an owner's tag writes and a template_tags_moved audit line;
  with none left it stays.
- hostBuildReport: a registering build takes `default` when the template has none (as
  before) or when `default` names a retired or rejected build, with a `tag` record
  (subject the host), tagsMeta and the audit line. A superseding rebuild keeps the
  twin's id, so its tags already follow, unchanged.
- The retire and reject answers gain `default` (DefaultTagMove, or null).
- The 410 for a tag naming a retired build names the tag and the fix.
- API 1.33.0: openapi, CHANGELOG, change-policy; the spec, the concept page and the
  reference table say what a retire, a reject and a registration do to `default`.

Closes rossoctl#909

Assisted-By: Claude Code
Signed-off-by: Rong Chang <[email protected]>
@webchang
webchang requested a review from pdettori as a code owner November 20, 2026 02:01
@pdettori pdettori added the ready-for-ai-review Request automated AI code review from clawgenti label Nov 20, 2026

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

Review — templates: default follows a retired or rejected build, and a new build retakes it

Clears the real stranding in #909: default only ever moved by hand, so retiring it turned every bare-id create into 410 template_retired while other registered builds existed, and a template whose builds were all retired never recovered.

  • The move on retire/reject happens inside the same cat.update that writes the retire/reject records, which runs under the activation lock and the template's use lock, so no create can observe default on a just-ended build with another registered build left. It picks the newest registered build by createdAt (the list's newest-first order breaks a tie), deliberately not the newest active one — active is derived per request from leases and default would flap with it, which the comment says.
  • The move is exactly what an owner's tag writes: the same tag record body {tag, buildId, before}, the same tagsMeta entry, the same template_tags_moved audit, and the answer's default carries the record's digest. With no registered build left it stays, and the 410 now names the tag and the fix (sandbox-handlers.ts resolveForUse) while a pinned id@<build id> keeps the old wording — the test pins both.
  • The registration retake fires only when default is absent or names a build buildById reports as retired or rejected. It cannot override an owner's pin, since moveTemplateTags only accepts a registered build; it never fires for a failed report (if (failed) return next); and a superseding rebuild is left alone, its twin's id already carrying the tags. subject: host:<id> and by: null (the deployment) are the right attributions, and the retake is written inside the update like the build and check records.
  • Answers and contract: default on the three routes (the whole-template answer through retireTemplate's spread of retireBuilds' result), DefaultTagMove with required: [buildId, before, record] and a nullable type in openapi, version 1.33.0 and the changelog entry per the change policy, and the spec's known-limit paragraph now states the default exception beside the rule that other tags keep the 410.
  • Tests cover the four cases that matter and would all fail before the change: the move to the newest with a retire then tag chain, a tagsMeta entry and a bare id no longer refused; no move for a build default does not name; no move with no registered build left, the tag-naming 410, the unchanged pinned message and the whole-template retire; the registration retake with the host's tag record and a third build not moving it; and the reject's move with its idempotent repeat.

One non-blocking gap: two operator pages still state the old rule — docs/operate/sandbox-service/offer-templates.md:119 ("later builds do not move it until the owner does") and docs/sandbox/how-to/template-from-image.md:226 ("a later build does not move it"). Neither is wrong about the owner's route, but both now omit the retire/reject move and the registration retake; one sentence pointing at the concept page would keep them in step.

CI 18/18 green. Author: webchang (MEMBER — maintainer). One commit, signed off.

activation.test.ts conflicted: upstream removed the duplicate 'never retires a build an
active session is pinned to' test (8986b49) where this branch added its rossoctl#909 tests;
kept the rossoctl#909 tests and the removal. The API version stays 1.33.0 (upstream is at 1.32.0).

Signed-off-by: Rong Chang <[email protected]>
@pdettori
pdettori merged commit 006bdcb into rossoctl:main Nov 20, 2026
18 checks passed
@pdettori pdettori added this to the v0.11.0 milestone Nov 20, 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.

templates: a bare template id resolves to a retired default build (410) while another build is active

3 participants