Skip to content

feat(control-plane): reuse a registered build only while a host holds its snapshot - #818

Merged
pdettori merged 9 commits into
rossoctl:mainfrom
webchang:pr/i816-reuse-held
Nov 16, 2026
Merged

pdettori merged 9 commits into
rossoctl:mainfrom
webchang:pr/i816-reuse-held

Conversation

@webchang

@webchang webchang commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Closes #816

What changed and why

  • A template create whose inputs match a registered build 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 answered 200, reused: true with a build whose snapshot no host held any more. The sandbox create on it was then refused 409 template_unavailable, and the same create could never build it again.
  • When fresh hosts report and none holds the snapshot, the create is admitted as a new build (202, no reused), 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.
  • That create notes on the new build which registered build it rebuilds (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.
  • At registration, that rebuild has the old build's manifest hash. When the old build is still 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 the built report. The old build becomes retired (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, default included, then name the new build. A retire record by policy names both builds. When another fresh host does hold the hash, the old build is still usable there, and T.unique rejects the rebuild, as before. A rebuild claimed by a host that already held the snapshot found it already built: T.unique rejects 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 rejected T.unique, as before, whoever holds the snapshot.
  • Two builds can now share one build id, one retired. The helpers buildById and buildByRef resolve 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 is shared (its snapshot is live), so it is never stopped or removed, and a host's removed for the id is refused.
  • A build still on its way (queued to built) is reused as before. A deployment without host agents is unchanged.
  • Docs: the lifecycle spec's §4 Reuse paragraph and the §6.1 registration section state the rules as built, with their limits, and the §7.1 record table lists the supersede's retire record. In openapi.yaml, the createTemplate description and the reused, buildId, tags and reason fields 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 answered 200 {reused: true, buildId}; once the host's inventory no longer holds it, the same create answers 202, queued, with no reused. The case fails with the fix reverted.
  • A new case, "does not count a stale host as holding a registered build for reuse (HOST_STALE_S)": the holder reported past HOST_STALE_S and another host reports holding nothing, so the create builds again.
  • A new case, "reuses a registered build while no fresh host reports at all (holding unknown)": with no host reported, and with the only host silent, the create reuses.
  • 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 a built report with the same hash and ends registered. GET /v1/templates/{id} shows one usable build for the hash, with default on it. The old build is retired (superseded), with no tags. The records end build, 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 rejected T.unique in 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's run lists it, nothing is stopped, and the retire record says leasesMoved: 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, rejected T.unique; the old build stays registered with its lease.
  • template-catalog.test.ts: buildById picks the build not ended, in either order.
  • Each new case fails with its fix reverted. The existing reuse tests (a build on its way is reused, a failed build is built again) pass unchanged.
  • 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

  • feat(control-plane): refuse a retire or reject while an active Moca Pi session is pinned to the build #819 took 1.22.0 on main. This branch merges main (a7d568d) and is now 1.23.0; main's 1.22.0 section is unchanged.
  • The issue said no API version change. This PR bumps to 1.23.0 anyway, following the change policy, because the documented answer to a create changes: while no host holds the snapshot, a matching create is now 202 with a new build, where it was 200 reused: true.
  • stillHeld counts fresh hosts only (freshHosts, HOST_STALE_S), as placement and ensureActiveLease do, so a host gone silent no longer gives reused: true while 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.
  • The supersede is narrowed to Template create reuses a registered build even when no host holds its snapshot any more #816's case. Only a build admitted as the rebuild of a registered build it skipped (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.
  • A supersede moves the old build's live leases to the new build, as the tags effectively move, so no activation is lost.

Assisted-By: Claude Code

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

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);
}

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: 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 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

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),

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: 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);

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: 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');

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 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]>
@webchang

Copy link
Copy Markdown
Member Author

Second round: the review's must-fix, two suggestions and the test

The 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 built report. A closing summary lists the follow-ups made while this round was reviewed, each with its commit and test.

packages/control-plane/src/sandbox-handlers.ts:1066 (must-fix)

"The fix stops at admission, but the rebuild it admits can't register."

Fixed in 9f52331, then narrowed and hardened in 41d5cec, 6692450 and 3763d7c (see the summary below). A create of a registered build's own inputs can be admitted because fresh hosts report and none holds that build's snapshot. That create is the build's rebuild, and the new build notes which build it rebuilds (rebuildOf, internal). When the rebuild reports built with the same manifest hash, it supersedes the old build in the same catalog update, provided:

  • the old build is still registered;
  • the host that claimed the rebuild did not already hold the snapshot;
  • no fresh host other than the reporting one holds the hash.

The supersede does this:

  • The old build becomes retired, with reason: {step: superseded} and a message naming the new build. It keeps its build id.
  • Its live leases move to the new build, each with its since and its activate record.
  • Tags store a build id. So the tags that named that id, default included, now name the new build, with no tag value rewritten. A superseded build lists no tags.
  • The registration check passes T.unique, with a message naming the superseded build. A retire record by policy follows it, with from: registered, the old build's buildRecord, supersededBy, supersededByRecord, leasesMoved and tags. No new record kind is added.

Every other case is rejected T.unique, as before:

  • another build of the same snapshot, such as one under another profile or gate record;
  • a rebuild while another fresh host holds the hash;
  • a rebuild whose claiming host already held the snapshot.

A rebuild that fails leaves the old build untouched.

Two entries can now share one build id, one of them retired. So every place that finds a build by id within a template now goes through one helper, buildById (buildByRef for a handle or an id). The helper returns the build that is not ended. This covers:

  • references and tags (resolveBuild);
  • GET, DELETE and reject on /builds/{build}, cancel and tag moves;
  • activate, with its lease written onto that build only;
  • the sandbox create's status re-check, and the session seed;
  • the host's build and worker reports, and the wanted state's re-check;
  • placement's worker map.

The superseded build's handle still names it. A retire of it is a no-op (record: null), and a reject of it is refused, as for any retired build. The new build is registered, so the superseded build is shared: it is never in stop or remove, and a host's removed for the id is refused build_in_use. A live sandbox or a pinned session recorded under the id counts as use of the new build.

Tests (test/host-flow.test.ts):

  • supersedes a registered build whose snapshot no host holds when it is built again (#816): register, the host reports holding nothing, create again (202, no reused), claim, built with the same hash. The rebuild ends registered. GET /v1/templates/{id} shows one usable build for the hash, with default on it. The old build is retired, superseded, with no tags. The records end build, check, retire and the export verifies. The wanted state neither stops nor removes the old build, removed for the hash is refused, and the next create reuses the new build.
  • addresses the build that took a superseded build id over: activating by the hash puts the lease on the new build, and an admin's reject by the hash rejects the new build.
  • test/template-catalog.test.ts: buildById picks the build not ended, in either order.

packages/control-plane/src/sandbox-handlers.ts:1252 and :1253 (suggestions)

"I'd use freshHosts(deps) here."

Fixed in 9f52331. stillHeld reads heldFresh, a new helper over freshHosts (HOST_STALE_S, 360 s), the hosts placement and ensureActiveLease use. A host gone silent no longer gives reused: true while another host reports. Registration's supersede check uses the same fresh hosts. When no fresh host reports at all, holding is unknown, and the build is reused (3763d7c, below).

Tests: does not count a stale host as holding a registered build for reuse (HOST_STALE_S) (test/template-create.test.ts) and does not count a stale host as holding the snapshot at registration (test/host-flow.test.ts).

packages/control-plane/test/template-create.test.ts:328 (suggestion)

"Drive this build through a host claim and a built report with the same manifest hash H."

Fixed in 9f52331, as the first host-flow test above. The template-create case now gives its host a current inventory time, so it still checks admission on its own.

Summary of the follow-ups

Each test listed fails with its part reverted.

  • The reporting host doesn't block its own rebuild (41d5cec). A host's inventory can list the snapshot it has just built before its built report arrives. So the reporting host is left out of the "held by another fresh host" check. Test: supersedes when only the reporting host lists the snapshot.
  • Only the rebuild supersedes (6692450). A create that skips a registered build because no fresh host holds its snapshot notes that build on the new one (rebuildOf). Registration supersedes only for a build carrying rebuildOf that names the registered twin. A build under another profile or gate record that hashes to the same snapshot is rejected T.unique, so a live, held build is never replaced and its attestation never changes. Tests:
    • rejects a second build of a snapshot the template already has, … holding it, three cases (no host, the reporting host, another host);
    • rejects a rebuild when another fresh host holds the snapshot by its report.
  • Leases move to the new build (3763d7c). Before, a supersede dropped the old build's live leases, and each holder's worker was stopped once idle. Now they move to the new build in the same update, and the retire record says how many moved (leasesMoved). Test: 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's run lists it, and nothing is stopped.
  • No fresh host means reuse (3763d7c). Right after a control-plane restart, or while the only host is silent past HOST_STALE_S, no fresh host reports. Holding is then unknown, so the registered build is reused, with no rebuild queued. Only fresh hosts that report and hold nothing of the snapshot admit a rebuild. A single-host deployment therefore never rebuilds and supersedes a healthy build. Tests:
    • reuses the registered build when no fresh host reports at all (a control-plane restart);
    • reuses the registered build when the only host is silent past HOST_STALE_S;
    • reuses a registered build while no fresh host reports at all (holding unknown) (test/template-create.test.ts).
  • A claiming host that already held the snapshot gets T.unique (3763d7c). At claim, a rebuild records whether the claiming host's last inventory already held the snapshot it rebuilds (claim.held, internal). Such a host takes its "already built" short cut, so its report is no rebuild. It is rejected T.unique, and the old build stays registered with its leases. Test: rejects a rebuild claimed by a host that already held the snapshot (the already built short cut).
  • API 1.23.0 (b98d9da). feat(control-plane): refuse a retire or reject while an active Moca Pi session is pinned to the build #819 merged and took 1.22.0 on main. This branch merges main. Its changelog section is now 1.23.0, as are info.version and the change policy, and main's 1.22.0 section is unchanged. The openapi-contract version test passes.

Docs (cb5a9a3, 41d5cec, 6692450, 1acf67f) cover the following:

  • The lifecycle spec's §4 Reuse paragraph: fresh hosts, and reuse when none reports.
  • The §6.1 registration section: the supersede, by the rebuild only; the reporting host left out; the claim-time check; the leases moving; and which build an id names.
  • The §7.1 record table: the superseded build's retire record.
  • The OpenAPI descriptions: the create, reused, the build's buildId, tags and reason, and the build read.
  • The 1.23.0 changelog entry.

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.

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 becomes retired (reason.step: superseded) and keeps its id. Its live leases move to the new build, tags (default included) resolve to it through buildById, and a retire record by policy names both builds. Every buildId lookup that could now hit two builds goes through buildById/buildByRef, including activation's workerOf, the lease write, retire/reject, tags, exchange seed and wanted.
  • suggestion (count fresh hosts only): done. stillHeld uses heldFresh/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 built short-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

@pdettori
pdettori merged commit 032c8f6 into rossoctl:main Nov 16, 2026
18 checks passed

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

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: {

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 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(

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 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);

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 — 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 {

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 — 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);

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

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: {

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 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(

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 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);

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 — 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 {

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 — 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);

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

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

webchang added a commit to webchang/moca that referenced this pull request Nov 16, 2026
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]>
@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.

Template create reuses a registered build even when no host holds its snapshot any more

4 participants