Managed runner integration
ArcBox Runners turns enrolled Macs and Linux hosts into a shared pool of self-hosted GitHub Actions runners. The runner agent joins the ArcBox control plane, reports what each host can serve, accepts work only when the host has room, and maps each accepted job to an isolated host process, Docker container, or disposable macOS VM.
System boundary
The managed runner system has three cooperating parts. The ArcBox platform places jobs across hosts and remains the source of job state. The runner agent is the host-side admission and execution authority. The local ArcBox daemon supplies macOS VM services when the host advertises that backend.
The feature is opt-in. A normal ArcBox runtime does not need a platform account or a runner connection until an operator enrolls the host.
| Part | Responsibility |
|---|---|
| Runner gateway | Accepts host enrollment, keeps the long-lived host stream, and offers jobs to suitable hosts. |
| Runner agent | Stores the host credential, advertises capabilities, decides whether to accept each offer, and runs or stops the job. |
| ArcBox daemon | Creates, starts, inspects, pulls images for, and removes disposable macOS guests. |
| GitHub Actions | Supplies the per-job runner configuration and later confirms the authoritative job result through its normal workflow events. |
The public gateway contract is runner/…/runner.proto. Local lifecycle and settings access uses the related runner-agent and control protocols.
References: docs/…/0006-restore-arcbox-runners.md• L8-20 runner/…/runner.proto• L5-29 runner/…/main.rs• L1-20
Enrollment and attachment
Enrollment changes a host from an unknown machine into a named runner host in one workspace. An operator supplies a pool enrollment token through the local agent interface or the socketless CLI path. The gateway exchanges that token for a long-lived host credential, while the agent keeps the credential locally and uses it for later outbound connections.
The host always dials out to the gateway. This lets hosts behind NAT participate without an inbound path. After enrollment, the agent opens a bidirectional attachment stream and sends its build identity, capabilities, host facts, and host identity. It then sends heartbeat telemetry while the stream remains live.
sequenceDiagram
participant O as Operator or desktop
participant A as Runner agent
participant G as Runner gateway
participant D as ArcBox daemon
O->>A: Enroll with pool token
A->>G: Enroll(token, host facts, capabilities)
G-->>A: Host ID and long-lived credential
A->>A: Persist credential
A->>G: Attach with host credential
G-->>A: AttachAccepted
A->>G: Heartbeats and host events
A->>D: Probe local VM service when VM capability is possible
The agent reports capabilities as (operating system, architecture, backend) pairs. These pairs describe which jobs the host can serve. They do not promise a fixed job count. The gateway uses heartbeat telemetry to rank hosts, but the agent makes the final admission decision from its current load and free memory.
An enrollment refusal can carry the expected agent version and a platform-specific download. The agent verifies and installs a managed update before it retries enrollment. If no download is available, it stays out of the pool and reports the expected version to the operator.
References: runner/…/enroll.rs• L45-109 runner/…/attach.rs• L400-482 runner/…/host.rs• L198-235 runner/…/runner.proto• L35-100
Capability and configuration state
The agent derives its advertised capabilities from the backends that are ready on the host. The same live registry drives gateway advertisement, local status, image preparation, and offer routing. This keeps a host from claiming a job type that its local runtime cannot serve.
The main execution choices are:
| Job or host capability | Execution path | Readiness signal |
|---|---|---|
| Native host runner | Uses a pre-installed Actions runner entry point. | The configured runner script is present. |
| Linux | Uses a Docker-compatible runtime and the selected runner image. | The runtime responds and the image can be pulled for each advertised architecture. |
| Darwin | Uses disposable macOS guests through the local daemon. | The daemon responds and the selected base image is installed. |
| Windows from WSL | Uses the Windows runner across the WSL interop boundary. | The interop probe succeeds and the Windows runner script is present. |
Settings have a requested target and an active current value. This split matters for changes that need a pull, a restart, or a live attach transition. Image changes become active only after preparation verifies the artifact. Backend mode and runner entry-point changes take effect on a full restart. The participate setting is different: it detaches or reattaches the existing host identity without deleting its credential.
The local state stream gives the desktop a view of enrollment, attachment, draining, capabilities, telemetry, in-flight jobs, recent offer results, and current versus target settings. The desktop does not own a second copy of this state.
References: runner/…/backends.rs• L1-21 runner/…/backends.rs• L94-202 runner/…/settings.rs• L26-72 runner/…/control.proto• L205-356
Job offer and admission
The gateway sends a ProvisionRunner offer over the attachment stream. The offer names the job, its required operating system and architecture, and a single-use GitHub JIT configuration. The agent maps the requested pair to one of its ready backends, checks live headroom, and either starts the runner or rejects the offer so the platform can try another host.
When the agent processes an offer, it follows this order:
- Treat a job already in flight as a duplicate rather than starting a second runner.
- Reject the offer when the host is draining or preparing to hand over to a new process.
- Find a backend for the requested operating system and architecture.
- Reject the offer when load or available memory crosses the local admission limits.
- Start the selected runner and send
RunnerAcceptedonly after startup reaches the backend's running point. - Send
RunnerRejectedwhen startup fails, so the platform can re-offer the job.
The offer verdict is retried until the gateway acknowledges it. A runner exit is a liveness signal, not the authoritative job result. GitHub's workflow completion remains authoritative. This distinction lets the platform fail fast when a runner dies before GitHub can report completion without replacing GitHub's job state.
flowchart TD
O[Gateway offers job] --> C{Job already in flight?}
C -- yes --> R[Replay or defer existing verdict]
C -- no --> D{Host draining?}
D -- yes --> X[Reject and re-offer]
D -- no --> B{Matching ready backend?}
B -- no --> X
B -- yes --> H{Enough live headroom?}
H -- no --> X
H -- yes --> S[Start runner]
S -- startup fails --> X
S -- runner started --> A[Accept offer]
A --> J[GitHub workflow reports job result]
A --> E[Runner exit gives liveness hint]
Cancellation travels in the same attachment. The agent keeps the job slot until the selected process, container, or guest is actually torn down. This prevents a canceled job from releasing capacity while its runner still exists.
References: runner/…/runner.proto• L190-290 runner/…/runner.rs• L1-16 runner/…/runner.rs• L263-395 runner/…/runner.rs• L407-418
Host and VM execution
Accepted jobs use the backend selected from the host's capability set. Host execution runs the pre-installed Actions runner. Docker execution starts a fresh container from the active Linux runner image. Darwin VM execution creates a disposable macOS guest through the daemon and starts the image-baked Actions runner over SSH.
The VM path connects the managed runner system to the broader ArcBox control plane without adding a runner protocol inside the guest. For each job, the agent asks the daemon to create and start a copy-on-write guest, waits for its reported address, runs the guest's runner entry point with the single-use JIT configuration, and removes the guest when the session ends or is canceled.
flowchart LR
P[Accepted job] --> R{Selected backend}
R --> H[Host runner process]
R --> D[Docker-compatible runtime]
R --> V[ArcBox daemon]
D --> C[Fresh Linux container]
V --> G[Fresh macOS guest]
G --> S[SSH to image-baked runner]
H --> W[Runner session]
C --> W
S --> W
W --> T[Wait for exit]
T --> K[Destroy process, container, or guest]
The VM backend is also used to prepare its own base image. A control-plane Prepare request pulls the target image through the daemon and promotes it to the active image only after the pull completes. If that pull makes the daemon ready, the agent activates the VM capability and re-attaches so the gateway sees the new capability set.
References: runner/…/runner.rs• L526-564 runner/…/runner.rs• L581-685 runner/…/docker.rs• L1-5 runner/…/vm.rs• L1-21 docs/macos-guest.md• L105-121
Lifecycle, update, and removal
The agent keeps enrollment, attachment, admission, and process replacement as separate lifecycle concerns. An operator can drain a live host, restart it in place, detach it while retaining its identity, or remove it from the pool completely.
The lifecycle actions have different effects:
| Action | Effect on jobs | Effect on identity |
|---|---|---|
| Drain | Finishes in-flight jobs and accepts no new offers. | Keeps the host enrolled. |
| Resume | Allows new offers after a local drain. | Keeps the same host identity. |
| Detach | Stops the attachment and leaves the host offline. | Keeps the credential for later reattachment. |
| Restart or update | Drains and replaces the process image. | Keeps enrollment and the credential. |
| Unenroll | Stops attachment, decommissions the remote host record, and clears the local credential. | A later enrollment creates a new host identity. |
Gateway-driven updates and operator restarts use a handover. The agent stops new admission, waits for in-flight work to finish, waits briefly for outstanding verdict acknowledgements, then replaces the managed binary and re-executes. The update path verifies the gateway-supplied digest and the binary's reported version before the swap. A binary outside the agent's managed install path is not replaced automatically.
The agent treats an invalidated credential as a parked state rather than deleting it on its own. This protects against a temporary server-side error. Explicit unenrollment is the action that revokes the credential remotely and clears the local copy.
References: runner/…/mod.rs• L531-680 runner/…/mod.rs• L735-805 runner/…/update.rs• L1-32 runner/…/update.rs• L152-245 runner/…/control.proto• L23-47
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the gateway capability model and local backend registry aligned. A new advertised
(os, arch)pair must have a matching offer route and a working runtime. - Preserve the target/current boundary for runner images. A setting update must not make an unverified image active before
Preparecompletes. - Keep enrollment credentials bound to the gateway that issued them. Gateway changes require unenrollment before re-enrollment.
- Keep update handover ordering intact: stop admission, settle runners and verdicts, verify the replacement, then re-exec.
- Keep VM image preparation and VM capability activation consistent. A newly pulled image must cause a fresh capability advertisement before darwin offers arrive.
- Treat
RunnerAcceptedandRunnerExitedas transport and liveness signals only. GitHub workflow completion remains the job outcome contract.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Gateway expects a different agent build | The host cannot enroll or attach. | The agent consumes the update payload, verifies the binary, and retries on the expected build. |
| Host lacks a matching ready backend | The offer is rejected and can move to another host. | Capabilities are derived from the live backend registry. |
| Load or free memory crosses the local limit | The host declines the offer even if it has the right labels. | Admission checks live telemetry for every offer. |
| Docker or the selected image cannot serve an advertised Linux architecture | Linux startup fails or the image remains unprepared. | Readiness and image preparation cover every advertised architecture. |
| macOS daemon refuses a guest start or reaches its guest cap | The darwin offer is rejected and the platform re-offers it. | VM startup is treated as an admission result and failed guests are removed. |
| Cancellation races with runner startup | A runner could outlive the job if teardown is not awaited. | The job slot remains active until the process, container, or guest is gone. |
| Gateway revokes a host credential | The agent stops reconnecting and remains parked. | Only explicit unenrollment clears the credential and creates a new host identity. |
Key files
| File | Why to read it |
|---|---|
| docs/…/0006-restore-arcbox-runners.md | Product boundary, runner-pool model, naming, and relationship to the ArcBox runtime. |
| runner/…/runner.proto | Gateway enrollment, attachment, offers, verdicts, updates, and cancellation contract. |
| runner/…/control.proto | Local lifecycle, state, settings, and image preparation contract. |
| runner/…/mod.rs | Agent-owned enrollment, attachment, detach, unenroll, drain, and restart lifecycle. |
| runner/…/backends.rs | Capability derivation and the shared registry that links readiness to routing. |
| runner/…/runner.rs | Per-offer admission and the common job supervision and teardown model. |
| runner/…/vm.rs | Bridge from accepted darwin jobs to the daemon's disposable macOS guests. |
| runner/…/image.rs | Target image preparation, promotion, and VM backend activation. |
| runner/…/update.rs | Verified agent replacement and process handover boundary. |
| docs/runner-agent-and-control-protocols.md | Child page for the agent's detailed behavior and local or gateway protocol contracts. |