Repository navigation
templates: move default off a retired or rejected build, and let a new build retake it - #943
Conversation
…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]>
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
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.updatethat writes theretire/rejectrecords, which runs under the activation lock and the template's use lock, so no create can observedefaulton a just-ended build with another registered build left. It picks the newest registered build bycreatedAt(the list's newest-first order breaks a tie), deliberately not the newest active one — active is derived per request from leases anddefaultwould flap with it, which the comment says. - The move is exactly what an owner's tag writes: the same
tagrecord body{tag, buildId, before}, the sametagsMetaentry, the sametemplate_tags_movedaudit, and the answer'sdefaultcarries the record's digest. With no registered build left it stays, and the 410 now names the tag and the fix (sandbox-handlers.tsresolveForUse) while a pinnedid@<build id>keeps the old wording — the test pins both. - The registration retake fires only when
defaultis absent or names a buildbuildByIdreports as retired or rejected. It cannot override an owner's pin, sincemoveTemplateTagsonly 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>andby: null(the deployment) are the right attributions, and the retake is written inside the update like the build and check records. - Answers and contract:
defaulton the three routes (the whole-template answer throughretireTemplate's spread ofretireBuilds' result),DefaultTagMovewithrequired: [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 thedefaultexception 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
retirethentagchain, atagsMetaentry and a bare id no longer refused; no move for a builddefaultdoes 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'stagrecord 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]>
Summary
A bare template id resolves to the template's
defaulttag. Only the first registered build tookdefault, and nothing moved it. So once that build was retired, every bare-id create was refused410 template_retiredwhile the template had another registered build; and when every build had been retired, a build registered later never tookdefaulteither (#909). This takes the issue's option 1 for both halves:defaultfollows the build it names when that build ends, and a new build retakes it when it names an ended one.What changes
retireBuilds,packages/control-plane/src/sandbox-handlers.ts): when a retire or a reject ends the builddefaultnames,defaultmoves to the newest registered build left, inside the template's update. "Newest" is bycreatedAt, 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, sodefaultwould flap with it. The move writes atagrecord ({tag: default, buildId, before}), as an owner'sPOST …/tagsdoes, setstagsMeta.defaultto the caller and writes atemplate_tags_movedaudit line. With no registered build left,defaultstays. A reject moves it too, because a create naming a rejected build answers400 unknown_template, which is worse than a 410.hostBuildReport,packages/control-plane/src/host-handlers.ts): a registering build takesdefaultwhen the template has none (as before), or whendefaultnames a retired or rejected build (buildById), with the sametagrecord (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.DELETE /v1/templates/{id}/builds/{build},POST /v1/templates/{id}/retireandPOST …/builds/{build}/rejectgaindefault:{buildId, before, record}when it moved, elsenull(DefaultTagMovein the OpenAPI document).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").default.templates retirewhendefaultmoved).Tests
Five new cases in
packages/control-plane/test/activation.test.ts:defaultbuild with two later builds:defaultmoves to the newest, with atagrecord and the answer'sdefault, and a bare id no longer answers 410;defaultdoesn't name: no move, notagrecord,default: null;defaultstays, the 410 names the tag (a pinned build's 410 doesn't), and a whole-template retire moves nothing;default, with atagrecord from the host, the bare id resolves to it, and a third build doesn't move it;defaultbuild movesdefaultto the other registered build; a repeat reject moves nothing.Before the fix (upstream's
sandbox-handlers.tsandhost-handlers.ts), all five fail. After it, the control-plane suite has 2012 passed (3 skipped), includingopenapi-contract.test.tsand the existing supersede tests inhost-flow.test.ts. The package'stscis clean, prettier is clean on the changed files, andscripts/check-doc-links.pyfinds 0 broken links.Closes #909
Assisted-By: Claude Code