Repository navigation
Description
Split out of #455 (the original context-delegation PR). Related: #358 (per-user PVC authorization and workload names), #378 (Claude Code subagents epic), rossoctl/context-service#51 (removed sandbox creation from Context Service).
Goal
Several users each delegate tasks to Moca, and each gets a private workload: sandboxes that only that user's tasks run on and, optionally, storage that survives the sandboxes.
POST /workloadscreates the workload's sandboxes. If the caller asks for durable storage, Moca also asks Context Service for a PVC (a Kubernetes persistent volume) and mounts it in those sandboxes.- Without a PVC, the context lives inside the sandbox pod and disappears when the sandbox is deleted. That suits one-off delegated tasks.
- With a PVC, the context survives sandbox restarts. That suits always-on workloads, such as BugStone pipelines whose repositories stay loaded in the sandbox.
DELETE /workloads/{id}removes the sandboxes, the PVC, and the Context.
Phase 1 (the earlier /workloads PR) runs every task on the operator's fixed pool of shared sandboxes. Phase 2 keeps the same API and adds per-workload sandboxes and storage.
Background
Moca's current Kubernetes deployment (deploy/k8s, called "P6" in the design docs) runs a fixed set of long-running sandbox workers. The operator sizes the set at install time (SH_SANDBOX_COUNT). Each worker connects to Moca through the relay. Moca's supervisor, the component that runs agent turns, picks a free worker for each task. Nothing creates or deletes sandboxes while Moca is running.
Design questions
-
Which component creates the sandboxes?
The supervisor has no Kubernetes permissions (automountServiceAccountToken: false), and it should stay that way, because it runs agent code. The proposal is a separate, trusted provisioner next to the control plane. It would hold only the permissions it needs: create and delete sandboxes and PVCs in one namespace. -
How does a task reach only its own workload's sandboxes?
Today each worker advertises a tier: a label naming the kind of sandbox, such ascontainerormicrovm(moca.dev/tier). The supervisor picks any free worker in the task's tier. Tiers are categories, not owners, and the operator fixes the list at install time (SH_SANDBOX_TIERS), so they can't represent per-user workloads.
Proposal: label each provisioned sandbox with its workload ID, and have the supervisor also filter on that label when a task names a workload. Tasks without a workload keep using the shared pool. -
How does the context get into a workload's sandbox?
- Phase 1 copies the frozen context bundle into a shared sandbox through SandboxExec (the relay's command API) for each task, because a shared, long-running sandbox can't mount a new PVC.
- In phase 2, a workload with a PVC mounts it directly: read-only for reference data, writable for a working directory. Nothing is copied from the PVC into the sandbox, which also avoids the 256 MiB bundle limit.
- Workloads created for delegated tasks (the
moca-delegate-taskskill) always get a PVC and always mount it. Other workloads may still choose to run without durable storage.
-
Who may use which PVC? (/workloads: authorize caller-named PVCs per subject, and scope workload names #358)
The old/workloadslet a caller name any PVC to mount (workspace.claimName), and nothing checked that the caller owned it. One user could name another user's PVC and read their files. The current stop-gap refusesclaimNamefrom authenticated callers, which also blocks bring-your-own storage for everyone.
Proposal: callers never name a raw PVC; they name a Context. Context Service already records per-user permissions on each Context: read, write, and attach. Moca asks Context Service, on the caller's behalf, whether the caller may attach that Context. If so, Context Service returns the PVC to mount. Another user's Context answers "not found". This would close /workloads: authorize caller-named PVCs per subject, and scope workload names #358 and remove the stop-gap. -
Limits: per-user caps on workloads and sandboxes, a maximum PVC size, and a list of allowed StorageClasses (the kinds of Kubernetes storage a workload may request).
Acceptance
A multi-user demo on Kind:
- Alice and Bob each create a workload and delegate tasks.
- Neither can see the other's context or working directory.
DELETEremoves everything each of them created.
Activity
docs: upgrade note for removed workload routes
feat: run tasks on a workload's context in shared sandboxes
evaline-ju commentedon Oct 15, 2026
Flagging four phase-2 items from #517's comment:
(1), (3), and (4) aren't in #476's current Design questions list. (2) is adjacent to #358
docs(spec,adr): per-workload sandboxes and storage (/workloads phase 2)
feat(demo): two-user Kind demo for per-workload sandboxes
feat(demo): two-user Kind demo for per-workload sandboxes
feat(demo): two-user Kind demo for per-workload sandboxes
feat(provisioner): sweep orphaned workload sandboxes
moonlight16 commentedon Oct 27, 2026
Phase 2 is done. Each workload can now have sandboxes and storage of its own, isolated from other users.
What landed
moca-provisionercreates each workload's own sandbox pods. It has tight permissions, an admission policy, and is off by default.writable, tasks' changes persist across tasks and pods.mocactl workloads create --sandboxes N --mount read-only|writable.Acceptance, all met: the two-user demo (
skills/moca-delegate-task/demo-two-users/) passed 34 of 34 on a fresh cluster:Follow-ups (not blocking):
Thanks to @ingpaolodettori-dev, @maia-iyer, @evaline-ju and @mrsabath for the reviews.