Skip to content

feat(runtime): host GuestExec layer + portable exit-signal error type (RIG-2493) - #702

Open
rigel-mintaka wants to merge 1 commit into
compass-runner/rig-2493-u2-guestd-supervisorfrom
compass-runner/rig-2493-u3-host-exec
Open

feat(runtime): host GuestExec layer + portable exit-signal error type (RIG-2493)#702
rigel-mintaka wants to merge 1 commit into
compass-runner/rig-2493-u2-guestd-supervisorfrom
compass-runner/rig-2493-u3-host-exec

Conversation

@rigel-mintaka

@rigel-mintaka rigel-mintaka commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

This PR is part of a stack containing 5 PRs:

  1. main
  2. feat(guest_control): grow GuestControl with the V2b exec surface (RIG-2493) #696
  3. feat(guestd): replace the Health-only stub with the V2b in-guest supervisor (RIG-2493) #701
  4. "feat(runtime): host GuestExec layer + portable exit-signal error type (RIG-2493)" (this PR)
  5. feat(runtime): fill MicroVMRuntime lifecycle methods (RIG-2493) #719
  6. test(runtime): shared ContainerRuntime contract suite across both backends (RIG-2493) #720

U3 + U3b of the frozen microVM Runner V2b plan (docs/designs/infra/runtime/compass-elastic-session-runtime/microvm-v2b-guest-supervisor-exec.md, §Plan U3/U3b, §(c)/§(e)). The host-side client half of the exec control plane: a GuestExec layer over U1's generated GuestControl client, plus the backend-portable error type the runner's kill-classifier keys on.

U3b — portable exit-signal error (internal/runtime/exit_status_error.go, new)

ExitStatusError{Code int; Signal syscall.Signal} with Error(), in package runtime. A remote guest exec cannot forge an *exec.ExitError, so the microVM waitFunc constructs this instead for a signalled guest exit. internal/runner/agent_exec.go's isDeliberateKill is widened to errors.As on *runtime.ExitStatusError first (a non-zero signal ⇒ deliberate kill), then the existing *exec.ExitError SIGKILL branch unchanged — so the podman byte-path is byte-identical and only the microVM backend gets the new classification.

U3 — GuestExec layer (internal/runtime/microvm/exec.go, new)

Plain structs (ExecCall/ExecResult/StreamCall/ExitStatus) mirror the proto so runtime types don't leak into microvm (microvm must not import runtime; U4 makes runtime import microvm).

  • Exec (one-shot RPC): a non-zero exit is a successful ExecResult; a refusal/transport failure is an error; a host-side timeout → *microvm.TimeoutError.
  • ExecStream (bidi): opens the stream, sends StartExec, awaits ExecStarted before returning; per-exec goroutines pump the Stdin pipe → stdin frames (Closestdin_close + CloseRequest) and demux stdout/stderr response frames onto io.Pipe read ends, closing them on ExecExit.
  • GuestStream.Kill issues a Signal RPC bounded by killSignalTimeout (never blocks teardown past it); Wait blocks on the demux goroutine and returns ExitStatus{Code,Signal}. A ctx-cancel stream break reports SIGKILL — guestd reaps the child bound to the broken stream.

podman.go — funcs-backed ChildHandle

Adds unexported newChildHandleFuncs(kill, wait func() error) *ChildHandle plus killFunc/waitFunc fields. Kill/Wait/Terminate branch to the funcs path when killFunc != nil, else drive the original cmd/cancel path untouched (podman byte-unchanged). Terminate = kill then wait, returning the wait error (the exit status) when non-nil else the kill error — so a crash-vs-teardown consumer gets the exit signal.

Verification

go build ./internal/runtime/... ./internal/runner/... clean; go vet clean over runtime, runtime/microvm, runner. Tests (all hardware-independent, no microvm build tag, no KVM):

  • exec_test.go — fake GuestControl server on a unix listener over h2c Connect, dialed by a real client: one-shot non-zero exit is success + spec mapping; refusal is an error; one-shot timeout → *TimeoutError; stream demux ordering (interleaved frames land on the correct pipes, drained concurrently); stdin framing + Closestdin_close; Kill issues the Signal RPC and Wait unblocks on the signalled exit; ctx-cancel breaks the stream and Wait reports SIGKILL.
  • child_handle_test.gonewChildHandleFuncs: Kill invokes/propagates; Wait surfaces *ExitStatusError unchanged; Terminate return-value precedence.
  • deliberate_kill_test.goisDeliberateKill accepts a real *exec.ExitError from a SIGKILLed local child (podman-path regression guard) and *runtime.ExitStatusError{Signal: SIGKILL}, rejects a non-signal ExitStatusError, an unrelated error, and nil.

Ledger-impact: none

Spec-impact: none. Refs RIG-2493

Co-authored-by: Matt Wilkinson matt@rigel.build

@linear-code

linear-code Bot commented Aug 28, 2026

Copy link
Copy Markdown

RIG-2493

@github-actions

github-actions Bot commented Aug 28, 2026

Copy link
Copy Markdown

Compass engineering docs preview: https://compass-runner-rig-2493-u3-h.compass-eng-docs.pages.dev

Deployed from compass-runner/rig-2493-u3-host-exec at 417292b.

