Introducing a new way to review your PRs.

Read the announcement

arcboxlabs / arcbox

Run AI agents on real and isolated machines — own kernel, filesystem, and network — with <100ms boot. Local first, OCI compatible, pure Rust.

View on GitHub

32 documents · Updated Nov 6, 2026

docs / runner-agent-and-control-protocols

Runner agent and control protocols

The runner agent is the host-side worker that joins a managed runner pool, keeps a secure connection to the runner gateway, and starts one GitHub Actions runner for each accepted job. A local control API lets the CLI and desktop app enroll the host, change its lifecycle state, prepare runner images, and observe the same state that the gateway sees. See Managed runner integration for the wider provisioning and pool model.

Enrollment and credentials

Enrollment turns a pool join token into a long-lived identity for one host. The agent then uses that identity for gateway attachment and stores it locally so a service restart can resume without another join token.

Enrollment exchange

The gateway accepts an Enroll request without host credentials because the enrollment token is the proof of permission to join. The request also describes the host platform, resources, facts, agent build, and job capabilities. A successful response returns a host ID and host token; a version mismatch returns an update request instead of creating a host.

The local control API supports enrollment while serve is running. The headless path can enroll before starting the long-lived process. Both paths use the same gateway contract and converge on the same stored credential.

References: runner/…/enroll.rs• L45-109 runner/…/lifecycle.rs• L59-73 runner/…/runner.proto• L5-11 runner/…/runner.proto• L35-77

Credential storage

The credential contains the host ID and the secret host token. macOS uses the login keychain by default. Linux uses an owner-only file. The store is scoped to the gateway so credentials for separate environments do not replace one another.

Unenrollment first makes a bounded best-effort request to revoke the host at the gateway, then clears the local credential even if the gateway is unavailable. A credential that the gateway already revoked is treated as the desired result.

References: runner/…/credentials.rs• L20-61 runner/…/credentials.rs• L63-89 runner/…/enroll.rs• L112-167

Gateway attachment

Attachment is the long-lived bidirectional stream between the agent and the gateway. The agent sends its identity and capabilities first, then sends telemetry and runner events while receiving job offers and lifecycle commands.

Attachment handshake

The agent puts the host token in x-arcbox-host-token metadata. Its first stream message is Attach, which declares the agent build, host facts, and the capabilities that the gateway may use for placement. The gateway accepts the stream only when the build matches its pinned version.

The agent sends a heartbeat about every 15 seconds. A heartbeat carries live load and memory data. Slow host facts may arrive later in one complete update. If the available backend set changes, the agent reconnects so the gateway receives a fresh capability declaration.

This diagram shows the handshake and the messages that keep the gateway attachment live.

sequenceDiagram
    participant A as Runner agent
    participant G as Runner gateway
    A->>G: Attach with token metadata, build, facts, capabilities
    G-->>A: AttachAccepted or AgentUpdate
    loop While attached
        A->>G: Heartbeat and runner events
        G-->>A: HeartbeatAck, offers, cancel, drain, acknowledgements
    end
    A-->>G: Reconnect after stream loss or capability change

References: runner/…/attach.rs• L51-61 runner/…/attach.rs• L336-480 runner/…/attach.rs• L647-677 runner/…/runner.proto• L13-21 runner/…/runner.proto• L144-187

Reconnection and parked states

A dropped stream does not stop a job. The agent keeps the supervisor and its outbound event queue across reconnects, then forwards the job's later events on the next stream. Connection failures use backoff. A revoked credential stops retries and parks the agent until an explicit unenroll, which avoids deleting a credential because of a temporary network or server error.

The gateway can also push a required build during a live stream. The agent stops taking new work, waits for safe handover, and updates instead of retrying the old build.

References: runner/…/attach.rs• L156-333 runner/…/attach.rs• L220-310 runner/…/runner.rs• L453-492

Job attachment and execution

The gateway sends a ProvisionRunner offer with a job ID, target operating system and architecture, a single-use just-in-time runner configuration, and an offer token. The agent is the admission authority: it decides whether it can start the runner now and returns accept or reject.

Offer admission

Admission first protects job identity. A duplicate offer never starts a second runner. The agent then rejects offers when it is draining, lacks a matching capability, exceeds its live load limit, or has too little free memory. Capacity is therefore a live decision rather than a fixed count advertised to the gateway.

The agent sends RunnerAccepted only after the selected runner is running. A startup failure sends RunnerRejected, which lets the platform offer the job to another host. A started runner later emits RunnerExited as a liveness hint. The GitHub completion webhook remains the authority for the job result.

This diagram shows how an offer becomes a local runner or a placement rejection.

