Repository navigation
feat(control-plane): reuse a registered build only while a host holds its snapshot - #818
Conversation
…its snapshot A template create whose inputs match a registered build was answered with that build (200, reused: true) even after its snapshot had gone from every host. The client then got 409 template_unavailable on the sandbox create, and sending the create again gave the same reused answer, so a rebuild with the same inputs was not possible. The reuse match now also asks, for a registered build, that some host's last inventory holds its manifest hash. When none does, the create is admitted as a new build (202) with the usual quota and gate checks. A build on its way is reused as before, and a deployment without host agents is unchanged. Refs rossoctl#816 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
… its snapshot The lifecycle spec's Reuse paragraph now states the rule as built, with its limits (only as current as the hosts' last inventories; a duplicate build right after a restart; the old build stays registered). The createTemplate description and the reused field say when a registered build counts. API 1.22.0: when a create is answered reused changes, so the changelog and the change policy name the new version. Refs rossoctl#816 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
clawgenti
left a comment
There was a problem hiding this comment.
Good fix — the failure mode it removes (a create answered with a build whose snapshot no host holds, permanently wedging that manifest hash from ever rebuilding) is real, and the tradeoff you picked (a duplicate build after a restart rather than an answer naming a missing snapshot) is the safe direction. The spec paragraph now states the rule and its staleness limits plainly, and the test walks queued → held → unheld cleanly.
Summary
Author: webchang (MEMBER — maintainer)
Areas reviewed: TypeScript (control-plane), docs (OpenAPI, spec, changelog, change policy)
Agent/IDE config (.claude/.vscode): none
Commits: 2 commits, all signed-off: yes
CI status: all checks passing
Note: this and #819 both claim 1.22.0; whichever lands second needs the renumber to 1.23.0 (changelog, openapi.yaml, change-policy).
Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).
| function stillHeld(deps: CpDeps, x: TemplateBuild): boolean { | ||
| if (x.status !== 'registered' || !deps.hosts) return true; | ||
| return deps.hosts.all().some(([, h]) => h.holds[x.buildId] !== undefined); | ||
| } |
There was a problem hiding this comment.
suggestion: stillHeld counts every host that has ever reported, including one gone silent — so a stale host that still lists the snapshot in its last inventory yields reused: true, and placement (fresh hosts only) would then refuse the sandbox create, reintroducing a milder version of the original template_unavailable wedge until the host reports again or ages out. You weighed this in the PR notes; since each host entry carries at, a freshness bound here (for example ignore hosts whose last report is older than the inventory staleness window already used elsewhere) would close it, at the cost of an occasional duplicate build. Worth considering now while the function is one line either way — also fine to leave as documented behavior.
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Summary
This PR makes a template create skip reuse of a registered build whose snapshot no host holds any more, and admit a new build instead (#816). The admission change is correct and well documented. But the rebuild it admits has the same manifest hash as the stale registered build, and registration's T.unique rule rejects it. So the #816 scenario still ends with no usable build, now after a wasted build. The fix also counts stale hosts, which placement doesn't.
Author: webchang (MEMBER — maintainer)
Areas reviewed: TypeScript (control-plane), tests, API docs/spec
Agent/IDE config (.claude/.vscode): none
Commits: 2 commits, all signed-off: yes
CI status: passing
Note: #819 also claims API 1.22.0, so whichever lands second renumbers to 1.23.0 (the PR body already says so).
Assisted-By: Claude Code
| // that register under one manifest hash). A registered one counts only while a host | ||
| // holds its snapshot (stillHeld). | ||
| reused = cur?.builds.find( | ||
| (x) => REUSABLE.has(x.status) && buildReuseKey(x) === want && stillHeld(deps, x), |
There was a problem hiding this comment.
must-fix: The fix stops at admission, but the rebuild it admits can't register. A rebuild of the same inputs produces the same manifest hash. At registration, hostBuildReport's T.unique check (host-handlers.ts ~L952: c.builds.find((x) => x !== y && x.buildId === manifestHash)) finds the old registered build. That build is still registered under that hash, because this PR leaves it as it is ("It does not repair the old build"). So the new build is rejected with T.unique: "another build of this template (…, registered) already has this manifest hash". host-flow.test.ts (~L190-226) already asserts this for a second build of one snapshot.
The result: in the #816 case, the user pays for a full build and still has no usable build. The next create is admitted again (the old build is still unheld), so each retry queues another doomed build.
Possible fixes: when the new build registers, have T.unique let a registered twin that no host holds be superseded (move it to retired/replaced in the same update, and carry default/tags to the new entry so two builds don't share one buildId), or retire the unheld twin at admission. Either needs a test that drives the rebuild through claim → built report and expects registered.
| */ | ||
| function stillHeld(deps: CpDeps, x: TemplateBuild): boolean { | ||
| if (x.status !== 'registered' || !deps.hosts) return true; | ||
| return deps.hosts.all().some(([, h]) => h.holds[x.buildId] !== undefined); |
There was a problem hiding this comment.
suggestion: As the PR notes say, this counts every reported host, stale ones included. The sandbox create it is meant to agree with counts fresh hosts only: ensureActiveLease reads hostViewsOf → freshHosts (HOST_STALE_S = 360 s) and refuses template_unavailable / not_held. So a host that went silent while still listing the snapshot reproduces the #816 bug (200 reused: true, then 409). I'd use freshHosts(deps) here. The other way to fail is a duplicate build while a host is briefly stale, and that is the safe direction the spec text already accepts for a restart.
| const again = await create(d); | ||
| expect(again.status).toBe(202); | ||
| expect(again.body).toMatchObject({ status: 'queued', buildId: null }); | ||
| expect(again.body).not.toHaveProperty('reused'); |
There was a problem hiding this comment.
suggestion: The test stops at 202 queued. Drive this build through a host claim and a built report with the same manifest hash H, and assert that it ends up registered and that GET /v1/templates/{id} shows one usable build for H. As written, this would have caught the T.unique rejection (see the comment on sandbox-handlers.ts:1066).
…pshot no host holds A create skips reuse of a registered build no host holds and admits a new build. That rebuild has the old build's manifest hash, so registration's T.unique rule rejected it, and the case ended with no usable build. At registration, when the built report's manifest hash belongs to a registered build of the template and no fresh host holds it, the new build registers and supersedes the old one in the same catalog update: the old build becomes retired (reason step superseded, its leases gone) and keeps its build id, the tags naming that id (default included) resolve to the new build, and a retire record by the policy names both builds. When a fresh host holds the hash, T.unique still rejects the rebuild. Two builds can now share one build id, one retired. buildById and buildByRef resolve a build id to the build not ended, and every lookup by build id within a template uses them: references and tags, the build routes (get, retire, reject, cancel, tags), activation and its lease write, the sandbox create's status re-check, the session seed, the host's build and worker reports, the wanted state's re-check and placement's worker map. A superseded build lists no tags. Reuse and registration count fresh hosts only (HOST_STALE_S), as placement and a sandbox create do. Refs rossoctl#816 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
… registered build The lifecycle spec's Reuse paragraph and the host agent's registration section say that reuse counts fresh hosts only, and that a rebuild whose manifest hash belongs to a registered build no fresh host holds supersedes it: the old build retired and keeping its id, its tags naming the new build, a retire record by the policy naming both. The record table lists the superseded build's retire record. The OpenAPI descriptions of the create, the build's id, tags and reason, and the build read say what a build id a superseded build shares names. The 1.22.0 changelog entry says the same. Refs rossoctl#816 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
…upersede The supersede check counted every fresh host, the reporting one included. A host's inventory can list the snapshot it has just built before its built report arrives, and the rebuild was then rejected T.unique. Registration now supersedes a registered twin unless a fresh host other than the reporting one holds the manifest hash (heldFreshElsewhere). When the reporting host held the snapshot all along (the already-built short cut), the result is still one registered build of it, on a host that holds it. Another fresh host holding it still means T.unique rejects. The spec, the OpenAPI create description and the 1.22.0 changelog entry say so, and the spec drops the limit this closes. Refs rossoctl#816 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
…egistered build Leaving the reporting host out of the supersede check also let a second build of the same snapshot under another profile or gate record replace a registered build that is live and held, the host's already-built short cut, swapping its attestation. A create that skips a registered build of the same inputs because no fresh host holds its snapshot now notes that build on the new one (rebuildOf, internal, never on the wire). Registration supersedes only when the build reported carries rebuildOf naming the registered twin and no fresh host other than the reporting one holds the hash. Every other build with the same hash is rejected T.unique, as before, whoever holds the snapshot. The spec, the OpenAPI create description and the changelog entry say so. Refs rossoctl#816 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
Takes main at a7d568d, which took API 1.22.0. This branch's changelog section becomes 1.23.0, as info.version and the change policy do. Refs rossoctl#816 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
…oss of the snapshot Superseding a registered build dropped its live activation leases, so each holder's worker was stopped once idle. The twin's live leases now move to the rebuild in the same update, each with its since and its activate record; the retire record says how many moved. A healthy build could be superseded on a single host after a control-plane restart, or while that host was silent past HOST_STALE_S: no fresh host, so the create was admitted as a rebuild, and the host's already-built report superseded the build. Two changes close it: - At admission, when no fresh host reports at all, holding is unknown and the registered build is reused as before. Only fresh hosts that report and hold nothing of it admit a rebuild. - At claim, a rebuild claimed by a host whose last inventory already held the snapshot it rebuilds is marked (claim.held, internal). Its built report is no rebuild: it is rejected T.unique, and the old build stays registered with its leases. Refs rossoctl#816 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
…he build The lifecycle spec's Reuse paragraph and its supersede paragraph, the OpenAPI create description and the 1.23.0 changelog entry say that a create reuses a registered build while no fresh host reports at all, that a rebuild claimed by a host already holding the snapshot is rejected T.unique, and that a supersede moves the old build's live leases to the new build. The record table names the superseded build's retire record. Refs rossoctl#816 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
Second round: the review's must-fix, two suggestions and the testThe must-fix is fixed by superseding the old build at registration, by its own rebuild only. Both suggestions are taken: reuse and registration count fresh hosts only. The test now drives the rebuild through a claim and a
|
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Summary
Follow-up to our review at 84ec418. All three points are addressed:
- must-fix (T.unique rejects the rebuild): fixed. A create that skips an unheld registered build records
rebuildOf. At registration, that rebuild supersedes the twin in the same catalog update when the twin is still registered, the claiming host didn't already hold the snapshot (claim.held), and no other fresh host holds it. The twin becomesretired(reason.step: superseded) and keeps its id. Its live leases move to the new build, tags (defaultincluded) resolve to it throughbuildById, and aretirerecord bypolicynames both builds. EverybuildIdlookup that could now hit two builds goes throughbuildById/buildByRef, including activation'sworkerOf, the lease write, retire/reject, tags, exchange seed and wanted. - suggestion (count fresh hosts only): done.
stillHeldusesheldFresh/freshHosts, and when no fresh host reports at all, the build is reused as before. - suggestion (drive the test through registration): done. host-flow covers supersede end to end (tags, records,
verifyExport, wanted/remove, reuse afterwards), plus the reporting-host-only, other-host-holds,already builtshort-cut, stale-host, restart and lease-move cases.
The merge of main (b98d9da) has conflicts only in docs (CHANGELOG, openapi version, change-policy). They are resolved correctly: this change is now 1.23.0, above #819's 1.22.0.
Author: webchang (MEMBER — maintainer)
Areas reviewed: TypeScript (control-plane), tests, API docs/spec
Agent/IDE config (.claude/.vscode): none
Commits: 9 commits, all signed-off: yes
CI status: passing
Assisted-By: Claude Code
clawgenti
left a comment
There was a problem hiding this comment.
Review of the reuse-gate + supersede state machine: I traced the reuse admission, the rebuildOf marker, the registration supersede, lease moves, tag moves, and every build-id lookup (buildById/buildByRef and their call sites), plus the docs and tests. The state machine is coherent — chained supersedes, second rebuilds, quota counting of moved leases, and place()'s worker resolution all check out, and the spec/OpenAPI/changelog wording matches the code (including the 1.23.0 bump). No must-fix issues found; the findings below are suggestions and nits.
Author: webchang (MEMBER — maintainer)
Areas reviewed: TypeScript (control-plane), docs (openapi, spec, changelog, change policy), tests
Agent/IDE config (.claude/.vscode): none
Commits: 9 commits, all signed-off: yes
CI status: passing (all checks)
| stream, | ||
| kind: 'retire', | ||
| subject: 'policy', | ||
| body: { |
There was a problem hiding this comment.
suggestion — The retire (and build/check) provenance records are appended inside the cat.update callback, before the document write at the end of queue.run. If the doc write fails after the appends, the audit trail says the twin was retired while the catalog still has it registered, and a retried host report would append duplicate records (the appends are side effects). This mirrors the pre-existing build/check pattern, so it's consistent, but the retire record is the first that asserts a state transition of a different build, so the inconsistency is more consequential. Suggested fix: append the records after a successful write, or note the ordering assumption in a comment, if the catalog ever gains retries.
| !heldFreshElsewhere(deps, manifestHash, host) | ||
| ? twin | ||
| : undefined; | ||
| results.push( |
There was a problem hiding this comment.
suggestion — The supersede (retiring the old build and moving its leases) runs under only the catalog's per-id queue, not under activationLock, while takeLeaseLocked's comment claims "a retire … take the lock too, so this read is current" and retireBuilds does take it. I traced the interleavings and found no lost lease — takeLeaseLocked's final cat.update re-resolves into = buildById(cur.builds, target.buildId), so a lease written before or after a concurrent supersede lands on / stays with the new registered build. But the placement trial, quota check and fresh check judge a snapshot a concurrent supersede can change, so the documented lock invariant is weaker in practice now. Suggested fix: take the activation lock around the registration supersede, or update the takeLeaseLocked comment. Why now: the supersede is new in this PR and is the first retire-path that bypasses the lock.
| } | ||
| : { rule: 'T.unique', passed: true }, | ||
| ); | ||
| const failed = results.find((r) => !r.passed); |
There was a problem hiding this comment.
suggestion — Dead end the new admission path makes easier to hit: if the old build is retired by its owner between the create (which set rebuildOf) and the rebuild's registration, supersedes is undefined (twin not registered) and the rebuild is rejected T.unique with the "create again after its snapshot is removed from the host" message — yet the snapshot is already gone from every fresh host (that's why the rebuild was admitted), and the retired build never leaves doc.builds, so those inputs can never register again. Identical behavior pre-existed for the different-profile case, so not a regression, but the new spec text (§6.1 "When that build is retired…") documents this dead end without covering it. Suggested fix: let a rebuild replace a retired-and-unheld twin as well, or document the dead end explicitly in the spec.
| ? doc.builds.find((z) => (z.handle ?? z.buildId) === build.rebuildOf) | ||
| : undefined; | ||
| const held = of !== undefined && deps.hosts?.get(host)?.holds[of.buildId] !== undefined; | ||
| return { |
There was a problem hiding this comment.
nit — heldFreshElsewhere(deps, manifestHash, host) and the claim-time held flag read the process-local host registry with no lock shared with inventory writes, so outcomes can depend on report ordering. This is guarded (a late-arriving holder flips the result to a safe T.unique rejection, never a wrong supersede) and the spec says the check is only as current as the last inventories — just noting the nondeterminism.
| } | ||
| : { rule: 'T.unique', passed: true }, | ||
| ); | ||
| const failed = results.find((r) => !r.passed); |
There was a problem hiding this comment.
nit — When the rebuild supersedes, the T.unique result is recorded passed: true with the "supersedes registered build…" message even when a different rule in results fails and the outcome is rejected — the check record then reads oddly (T.unique passed, outcome rejected). Cosmetic.
clawgenti
left a comment
There was a problem hiding this comment.
Review of the reuse-gate + supersede state machine: I traced the reuse admission, the rebuildOf marker, the registration supersede, lease moves, tag moves, and every build-id lookup (buildById/buildByRef and their call sites), plus the docs and tests. The state machine is coherent — chained supersedes, second rebuilds, quota counting of moved leases, and place()'s worker resolution all check out, and the spec/OpenAPI/changelog wording matches the code (including the 1.23.0 bump). No must-fix issues found; the findings below are suggestions and nits.
Author: webchang (MEMBER — maintainer)
Areas reviewed: TypeScript (control-plane), docs (openapi, spec, changelog, change policy), tests
Agent/IDE config (.claude/.vscode): none
Commits: 9 commits, all signed-off: yes
CI status: passing (all checks)
Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).
| stream, | ||
| kind: 'retire', | ||
| subject: 'policy', | ||
| body: { |
There was a problem hiding this comment.
suggestion — The retire (and build/check) provenance records are appended inside the cat.update callback, before the document write at the end of queue.run. If the doc write fails after the appends, the audit trail says the twin was retired while the catalog still has it registered, and a retried host report would append duplicate records (the appends are side effects). This mirrors the pre-existing build/check pattern, so it's consistent, but the retire record is the first that asserts a state transition of a different build, so the inconsistency is more consequential. Suggested fix: append the records after a successful write, or note the ordering assumption in a comment, if the catalog ever gains retries.
| !heldFreshElsewhere(deps, manifestHash, host) | ||
| ? twin | ||
| : undefined; | ||
| results.push( |
There was a problem hiding this comment.
suggestion — The supersede (retiring the old build and moving its leases) runs under only the catalog's per-id queue, not under activationLock, while takeLeaseLocked's comment claims "a retire … take the lock too, so this read is current" and retireBuilds does take it. I traced the interleavings and found no lost lease — takeLeaseLocked's final cat.update re-resolves into = buildById(cur.builds, target.buildId), so a lease written before or after a concurrent supersede lands on / stays with the new registered build. But the placement trial, quota check and fresh check judge a snapshot a concurrent supersede can change, so the documented lock invariant is weaker in practice now. Suggested fix: take the activation lock around the registration supersede, or update the takeLeaseLocked comment. Why now: the supersede is new in this PR and is the first retire-path that bypasses the lock.
| } | ||
| : { rule: 'T.unique', passed: true }, | ||
| ); | ||
| const failed = results.find((r) => !r.passed); |
There was a problem hiding this comment.
suggestion — Dead end the new admission path makes easier to hit: if the old build is retired by its owner between the create (which set rebuildOf) and the rebuild's registration, supersedes is undefined (twin not registered) and the rebuild is rejected T.unique with the "create again after its snapshot is removed from the host" message — yet the snapshot is already gone from every fresh host (that's why the rebuild was admitted), and the retired build never leaves doc.builds, so those inputs can never register again. Identical behavior pre-existed for the different-profile case, so not a regression, but the new spec text (§6.1 "When that build is retired…") documents this dead end without covering it. Suggested fix: let a rebuild replace a retired-and-unheld twin as well, or document the dead end explicitly in the spec.
| ? doc.builds.find((z) => (z.handle ?? z.buildId) === build.rebuildOf) | ||
| : undefined; | ||
| const held = of !== undefined && deps.hosts?.get(host)?.holds[of.buildId] !== undefined; | ||
| return { |
There was a problem hiding this comment.
nit — heldFreshElsewhere(deps, manifestHash, host) and the claim-time held flag read the process-local host registry with no lock shared with inventory writes, so outcomes can depend on report ordering. This is guarded (a late-arriving holder flips the result to a safe T.unique rejection, never a wrong supersede) and the spec says the check is only as current as the last inventories — just noting the nondeterminism.
| } | ||
| : { rule: 'T.unique', passed: true }, | ||
| ); | ||
| const failed = results.find((r) => !r.passed); |
There was a problem hiding this comment.
nit — When the rebuild supersedes, the T.unique result is recorded passed: true with the "supersedes registered build…" message even when a different rule in results fails and the outcome is rejected — the check record then reads oddly (T.unique passed, outcome rejected). Cosmetic.
clawgenti
left a comment
There was a problem hiding this comment.
Tracking marker for the review above (my first posted copy, #pullrequestreview-5922527508, omitted this marker and cannot be edited after submission).
Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).
Upstream main at 032c8f6 (merge of rossoctl#818). Brings, since ccf393b: - rossoctl#819: the retire/reject guard for an active session pinned to a build, with ownership.ts's index of the sessions pinned to each build; - rossoctl#804: packages/knative-server renamed to packages/server; - rossoctl#818: a registered build is reused only while a fresh host holds its snapshot (no fresh host at all: reused as before), and a supersede at registration narrowed to rebuildOf-flagged rebuilds (excludes the reporting host, records claim.held, moves the leases); buildById and buildByRef. The fork carried earlier ports of rossoctl#818 and rossoctl#819 (d43a7a8 stillHeld; 144314a and e674b3c the pinned-session retire guard and its pruning). Upstream's versions win. Conflicts, each resolved to upstream's side: - docs/api/openapi.yaml: the create's reuse paragraph (fresh hosts, supersede) and retire's build_in_use wording. - packages/control-plane/src/ownership.ts: buildSessionsKey's comment (retire or reject), indexSession and cascadeDelete's key local, and hasActiveSessionOnBuild's comment. - packages/control-plane/src/sandbox-handlers.ts: stillHeld (fresh hosts, heldFresh, no fresh host means reuse) and buildsInUse's comment. - packages/control-plane/test/activation.test.ts: the pinned-session retire test and the pruning test, as upstream has them. - packages/control-plane/test/template-create.test.ts: the reuse test, plus upstream's stale-host and no-fresh-host cases. After the resolution these five files are byte-identical to upstream's, so no fork duplicate of the ports remains. CHANGELOG.md is upstream's. No fork-only file references packages/knative-server. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
Closes #816
What changed and why
registeredbuild now reuses it only while a fresh host (its last inventory at most HOST_STALE_S, 360 s, old, the hosts placement counts) holds its manifest hash. Before, a create was answered200, reused: truewith a build whose snapshot no host held any more. The sandbox create on it was then refused409 template_unavailable, and the same create could never build it again.202, noreused), with the usual quota and gate checks. When no fresh host reports at all (right after a control-plane restart, or the only host silent past HOST_STALE_S), whether the snapshot is held is unknown, and the registered build is reused as before.rebuildOf). When a host claims the rebuild, the claim notes whether that host's last inventory already held the snapshot (claim.held). Both are internal and never on the wire.registered, the claiming host did not already hold the snapshot, and no fresh host other than the reporting one holds the hash, the rebuild registers and supersedes the old build in the same catalog update. The reporting host is left out because it has just built the snapshot, and its inventory may list it before thebuiltreport. The old build becomesretired(reason.step: superseded) and keeps its build id. Its live leases move to the new build, so each holder's worker keeps running. The tags that named the id,defaultincluded, then name the new build. Aretirerecord bypolicynames both builds. When another fresh host does hold the hash, the old build is still usable there, andT.uniquerejects the rebuild, as before. A rebuild claimed by a host that already held the snapshot found it already built:T.uniquerejects it, and the old build stays registered with its leases. A rebuild that fails leaves the old build untouched. Only the rebuild supersedes: any other build with the same hash (another profile or gate record, which the host finds already built) is rejectedT.unique, as before, whoever holds the snapshot.buildByIdandbuildByRefresolve an id to the build that is not ended. Every lookup by build id within a template uses them: references and tags, the build routes, activation and its lease, the sandbox create's re-check, the session seed, the host's reports, the wanted state and placement's worker map. The superseded build isshared(its snapshot is live), so it is never stopped or removed, and a host'sremovedfor the id is refused.queuedtobuilt) is reused as before. A deployment without host agents is unchanged.retirerecord. Inopenapi.yaml, thecreateTemplatedescription and thereused,buildId,tagsandreasonfields say when a registered build counts and which build a shared id names. API version 1.23.0 (changelog and change policy updated), because the answer to a create in this case changes.Tests
template-create.test.ts, new case "reuses a registered build only while a host holds its snapshot", with a host registry in the deps: a queued build is reused while no host holds anything; a registered build held by a host is answered200 {reused: true, buildId}; once the host's inventory no longer holds it, the same create answers202, queued, with noreused. The case fails with the fix reverted.host-flow.test.ts, "supersedes a registered build whose snapshot no host holds when it is built again (Template create reuses a registered build even when no host holds its snapshot any more #816)": the rebuild goes through a claim and abuiltreport with the same hash and endsregistered.GET /v1/templates/{id}shows one usable build for the hash, withdefaulton it. The old build isretired(superseded), with no tags. The records endbuild,check,retire, and the export verifies. The wanted state neither stops nor removes the old build, and the next create reuses the new one.host-flow.test.ts, "addresses the build that took a superseded build id over": activating and an admin's reject by the hash act on the new build.host-flow.test.ts, "supersedes when only the reporting host lists the snapshot", and "rejects a rebuild when another fresh host holds the snapshot by its report".host-flow.test.ts, "does not count a stale host as holding the snapshot at registration". The existing "rejects a second build of a snapshot" case now runs three ways (no host, the reporting host, another host holding the snapshot): a build under another profile is rejectedT.uniquein each.host-flow.test.ts, "moves the superseded build's live leases to the rebuild, so its holder's worker keeps running": a leased build is superseded; the lease is on the new build, the host'srunlists it, nothing is stopped, and theretirerecord saysleasesMoved: 1.host-flow.test.ts, "reuses the registered build when no fresh host reports at all (a control-plane restart)" and "… when the only host is silent past HOST_STALE_S": the create reuses, with no build queued.host-flow.test.ts, "rejects a rebuild claimed by a host that already held the snapshot (the already built short cut)": admitted as a rebuild, claimed by a host holding the snapshot, rejectedT.unique; the old build stays registered with its lease.template-catalog.test.ts:buildByIdpicks the build not ended, in either order.pnpm -r typecheck, the control-plane suite (with Redis), the openapi contract test and pre-commit pass.Every commit is signed off (DCO).
Notes for review
202with a new build, where it was200 reused: true.stillHeldcounts fresh hosts only (freshHosts, HOST_STALE_S), as placement andensureActiveLeasedo, so a host gone silent no longer givesreused: truewhile another host reports. When no fresh host reports at all, it reuses: a single-host deployment after a restart, or with its host silent, never rebuilds and supersedes a healthy build.rebuildOf) may supersede it, so a live, held build is never replaced by a build under another profile or gate record, and its attestation never changes. The reporting host is left out of the "held elsewhere" check, because it has just built the snapshot, but only when it did not hold the snapshot at its claim.Assisted-By: Claude Code