Repository navigation
Closed
Milestone
Description
Problem
Upstream's templates are a fixed JSON list in SH_SANDBOX_TEMPLATES
(packages/control-plane/src/sandbox-config.ts), served by GET /v1/templates on the sandbox route
profile only (src/routes.ts), each id mapped straight to one worker. So:
- adding, changing or removing a template is a redeploy (
deploy/sbx/setup.sh, RUNBOOK §5); - a template has no versions: a new snapshot of the same environment is a new id or an in-place swap
of the worker under live sandboxes; - a client cannot see whether a template can serve now (is its worker attached?): a template with no
worker fails only when it is used; - a Moca Pi session (the
harnessprofile) cannot read the templates at all.
Proposal
Templates live in a store the control plane owns, imported once from the env list, and are served with
their builds as resources.
- Store (
packages/control-plane/src/template-catalog.ts,FileTemplateCatalog): a directory on a
persistent volume,SH_PROVENANCE_DIR, shared with the provenance store of Record template provenance in a hash chain, verifiable offline #730 (each catalog change
writes its record there).SH_SANDBOX_TEMPLATESis imported once into an empty store (acreate
record per template) and ignored after that, with a warning when it differs. Unset, nothing changes:
templates come from the env list at every start, as today. - Templates, builds, tags: a template is a name over immutable builds. A build's id is its
snapshot's manifest hash (sha256:…); an imported entry is one registered buildimported:<12 hex>
(stable per worker, never the worker id, which clients never see). Tags map to builds;defaultis
what a bare id names. - References: a sandbox create names
id,id:tagorid@sha256:…; the reference is looked up
to one build at create and kept for the sandbox's life; an unknown one is400 unknown_templateat create, as today; the read routes answer404 template_not_found. - Readiness from facts: for a registered build,
active(the relay holds an attached record for
its worker, the same record the harness routes on, with its capacity),inactive, orunknownwhen
presence cannot be read; later issues addactivating,deactivating,unavailableandretired. - Routes, on both route profiles (
BOTH), so a Moca Pi brain and a stock agent read the same
templates:GET /v1/templates(today's first fields unchanged, plusowner,visibility,onboarding,
readiness,tags,builds, and ahostsblock that later host issues fill);GET /v1/templates/{id},GET /v1/templates/{id}/builds[/{build}](each build with its own
spec, seed included, so a client that runs the seed itself reads the build it was served, never
the newest),GET /v1/templates/{id}/tags(each tag's build, when and by whom).privatetemplates are visible only to their owner and admins (others get 404).
- Deploy: an overlay
deploy/k8s/overlays/ocp-sbx/template-store(a PVC mounted as
SH_PROVENANCE_DIR) andsetup.sh SBX_TEMPLATE_STORE=1. - mocactl (the client part of this unit):
sbx templatesshows readiness and tags;
sbx templates show ID [--build BUILD];sbx create --template ID[@BUILD] [--seed], where--seed
runs the served build's own seed and checks/workspaceis a clean tree, recording its HEAD as the
sbx baseline sopullreturns only later changes andrmneeds no--force.
What the PR will contain
One PR, about 1,760 added lines with tests on the server side, plus this unit's part of the mocactl
client (sized when the branch is cut; the whole client is about 4,800 lines, filed with the server
issues it drives).
- control-plane:
src/template-catalog.ts,src/sandbox-store.ts,src/sandbox-redis.ts;
src/sandbox-handlers.ts(visibleTemplate(s),readinessFacts,templateBody,buildBody,
resolveForUse, the read handlers,createSandbox's lookup);src/routes.ts,src/index.ts,
src/main.ts(templateCatalogFromEnv, which also opens Record template provenance in a hash chain, verifiable offline #730's store);
test/template-catalog.test.ts,test/sandbox-handlers.test.ts(routing across a worker change). - deploy:
deploy/k8s/overlays/ocp-sbx/template-store/{kustomization,patch-control-plane,pvc}.yaml;
deploy/sbx/setup.sh,tests/setup.test.sh,tests/overlay.test.sh. - mocactl:
src/sbx/api.ts(the read calls),src/sbx/templates.ts(show,create --seed),
src/sbx/push.ts(the baseline),src/sbx/cli.ts; their cases intest/sbx-templates.test.ts,
test/contract.test.ts. - docs:
docs/api/openapi.yaml(templates, builds, readiness; a minor API version bump),
docs/api/CHANGELOG.md,docs/reference/http-api.md,docs/reference/configuration.md
(SH_PROVENANCE_DIR); the template lifecycle design
(docs/specs/2026-11-03-template-lifecycle-and-provenance-design.md) §1-§4.
Depends on
#730 (the provenance store: the catalog's records).
How to verify
pnpm -C packages/control-plane test -- template-catalog sandbox-handlersbash deploy/sbx/tests/overlay.test.sh;bash deploy/sbx/tests/setup.test.shpnpm -C packages/mocactl test -- sbx-templates contract- On a namespace with
SBX_TEMPLATE_STORE=1: the env list's templates are listed withreadiness: activewhile their workers are attached; the nextsetup.shrun with a changed list warns and keeps
the store;sbx create --template ID@sha256:…is served by that build.
Limits / out of scope
- An imported template has no owner (
owner: null) until an admin hands it over (Manage template tags, description, visibility and owner through the API #747). - The env list is not re-read after the first start; changes after that go through the API (Let users create sandbox templates self-serve, gated by a machine-checked policy #737,
Manage template tags, description, visibility and owner through the API #747, Retire a template, or one build of it, through the API #749). - One control-plane process per store directory (no shared store across replicas).
- Paged build logs (
…/builds/{build}/logs) and an HTTP provenance export are not in this PR.
Assisted-By: Claude Code
Activity
feat(control-plane): record template provenance in a hash chain, veri…
feat(control-plane): keep templates in a store, with builds, tags, re…
feat(sbx): setup.sh SBX_TEMPLATE_STORE puts the template store on a v…
feat(mocactl): sbx templates show, and create --template ID@BUILD --seed
fix(control-plane): the one-time template import resumes after a crash