feat(guestd): replace the Health-only stub with the V2b in-guest supervisor (RIG-2493) - #701
Open
rigel-mintaka wants to merge 1 commit into
Conversation
|
Compass engineering docs preview: https://compass-runner-rig-2493-u2-g.compass-eng-docs.pages.dev Deployed from |
rigel-mintaka
force-pushed
the
compass-runner/rig-2493-u2-guestd-supervisor
branch
2 times, most recently
from
August 28, 2026 04:35
23e0315 to
7e0a64e
Compare
rigel-mintaka
force-pushed
the
compass-runner/rig-2493-u1-guest-control-exec-proto
branch
from
August 28, 2026 10:06
6410d64 to
1d0d884
Compare
rigel-mintaka
force-pushed
the
compass-runner/rig-2493-u2-guestd-supervisor
branch
from
August 28, 2026 10:08
7e0a64e to
efbf696
Compare
…rvisor (RIG-2493) U2 of the frozen microVM Runner V2b plan (`docs/designs/infra/runtime/compass-elastic-session-runtime/microvm-v2b-guest-supervisor-exec.md`, §Plan U2 / §(b)). Replaces the V2a `healthService` (which U1 left embedding `UnimplementedGuestControlHandler` to satisfy the widened interface) with the full `supervisor` implementing every `GuestControl` RPC. ### What - **State gate** (`booting → ready → provisioned`, mutex-guarded): `Exec`/`ExecStream` refuse with `FailedPrecondition` until `Provision` opens the gate. - **`Provision`** records `default_exec_uid` (validated non-zero) + `base_env`; a non-empty `nft_script` answers `Unimplemented` (V3's); a second call or a not-ready guest answers `FailedPrecondition`. - **`Exec`** (one-shot): uid resolve (absent → session default, `0` → refused), env merge (exec keys win), stdin via `bytes.Reader` never argv, 8 MiB-capped stdout/stderr buffers (`ResourceExhausted` on overflow — the acknowledged divergence from the podman contract, OQ-E), guest-side timeout, non-zero exit is a **successful** `ExecResponse`, ctx-cancel → SIGKILL + reap. - **`ExecStream`** (bidi): first frame must be `StartExec`; `ExecStarted` is emitted first; a shared send-mutex serializes the demuxed `stdout`/`stderr`/`ExecExit` down-frames; stdin frames + `StdinClose` half-close the child; a broken stream or ctx-cancel → SIGKILL + reap; the terminal `ExecExit` always comes from our own reap. - **`Signal`**: `exec_id` → process-group signal; unknown/exited exec → no-op success; empty `exec_id` → `initiateStop` (the §(d) guest-stop path). - **Stop → power-off**: `run()` derives a serving ctx wired to `stopServing`; after serve returns, an RPC-triggered stop with no serve error calls `powerOff()` (`syscall.Reboot(LINUX_REBOOT_CMD_POWER_OFF)`), the PID-1-legal shutdown. The Unix-signal path (`cmd/compass-guestd` `signal.NotifyContext`) is a **distinct** trigger and returns as before, per §(d). - **Peer-CID guard**: `peerCIDListener` refuses any non-host CID before the first HTTP byte (hermetic non-vsock listeners are allowed); the handler carries `WithReadMaxBytes(16 MiB)` (OQ-E). - **Boot nonce**: `cmdline.go` parses `compass.boot_nonce=<hex>` (absent → nil, empty/non-hex → error); the supervisor echoes it on `HealthResponse.boot_nonce` (U1's additive field) so Start binds the guest to the VM it launched (§(e)). Boot steps 1–4 are byte-identical; only the serve step is retyped to `*supervisor` and gains the `powerOff` seam. ### Verification `go build ./...` clean (whole module); `go test ./internal/guestd/...` ok; `go test -race ./internal/guestd/...` ok; `gofmt -l internal/guestd/` clean. The hermetic suite (`supervisor_test.go`) drives an in-memory h2c listener with real host child processes and covers every §(b) acceptance row (gate refusal, uid-0 refusal, default-uid resolution, stdin-not-argv, env merge, non-zero-exit success, stream demux ordering, signal-kills-live-child, signal-on-exited no-op, broken-stream reap, peer-CID pure function, RPC-stop → power-off). ### Guest PATH resolution (CI fix, folded) `buildChild` spawned via `exec.Command(argv[0], …)`, whose bare-name resolution runs `LookPath` against guestd's OWN process environment — and guestd is PID 1 with no `PATH`, so a bare `argv[0]` (`echo`, `sh`, and in production `compass-agent`) never resolved: the first live KVM boot failed the exec rows with `executable file not found in $PATH`. The hermetic suite false-greened because it runs in-process with the test's ambient `PATH`. Fix (the container-baked-PATH analog, §(b)): `mergeEnv` floors a default `PATH=/bin:/usr/bin:/sbin:/usr/sbin` when neither the session base env nor the exec env supplies one, and `buildChild` resolves `argv[0]` against that merged `PATH` (via `resolveProgram`, honoring the session env, not the process env) — a name with a slash is used as-is, so absolute-path execs are unchanged. Regression: `TestExecResolvesBareCommandViaSessionPATH` (a base_env PATH pointing at a probe absent from the process PATH; fails before the fix) and `TestMergeEnvFloorsDefaultPATH`. Ledger-impact: none Spec-impact: none. Refs RIG-2493 Co-authored-by: Matt Wilkinson <matt@rigel.build>
rigel-mintaka
force-pushed
the
compass-runner/rig-2493-u2-guestd-supervisor
branch
from
August 28, 2026 11:08
efbf696 to
8a86859
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR is part of a stack containing 5 PRs:
mainU2 of the frozen microVM Runner V2b plan (
docs/designs/infra/runtime/compass-elastic-session-runtime/microvm-v2b-guest-supervisor-exec.md, §Plan U2 / §(b)). Replaces the V2ahealthService(which U1 left embeddingUnimplementedGuestControlHandlerto satisfy the widened interface) with the fullsupervisorimplementing everyGuestControlRPC.What
booting → ready → provisioned, mutex-guarded):Exec/ExecStreamrefuse withFailedPreconditionuntilProvisionopens the gate.Provisionrecordsdefault_exec_uid(validated non-zero) +base_env; a non-emptynft_scriptanswersUnimplemented(V3's); a second call or a not-ready guest answersFailedPrecondition.Exec(one-shot): uid resolve (absent → session default,0→ refused), env merge (exec keys win), stdin viabytes.Readernever argv, 8 MiB-capped stdout/stderr buffers (ResourceExhaustedon overflow — the acknowledged divergence from the podman contract, OQ-E), guest-side timeout, non-zero exit is a successfulExecResponse, ctx-cancel → SIGKILL + reap.ExecStream(bidi): first frame must beStartExec;ExecStartedis emitted first; a shared send-mutex serializes the demuxedstdout/stderr/ExecExitdown-frames; stdin frames +StdinClosehalf-close the child; a broken stream or ctx-cancel → SIGKILL + reap; the terminalExecExitalways comes from our own reap.Signal:exec_id→ process-group signal; unknown/exited exec → no-op success; emptyexec_id→initiateStop(the §(d) guest-stop path).run()derives a serving ctx wired tostopServing; after serve returns, an RPC-triggered stop with no serve error callspowerOff()(syscall.Reboot(LINUX_REBOOT_CMD_POWER_OFF)), the PID-1-legal shutdown. The Unix-signal path (cmd/compass-guestdsignal.NotifyContext) is a distinct trigger and returns as before, per §(d).peerCIDListenerrefuses any non-host CID before the first HTTP byte (hermetic non-vsock listeners are allowed); the handler carriesWithReadMaxBytes(16 MiB)(OQ-E).cmdline.goparsescompass.boot_nonce=<hex>(absent → nil, empty/non-hex → error); the supervisor echoes it onHealthResponse.boot_nonce(U1's additive field) so Start binds the guest to the VM it launched (§(e)).Boot steps 1–4 are byte-identical; only the serve step is retyped to
*supervisorand gains thepowerOffseam.Verification
go build ./...clean (whole module);go test ./internal/guestd/...ok;go test -race ./internal/guestd/...ok;gofmt -l internal/guestd/clean. The hermetic suite (supervisor_test.go) drives an in-memory h2c listener with real host child processes and covers every §(b) acceptance row (gate refusal, uid-0 refusal, default-uid resolution, stdin-not-argv, env merge, non-zero-exit success, stream demux ordering, signal-kills-live-child, signal-on-exited no-op, broken-stream reap, peer-CID pure function, RPC-stop → power-off).Ledger-impact: none
Spec-impact: none. Refs RIG-2493
Co-authored-by: Matt Wilkinson matt@rigel.build