Repository navigation
feat(control-plane): refuse a retire or reject while an active Moca Pi session is pinned to the build - #819
Conversation
… is pinned to the build
A Moca Pi session created with a template keeps the build it resolved
to for its life, and each turn needs that build's worker. The retire
and reject guard counted live sandboxes only, so a retire (or an
admin's reject) under such a session went through: the build's leases
went, its worker was stopped and its snapshot removed, and the
session's next turn could not be served.
Sessions are now indexed by the build they are pinned to (a sorted set
per build, the build id hashed into the key as the owner index does):
added at session create, removed by the delete cascade. buildsInUse
asks the index whether an active session is still pinned to the build,
and the retire or reject is refused 409 build_in_use ("is pinned by an
active session"), as for a live sandbox.
A member whose record is gone, is not active (left deleting by a crash
mid-cascade) or names another build does not count, and the check
removes it from the set as it scans, so such a crash never blocks a
retire for good and the set does not keep growing.
Refs rossoctl#817
Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
… the build The lifecycle spec's retire (§5.1) and reject (§5.2) sections now count an active pinned session as use, with the index's limits, in place of the note that sessions did not yet name a build. The retire, retire-build and reject descriptions and their 409 answers say so. API 1.22.0: an existing refusal gains a cause, so the changelog and the change policy name the new version. Refs rossoctl#817 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
…it's 900 s default The user guide said a retire is refused while "a sandbox or session" uses the build. With this branch's guard that is exact only as: a live sandbox runs on the build, or an active Moca Pi session is pinned to it. It also gave retire --wait's default as 300 s; the CLI's default (RETIRE_TIMEOUT_S) is 900 s, past the 600 s a host keeps shipping an ended sandbox's egress before it removes the build. No other doc gives 300 s for it. Refs rossoctl#817 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.
Thanks — this closes the gap the lifecycle spec called out, and the design is sound: the per-build index mirrors the owner index (hashed key, same zset pattern), the check prunes crash-orphaned members so a stale entry can never wedge a retire permanently, and the known races (create-vs-retire ordering, pre-index sessions) are honestly documented in the spec rather than papered over. Tests cover the three behaviors that matter: block, unblock on delete, and prune-with-active-survivor.
A couple of small notes below; the rest is fine as is.
Summary
Author: webchang (MEMBER — maintainer)
Areas reviewed: TypeScript (control-plane), docs (OpenAPI, spec, changelog, user guide)
Agent/IDE config (.claude/.vscode): none
Commits: 3 commits, all signed-off: yes
CI status: all checks passing
Note: this and #818 both claim 1.22.0; per your note, whichever lands second needs the renumber to 1.23.0 (changelog, openapi.yaml, change-policy) — easy to miss on merge.
Verified: SessionRecord.state is only 'active' | 'deleting' on head (ownership.ts:75), so the rec.state === 'active' && !rec.tombstone membership check can't evict a session in an intermediate state; and RETIRE_TIMEOUT_S = 900 in packages/mocactl/src/sbx/templates.ts:40 matches the user-guide correction.
Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).
| `409 build_in_use` while a live sandbox runs on it. Idempotent: an already rejected build | ||
| is answered with `record: null`. Not reversible: a new build is the way back. Needs | ||
| `409 build_in_use` while a live sandbox runs on it or an active session is pinned to it. | ||
| Idempotent: an already rejected build is answered with `record: null`. Not reversible: a new build is the way back. Needs |
There was a problem hiding this comment.
nit: this added line runs ~115 characters where the file's description blocks wrap at 100 — the sentence rewrap merged two lines. Suggested fix: break before "Not reversible:" to restore the wrap the surrounding descriptions use. Cosmetic only; the contract test and docs CI pass either way.
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Summary
This PR counts an active Moca Pi session pinned to a build as use, so retire, retire-build and an admin's reject are refused 409 build_in_use while one exists (#817). It does this through a per-build session zset, which the delete cascade maintains and the check prunes of ended or crashed members. The implementation, tests and docs are solid, and the acknowledged limits (create/retire race, pre-index sessions) are reasonable. One design point: an idle session can block an admin's reject indefinitely. Plus one nit.
Author: webchang (MEMBER — maintainer)
Areas reviewed: TypeScript (control-plane, Redis index), tests, API docs/spec, user guide
Agent/IDE config (.claude/.vscode): none
Commits: 3 commits, all signed-off: yes
CI status: passing (all 17 checks)
Note: #818 also claims API 1.22.0, so whichever lands second renumbers to 1.23.0.
Assisted-By: Claude Code
| if (typeof deps.index?.hasActiveSessionOnBuild === 'function') { | ||
| for (const x of builds) { | ||
| if (out.has(x.buildId) || !x.buildId) continue; | ||
| if (await deps.index.hasActiveSessionOnBuild(x.buildId)) |
There was a problem hiding this comment.
suggestion (design): This now blocks an admin's reject too, and nothing can clear the block except the session's owner. Sessions don't idle out (the spec says: "blocks … until it is deleted, however long ago its last turn was"), and deleteSession is owner-only (assertOwner). So on a deployment-visible template, any user's forgotten session pins the build indefinitely. That stops the owner's retire, and also the admin's reject after the fact, which is the lever for a build that "later turns out wrong" (§5.2). Consider either letting reject count live sandboxes only (a wrong build should cut off sessions on it), or adding an admin override. At minimum, the spec's limits list should say an admin cannot get past it.
| for (const x of builds) { | ||
| if (busyBuilds.has(x.buildId) || (x.worker !== '' && legacyWorkers.has(x.worker))) | ||
| out.set(x.buildId, 'still serves a live sandbox'); | ||
| if (typeof deps.index?.hasActiveSessionOnBuild === 'function') { |
There was a problem hiding this comment.
nit: As the PR body offers: every OwnershipIndex has hasActiveSessionOnBuild now, so the typeof … === 'function' guard and the "a deployment whose index has no such check" wording in the doc comment can go.
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 #817
What changed and why
POST /v1/templates/{id}/retire,DELETE /v1/templates/{id}/builds/{build}) or an admin's reject (POST /v1/templates/{id}/builds/{build}/reject) is now refused409 build_in_use("is pinned by an active session") while an active Moca Pi session is pinned to the build. Before, only live sandboxes counted, so a retire could stop the worker and remove the snapshot that a pinned session's next turn needs.buildsInUseasks the index whether an active session is still pinned to the build. A deployment whose index has no such check behaves as before.deletingby a crash mid-cascade) or names another build does not count, and the check removes it from the set. So a crash between the cascade's steps cannot block a retire for good, and the set does not keep growing.409answers inopenapi.yamlsay so. API version 1.22.0 (changelog and change policy updated), because an existing refusal gains a cause.retire --wait's default as 300 s; it now gives the CLI's 900 s, which outlasts the 600 s a host keeps shipping an ended sandbox's egress before it removes the build.Tests
activation.test.ts, with a template store, a host inventory and the session index:409 build_in_use, and the build staysregistered; after the session is deleted, the retire answers200.200.All three fail with the session check reverted; the pruning case also fails with only the pruning reverted.
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
409 build_in_use) gains a cause.buildsInUsekeeps atypeof deps.index?.hasActiveSessionOnBuild === 'function'guard, so an index without the method behaves as before. Every index has it today, so the guard can go if you prefer.Assisted-By: Claude Code