flowchart TD
    O[ProvisionRunner offer] --> D{Duplicate job?}
    D -->|Yes| R[Replay or park the prior verdict]
    D -->|No| G{Draining, unsupported, busy, or low memory?}
    G -->|Yes| J[RunnerRejected]
    G -->|No| B[Select local backend]
    B --> S{Runner starts?}
    S -->|No| J
    S -->|Yes| A[RunnerAccepted]
    A --> W[Run and watch job]
    W --> E[RunnerExited liveness hint]

References: runner/…/runner.rs• L61-101 runner/…/runner.rs• L263-395 runner/…/runner.rs• L969-1029 runner/…/runner.proto• L190-221 runner/…/runner.proto• L272-290

Cancellation and cleanup

CancelRunner is a level-triggered request for a job that the platform already concluded. The agent keeps the job in flight until the runner resource is actually gone. This rule prevents a new offer from reusing the same job ID while an old process, container, or guest still runs.

The agent tracks accepted and rejected events until the gateway acknowledges them. It resends unacknowledged events across stream reconnects. This protects the offer decision from a gateway failure after it read the message.

References: runner/…/runner.rs• L407-417 runner/…/runner.rs• L1022-1047 runner/…/runner.proto• L258-270

Docker and VM interoperation

The agent presents one capability set while choosing different local execution boundaries for each job. The shared backend registry keeps capability advertisement, offer routing, image preparation, and status reporting aligned.

Docker-backed Linux jobs

Linux jobs can run in a Docker-compatible runtime. The agent verifies that the runtime can pull a runner image for each advertised architecture. For each job it pulls the selected image, creates a named container, passes the JIT configuration to the runner, captures output when possible, and removes the container after completion or cancellation.

On macOS the first Docker target is ArcBox's Docker-compatible socket. The agent can fall back to another local Docker runtime when ArcBox is not reachable. An architecture is advertised only when the configured runner image can be realized for it.

References: runner/…/docker.rs• L1-5 runner/…/docker.rs• L197-227 runner/…/docker.rs• L263-369 runner/…/runner.rs• L839-927

VM-backed macOS jobs

Darwin jobs can run in disposable macOS guests managed by the local ArcBox daemon. The agent creates a per-job guest from the selected base image, waits for its address and SSH service, starts the preinstalled runner with the JIT configuration, and destroys the guest when the session ends.

The guest is the isolation boundary. The agent does not need a second process-control protocol inside the guest: destroying the guest stops the runner. The daemon's guest limit is part of admission because a refused guest start causes the agent to reject the offer.

References: runner/…/vm.rs• L1-22 runner/…/vm.rs• L94-123 runner/…/vm.rs• L195-277 runner/…/runner.rs• L581-685

WSL Windows interoperation

When the agent runs inside WSL2, it can serve Windows jobs through the Windows runner installed on the host. A PowerShell bridge starts the Windows process and reports its Windows PID. Normal completion follows the bridge. Cancellation uses Windows taskkill for the process tree because killing only the Linux relay would leave the Windows runner behind.

This path is advertised only after the interop probe and runner-path checks succeed. The bridge also limits the JIT command size because it crosses the Windows command-line boundary.

References: runner/…/interop.rs• L1-23 runner/…/interop.rs• L108-147 runner/…/interop.rs• L162-251 runner/…/interop.rs• L295-358

Handover and updates

The agent uses one handover model for gateway updates, operator restarts, and termination. All paths stop new admission and clean up runners before the process exits or replaces its image. The reason for shutdown determines whether the next process image starts.

Graceful handover

An operator restart waits for in-flight jobs to finish and for outstanding gateway event acknowledgements when the stream is live. A forced restart cancels in-flight jobs. A termination signal always means exit and cannot be turned into a restart by a race with an earlier request.

The process reports draining while a handover is pending. This closes the admission boundary before teardown starts and keeps the observable state consistent with the work that remains.

References: runner/…/handover.rs• L1-31 runner/…/handover.rs• L157-263 runner/…/lifecycle.rs• L34-47 runner/…/mod.rs• L735-803

Self-update flow

The gateway can require a precise agent build during enrollment or attachment. When it provides a binary URL and SHA-256 value, the agent downloads the binary, verifies it, checks that the binary reports the expected version, swaps it into the managed install path, and re-execs after teardown. If no usable payload exists, the agent parks for operator action.

The same update path serves enrollment refusal and live attachment updates. The managed-path check prevents a development or manually installed binary from replacing itself without ownership of the service installation.

References: runner/…/update.rs• L48-70 runner/…/update.rs• L152-189 runner/…/update.rs• L210-283 runner/…/attach.rs• L242-310

Generated protocol contracts

The repository keeps two generated gRPC contracts with different owners. The gateway contract is the public wire boundary between a host and the managed runner service. The control contract is the local boundary between the agent and its operator clients.

Gateway protocol

