Skip to content

/workloads phase 2: give each workload its own sandboxes and, optionally, durable storage #476

Closed

Description

@moonlight16

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 /workloads creates 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

  1. 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.

  2. 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 as container or microvm (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.

  3. 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-task skill) always get a PVC and always mount it. Other workloads may still choose to run without durable storage.
  4. Who may use which PVC? (/workloads: authorize caller-named PVCs per subject, and scope workload names #358)
    The old /workloads let 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 refuses claimName from 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.

  5. 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.
  • DELETE removes everything each of them created.

cc @pdettori @maia-iyer @evaline-ju

Activity

  1. evaline-ju commented on Oct 15, 2026

    @evaline-ju
    Contributor

    Flagging four phase-2 items from #517's comment:

    1. Egress accounting for writable workloads (ADR-0006). A workload PVC that is both agent-writable and client-readable is a new egress channel. Open question: do writes count against credentialed-egress, or are they a separate category?
    2. Provenance granularity. Durable, writable storage breaks the one-event-per-revision model phase-1 uses. Open question: per-write events, per-/v1/runs boundary, or scheduled content-addressed snapshots?
    3. Operator admin read access. For incident response, is there an in-band path for an operator to read a tenant's workspace, or only out-of-band kubectl exec?
    4. Writable continuity across sandbox restart. If a writable run is in flight when its sandbox dies, does the harness re-attach to a new pod with the PVC remounted, and how are partial writes reconciled? This is what makes the "transparent session resume" story hold for writable runs, not just read-only ones.

    (1), (3), and (4) aren't in #476's current Design questions list. (2) is adjacent to #358

  2. moonlight16 commented on Oct 27, 2026

    @moonlight16
    MemberAuthor

    Phase 2 is done. Each workload can now have sandboxes and storage of its own, isolated from other users.

    What landed

    Acceptance, all met: the two-user demo (skills/moca-delegate-task/demo-two-users/) passed 34 of 34 on a fresh cluster:

    1. each user has their own workload;
    2. tasks run only on their workload's sandboxes;
    3. neither user can see the other's files, and the relay refuses forged sandboxes;
    4. writable changes persist with no per-task copy;
    5. delete leaves nothing behind, and feat(provisioner): sweep orphaned workload sandboxes (phase 2) #615 covers a delete that fails partway;
    6. old-style workloads still work as before.

    Follow-ups (not blocking):

    Thanks to @ingpaolodettori-dev, @maia-iyer, @evaline-ju and @mrsabath for the reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions