Repository navigation
docs(sandbox): templates -- the model, the API reference, provenance and session pinning - #924
Conversation
…and session pinning The template feature had a how-to and runbook steps but no model or reference page. From TEMPLATE_LIFECYCLE.md and the client developer guide's template parts, kept only where the published docs had nothing, corrected against the code and openapi.yaml: - docs/sandbox/concepts/templates.md (new): templates, builds, tags, the policy, host agents and activation leases; a build's onboarding status and a registered build's readiness as tables and diagrams; how a sandbox or session picks its build (id, id:tag, id@build, default). - docs/sandbox/reference/templates-api.md (new): the template, policy, quota and activation routes (who may call, what it does, the mocactl sbx command), conventions (the read routes work without a template store; everything else needs one), the error codes with 409 policy_changed and 403 mode_not_allowed, the policy rule ids, and the quotas with their defaults (100 / 10 / 8 / 200) and refusals. - runbook: in §5, which policy writes need an admin named in the settings, and how gate records are trusted or self-attested; a new unnumbered "Provenance records: export, verify and redact" section (redact-provenance.py --catalog-only redacts every catalog entry and takes no template id). The numbered §1-§14 are unchanged. - how-to/templates.md: "Pin a session to a build" (mocactl run --option sandboxTemplate=...), "From your own code", and a fix: a SANDBOX create after a retire answers 410; a template create on a retired id queues a new build. The user guide and the glossary link the pages. Claims the code did not bear out were dropped (among them the source's "a stored invalid policy fails until an admin PUTs a valid one": PUT /v1/policy reads the stored policy first). The export/verify/redact scripts were run end to end on a synthetic store; the two kubectl steps are marked unverified on a cluster. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Review — docs(sandbox): templates — the model, the API reference, provenance and session pinning
Both pages fill a real gap, and the corrections the PR calls out check out. I verified about 45 claims against the code and openapi.yaml; nothing blocking, two precision nits inline.
Placement and shape
docs/sandbox/concepts/templates.md(sidebar_position 3) anddocs/sandbox/reference/templates-api.md(position 2) slot in beside the existing concepts/reference pages with no position collision, and both are linked from the user guide and the how-to.- The banner matches the CONTRIBUTING-DOCS template word for word, and "Moca Pi" / lowercase
mocafollow existing usage.
Reference accuracy (sampled)
- Store gating is as described: the five GET reads fall back to the declared list (
sandbox-handlers.ts:2576-2619;visibleTemplatesandtrustedSettolerate a missing policy store), whilegetPolicy/getQuotaand every write go throughpolicyStore/writableand answer400 invalid_requestwithoutSH_PROVENANCE_DIR(:884-906,:2642,:2816). - Error codes and statuses match
errors.ts(policy_changed409 at:138,mode_not_allowed403 at:141, and the rest of the table). - Quota defaults 100/10/8/200 (
template-policy.ts:167,DEFAULT_OWNEDat:119); the live cap is 3 per subject (sandbox-config.ts:272) with a deployment total. - Lease 60–86400 s, default the largest
idleLimitSecondsof the holders, else 3600 (sandbox-handlers.ts:1604-1622);Retry-After30 s or the start line (:2079,activation.ts:575). - Rule ids, the M7 bounds (128 MiB, 1–32 vCPUs, 256 MiB), M8/M9,
X1.self.scope/X1.self.egress/X12.self, X10/X11/X12/X14/X15 all matchtemplate-policy.ts(:380-655). - Onboarding and readiness tables match
buildBody/templateBody(:721-819), including the honest "builtis brief" note (thebuiltreport runs registration in the same catalog update,host-handlers.ts:1075-1104), cancel →failed/cancelled(:1398-1421), a pre-registration retire answeringbuildId: null(:1997-1999), and reject being registered-only (:1935-1941). - Use path:
resolveForUse's 410/400 split (:839-871),template_not_activewithreadiness+Retry-Afterand theactivate: falsevariant (:2087-2160), and the session create's enrolled-only activation (handlers.ts:1164-1171) are all as written.
Provenance section
- Store layout,
moca-provenance-record/1, the kind list (withusedefined and never written — no writer in the tree), record-before-head (provenance.ts:246-250), andexportskipping a blob the store does not hold (:310-336) match the page. verify-provenance.pyandredact-provenance.pymatch their docstrings:--head STREAM=sha256:…repeatable, exit 0/1/2,--catalog-onlytakes no id and touches no record, andredactions.lognever holds the matched text.- The widening and self-attest prose in §5 matches
policyWidens/profileWidens(sandbox-handlers.ts:2479-2569) and the per-sha256 claim queue (:966-1050) precisely, including the 403-for-API-grant-admins rule.
Session pinning
- Fields (
sandboxTemplate,sandboxBuildId,templateManifestHash,handlers.ts:554-561),sendUnlisted(session-options.ts:110-125),--optionignored on resume (headless.ts:499-503), the seed origin (run-turn.ts:390-444) andSH_TURN_PATCH_MAX_BYTES(:522-529) all hold.
Checks
make check-links: 238 files, 0 broken;check-docs-publish.sh: 85 published files, no match; runbook §1–§14 headings byte-identical tomain; CI 18/18, docs job and site build included.
Two nits inline: the model page's absolute "a worker runs only while someone holds an activation lease" (true for a host-built build, not for one the deployment runs), and the create body's "visibility defaults to deployment" (a self-attested create stores private).
Author: pdettori (MEMBER — maintainer). One commit, signed off.
| listens. It reports what the host holds, claims queued builds, builds and probes them, reports | ||
| the result, and starts or stops the workers the control plane wants on that host | ||
| ([The template host agent](../../operate/sandbox-service/runbook.md#the-template-host-agent)). | ||
| - **A worker runs only while someone holds an activation lease.** An **activation lease** is a |
There was a problem hiding this comment.
suggestion: true for a build a host agent runs, but not for one the deployment runs itself: a build declared in SH_SANDBOX_TEMPLATES (id imported:<12 hex>) is never host-managed — hostManaged() returns false for it (activation.ts:200), so requireActive returns before any lease exists (sandbox-handlers.ts:2099-2106), and activate refuses it with 400 invalid_request (:1536-1548). The API reference says this under Activation; one clause here ("…for a build a host agent runs") would keep the model page from reading as absolute.
There was a problem hiding this comment.
Fixed in c986909. The bullet now opens "A host-built build's worker runs only while someone holds an activation lease", and adds that a build the deployment declares itself (SH_SANDBOX_TEMPLATES, an imported: id) isn't host-managed: it needs no lease, and activating it is refused with 400 invalid_request (hostManaged(), activation.ts:200).
| `moca-sbx-template-spec/1` document; its guest size is `guest_ram_mb` or its alias `guest_mb`, | ||
| never both, and an `id` or `image` inside it must equal the create's. `gateRecord` is the gate | ||
| record file, byte for byte. The whole body is at most 1 MiB. `visibility` defaults to | ||
| `deployment`. |
There was a problem hiding this comment.
nit: with one exception worth a clause: a self-attested create (an X1 profile with selfAttest, and a gate record the policy does not trust) stores private when visibility is omitted — and an explicit deployment there is refused 409 self_attested (sandbox-handlers.ts:1105-1111, :1262-1270). As written, a self-attesting client reads the default as deployment and is surprised by the refusal.
There was a problem hiding this comment.
Fixed in c986909: "visibility defaults to deployment, except on a self-attested create (a profile with selfAttest and a gate record the policy does not trust): that one is stored private, and an explicit deployment is refused 409 self_attested" (sandbox-handlers.ts:1105-1111, :1262-1270). That's consistent with the page's existing self_attested rows.
…e; self-attested visibility) - concepts/templates.md: "a worker runs only while someone holds an activation lease" is true for a host-built build; a build the deployment declares itself (SH_SANDBOX_TEMPLATES, an imported: id) is not host-managed, needs no lease, and activating it is refused (400 invalid_request) -- activation.ts:200, sandbox-handlers.ts. - reference/templates-api.md: visibility defaults to deployment except on a self-attested create, which is stored private, an explicit deployment there being refused 409 self_attested (sandbox-handlers.ts:1105-1111, :1262-1270). Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
webchang
left a comment
There was a problem hiding this comment.
Thanks for carrying the template material into the new layout. I checked the routes, readiness reasons, lease range, quotas, CLI flags and the provenance scripts against the code, and they match; c986909's lease and visibility fixes read right. Two small fixes left:
docs/sandbox/concepts/templates.md:21(the tags bullet): please add thedefaultrule. Only a template's first registered build takesdefault; a later build does not move it, and the owner moves it withmocactl sbx templates tag ID default --build B(host-handlers.ts:1107-1109). Without that sentence a reader expects a bare id to name the newest build, which is what #909 reports.concepts/templates.md:137(activation refusals):409 template_unavailableis also an activation refusal (no host holds the build, ormemfile_mismatch); the reference page lists it. Add it, or link to the reference's list.
…navailable on activation) - concepts/templates.md, tags: only a template's FIRST registered build takes `default`; a later build does not move it, so a bare id keeps naming the first build until the owner moves the tag with `mocactl sbx templates tag ID default --build BUILD` (host-handlers.ts:1107-1109) -- the expectation rossoctl#909 reports. - concepts/templates.md, activation: 409 template_unavailable (readiness: unavailable) when the reference names no registered build, no host holds the snapshot, or every holder reports a memory file of the wrong size (reason: memfile_mismatch, which only a rebuild clears) -- sandbox-handlers.ts:1529-1535, :1683-1697; with a link to the reference's error codes. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
|
@webchang Both points are fixed in 51a8463.
From a clean clone: 238 files, 0 broken links; site build, no broken links. |
Summary
The template feature had a how-to (
docs/sandbox/how-to/templates.md) and runbook steps, but no model page and no reference page; that material was only in specs,deploy/sbx/template-onboarding/andopenapi.yaml. This PR adds both. It draws onTEMPLATE_LIFECYCLE.mdand the template parts of the client developer guide, keeping only what the published docs lacked (about 70% of the source repeats published pages and is linked instead), and corrects it against the code andopenapi.yaml.docs/sandbox/concepts/templates.md, "Templates, builds and activation"statusand a registered build'sreadiness, as tables and mermaid diagrams. How a sandbox or session picks its build (id,id:tag,id@build,default). Activation lease vs lease modedocs/sandbox/reference/templates-api.md, "Template API"mocactl sbxcommand. Also conventions, error codes, policy rule ids, and quotas with their defaults (templates 100, builds queued 10, active 8, owned 200) and refusals. Host routes get one sentence pointing to the runbookrunbook.md§5runbook.md, new unnumbered sectionhow-to/templates.mdmocactl run --option sandboxTemplate=…), "From your own code", and a fix: a sandbox create after a retire answers 410, while a template create on a retired id queues a new builduser-guide.md,glossary.mdCorrections to the source material
These come from a review that checked about 60 claims against the code and
openapi.yaml:redact-provenance.py --catalog-onlytakes no template id and redacts every catalog entry (redact-provenance.py:4-8). The source's command would fail or redact more than intended.400without it.409 policy_changed(errors.ts:138, fromPUT /v1/policy?expect=) and403 mode_not_allowedare now in the table.PUT /v1/policynow documents its?expect=compare-and-set; sandbox create documentsidleLifetimeS/--lifetime;builtfollows the contract.PUT /v1/policyreads the stored policy first, so it fails too);mocactl run.CONTRIBUTING-DOCS.md.The evidence list (claim → file:line) for the 17 most important facts is in the PR thread on request. The provenance export, verify and both redact forms were run end to end on a synthetic store: verify exits 0, and after a redaction an old export checked against the new head exits 1. The two
kubectlcopy steps are marked (unverified on a cluster).Testing (from a clean clone of the branch)
make check-links: 238 files, 0 broken links.scripts/check-docs-publish.sh: 85 published files, no matches;grep -iE 'sbx[0-9]|cohort|w3id'on the changed pages finds nothing.scripts/check-docs-site.sh: 63 pages, no broken links or anchors.Assisted-By: Claude Code