The gateway contract in runner/…/runner.proto defines enrollment, authenticated attachment, unenrollment, capabilities, telemetry, job offers, verdicts, cancellation, draining, and update pushes. Its capability messages describe routing possibilities; they do not promise a numeric worker count.

The generated Rust module exposes the published arcbox.runner.v1 types and tonic clients. Changes to this contract affect the gateway and every runner agent that speaks it.

References: runner/…/runner.proto• L1-29 runner/…/runner.proto• L102-129 runner/…/lib.rs• L1-13

Local control protocol

The local contract in runner/…/control.proto runs over an owner-only Unix socket. It exposes lifecycle commands, status, state watch, settings, and streamed image preparation. The CLI and desktop app do not keep a second copy of agent state; they read the snapshots and responses from this service.

Clients call GetAgentInfo first and use reported features rather than requiring an exact client and agent version match. The protocol uses additive evolution and increases its API version only for breaking changes.

References: runner/…/control.proto• L5-50 runner/…/control.proto• L125-162 runner/…/lib.rs• L1-15 runner/…/mod.rs• L61-114

State and image contracts

The state service sends the current snapshot first and then sends one snapshot for each change. A snapshot joins enrollment, draining, capabilities, in-flight jobs, recent offer verdicts, telemetry, and settings so a client can render one coherent view.

Image preparation keeps requested image values separate from verified values. A streamed prepare operation pulls the Linux image through Docker or the macOS image through the daemon, then promotes the image only after the owning runtime accepts it. This keeps new jobs on artifacts that the active backend can use.

References: runner/…/watch.rs• L24-43 runner/…/image.rs• L122-245 runner/…/control.proto• L205-225 runner/…/control.proto• L346-388

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep gateway capability values, backend routing, local state snapshots, and attach re-registration aligned. A capability that is advertised but cannot start a job creates repeated placement failures.
  • Keep RunnerAccepted, RunnerRejected, RunnerExited, and OfferVerdictAck correlation rules aligned. The gateway and agent must agree which token is safe to resend or settle.
  • Keep enrollment gateway selection and credential-store scoping aligned. A gateway override must persist with the credential under the same environment key.
  • Keep the JIT configuration contract valid across Docker, SSH, and WSL command boundaries. Encoding or quoting changes can make a runner start failure look like a placement failure.
  • Keep image target and verified current behavior aligned with the backend that consumes the image. Promoting an image before all required platforms are ready can break only some job offers.
  • Keep control clients feature-based when adding local RPCs. The CLI and desktop app can update on a different schedule from the agent.

Important failure modes

TriggerConsequenceGuard
Gateway rejects the host tokenThe agent parks instead of retrying forever or deleting the credentialRequire explicit unenrollment before clearing the credential
Agent accepts before the runner is usableThe job is marked placed while no runner can receive workSend acceptance only after process, container, Windows process, or guest startup succeeds
Gateway loses a verdict after reading itThe workflow can wait with no placement resultTrack the event and resend it until OfferVerdictAck
Cancellation releases the job slot too earlyA duplicate offer can start beside an old runnerAwait process-group, container, guest, or Windows-tree teardown before release
Linux image works for one advertised architecture onlyOffers for another architecture fail after placementPull the image for every advertised architecture before promotion
WSL relay is killed instead of the Windows treeThe Windows runner can remain orphanedCancel through Windows taskkill using the PID handshake
Update payload has the wrong digest or versionThe agent could install an untrusted or looping binaryVerify gateway-provided SHA-256 and the binary's reported version before swap
Restart response is lost during re-execA client can report a false restart failureTreat transport loss as possible success and compare instance_id after reconnect

Key files

FileWhy to read it
runner/…/mod.rsShows the local control server and the enrollment, attachment, participation, and restart state machine.
runner/…/attach.rsShows the authenticated gateway stream, reconnect behavior, heartbeat, update handling, and event delivery.
runner/…/runner.rsShows offer admission, backend routing, cancellation, verdicts, and runner lifetime ownership.
runner/…/enroll.rsShows the gateway enrollment and terminal unenrollment exchange.
runner/…/credentials.rsShows how host identity and secret credentials persist across restarts and gateways.
runner/…/docker.rsShows the Docker-compatible Linux job boundary and image readiness rules.
runner/…/vm.rsShows the disposable macOS guest job boundary and daemon interaction.
runner/…/interop.rsShows the WSL-to-Windows process and cancellation boundary.
runner/…/handover.rsShows how updates, restarts, and termination share one safe teardown model.
runner/…/update.rsShows the verified binary update and re-exec contract.
runner/…/runner.protoDefines the public gateway enrollment, attachment, placement, lifecycle, and update messages.
runner/…/control.protoDefines the local lifecycle, state, settings, image, and compatibility contract.