Skip to content

docs(spec): phase 2 workloads get a PVC owned by MOCA, not Context Service - #590

Merged
moonlight16 merged 2 commits into
rossoctl:mainfrom
moonlight16:docs/phase2-moca-owns-pvc
Oct 22, 2026
Merged

moonlight16 merged 2 commits into
rossoctl:mainfrom
moonlight16:docs/phase2-moca-owns-pvc

Conversation

@moonlight16

Copy link
Copy Markdown
Member

Amends the phase 2 design (#553, per-workload sandboxes) for PR 3 (the storage mount).

The decision. MOCA owns each workload's PVC, not Context Service. This is §11 item 3 (future simplifications), now chosen.

  • The provisioner from feat(provisioner): per-workload sandboxes, without a PVC (phase 2, PR 2) #588 creates PVC <wl> in moca-sandbox, and deletes it along with the sandboxes.
  • An init container seeds the PVC once from the Context's frozen bundle. The worker downloads that bundle as phase 1 delivery already does, and hands it to the provisioner, so the provisioner never holds a Context Service credential.

What this means for Context Service. MOCA uses it exactly as in phase 1: upload, freeze and export. Nothing in Context Service changes or is deprecated. context-service#40 (trusted resolve-attachment) and context-service#59 (caller-named claims) are no longer on phase 2's path, and Context Service's namespace no longer has to move.

Sections updated: spec §2, §5, §6, §8, §10 and §11, plus ADR-0043 and the flow diagram.

Left until #588 merges: three sentences in §4.1 and ADR-0043 that #588 rewrites still say the provisioner creates no PVCs. Until then, §5.1 states PR 3's permission additions.

🤖 Generated with Claude Code

…rvice

The provisioner creates each workload's PVC in moca-sandbox and deletes it
with the sandboxes. An init container seeds it once from the frozen bundle,
which the worker downloads as phase 1 does and hands to the provisioner.
Context Service is used exactly as in phase 1; context-service#40 and rossoctl#59 are
off phase 2's path and its namespace no longer moves. Updates spec §2, §5,
§6, §8, §10, §11 (item 3 chosen), ADR-0043 and the flow diagram.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Jeremy Cohn <[email protected]>
@moonlight16
moonlight16 requested a review from pdettori as a code owner October 22, 2026 19:19
@pdettori pdettori added the ready-for-ai-review Request automated AI code review from clawgenti label Oct 22, 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.

Summary

Spec/ADR amendment: MOCA (the #588 provisioner) owns each phase 2 workload's PVC, seeded once by init containers from a bundle the worker downloads via Context Service's phase 1 export, so context-service#40/#59 are no longer on phase 2's path. The decision is coherent, and the security reasoning (no writable mount of revision/, the seed flag kept out of the PVC, temp-dir seeding) carries over well. I have four design suggestions for PR 3 to settle; none of them block a docs change.

Not in an inline comment (outside the diff hunks): §4.1 still says the Role has only get on persistentvolumeclaims ("check that a resolved claim exists"), and ~L230 says "none on PVCs beyond get: Context Service creates and deletes the claim". The PR body says only the "creates no PVCs" sentences are left for #588, but these two contradict §5.1 now. Please add a dated note or a forward pointer to §5.1 so the spec doesn't contradict itself in the meantime.

Author: moonlight16 (MEMBER — maintainer)
Areas reviewed: Docs (spec, ADR-0043, SVG)
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, all signed-off: yes
CI status: passing (all checks green)

(`GET /internal/v1/namespaces/{ns}/contexts/{name}/revisions/{sha256}/bundle`, with phase 1's size,
inflate and entry ceilings) and hands it to the provisioner with
`PUT /internal/v1/workloads/{name}/{generation}/bundle` before the `PUT` that creates the
StatefulSet. The provisioner holds it, within a byte budget, until the seed has run. The init

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 bundle is held in provisioner memory "within a byte budget". Please name the knob and default (e.g. MOCA_PROVISIONER_SEED_BUDGET_BYTES), say what happens when the budget is full (does PUT …/bundle return 503 + Retry-After?), and say how it relates to phase 1's bundle ceiling × MOCA_OWNER_MAX_SANDBOXES/concurrent activations. Also: after a provisioner restart the record "stays provisioning until the next activate retry". Is that retry client-driven only? If so, GET /workloads/{id} should surface a reason, or the client sees an init container crash-looping with nothing pointing at the fix.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done in 5734a64 (§5.2). The knob is MOCA_PROVISIONER_SEED_BUDGET_BYTES, default 1 GiB across all workloads waiting to seed (about four bundles at phase 1's 256 MiB ceiling). A PUT …/bundle that would exceed it answers 503 seed_budget_full with Retry-After, and activate passes that on. The retry after a provisioner restart is client-driven: the seed port answers 404 seed_bundle_missing, the provisioner's GET reports it, and GET /workloads/{id} shows provisioning with error: seed_bundle_missing until the next activate resends the bundle.

`PUT /internal/v1/workloads/{name}/{generation}/bundle` before the `PUT` that creates the
StatefulSet. The provisioner holds it, within a byte budget, until the seed has run. The init
container fetches it from the provisioner's seed port (`GET /seed/v1/bundle`) with the workload's
attach token (`SANDBOX_TOKEN_FILE`) as its bearer, and the token's `wl` and `gen` pick the bundle.

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: reusing the attach token as the seed-port bearer widens its audience. §3 says aud: moca-relay-attach is "so it never passes as a session, API or sandbox token", but now a second service accepts it too. That's probably acceptable (model code can read the bundle anyway, as noted), but please state it in §3 or §12. Then either have the provisioner accept moca-relay-attach explicitly on the seed port only, or mint a separate short-lived seed claim. Note too that §4's "internal API is reached only by the supervisor's workers" now needs the seed port on a separate listener/port so that NetworkPolicy can still keep workload pods off /internal/v1.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Agreed, done in 5734a64. The seed port is a separate listener (8081), so the NetworkPolicy keeping /internal/v1 to the workers still holds and workload pods reach only 8081. §5.2 now states the token's second audience: the seed port alone accepts moca-relay-attach, checking typ, iss, aud, exp and the key, and its only extra power is reading its own workload's bundle. §3.1's aud row points there. I kept the attach token rather than a separate seed claim, since a second token adds minting and rotation for no new protection.

(the provisioner reads pod status), the provisioner removes the annotation and drops the held
bundle. The StatefulSet uses `updateStrategy: OnDelete`, so that patch restarts no pod, and pods
that restart later come back without it. Model code cannot delete its way to a re-seed.
- **Seed into a temp dir, never into existing content.** Each init container refuses to seed when

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: with count > 1 this rule needs a defined outcome. #588 creates the StatefulSet with podManagementPolicy: Parallel, and the moca.dev/seed-revision annotation is removed only after the first pod's init containers complete. So pod 1 starts with the annotation and finds revision/<rev> and moca-workspace already seeded by pod 0 (or, on RWX, seeding concurrently). If "refuses" means a non-zero exit, pod 1 crash-loops and ready never reaches count. If it means a skip, an empty-but-crashed tree could pass. Please spell out "already seeded → exit 0" (e.g. a completed-marker check on the rename target), plus mutual exclusion for concurrent seeds on RWX, or seed from ordinal 0 only.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good catch. Defined in 5734a64: only ordinal <wl>-0 seeds (ordinal from the pod name via the downward API). Every other pod's init container waits until both targets exist, then exits 0 without writing. The rename into place is the completed marker, so an existing target is fully seeded and a crash leaves only a temp dir. One writer means no locking is needed on RWO or RWX. Added a §12 test for count: 2.

does not affect them, because upload and export stream over `pods/exec`, not the pod network.
Context Service's side does not move: the Context, the managed PVC `createContext` asks for, its
helper pods and `CONTEXT_SERVICE_NAMESPACE` stay as they are, and no pod mounts that PVC. A phase 2
workload therefore holds its revision twice, once in each PVC.

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: "holds its revision twice". With writable, it's really three copies (CS PVC, revision/<rev>, moca-workspace). Worth saying, together with whether workspace.size must cover 2× the bundle's inflated size on the MOCA PVC, so users sizing a writable workload don't hit ENOSPC in the seed.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 5734a64: a writable workload holds it three times (Context Service's PVC, revision/<revision>, moca-workspace). workspace.size must cover the inflated bundle once for read-only, and twice plus the run's writes for writable; the worker refuses a smaller size with 400 workspace_size_too_small before a seed could hit ENOSPC.

