Skip to content

feat(demo): two-user Kind demo for per-workload sandboxes (phase 2, PR 4) - #604

Merged
moonlight16 merged 5 commits into
rossoctl:mainfrom
moonlight16:feat/two-user-demo
Oct 24, 2026
Merged

moonlight16 merged 5 commits into
rossoctl:mainfrom
moonlight16:feat/two-user-demo

Conversation

@moonlight16

@moonlight16 moonlight16 commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

Shows phase 2 working end to end for two users on one cluster: each gets their own sandboxes and storage, and neither can reach the other's. It stacks on #600 (a PVC per workload), which builds on #588 (the provisioner) and #560 (the relay trusts workload labels only from a signed token). Part of #476 (per-workload sandboxes and storage).

What the demo shows, on a local Kind cluster with a scripted mock model (no model key):

  • Each user has their own workload. Alice and Bob each upload their own repo. Alice's workload has 2 sandboxes with writable storage, Bob's 1 sandbox with read-only storage.
  • Tasks stay on their own sandboxes. Alice's tasks run only on her sandbox pods, Bob's only on his. A task with no workload runs on the shared pool.
  • Neither user can see the other's files.
    • Each user's task finds only its own files.
    • Bob asking for, running on or deleting Alice's workload gets "not found".
    • The relay (the service that connects sandboxes to MOCA) refuses a fake sandbox claiming to be Alice's, whether it uses the shared token or Bob's.
  • Writable changes persist. A file Alice writes on one pod is there on both of her pods, for her later tasks. Bob's read-only storage refuses writes.
  • Delete leaves nothing behind. After mocactl workloads delete, no pods, StatefulSet, Service, token Secret, PVC or Context remain.
  • Old-style workloads still work. A workload created without --sandboxes runs on the shared pool with a per-run copy, as before.

Also in this PR: mocactl workloads create --sandboxes N --mount read-only|writable. With these flags, create waits until the workload is ready, and workloads get shows sandbox and mount status. Tests and docs are updated.

Run it: skills/moca-delegate-task/demo-two-users/setup.sh --build, then run.sh, then setup.sh --delete. run.sh prints a PASS/FAIL table and exits non-zero on any failure. On a fresh cluster it passed 34 of 34.

Not in this PR: the cleanup sweep that removes leftovers when a delete step fails.

🤖 Generated with Claude Code

Phase 2 PR 4 (acceptance 1-6 of rossoctl#476, except orphans after a failed delete
step, which needs the reconciler).

- skills/moca-delegate-task/demo-two-users: setup.sh, run.sh (PASS/FAIL
  table), README; Alice (2 writable sandboxes) and Bob (1 read-only)
- mocactl workloads create --sandboxes N --mount read-only|writable; create
  waits until ready; workloads get shows sandboxes, mount and error
- mock model: MOCA-DEMO2-WHO/WRITE/READBACK/PEEK scripts

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