@rigel-mintaka
rigel-mintaka force-pushed the compass-runner/rig-2493-u2-guestd-supervisor branch from a66b253 to 23e0315 Compare August 28, 2026 04:12
@rigel-mintaka
rigel-mintaka force-pushed the compass-runner/rig-2493-u3-host-exec branch from facc61c to 8a00c7e Compare August 28, 2026 04:15
@rigel-mintaka
rigel-mintaka force-pushed the compass-runner/rig-2493-u2-guestd-supervisor branch from 23e0315 to 7e0a64e Compare August 28, 2026 04:35
@rigel-mintaka
rigel-mintaka force-pushed the compass-runner/rig-2493-u3-host-exec branch from 8a00c7e to 869399a Compare August 28, 2026 04:37
@rigel-mintaka
rigel-mintaka force-pushed the compass-runner/rig-2493-u2-guestd-supervisor branch from 7e0a64e to efbf696 Compare August 28, 2026 10:08
@rigel-mintaka
rigel-mintaka force-pushed the compass-runner/rig-2493-u3-host-exec branch from 869399a to 81856f8 Compare August 28, 2026 10:09
… (RIG-2493)

U3 + U3b of the frozen microVM Runner V2b plan (`docs/designs/infra/runtime/compass-elastic-session-runtime/microvm-v2b-guest-supervisor-exec.md`, §Plan U3/U3b, §(c)/§(e)). The host-side client half of the exec control plane: a `GuestExec` layer over U1's generated `GuestControl` client, plus the backend-portable error type the runner's kill-classifier keys on.

### U3b — portable exit-signal error (`internal/runtime/exit_status_error.go`, new)

`ExitStatusError{Code int; Signal syscall.Signal}` with `Error()`, in package `runtime`. A remote guest exec cannot forge an `*exec.ExitError`, so the microVM `waitFunc` constructs this instead for a signalled guest exit. `internal/runner/agent_exec.go`'s `isDeliberateKill` is widened to `errors.As` on `*runtime.ExitStatusError` **first** (a non-zero signal ⇒ deliberate kill), then the existing `*exec.ExitError` SIGKILL branch **unchanged** — so the podman byte-path is byte-identical and only the microVM backend gets the new classification.

### U3 — GuestExec layer (`internal/runtime/microvm/exec.go`, new)

Plain structs (`ExecCall`/`ExecResult`/`StreamCall`/`ExitStatus`) mirror the proto so `runtime` types don't leak into `microvm` (`microvm` must not import `runtime`; U4 makes `runtime` import `microvm`).

- **`Exec`** (one-shot RPC): a non-zero exit is a successful `ExecResult`; a refusal/transport failure is an error; a host-side timeout → `*microvm.TimeoutError`.
- **`ExecStream`** (bidi): opens the stream, sends `StartExec`, **awaits `ExecStarted`** before returning; per-exec goroutines pump the `Stdin` pipe → stdin frames (`Close` → `stdin_close` + `CloseRequest`) and demux `stdout`/`stderr` response frames onto `io.Pipe` read ends, closing them on `ExecExit`.
- **`GuestStream.Kill`** issues a `Signal` RPC bounded by `killSignalTimeout` (never blocks teardown past it); **`Wait`** blocks on the demux goroutine and returns `ExitStatus{Code,Signal}`. A ctx-cancel stream break reports SIGKILL — guestd reaps the child bound to the broken stream.

### `podman.go` — funcs-backed ChildHandle

Adds unexported `newChildHandleFuncs(kill, wait func() error) *ChildHandle` plus `killFunc`/`waitFunc` fields. `Kill`/`Wait`/`Terminate` branch to the funcs path when `killFunc != nil`, else drive the original `cmd`/`cancel` path **untouched** (podman byte-unchanged). `Terminate` = kill then wait, returning the wait error (the exit status) when non-nil else the kill error — so a crash-vs-teardown consumer gets the exit signal.

### Verification

`go build ./internal/runtime/... ./internal/runner/...` clean; `go vet` clean over `runtime`, `runtime/microvm`, `runner`. Tests (all hardware-independent, no `microvm` build tag, no KVM):

- `exec_test.go` — fake `GuestControl` server on a unix listener over h2c Connect, dialed by a real client: one-shot non-zero exit is success + spec mapping; refusal is an error; one-shot timeout → `*TimeoutError`; stream demux ordering (interleaved frames land on the correct pipes, drained concurrently); stdin framing + `Close` → `stdin_close`; `Kill` issues the `Signal` RPC and `Wait` unblocks on the signalled exit; ctx-cancel breaks the stream and `Wait` reports SIGKILL.
- `child_handle_test.go` — `newChildHandleFuncs`: `Kill` invokes/propagates; `Wait` surfaces `*ExitStatusError` unchanged; `Terminate` return-value precedence.
- `deliberate_kill_test.go` — `isDeliberateKill` accepts a real `*exec.ExitError` from a SIGKILLed local child (podman-path regression guard) and `*runtime.ExitStatusError{Signal: SIGKILL}`, rejects a non-signal `ExitStatusError`, an unrelated error, and nil.

Ledger-impact: none

Spec-impact: none. Refs RIG-2493

Co-authored-by: Matt Wilkinson <matt@rigel.build>
@rigel-mintaka
rigel-mintaka force-pushed the compass-runner/rig-2493-u2-guestd-supervisor branch from efbf696 to 8a86859 Compare August 28, 2026 11:08
@rigel-mintaka
rigel-mintaka force-pushed the compass-runner/rig-2493-u3-host-exec branch from 81856f8 to 417292b Compare August 28, 2026 11:09
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.

1 participant