- seed budget knob, 503 when full, and the restart error on GET /workloads/{id}
- the seed port is its own listener; the attach token's second audience is stated
- only ordinal 0 seeds; the rename is the completed marker; others exit 0
- three copies for writable, and the workspace.size rule
- §4.1 points to §5.1 for the PVC permissions until rossoctl#588 merges

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Jeremy Cohn <[email protected]>
@moonlight16

Copy link
Copy Markdown
Member Author

Thanks, Paolo. All four suggestions are in 5734a64, and §4.1's PVC row and the paragraph after it now point to §5.1 (dated) until #588 merges, so the spec no longer contradicts itself.

@moonlight16
moonlight16 merged commit 7b822ff into rossoctl:main Oct 22, 2026
14 checks passed
moonlight16 added a commit to moonlight16/moca that referenced this pull request Oct 23, 2026
Phase 2 PR 3 (docs/specs/2026-10-16-workload-sandboxes-design.md §5, from rossoctl#590).

- provisioner: creates PVC <wl> in moca-sandbox at activation and deletes it
  with the sandboxes (inside the serialized delete); holds the frozen bundle
  (PUT .../bundle, seed budget) and serves it on a separate seed port to the
  workload's attach token
- pod 0's init containers extract it once into revision/<rev> (read-only)
  and, for writable, moca-workspace; other pods wait; OnDelete + the
  moca.dev/seed-revision annotation keep a restart from re-seeding
- runs on a mounted workload work in /workspace/context on the PVC
- RWO with pod affinity by default; RWX only for an rwx-marked class
- admission policy: the volume allow-list admits the workload's own PVC only;
  PVC name, class and access-mode rules; Role and quota cover PVCs
- workers: workspace.mount, size check, seed errors passed through

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

3 participants