Skip to content

Epic: Coding-agent subagents on MOCA — detached, gated, collectable leaf sessions #378

Open

Description

@pdettori

Epic: Coding-agent subagents on MOCA

The scenario

A developer works in a coding agent. Claude Code is the first client; any agent that can run a CLI or an MCP server can follow. Midway through a task, the agent spawns subagents: a few research questions, a dependency audit that ends in a proposed change, and later an implementation attempt on a branch. They run as MOCA sessions: Pi with the developer's promoted bundle (ADR-0030; today the bundle comes from Claude Code's /promote), with tools in a MOCA sandbox.

The developer closes the laptop. The subagents keep running on MOCA. One stops to ask "bump lodash to 4.17.21 in 14 packages?", and the developer approves from their phone. When they reopen the agent, it already knows what finished, what failed and what is waiting. It pulls the results in as bounded summaries and patch files, and reviews them before anything touches the working tree.

The coding agent stays the orchestrator. MOCA gives its subagents durable, isolated, managed execution that outlives the laptop, which built-in subagents can't do because they live inside the agent's process.

Why Pi with a promoted bundle, not the coding agent itself, as the subagent runtime. Coding agents such as Claude Code run their tools inside their own process, so the brain can't be separated from the hands.

  • Running it in the worker puts model-written shell next to the API key in the hardened worker.
  • Running all of it inside the sandbox loses the Redis session seam, compaction and scale-to-zero.

Pi gives the split by construction. The parity contract is whatever /promote preflight carries: skills, the CLAUDE.md chain, memory as a read-only snapshot, and the core tools. Parity is defined per source agent. Claude Code's /promote is the only promotion path today; another agent's config format would need its own, which this epic doesn't cover. Pi has no Task tool (promotion spec §9), so the fan-out is flat: the tree lives in the orchestrating agent.

