Skip to content

control-plane: a template build's lastUsedAt is its own, not its worker id's - #941

Merged
webchang merged 1 commit into
rossoctl:mainfrom
webchang:pr/i936-lastused-per-build
Nov 20, 2026
Merged

webchang merged 1 commit into
rossoctl:mainfrom
webchang:pr/i936-lastused-per-build

Conversation

@webchang

Copy link
Copy Markdown
Member

Summary

A template build's lastUsedAt reported when its worker id was last used, not when the build was. Every build of a template from one image shares one worker id (sbx_<template id>_<image tag12>), so a freshly registered build reported an earlier, retired build's last sandbox, and a retired build reported the newer one's.

Closes #936

What changes

  • packages/control-plane/src/sandbox-handlers.ts: the readiness facts keep the newest sandbox creation per build id (every sandbox record created on a build carries buildId), and per worker only for records from before build tracing, which carry none. A build's lastUsedAt is the later of its own and its worker's untraced records, or null. The fallback is transient: records without a buildId predate build tracing and expire after SH_SANDBOX_RETENTION_SECONDS (14 days by default, sandbox-config.ts:270), after which every build's value is its own.
  • docs/api/openapi.yaml: TemplateBuild.lastUsedAt's description says it is per build, that builds of one template from one image share a worker id, that a build superseded by a rebuild of the same snapshot (feat(control-plane): reuse a registered build only while a host holds its snapshot #818) shares its build id with its successor (so the retired twin reports its successor's use), and how an untraced record counts.

No version bump and no changelog entry: the field, its type and its shape are unchanged, and this corrects what it reports to match its description, a fix that is neither additive nor breaking under the change policy. Happy to add one if you'd prefer.

Tests

  • New, in test/template-catalog.test.ts: two builds of one template sharing a worker id, sandboxes only on the retired build → the retired build reports its sandbox's time and the registered one null; with an untraced record added, it counts for both builds of that worker.
  • Before the fix the new test fails (the registered build reported the retired build's time); after it, the control-plane suite passes (2,008 passed, 3 skipped), tsc --noEmit is clean, and the docs link check finds 0 broken links.

Assisted-By: Claude Code

… worker's

Every build of a template from one image shares one worker id
(sbx_<template>_<image tag12>), and lastUsedAt was keyed by worker, so a new
build reported an earlier, retired build's last sandbox, and a retired build
the newer one's. lastUsed is now kept per build id, which every sandbox record
created on a build carries; a record from before build tracing (no buildId)
still counts for every build of its worker, as before.

Closes rossoctl#936

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

@ingpaolodettori-dev ingpaolodettori-dev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review — control-plane: a template build's lastUsedAt is its own, not its worker id's

Right diagnosis and a small, exact fix. A build's worker id is sbx_<template>_<image tag12>, shared by every build of one template from one image, so the per-worker timestamp attributed a retired build's sandboxes to a fresh build and vice versa. The facts now keep the newest creation per build id, with a per-worker map that only receives records carrying no buildId — which is exactly the pre-tracing rule the openapi description now states ("A sandbox record from before build tracing counts for every build of its worker").

  • lastUsedAt takes the later of the build's own newest record and its worker's legacy ones; null only when neither exists, so a build with no use still reports null rather than the map's absence (:0 handled by the t > 0 guard).
  • inUse is untouched and stays per worker, which is correct — capacity belongs to the worker, use belongs to the build.
  • The test builds the real shape: one worker, a retired old build and a registered new one, a record on the old build only (new build null), then a pre-tracing record that both inherit. It would have failed before the change (both would report 150).
  • The openapi note about a superseded twin sharing its successor's build id (#818) is honest about the one case the id cannot separate.

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

@webchang
webchang merged commit fb7a4d5 into rossoctl:main Nov 20, 2026
18 checks passed
@pdettori pdettori added this to the v0.11.0 milestone Nov 20, 2026
webchang added a commit to webchang/moca that referenced this pull request Nov 20, 2026
Carries rossoctl#941-rossoctl#946, rossoctl#948, rossoctl#950 and rossoctl#338's rossoctl#949/rossoctl#951 (API 1.33.0).
One conflict: docs/operate/sandbox-service/install.md's settings
table; upstream's table kept (its rossoctl#945 SBX_STORAGE_CLASS wording,
the OIDC and proxy-hop rows) plus the fork's SBX_GATE_RECORD_SCHEMA
row. The fork-only set is unchanged: the same 30 files.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
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.

A template build's lastUsedAt reports its worker id's last use, not the build's

3 participants