The demo is well put together. run.sh checks real isolation signals: pod placement by owner label, PVC claim names and subPath/readOnly, the relay's refusal log lines (which match relay.ts:267/281 verbatim), and the post-delete leftovers. The mocactl --sandboxes/--mount and readiness-poll changes match the harness's publicView and provision semantics on main (dc4f9c2, #600 now merged). One blocking problem is in setup.sh --delete's safety guard: setup.sh stamps the "made by this script" marker into whatever directory MOCA_DEMO_STATE names, pre-existing or not. So a mis-set MOCA_DEMO_STATE (say $HOME) gets marked, chmod-ed to 700, and then rm -rf-ed by --delete, which is exactly the case the marker is supposed to prevent.

Author: moonlight16 (MEMBER — maintainer)
Areas reviewed: Shell (setup.sh, run.sh, mock-anthropic test), TypeScript (mocactl cli/workloads/api + tests), JS (mock-anthropic.mjs), YAML (kind.yaml), Docs (cli-mocactl.md, mocactl README, demo README)
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, all signed-off: yes
CI status: passing (all 15 checks green, including k8s-kind-e2e). The demo itself isn't run in CI; the author reports 34/34 on a fresh cluster, and this review didn't run it.

Must-fix

  1. setup.sh:158 marks any STATE_DIR as the demo's, which defeats the --delete guard at L77-80 (details inline).

Non-blocking: create --sandboxes deletes the workload on the first recorded error, including seed_bundle_missing, whose documented remedy is "repeat the activate" (docs/context-service.md:211). There's also a check label and a doc sentence that could be tightened.

die "--skip-build: $CS_IMAGE is not on the cluster yet; run setup.sh once without --skip-build"
fi
mkdir -p "$STATE_DIR/bin"
: >"$STATE_DIR/$STATE_MARKER"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

must-fix: this stamps the marker into $STATE_DIR unconditionally, even when the directory already existed and holds other content. --delete (L77-80) trusts that marker as proof the directory is "only a directory this script made" and then runs rm -rf "$STATE_DIR". So MOCA_DEMO_STATE=$HOME setup.sh (or ~/.local/state, or any mis-set path) followed by setup.sh --delete deletes that whole directory. L228 also chmod 700s it in the meantime. Please write the marker only when this run creates the directory, or when it is empty (e.g. [ ! -e "$STATE_DIR" ] || [ -f "$STATE_DIR/$STATE_MARKER" ] || [ -z "$(ls -A "$STATE_DIR")" ] || die … before the mkdir). Alternatively, have --delete remove only the subpaths it knows (bin/, alice/, bob/, results/, the marker).

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, fixed in cb5987b. setup.sh now refuses an existing, non-empty directory that has no marker, before it writes anything, so a mis-set MOCA_DEMO_STATE like $HOME is never marked, chmod-ed or deleted. A new or empty directory, or one already marked, is used as before. The phase 1 demo's setup.sh (#544) had the same bug, so I fixed it there too.

const deadline = rt.now() + (opts.readyTimeoutMs ?? READY_TIMEOUT_MS);
try {
while (active.status === 'provisioning') {
if (active.error) {

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: any recorded error here fails the create and deletes the workload. That's right for workload_refused or sandboxes_count_exceeded, which no retry can fix. But for seed_bundle_missing, which getWorkload reports through withSeedError when the provisioner restarted or MOCA_PROVISIONER_SEED_HOLD_S lapsed (e.g. a claim that sat Pending for 10 minutes), docs/context-service.md:211 gives the remedy as "Repeat the activate with the same revision". A slow PVC bind would then turn into a deleted workload. Consider calling client.activate(id, uploaded.revision) again once for seed_bundle_missing (and maybe for provisioner_error/context_service_error) before giving up, and documenting which errors are terminal.

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 cb5987b. On seed_bundle_missing, create now activates once more with the same revision, the remedy docs/context-service.md gives. If the error comes back, or any other error is recorded, it still fails and deletes the workload. I kept provisioner_error and context_service_error terminal, since the worker already retries those, and documented the rule in the mocactl README and cli-mocactl.md. Tests cover both a recovery and a second loss.

CONTEXTS="$(contexts)"
echo "Contexts: $CONTEXTS"
set -- $CONTEXTS
check 1 "Context Service holds the three workloads' Contexts, Alice's and Bob's among them" \

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: the check requires exactly 3 Context Service PVCs in the whole cluster. That holds on the fresh cluster setup.sh makes, but a re-run after an interrupted run whose cleanup couldn't delete (or a phase 1 demo on the same cluster) fails this row with a misleading label. Either say "exactly three Contexts (fresh cluster)" in the label, or count only $ALICE_KEY, $BOB_KEY and the phase 1 key.

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 cb5987b: the row now reads "exactly this run's three Contexts (fresh cluster)". Counting only our keys isn't possible for the phase 1 workload, which has no StatefulSet to read its key from, so I took the label option.

Comment thread docs/reference/cli-mocactl.md Outdated
`writable`, or `--mount` without `--sandboxes`; all before any request.
- `create --sandboxes`: activation answers `provisioning` while the workload's own sandboxes start;
`create` polls `GET /workloads/{id}` every 2 s for up to 5 minutes and exits 1 (deleting the
workload) on a recorded `error` or the timeout. Exit 1 for a refusal, including a file larger than the grant's `maxBytes` or an

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: the new create --sandboxes bullet ends by running into the old "Exit 1 for a refusal, including a file larger than the grant's maxBytes…" sentence, so the general exit-1 rule now reads as if it applied only to --sandboxes. Moving that sentence back under the create exit-2 bullet, or into its own bullet, keeps the two separate.

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 cb5987b: the general create exit-1 rule is its own bullet again, ahead of the --sandboxes polling bullet.

- setup.sh (both demos): mark the state dir only when this run creates it, or
  it is empty or already ours, so --delete can never remove a mis-set path
- mocactl workloads create: activate once more on seed_bundle_missing, the
  documented remedy, before deleting the workload
- run.sh: the Context count check says it expects a fresh cluster
- cli-mocactl.md: the general create exit-1 rule is its own bullet again

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 are in cb5987b, including the state-dir fix, which I also applied to the phase 1 demo. Could you take another look?

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

Thanks. cb5987b fixes all four items from the d31262b review, and I checked each one against the code:

  1. must-fix (state-dir marker): fixed. setup.sh now refuses an existing, non-empty, unmarked $STATE_DIR before it marks, chmods or writes anything, so --delete can no longer remove a mis-set MOCA_DEMO_STATE. Applying the same fix to the phase 1 demo/setup.sh was a good call.
  2. suggestion (seed_bundle_missing): fixed. A same-revision activate on a provisioning workload goes through provision() on main, which resends the bundle and clears error, so the single retry really recovers, and a second loss or any other error still fails and deletes. The new test covers both paths, and the docs now say which errors are terminal.
  3. nit (Context count label) and 4. nit (exit-1 bullet): fixed.

Two small nits inline about where the new guard sits, neither blocking. CI is green at cb5987b.

fi
# Mark only a directory this run creates, or one that is empty or already ours: --delete trusts
# the marker, so a mis-set MOCA_DEMO_STATE (say $HOME) must never be marked.
if [ -e "$STATE_DIR" ] && [ ! -f "$STATE_DIR/$STATE_MARKER" ] && [ -n "$(ls -A "$STATE_DIR")" ]; then

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: the guard is right, but it runs only after the Kind cluster has been created (or checked) and the Context Service image built and loaded. So a mis-set MOCA_DEMO_STATE costs a few minutes and leaves a cluster behind before the refusal. It depends only on STATE_DIR/STATE_MARKER, so it could sit right after the argument parsing (after the --delete branch) and fail before any work. The same applies to demo/setup.sh:154.

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 0db4f75: the guard now runs right after argument parsing in both demos, before any cluster or image work. I checked that a non-empty, unmarked MOCA_DEMO_STATE is refused at once, with no cluster created and the directory untouched.

elif ! docker exec "$CLUSTER-control-plane" crictl inspecti "$CS_IMAGE" >/dev/null 2>&1; then
die "--skip-build: $CS_IMAGE is not on the cluster yet; run setup.sh once without --skip-build"
fi
# The matching client, for ctx pack (#56 is needed on the client as well as the server).

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: the new guard landed between # The matching client, for ctx pack (#56 …) and the go build of contextctl it describes, so that comment now reads as if it were about the state-dir check. Move the guard above it, or move it up as in the other comment.

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 0db4f75: with the guard moved up, the "matching client" comment sits directly above the go build it describes again.

The guard sits right after argument parsing in both demos, so a mis-set
MOCA_DEMO_STATE fails at once, before a cluster is built, and the phase 1
demo's 'matching client' comment is back beside the build it describes.

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

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

Follow-up review at 0db4f75: both cb5987b nits are fixed. The state-dir guard now runs right after argument parsing in both demos, before any cluster or image work, and the "matching client" comment in demo/setup.sh sits back above the contextctl build. No new findings.

trivy-scan is red at this head even though the change only moves shell lines (it was green at cb5987b), so it's probably a new advisory against an existing dependency rather than this PR.

A HIGH denial of service in body-parser 2.3.0, pulled in through
@modelcontextprotocol/sdk -> express, fails the trivy-scan check on every PR
since the CVE was published. Lockfile only: body-parser 2.3.0 -> 2.4.0 (adds
qs 6.16.1); other entries only re-resolve their peer suffixes.

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

Copy link
Copy Markdown
Member Author

trivy-scan started failing on every PR after CVE-2026-111181 (body-parser 2.3.0, HIGH, DoS) was published; main has the same lockfile. 091260e bumps it to 2.4.0, lockfile only (it comes in through @modelcontextprotocol/sdk → express). A frozen install works, trivy is clean on the lockfile, and the mocactl, knative-server and control-plane suites pass. Happy to split it into its own PR if you'd rather.

trivy-action builds its SARIF report with every severity, and fast-uri 3.1.8
(through ajv) has four new MEDIUM/LOW CVEs (CVE-2026-110095, -110180,
-110306, -110725), so trivy-scan kept failing after the body-parser bump.
Lockfile only: fast-uri 3.1.8 -> 3.1.9. trivy 0.70.0 (the action's version)
is clean at every severity.

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

Copy link
Copy Markdown
Member Author

trivy-scan is green again with a second lockfile-only bump in ecc2002: trivy-action builds its SARIF report at every severity, and fast-uri 3.1.8 (through ajv) had four new MEDIUM/LOW CVEs, so it's now 3.1.9. Both bumps are lockfile-only, with a frozen install, trivy 0.70.0 clean at every severity, and the mocactl, knative-server, control-plane and harness suites passing. Main has the same two CVEs, so other open PRs will hit this until this merges.

@moonlight16
moonlight16 merged commit bbeca5f into rossoctl:main Oct 24, 2026
15 checks passed
moonlight16 added a commit that referenced this pull request Oct 27, 2026
…ew pack rules

- SKILL.md: --sandboxes N --mount read-only|writable (#604), when to use
  writable vs read-only, the 400 when the feature is off, the caps
- contextctl v0.3.0 pack filters: .claude and gitignored files skipped
- spawn --writable vs a --mount writable workload; changes never reach the
  local tree either way
- references/internal-flow.md: per-workload sandboxes

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