Vocabulary (per #279)

Term Meaning
coding agent The orchestrator the developer works in. Claude Code is the first client; any agent that can drive mocactl or an MCP server can be one.
subagent The coding-agent user's word. One subagent is one MOCA session.
leaf turn A turn MOCA runs for a session on the leaf path. Today that is data-plane POST /runs with kind = prompt, converge or solve.
async turn A leaf turn submitted now and run later by a worker. Per #279 it is async: true on a session, never a second /v1/runs resource.
batch Subagents spawned together. It lives on the caller's side (the coding agent's ledger), not in MOCA (#279 resolution item 2). A later server grouping identity would be parentSessionId.

Where things stand

Written against main @ 24c6f5e; the rows for the bundle, tokens, client disconnect, mocactl and Knative were re-checked on 2026-10-13 against main @ 08eb2a9. file:line references in the other rows are from 24c6f5e and may have drifted.

Part State
Sessions, login, per-user credentials on the VM Works. The control plane is on deploy/vm (#366) and on deploy/k8s (#426). Credential shapes and curl/git in the sandbox landed in PR #372 (#368). The #367 acceptance run is open.
Leaf runtime: sandbox lease, bundle overlay, Pi loop, compaction, result record, gate park/resume Works. Sync and async paths share it through runLeaf.
Async leaf turns with authentication Refused, 501 (packages/knative-server/src/server.ts, the async: true branch of /runs, MI1 R7). Pending MU2.
Queue consumer on P6 or compose None. The only one is packages/knative-server/src/leaf-job.ts under KEDA (ADR-0015), which ADR-0041 deprecated on 2026-10-11 (removal no earlier than the end of October 2026).
Client disconnect Sync /runs keeps running and writes its result record. This is still accidental, not a contract: ADR-0028 has no disconnect text (A1, #380). /v1/turn aborts by default, but with SH_TURN_DETACH=1 (on for compose, vm and k8s), a session token and SSE, a turn can opt into detachable: true. It then survives a disconnect, and mocactl re-attaches or cancels over a per-turn frame log and lease (#481, ADR-0040). mocactl spawn relies on the detached sync /runs path (#496).
Bundle A session's configRef is set at creation (mocactl promote, mocactl run --config; #458, ADR-0038), and /v1/turn takes it from the control-plane exchange. prompt and solve leaves load it (solve since #468); converge doesn't yet (#397). /runs still reads configRef from the request body, not from the session.
Turn state A missing record reads as queued (server.ts:678-680). There's no running and no heartbeat. One result record per session, 24 h TTL (server.ts:49).
Events, notifications, cancel, caps, quotas (#360) None.
Tokens API token 15 min, with a rotating, revocable refresh token (30 days idle, 90 days at most; #467, ADR-0039). Session token 5 min. mocactl auth token gives a hook a fresh token without a prompt.
Coding-agent integration (Claude Code plugin first) None. deploy/claude/ has /promote.
mocactl subagent commands Partly. spawn, subagents and get landed (#496, with a local ledger). watch, approve/reject, follow-up and the async backend are not built. mocactl also has login/logout, auth token, sessions, credentials, run, promote and bundles.

What each leaf kind can do today

Kind Loads your bundle Gets a repo Returns Can ask you (gate)
prompt ✓ ✗, except through a /workloads workspace text (responded) ✗
converge ✗ (#397) ✓ clones repoUrl+ref verdict ✓ (request_approval)
solve ✓ (#468) ✓ clones repoUrl+ref patch, with no base commit ✗

The implementation subagent in the scenario (your skills, your repo, a patch, and the ability to ask you) isn't one leaf kind today.

The target flow

  1. Spawn. The plugin submits an async turn per subagent to the control plane: kind, prompt, repo/ref, caps, and an idempotency key. The control plane writes an owned turn record and queues a reference to it. No bearer token goes in the queue (MI1 §6.5). The response is 202 with the session id and turn id. The plugin records each subagent in a local ledger.
  2. Execute. A P6 leaf worker takes the turn. It gets grants minted from the turn record (MI1 §6.2 and §6.5), marks the turn running with a heartbeat, leases a sandbox, overlays the bundle and runs Pi. It writes the result and artifacts, and emits an event.
  3. Observe. While the user is at the laptop, mocactl watch --json runs under the agent's background-monitor facility (Claude Code's Monitor tool). Each state change is one line, so the agent reacts without polling from inside its context.
  4. Detach. The laptop closes. Queued and running turns carry on, and tokens don't matter while you're away because grants are minted at dequeue.
  5. Gate. A leaf calls request_approval. The session parks, the control plane emits an event, and the notifier pushes to the phone. A decision through an API that requires login queues the resume as an async turn, and a gate deadline fires a default action.
  6. Reattach. On reattach (claude --resume in Claude Code), a SessionStart-style hook reads events since its cursor and injects "while you were away: 2 responded, 1 paused (gate 0: …)".
  7. Collect. get returns a bounded summary. Text and patches go to files, and patches carry their base commit. The agent applies a patch into a worktree, verifies it with a sandboxed leaf, and can send a follow-up turn to the same session.

Principles for the long-term track

  1. Session-centric (Ambiguity between "run" and "session" — clarify or eliminate the term #279). A subagent is a session and its work is turns. Batches stay with the caller.
  2. The control plane owns what is pending (MI1 §6.5). Grants are minted from the turn record at dequeue.
  3. The server enforces safety. Archetypes §5.1 expects a deterministic, non-LLM orchestrator, and a coding agent is neither. So MOCA treats it as an untrusted, nondeterministic external caller: caps, cancel, quotas, idempotency and gate deadlines hold even if the client misbehaves. Durable orchestration inside MOCA, if it ever comes, is deterministic.
  4. The client owns the experience and the review: the ledger, UX, patch review and verification. MOCA supplies the primitives: events, bounded artifacts, decisions.
  5. P6 first, substrate-neutral. The Knative/KEDA path isn't extended (RA1; deprecated by ADR-0041). Epic: P6 on Kubernetes — process manager, relay, Redis and control plane as K8s workloads; only P4 on a VM/bare metal #426's deploy/k8s runs the P6 process model on Kubernetes and is equally in scope: whatever lands must work on the Epic: VM demo slice — P6 + P4 on one VM, multi-user mocactl login, sandbox research turns #370 VM and on deploy/k8s, not just one.

Children (dependency order)

Each child is written so a planner can start it in a fresh session.

Track A: a quick demo on the #370 VM or the #426 K8s stack. Fan out research subagents from a coding agent (Claude Code, the first client, is what the demo is written for), quit or close the laptop, reopen, and a hook reports the results. It relies on detached sync /runs prompt leaves, pinned as an interim contract. #426's deploy/k8s (slice 1, #423) runs the same processes, env and wire as the VM — only the process manager, addressing and isolation differ — so the demo is written against the common API and verified on both substrates: the VM first, then deploy/k8s (port-forwards on Kind, Routes on OCP).

Track B, milestone B-M1 "detached for real": async turns on P6, turn state, cancel and caps.

Milestone B-M2 "away mode":

Milestone B-M3 "implementation subagents":

Milestone B-M4 "beyond":

Related work (not children):

What the demo does NOT claim (say so in the runbook)

Interaction with #370, #426 and the MI1 roadmap

Risks to design against

  • Results flow into the most privileged process there is. That's the user's local coding agent (Claude Code, say), often in bypass-permissions mode or its equivalent.
    • Returned text can carry prompt injection.
    • A patch that touches .claude/settings.json, hooks, Makefile, package scripts or .pre-commit-config.yaml runs on the laptop at the next make test.
    • B12 covers this: returned text is data, patches go through a path policy and into a worktree, verification runs in a sandbox, and nothing is auto-applied.
  • Runaway fan-out with nobody watching. Cancel, caps and quotas ship with async turns (B13), not after them.
  • At-least-once delivery (ADR-0015). Side effects outside the session must be idempotent.
  • Context economics. A built-in subagent returns one final message. get must return bounded summaries and write the full content to files. MCP output limits apply.
  • Parity drift. A local .claude that has changed since the last promote runs stale on MOCA, and skills that mention Claude Code-only tools quietly degrade (B11, B15).
  • Positioning against coding agents' own remote features (Claude Code's, for one). The plugin must say why MOCA: self-hosting, a choice of sandbox tier and model provider, per-user credential custody, durable gates, compaction.

Decisions needed from the owner

# Question Proposed answer
Q1 Is an LLM orchestrator acceptable given archetypes §5.1? Yes, as an external, untrusted caller, with all safety enforced on the server.
Q2 Async API shape per #279? Async turns on sessions (for example POST /v1/sessions/{id}/turns {async:true}), no batch resource. B1 decides.
Q3 Any server-side grouping? No. The caller's ledger plus the existing owner listing. Revisit with parentSessionId (B16).
Q4 Pin detached sync /runs for the demo (A1)? Yes, and retire it in B4.
Q5 Default retention for results and artifacts? 7 days, configurable.
Q6 First notification channel? A signed webhook, plus ntfy (self-hostable).
Q7 Demo tier? Container tier for research. P4 (#369) as an optional local-content act.
Q8 Interim grants before S2? Allowed under single only, tested and flagged as interim.

Working conventions

  • Plans live in docs/plans/ (gitignored), one per child, written with superpowers:writing-plans.
  • Commits are signed off (git commit -s) with an Assisted-By trailer.
  • Anyone using the shared KVM rig alerts the owner first.

Retitled 2026-10-12 from "Claude Code subagents": the epic now covers coding agents in general. Claude Code stays the first client and the reference integration.

Updated 2026-10-13: refreshed the statements that merged work had made stale (bundle, tokens, client disconnect, mocactl, Knative deprecation), annotated the affected children, and listed related work.

Updated 2026-11-24: ticked the ten children that closed since (#379 as not planned; A1 and B1–B8 as completed), each with the PR that closed it, corrected A2's remaining scope to follow-up alone, and marked the three related-work items that have closed. The Where things stand and What each leaf kind can do today tables still describe main @ 24c6f5e and are stale against the async turn, gate, event-stream and notification work — they are not rewritten here.

Activity

  1. added
    enhancement
    on Sep 30, 2026
  2. changed the title [-]Epic: Claude Code subagents on MOCA — detached, gated, collectable leaf sessions[/-] [+]Epic: Coding-agent subagents on MOCA — detached, gated, collectable leaf sessions[/+] on Oct 13, 2026
  3. added this to the v0.12.0 milestone on Nov 17, 2026
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

    enhancement

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions