Protocol and service contracts
ArcBox uses Protocol Buffer contracts to give the daemon, guest agent, SDKs, and fleet tools one shared view of messages and RPC methods. The contracts define data and service meaning; generated Rust code exposes that meaning to each caller, while the daemon and fleet agent decide which declared services are live. This page expands the contract view from RPC and protocols.
Contract families
The repository has two related contract groups. ArcBox contracts describe local VM, container, system, migration, agent, and sandbox work. Fleet contracts describe how a fleet agent joins a gateway and how local tools control that agent.
ArcBox packages
The arcbox.v1 package is the main ArcBox contract. It covers machine and guest-agent work, container and image operations, system services, Kubernetes, migration, statistics, volumes, networks, and macOS guests. Shared values such as mounts, ports, limits, and timestamps live in the same package so the services use one meaning for them (rpc/…/common.proto• L1-69, rpc/…/api.proto• L16-29).
The arcbox.sandbox.v1 package is the product-facing sandbox contract. Its control plane manages sandbox life, events, ports, templates, and capabilities. Its data plane manages executions and file access. Snapshot calls cover checkpoint and restore. This split lets a cloud deployment route control calls through a fleet-aware front door and keep process or file data near the sandbox (rpc/…/sandbox.proto• L1-23).
The sandbox package is public and self-contained. The other ArcBox package is an internal daemon and host-to-guest surface. This audience split is a product boundary, not only a folder layout (rpc/…/buf.yaml• L4-25).
References: rpc/…/common.proto• L1-69 rpc/…/api.proto• L16-29 rpc/…/sandbox.proto• L1-23 rpc/…/buf.yaml• L4-25
Fleet packages
The arcbox.fleet.v1 package is the gateway contract. A machine enrolls with a token, receives a long-lived credential, and keeps an authenticated bidirectional attach stream. The stream carries heartbeats, runner offers, runner results, cancellation, drain orders, and update signals. The agent advertises what its host can serve; the gateway uses that information for placement (fleet/…/fleet.proto• L5-29, fleet/…/fleet.proto• L102-129).
The arcbox.fleet.control.v1 package is a separate local contract. It lets the CLI and desktop app inspect and change the fleet agent without owning its state. It exposes lifecycle actions, settings, image preparation, and a live state stream over the agent's Unix socket. It is internal and is not the published gateway schema (fleet/…/control.proto• L5-50, fleet/…/lib.rs• L1-6).
The two Fleet packages may contain similar concepts, such as capabilities and backend kinds. They remain separate so the public gateway contract and the local control contract can evolve on their own (fleet/…/control.proto• L164-179).
References: fleet/…/fleet.proto• L5-29 fleet/…/fleet.proto• L102-129 fleet/…/control.proto• L5-50 fleet/…/control.proto• L164-179
Service surfaces
The same schema can support different service surfaces. A declared method is a promise about message shape and call behavior, but a generated client or reflection entry does not prove that a running process implements it.
Daemon service surface
The daemon exposes one local endpoint. Its active services are registered on the Connect router, and the same handlers answer Connect, native gRPC, and gRPC-Web. This gives simple HTTP clients and typed gRPC clients the same service behavior (app/…/mod.rs• L208-255, app/…/control_plane.rs• L1-11).
The active router is smaller than the declared schema. Some declarations exist for the shared message set, tests, or a different runtime path. Reflection advertises the complete ArcBox descriptor set, so a discovered service can still return not-found when that service is not registered on the daemon router (app/…/control_plane.rs• L85-105).
References: app/…/mod.rs• L208-255 app/…/control_plane.rs• L1-11 app/…/control_plane.rs• L85-105
Fleet gateway surface
The fleet agent is a client of FleetGatewayService, not the gateway server. It sends Attach as the first stream message, puts the machine credential in metadata, and then sends heartbeats while it receives work orders. A changed backend set causes a fresh attach so the gateway sees the new capability set (fleet/…/lib.rs• L1-6, fleet/…/attach.rs• L379-455).
The local fleet control surface has the opposite role: the fleet agent is the server and the CLI or desktop app is the client. Clients call GetAgentInfo first and use reported features instead of rejecting an agent only because its API version differs (fleet/…/control.proto• L5-13, fleet/…/lifecycle.rs• L16-56).
References: fleet/…/lib.rs• L1-6 fleet/…/attach.rs• L379-455 fleet/…/control.proto• L5-13 fleet/…/lifecycle.rs• L16-56
gRPC expectations
Clients should treat method shape as part of the contract. Unary calls return one result. Server streams carry progress, events, output, or state snapshots. Client streams carry chunks or interactive input. Bidirectional streams carry input and output at the same time. Keepalive frames and stream end rules are part of the expected behavior for long calls (rpc/…/machine.proto• L71-87, rpc/…/process.proto• L24-75, rpc/…/filesystem.proto• L21-59).
The daemon's HTTP/1.1 path supports Connect and gRPC-Web. Native gRPC uses HTTP/2. Reflection also uses the endpoint, but its bidirectional reflection call needs HTTP/2; an HTTP/1.1 reflection request can return 501 without affecting ordinary unary calls (app/…/control_plane.rs• L85-105). See Connection and transport for endpoint and byte-carriage concerns.
References: rpc/…/machine.proto• L71-87 rpc/…/process.proto• L24-75 rpc/…/filesystem.proto• L21-59 app/…/control_plane.rs• L85-105
Message ownership
Generated message types and generated service bindings have different owners. Keeping that boundary clear prevents a schema edit from reaching one caller but not another.
ArcBox message types
arcbox-protocol generates the ArcBox message types from the .proto sources. It exposes the canonical v1 and sandbox_v1 paths plus compatibility re-exports for older call sites. The generated message files are committed so consumers and IDEs see the source contract without relying on a build directory (rpc/…/lib.rs• L35-46, rpc/…/mod.rs• L10-34).
The generated types do not define user-facing or saved JSON shapes. Callers that need stable JSON use hand-written data transfer types. This keeps a wire-schema change from silently changing a file format or a scripted command result (rpc/…/build.rs• L49-60).
References: rpc/…/lib.rs• L35-46 rpc/…/mod.rs• L10-34 rpc/…/build.rs• L49-60
gRPC bindings
arcbox-grpc generates tonic client and server bindings from the same ArcBox sources. It maps message references back to arcbox-protocol and exports a descriptor set for reflection. These bindings are the typed gRPC view of the service contract (rpc/…/build.rs• L9-53, rpc/…/lib.rs• L43-74).
The daemon's serving path uses Connect handlers and buffa-generated types. The tonic bindings remain useful for native clients and for tests that prove the gRPC wire format reaches the same daemon endpoint. Buffa and prost encode the same Protocol Buffer bytes, but they are different Rust representations (rpc/…/lib.rs• L3-23, app/…/control_plane.rs• L269-295).
References: rpc/…/build.rs• L9-53 rpc/…/lib.rs• L43-74 rpc/…/lib.rs• L3-23 app/…/control_plane.rs• L269-295
Connect bindings
arcbox-connect generates the runtime message and service types used by daemon handlers, the host-to-guest wire, and Connect clients. Its descriptor set also feeds daemon reflection. This makes the Connect output the live ArcBox representation even though the repository keeps prost and tonic output for other consumers (rpc/…/lib.rs• L9-23, rpc/…/lib.rs• L37-43).
The Connect crate uses a committed descriptor because its source .proto files live in another package. A source hash checks the descriptor in workspace builds, while the committed descriptor lets a registry build work without access to the neighboring source directory (rpc/…/build.rs• L10-26, rpc/…/build.rs• L88-129).
References: rpc/…/lib.rs• L9-23 rpc/…/lib.rs• L37-43 rpc/…/build.rs• L10-26 rpc/…/build.rs• L88-129
Fleet bindings
Each Fleet contract has its own tonic-generated Rust module. The gateway crate vendors the public gateway schema and generates both sides for tests, while the agent uses the client side in production. The local control crate generates client and server bindings because the fleet agent serves that API and the CLI and desktop app consume it (fleet/…/build.rs• L1-17, fleet/…/build.rs• L1-16).
References: fleet/…/build.rs• L1-17 fleet/…/build.rs• L1-16 fleet/…/lib.rs• L1-14 fleet/…/lib.rs• L1-15
Host-to-guest boundary
The AgentService declaration describes the messages and intended operations between the host and guest, but the live agent channel is not a gRPC server. The engine sends a message type and Protocol Buffer payload inside a length-prefixed frame; the guest agent decodes the frame and dispatches it to the matching handler (rpc/…/agent.proto• L11-56, engine/…/wire.rs• L7-30, guest/…/rpc.rs• L70-121).
The message type registry is therefore part of the service contract for this boundary. Adding a schema message alone does not create a live operation. The host registry, guest dispatch, response type, and engine caller must agree before a request can cross the VM boundary (common/…/wire.rs• L43-87, engine/…/agent_client.rs• L200-343).
The agent handshake checks protocol_version when the host decides whether the guest is ready. The separate agent version field is informational. This check protects the custom channel from silent field-skew when the daemon and staged guest agent come from different releases (rpc/…/agent.proto• L67-77, engine/…/agent_client.rs• L345-387).
References: rpc/…/agent.proto• L11-56 engine/…/wire.rs• L7-30 guest/…/rpc.rs• L70-121 common/…/wire.rs• L43-87 engine/…/agent_client.rs• L345-387
Contract evolution
All shared contracts use additive evolution. New fields and methods can be ignored by older peers. Removing or renumbering a field can change how an older peer reads a message, so retired field numbers stay reserved. ArcBox CI checks this rule for its internal and public modules (rpc/…/README.md• L33-47, rpc/…/buf.yaml• L22-28).
Fleet contracts apply the same idea at their own boundaries. The gateway schema is synced from its published Buf module. The local control schema uses a wire-and-JSON breaking check because independently shipped desktop and agent builds must keep their message and JSON forms compatible (fleet/…/buf.yaml• L1-11, fleet/…/buf.yaml• L1-15).
When an existing host-to-guest message changes meaning, the agent protocol version must increase and the host's minimum accepted version must reflect the support window. A purely additive field that older peers can ignore does not need that version change (common/…/wire.rs• L1-29).
References: rpc/…/README.md• L33-47 rpc/…/buf.yaml• L22-28 fleet/…/buf.yaml• L1-11 fleet/…/buf.yaml• L1-15 common/…/wire.rs• L1-29
Code-generation flow
The source .proto files are the contract. Each consumer-facing layer generates the view it needs, and the generated outputs must describe the same source set. The flow below shows where a schema edit travels.
flowchart LR
Proto[Protocol Buffer sources] --> Messages[arcbox-protocol messages]
Proto --> Tonic[arcbox-grpc tonic bindings]
Proto --> Descriptor[Committed Connect descriptor]
Descriptor --> Connect[arcbox-connect buffa messages and services]
Messages --> Tests[Prost-based test peers]
Tonic --> Clients[Typed gRPC clients and test servers]
Connect --> Daemon[Daemon handlers and reflection]
ProtoFleet[Vendored Fleet sources] --> Fleet[Generated Fleet bindings]
ArcBox generation
ArcBox message generation writes committed files under rpc/arcbox-protocol/src/generated. gRPC generation reads the same sources and imports those message types. Connect generation reads the committed descriptor and checks its source hash in workspace builds. A new ArcBox .proto file must be known to all relevant source lists or one generated surface will be incomplete (rpc/…/build.rs• L19-38, rpc/…/build.rs• L13-28, rpc/…/protos.txt• L1-24).
After a source edit, refresh the committed generated message files and the Connect descriptor before treating the change as complete. The descriptor refresh uses make refresh-connect-descriptor; it is a source-sync step, not a runtime service step (rpc/…/README.md• L25-31, rpc/…/refresh.sh• L1-11).
References: rpc/…/build.rs• L19-38 rpc/…/build.rs• L13-28 rpc/…/protos.txt• L1-24 rpc/…/README.md• L25-31 rpc/…/refresh.sh• L1-11
Fleet generation
The gateway contract is generated from a vendored copy of the public Fleet schema. Refresh that copy from the published Buf module before rebuilding the crate. The local control contract is generated from its internal source and is never published (fleet/…/build.rs• L1-17, fleet/…/buf.yaml• L1-11, fleet/…/build.rs• L1-16).
References: fleet/…/build.rs• L1-17 fleet/…/buf.yaml• L1-11 fleet/…/build.rs• L1-16 fleet/…/lib.rs• L1-6
Change checklist
When these files or sections are changed, remember to consider these:
- When an ArcBox .proto file changes, keep the committed message output, tonic bindings, Connect descriptor, and Connect-generated service surface aligned.
- When a new daemon service is declared, add its handler to the Connect router. Reflection can expose a service that the router does not serve.
- When a host-to-guest operation is added, update the
MessageTyperegistry, guest dispatch, response mapping, and engine caller. Do not rely on the schema-onlyAgentServicedeclaration. - When a public sandbox contract changes, keep the public Buf module self-contained and preserve the control-plane/data-plane split.
- When a Fleet concept changes, check both the gateway contract and the local control contract. Similar message shapes are not shared types by design.
- When a generated descriptor changes, refresh its source hash and confirm reflection describes the same source set as Connect handlers.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A declared daemon service is missing from the Connect router | The service is visible to reflection but calls fail at the endpoint | Register the handler on arcbox_api::connect::router and keep the router registration check current |
| A .proto edit omits one generation list or the Connect descriptor refresh | One client, server, or reflection view uses stale or missing contract data | Update the source lists, rebuild generated output, and run make refresh-connect-descriptor |
| A host-to-guest RPC changes only agent.proto | No live guest action runs because the frame dispatcher does not know the operation | Update MessageType, guest dispatch, response mapping, and AgentClient together |
| A meaning-bearing agent change keeps the old protocol version | A mixed host and guest pair can pass the handshake and misread the message | Bump AGENT_PROTOCOL_VERSION and review MIN_AGENT_PROTOCOL_VERSION |
| A client treats reflection as proof that a service is live | Discovery succeeds but the call returns not-found | Use the active router as the runtime availability source |
| Fleet gateway and local control messages are merged because their fields look alike | An external contract becomes coupled to an internal contract | Keep arcbox.fleet.v1 and arcbox.fleet.control.v1 generated and versioned separately |
Key files
| File | Why to read it |
|---|---|
| rpc/…/buf.yaml | Defines the internal ArcBox and public sandbox audience boundary |
| rpc/…/agent.proto | Defines host-to-guest messages and the schema-only agent service |
| rpc/…/sandbox.proto | Defines the sandbox control-plane and data-plane split |
| rpc/…/lib.rs | Shows the public Rust paths and compatibility re-exports for messages |
| rpc/…/build.rs | Shows message generation and well-known type mapping |
| rpc/…/build.rs | Shows tonic service generation from shared ArcBox sources |
| rpc/…/lib.rs | Shows gRPC client, server, and reflection exports |
| rpc/…/build.rs | Shows the committed-descriptor boundary for Connect generation |
| rpc/…/lib.rs | Shows the live buffa representation and reflection descriptor |
| app/…/mod.rs | Shows which services the daemon actually registers |
| app/…/control_plane.rs | Shows one endpoint serving Connect, gRPC, gRPC-Web, and reflection |
| fleet/…/fleet.proto | Defines the public gateway enrollment and attach contract |
| fleet/…/control.proto | Defines the internal local fleet-agent API |
| fleet/…/attach.rs | Shows the production gateway client handshake and stream behavior |
| fleet/…/mod.rs | Shows the local control server and its service registration |
| common/…/wire.rs | Defines host-to-guest message IDs and agent protocol versions |
| engine/…/agent_client.rs | Shows how the host turns generated messages into agent calls |
| guest/…/rpc.rs | Shows the guest frame and dispatch boundary |