Skip to content

feat(microvm): P4 microVM worker on P6 — installer, rootfs recipe, first real turns (#369) - #376

Merged
pdettori merged 13 commits into
rossoctl:mainfrom
pdettori:feat/369-p4-on-p6
Sep 30, 2026
Merged

pdettori merged 13 commits into
rossoctl:mainfrom
pdettori:feat/369-p4-on-p6

Conversation

@pdettori

Copy link
Copy Markdown
Member

Summary

VM demo D (#369, part of epic #370): the P4 Firecracker microvm-worker installed next to a P6 host, attached to P6's relay under its own relay token, and serving real harness turns. Every tool call runs in a fresh microVM over a per-session workspace.

Depends on #375. Without it, every tool call in a new session's first /turn fails on this tier.

What's in it

  • deploy/microvm/setup-microvm.sh: the sibling installer.
    • It reads P6's installed relay.env and writes no P6-owned file. The relay gets the per-sandbox token SH_RELAY_TOKEN_<id> through a drop-in and a new env file.
    • The token is generated once and never rotated.
    • It refuses while any sh-sandbox-* container exists: the host is P4-only, see "Tier pinning".
    • It waits for the worker's presence record, and a re-run changes nothing.
    • The sandbox id must be underscore-only, because systemd drops dashed env names. Verified on the rig.
    • MICROVM_MAX_COMMITTED_MB supports hosts smaller than the shipped 24 GiB budget. It re-states the unit's other assertions after resetting AssertMemory=.
  • deploy/microvm/build-rootfs.sh: the rootfs recipe. It exports P6's own sandbox image as the golden rootfs, reading the image and never changing it. build-snapshot.sh's guest probe now checks the container tier's full capability set, pinned against cmd/worker's probed list.
  • SH_WORKSPACE_IDLE, the P4 microVM tier: WorkspaceIdle=30min deletes a HITL session's workspace mid-session, silently #338 demo mitigation, on microvm-worker: unset keeps 30 minutes, and the installer writes 8h.
  • One journal line per Exec: vmpool: exec req= workspace_key= vm= cold= exit= err=, never the command text. This is the acceptance evidence.
  • Live-run tooling: mock-anthropic.mjs, a scripted loopback model, and p4-turn-smoke.sh, a turn driver with failure paths. The driver is tested against a mock of the real /turn contract.
  • deploy/microvm/P4-ON-P6.md: the runbook, with verified and not verified from the rig run, the limits, and uninstall. A pointer is added from deploy/vm/README.md.

Tier pinning (gap 4)

selectPoolSandbox leases the least-loaded of all presence records. It selects again every turn, and records carry no tier label, so with both tiers attached a session can hop tiers and lose its workspace.

The decision was T1, a P4-only host. Per-session tier selection is a follow-up.

Verified on a KVM rig (2026-09-30)

m8i.xlarge with nested virtualisation, 16 GiB, Amazon Linux 2023, Firecracker v1.17.0. P6 came from deploy/vm before the control plane landed.

  • Installer: attached; the re-run printed nothing to change.
  • Snapshot: its manifest advertises base64 bash curl file git python3 rg.
  • Scripted-model run, 26/26 checks:
    • multi-tool turns ran in microVMs, one VM per Exec;
    • the workspace survived between turns;
    • a second session got a separate workspace;
    • a worker restart mid-Exec gave worker disconnected;
    • killing the running VM gave vsock-short-response: vmpool: guest closed before End: EOF.
  • Real model, a direct Anthropic key on Haiku:
    • two turns of one session, where turn 2 showed turn 1's commit;
    • 12 Execs, 12 distinct VMs, one workspace_key;
    • the guest's uname -a reads Linux (none) 6.18.44+.
  • P4 microVM tier: WorkspaceIdle=30min deletes a HITL session's workspace mid-session, silently #338 measurement: one idle session's workspace costs 66 MiB on disk (2 GiB apparent).

Not verified:

Limits, stated in the runbook:

Tests

  • make test, make typecheck and make lint pass.
  • go test ./... in remote-worker passes.
  • All six deploy/microvm/tests/*.test.sh suites pass: four new, two extended.
  • Two whole-branch reviews; their findings are fixed.

Refs #369, #370, #338.

🤖 Generated with Claude Code

The 30-minute default reclaims an idle interactive session's workspace (rossoctl#338).
Unset keeps the default; Normalize still enforces StandbyIdle < WorkspaceIdle.
Refs rossoctl#369, rossoctl#338

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
…n rootfs

Refs rossoctl#369

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
Reads P6's installed relay.env, generates a per-sandbox relay token once, and
wires the relay and worker with drop-ins so no P6-owned file is edited.
Refuses while container sandboxes are attached (P4-only host).
Refs rossoctl#369

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
One always-on line per Exec, without the command text, so the journal shows
which session's workspace each tool call used and which microVM ran it.
The test binary defaults the line to a no-op: its volume starved a
wall-clock socket-poll test.
Refs rossoctl#369

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
…e run

Refs rossoctl#369

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
…recovers a failed worker

- p4-turn-smoke.sh creates sessions by omitting sessionId (a made-up id is a
  404), reads tool output from the response text, and makes every negative
  check depend on the turn's response being present. Failure path 2 kills
  the Running VM (Firecracker GET /), not the newest process.
- mock-anthropic.mjs puts the tool results into its final text, the only part
  a non-streaming /turn returns.
- setup-microvm.sh starts a stopped or failed worker on re-run, clears the
  worker's presence record before starting it, and counts stopped sandbox
  containers (podman-restart brings them back at boot).
- p4-turn-smoke.test.sh runs the driver against a mock of the /turn contract.
Refs rossoctl#369

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
…r host

The shipped unit budgets 24 GiB and asserts >=23G, so it refuses on a 16 GiB
host. The option writes a drop-in with a smaller SH_MAX_COMMITTED_MB and a
matching AssertMemory (90% of the budget, the band the shipped unit is held
to); unsetting it removes the drop-in.
Refs rossoctl#369

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
Adds deploy/microvm/P4-ON-P6.md (P4-only host, snapshot recipe, installer,
turns, automated check, workspace lifetime, verified/not verified from the
2026-09-30 KVM rig run, limits, uninstall) and the pointer to it from
deploy/vm/README.md.
Refs rossoctl#369

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
…e; runbook corrections

- The AssertMemory= reset in 60-moca-memory.conf clears every Assert*= of the
  unit, the /dev/kvm guard included (checked on the rig). The drop-in now
  re-states the shipped unit's other assertions after the reset.
- MICROVM_MAX_COMMITTED_MB refuses a leading zero, which bash would read as
  octal while Go reads decimal.
- P4-ON-P6.md: an exposure warning where unauthenticated /turn is introduced,
  with the commands to turn auth off and back on; the control-plane note on
  the P4-only step; a sudo PATH note; corrected verified rows; the smoke
  settings via EnvironmentFile; an explicit rootfs --image; an uninstall that
  removes the key files and warns it deletes session data.
Refs rossoctl#369

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
…flags

- setup-microvm.test.sh read modes with `stat -f %Lp || stat -c %a`. On GNU
  stat, -f is FILESYSTEM status and succeeds, so the fallback never ran and CI
  saw a filesystem report instead of 600. Try GNU stat first.
- build-rootfs.sh: `[ ] && [ ] || usage` becomes an if (SC2015, flagged by
  CI's shellcheck; build-rootfs.test.sh runs shellcheck at every severity).
- setup-microvm.test.sh: its assertion loop reads lines via process
  substitution (SC2013), keeping check()'s counter in the test's shell.
Refs rossoctl#369

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
Refs rossoctl#369

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

@mrsabath mrsabath left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed the installer, the rootfs recipe, the turn driver, the vmpool/microvm-worker Go changes, the mock model and the runbook. All 13 CI checks green, including shellcheck, deploy-scripts, microvm-gates, CodeQL and Trivy.

No must-fix issues. Two non-blocking comments inline.

What I checked and found clean

  • Secret handling in the installer. Token generated once from /dev/urandom and length-validated; both env files land at 0600; render_env stages under umask 077. The relay's file is rendered from scratch rather than merged, with the right reason stated — a changed MICROVM_SANDBOX_ID must not leave the old id's token still valid at the relay. The tests assert the worker env carries neither MOCA_RELAY_EXEC_TOKEN nor SH_RELAY_TOKEN*, and that P6's relay.env is untouched.
  • The "never logs the command" claim, which is the security assertion this PR rests on. execLog omits the command and TestRunnerLogsTheWorkspaceKeyAndVMOfEveryExec passes Command: "echo SECRET-VALUE" then asserts the line does not contain it — a real guard, not a decorative one. WorkspaceKey goes through %q, so a hostile session id cannot break journal parsing. The no-VM path is covered separately.
  • poolConfig's new SH_WORKSPACE_IDLE block. Traced all four branches against the first-error-wins idiom the five knobs above it use: consistent, and an invalid value cannot fall through to a zero WorkspaceIdle. Normalize still enforces StandbyIdle < WorkspaceIdle, and the refusal cases (8, soon, 0s, -1h) are each tested.
  • The AssertMemory= reset. The empty-value reset clears every assertion, and the script re-states the others by reading them out of the shipped unit rather than hardcoding them — so the /dev/kvm guard survives, and a newly added assertion is carried too.
  • mktemp in render_env. Checked whether the token could transit a default-umask temp file: mktemp is 0600, and SANDBOX_TOKEN uses keep mode, which continues before the awk/mktemp path is reached. No exposure.
  • absent() in the smoke driver. Verified the proof string is not vacuous by tracing the mock's plan()/reply() state machine: on a failed tool call the harness still feeds a tool_result back, step advances, and the final text is done-sleep\n<error>. So the proof holds and slept is absent only when the sleep genuinely did not finish. The helper's doc comment explaining why the proof argument exists at all is the right instinct.
  • start_worker ordering. The presence record is cleared before the start, so verify_attached cannot be satisfied by a stale record from a previous connection — exactly the token-mismatch silent failure the check exists for. The stop→HDEL→start ordering is pinned.
  • Idempotency. install_if_changed/commit_env only touch files whose content differs, and render_env replaces values in place rather than delete-and-append, so an unchanged re-run does not reorder the file. The suite asserts a byte-identical tree and zero daemon-reload/restart on re-run.
  • build-rootfs.sh only reads the image (podman create + export, container removed via trap), refuses a non-empty --out, strips the inert remote-worker binary from the guest tree, and records image + digest provenance.
  • Security sweep — no hardcoded secrets (the only literal is mock-not-a-secret), no curl | sh, no eval, no unpinned action refs. The runbook explicitly warns that ANTHROPIC_BASE_URL would send the key to a third party and that ANTHROPIC_AUTH_TOKEN strips x-api-key; that hazard is usually left implicit.
  • Commits — 12, all signed off, conventional prefixes, every subject within 72 characters.

Notes

  • I could not run the tests. No clone of this repo was available to me, so I reviewed the diff and fetched files at f471b1f through the API but executed nothing — the make test / go test / six-suite claims are unverified by me. CI's own check, lint, shellcheck and deploy-scripts jobs are green, which covers more ground than I could.
  • The P4-only guard is install-time only, and deliberately so: preflight refuses while any sh-sandbox-* container exists, but nothing stops a later setup-vm.sh run or podman-restart.service from reattaching the container tier afterwards. The script comment and the runbook's "A P4-only host" section both say this, and the PR body discloses it as gap 4 / decision T1. Noted only so the deferral is visible in the review record, not as something to fix here.
  • The MICROVM_MAX_COMMITTED_MB > SHIPPED_RESERVE_MB guard is a good catch: a budget at or below the reserve admits nothing, so refusing early beats a worker that starts and silently accepts no work.
  • Of the untested items you list, the reboot is the one I would most want covered before this is relied on, since podman-restart.service interacts with the tier-pinning gap above.

Bel lavoro — the runbook's split between verified and not verified is what made this reviewable at this size.

for t in "$@"; do printf '#!/bin/sh\n' >"$FIXTURE/usr/bin/$t"; chmod +x "$FIXTURE/usr/bin/$t"; done
printf 'bin\n' >"$FIXTURE/usr/local/bin/remote-worker"; chmod +x "$FIXTURE/usr/local/bin/remote-worker"
}
ALL_TOOLS=(bash git rg python3 base64 file ls cat)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

suggestion — this list can drift from the Go source, which is the failure build-snapshot.test.sh (in this same PR) goes out of its way to prevent.

That suite parses var probed = []string{…} straight out of remote-worker/cmd/worker/main.go and asserts the guest probe covers every entry, so adding a tool to the container tier turns the test red instead of drifting silently. That is the right pattern.

Here, ALL_TOOLS is a hand-copied duplicate of the script's own REQUIRED_TOOLS, pinned to nothing. Add a tool to probed in Go and build-snapshot.test.sh goes red while build-rootfs.sh keeps passing and keeps producing a rootfs that lacks it — surfacing later as a failed tool call, which is precisely the outcome REQUIRED_TOOLS' own comment says it exists to prevent.

Reusing the extraction already written next door would close it:

container_caps="$(sed -nE 's/^var probed = \[\]string\{(.*)\}$/\1/p' \
  "$DIR/../../remote-worker/cmd/worker/main.go" | tr -d '"' | tr ',' ' ')"

then assert REQUIRED_TOOLS ⊇ $container_caps. A subset assertion rather than equality, since ls and cat are a deliberate superset for the harness's own file ops.

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 b1de35c. ALL_TOOLS is now read from the script's own REQUIRED_TOOLS instead of a hand-kept copy. A new block asserts REQUIRED_TOOLS ⊇ the probed list from cmd/worker/main.go, using the same sed extraction as build-snapshot.test.sh. It checks a superset, as you suggested, since ls/cat are there for the harness's file ops.

To confirm it catches drift, I ran it against a copy of build-rootfs.sh with rg removed from REQUIRED_TOOLS. It fails with REQUIRED_TOOLS includes 'rg' (want 'yes', got 'no').

Comment thread deploy/microvm/p4-turn-smoke.sh Outdated
# <name>.txt (the response text), and prints nothing.
turn() {
local body
if [ -n "$2" ]; then body="{\"sessionId\":\"$2\",\"prompt\":\"$3\"}"; else body="{\"prompt\":\"$3\"}"; fi

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit — the prompt is interpolated into JSON unescaped.

Nothing is broken today: all three call sites pass bare literals (P4-SMOKE-WRITE, P4-SMOKE-READ, P4-SMOKE-SLEEP), none of which contain a quote, backslash or newline. So this is purely about the next prompt someone adds — one with an apostrophe produces malformed JSON and a 400 that looks like a server problem rather than a quoting problem.

The script already depends on node for json_field, so building the body correctly costs nothing extra:

body="$(node -e 'const [s,p]=process.argv.slice(1);
  process.stdout.write(JSON.stringify(s ? {sessionId:s, prompt:p} : {prompt:p}))' "$2" "$3")"

Entirely defensive — take it or leave it.

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.

Taken, in b1de35c. turn() now builds the body with JSON.stringify through node, which the script already needs for json_field. A prompt with a quote now encodes as {"prompt":"it's a \"quoted\" line"}. p4-turn-smoke.test.sh covers both body shapes, with and without sessionId, because its curl mock parses every body with JSON.parse.

…ON-encode turn bodies

Review follow-ups on rossoctl#376:
- build-rootfs.test.sh reads REQUIRED_TOOLS from the script instead of a
  hand-kept copy, and asserts it covers cmd/worker's probed list, the way
  build-snapshot.test.sh pins the guest probe.
- p4-turn-smoke.sh builds the /turn body with JSON.stringify, so a prompt
  with a quote, backslash or newline cannot produce malformed JSON.
Refs rossoctl#369

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
@pdettori
pdettori merged commit f6c3781 into rossoctl:main Sep 30, 2026
13 checks passed
@pdettori
pdettori deleted the feat/369-p4-on-p6 branch September 30, 2026 22:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants