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 / connection-and-transport

Connection and transport plumbing

ArcBox separates protocol meaning from the path that carries it. arcbox-connect supplies the runtime message and service surface for the Connect-facing API and the host-to-guest wire, while arcbox-transport supplies reusable socket and stream behavior. Together they let the daemon use a local Unix endpoint and let the engine reach an agent inside a VM without changing the higher-level request model. See RPC and protocols for the wider RPC map and Protocol and service contracts for message and service definitions.

Connection surfaces

Daemon control-plane connection

The daemon control-plane connection joins host clients to service handlers through a Unix domain socket. The socket carries HTTP traffic, so one endpoint can answer Connect, native gRPC, and gRPC-Web requests; arcbox-connect provides the generated runtime surface and the daemon router chooses which declared services are live.

This path is local to the host. HTTP/1.1 supports ordinary Connect and gRPC-Web calls, while HTTP/2 supports native gRPC and long-lived streams. The connection drains active work when the daemon shuts down instead of dropping every request at once.

References: app/…/control_plane.rs• L1-11 app/…/control_plane.rs• L32-67 app/…/control_plane.rs• L70-83

Host-to-guest agent connection

The host-to-guest connection joins arcbox-engine to arcbox-agent inside a running VM. It is not a gRPC service at runtime. The engine sends a custom framed message identified by MessageType, and the guest agent decodes that frame before dispatching the request.

The guest agent listens on the shared agent port 1024. A vsock address uses a context ID to select the VM and a port to select the service; from the guest view, the host has CID 2, while guest VMs use CID values 3 and above. The agent accepts each connection and handles its requests in a task, which keeps one peer from blocking new connections.

References: rpc/…/mod.rs• L1-23 rpc/…/addr.rs• L4-32 guest/…/agent.rs• L15-18 guest/…/agent.rs• L62-87

Transport abstractions

Transport contract

The Transport contract gives RPC callers one model for connection state, sending, receiving, and disconnecting. TransportListener adds the matching bind and accept model for server-side endpoints. Higher layers can therefore select Unix sockets or vsock without changing how they manage a request exchange.

The abstraction carries bytes rather than protocol objects. Framing and message decoding remain above it, which keeps socket setup, stream I/O, and protocol interpretation as separate concerns.

References: rpc/…/lib.rs• L37-73 rpc/…/error.rs• L9-39

Unix socket transport

UnixTransport provides an asynchronous stream abstraction for a Unix domain socket. It can connect to a path or wrap an accepted stream, then carry length-prefixed byte messages through the common transport contract.

The daemon control plane also uses a Unix domain socket, but it serves HTTP directly through its HTTP connection layer. Do not infer that the daemon's HTTP exchange uses the framed UnixTransport message format; the endpoint protocol and the generic byte transport are separate uses of the same local socket type.

References: rpc/…/unix.rs• L11-35 rpc/…/unix.rs• L37-86 app/…/control_plane.rs• L13-19 app/…/control_plane.rs• L41-63

Vsock transport

VsockTransport carries framed agent traffic across the VM boundary. On Linux it uses the host's vsock socket support. On macOS it receives a connected file descriptor from the hypervisor integration because Virtualization.framework owns the connection setup.

The same transport can split an established connection into independent send and receive halves. This supports full-duplex streams such as readiness watches, interactive execution, and file transfer while preserving one frame format for both directions.

References: rpc/…/mod.rs• L1-16 rpc/…/transport.rs• L88-175 rpc/…/linux.rs• L33-67 rpc/…/darwin.rs• L18-24

Platform transport modes

The engine chooses the transport mode from the VM backend. Async mode serves real vsock file descriptors and supports the full agent surface. The macOS Hypervisor.framework path uses a Unix socketpair and a blocking transport with bounded poll deadlines because this path must not stall the Tokio reactor during rapid connection retries.

The blocking mode is for bounded request-and-response work. It rejects streaming operations, so a caller that needs a sequence of events or interactive data must use the async mode. Both modes use the same 16 MiB maximum frame size; this keeps a frame accepted by one backend valid for the other and limits memory allocation from peer-controlled lengths.

References: engine/…/transport.rs• L6-31 engine/…/transport.rs• L33-75 rpc/…/blocking.rs• L1-27 rpc/…/transport.rs• L11-44

Agent wire flow

Frame envelope

The agent wire uses a versioned length-prefixed envelope around each Protocol Buffer payload. The envelope identifies the operation with a numeric MessageType, carries an optional trace ID, and then carries the encoded request or response payload.

The length field covers the type, trace-length field, trace bytes, and payload. The transport reads the complete outer frame, while the engine and guest agent interpret the inner fields. Error responses use the same envelope and carry a status code plus message so the engine can return a useful agent error to the daemon.

The following flow shows the boundary between connection setup, byte transport, and protocol handling.

sequenceDiagram
    participant E as Engine AgentClient
    participant T as Vsock or blocking transport
    participant A as Guest agent
    participant G as Guest service

    E->>E: Encode MessageType, trace ID, and payload
    E->>T: Send length-prefixed frame
    T->>A: Carry frame across connection
    A->>A: Read, decode, and dispatch
    A->>G: Run agent operation
    G-->>A: Return result or event
    A-->>T: Send typed response frame
    T-->>E: Return complete frame
    E->>E: Check response type and decode payload

References: engine/…/wire.rs• L7-30 guest/…/rpc.rs• L181-254 guest/…/rpc.rs• L257-304 engine/…/agent_client.rs• L200-261

Unary exchange

A unary exchange opens or reuses the agent connection, sends one framed request, and waits for one framed response. The engine checks the returned type before it treats the payload as the expected result, which prevents a correctly encoded but unrelated response from being accepted as success.

The client adds the current trace ID to the request when one exists. If the guest returns the Error type, the client reads its status code and message and maps it into the engine error model. This preserves the reason for a guest-side failure across the transport boundary.

References: engine/…/agent_client.rs• L160-185 engine/…/agent_client.rs• L200-261 engine/…/wire.rs• L69-89

Streaming exchange

A streaming exchange keeps a connection open and sends multiple typed frames for one request. Readiness, statistics, memory pressure, process output, and file data use this shape when one result is not enough.

Streaming needs an async transport and a separate send or receive path when the operation is full-duplex. The engine also applies bounded buffering so a slow consumer creates backpressure instead of allowing guest output to grow host memory without limit.

References: engine/…/transport.rs• L33-75 engine/…/agent_client.rs• L71-75 engine/…/agent_client.rs• L561-633 rpc/…/transport.rs• L47-85

Raw stream adaptation

Some callers need a transparent byte stream rather than agent RPC frames. VsockStream adapts a connected descriptor to asynchronous read and write operations for uses such as HTTP proxying and bidirectional tunnels.

The stream can wrap either a real descriptor or a Unix socketpair. Its shutdown policy matters for tunnels: normal streams half-close the write side, while selected macOS paths keep the connection open until drop because a half-close can tear down the full vsock connection.

References: rpc/…/README.md• L30-50 rpc/…/stream.rs• L8-36 rpc/…/stream.rs• L90-115 rpc/…/stream.rs• L193-227

Descriptor refresh boundary

Committed Connect descriptor

arcbox-connect generates its buffa message types and Connect service surface from a committed descriptor set. The descriptor is required because the Protocol Buffer sources live in the separate arcbox-protocol package; a registry build cannot read that neighboring source directory.

The crate embeds the same descriptor set for server reflection. This makes the reflected API describe the generated Connect surface rather than a separately assembled list. The descriptor list is shared by the build script and refresh script, so both paths cover the same files.

References: rpc/…/build.rs• L10-26 rpc/…/build.rs• L35-85 rpc/…/lib.rs• L37-43 rpc/…/protos.txt• L1-24

Source and descriptor consistency

The Connect build checks a hash of the compiled Protocol Buffer sources against the recorded hash. If a source changes without a descriptor refresh, the build stops instead of generating a stale Connect surface. This check applies in the workspace where the source directory is present; packaged builds use the committed descriptor as their source.

After a Protocol Buffer edit, refresh the descriptor and source hash with make refresh-connect-descriptor. The refresh uses protoc and includes imports and source information, while normal builds do not need protoc. A new Protocol Buffer file also needs to be added to the shared list before the refresh can cover it.

References: rpc/…/build.rs• L51-66 rpc/…/build.rs• L88-129 rpc/…/refresh.sh• L1-11 rpc/…/refresh.sh• L59-86 Makefile• L62-68

Change checklist

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

  • When a Protocol Buffer source used by Connect changes, refresh the committed descriptor and source hash before rebuilding the Connect crate.
  • When a new Protocol Buffer file is added, keep the Connect descriptor list aligned with the protocol and gRPC build inputs. Otherwise one surface can omit the new message or service.
  • When an agent RPC changes, keep the MessageType, frame decoder, guest dispatch, and engine caller aligned. A schema-only service declaration does not create a live host-to-guest operation.
  • When transport behavior changes, verify both real-vsock async mode and the macOS Hypervisor.framework blocking mode. Their setup and streaming limits differ even though their frames must match.
  • When changing frame parsing or allocation limits, keep the 16 MiB limit and big-endian frame length consistent across async and blocking transports.
  • When changing a tunnel's shutdown behavior, check the selected VsockShutdown mode. A half-close can end a macOS tunnel earlier than the caller expects.

Important failure modes

TriggerConsequenceGuard
Protocol Buffer sources change without refreshing the committed Connect descriptorThe Connect build rejects the stale source hash, or a packaged consumer keeps an old generated surfaceRun make refresh-connect-descriptor and commit the descriptor and hash with the source change
A new file is missing from descriptor/protos.txtConnect generation and reflection omit the file even if another code-generation path sees itAdd the file to the shared list used by both the build and refresh paths
A streaming agent call uses the blocking transportThe call fails because the blocking path does not provide async stream supportSelect the async agent transport for streaming and full-duplex calls
Async and blocking transports use different frame limits or byte orderOne backend accepts frames that the other cannot read safely or consistentlyKeep the 16 MiB limit and big-endian length prefix identical in both paths
A caller treats the declared AgentService as the live guest APIThe request never reaches the guest because runtime dispatch uses MessageType frames insteadUpdate the host caller, wire type, guest decoder, and guest dispatcher together
A macOS tunnel uses half-close shutdownVirtualization.framework can tear down the whole connection before the tunnel finishesUse CloseOnDropOnly for the affected tunnel path

Key files

FileWhy to read it
rpc/…/lib.rsShows the runtime Connect types and the descriptor exposed for reflection
rpc/…/build.rsShows why the descriptor is committed and how source drift is rejected
rpc/…/refresh.shShows the required descriptor refresh operation after Protocol Buffer edits
rpc/…/lib.rsDefines the common transport and listener contracts
rpc/…/transport.rsShows framed vsock I/O, split streams, and frame-size protection
rpc/…/stream.rsShows adaptation of connected descriptors and tunnel shutdown behavior
rpc/…/blocking.rsShows the macOS Hypervisor.framework bounded blocking mode
engine/…/agent_client.rsShows host-side connection selection and request/response flow
engine/…/wire.rsDefines the shared agent frame envelope and response parsing
guest/…/agent.rsShows guest listener startup and per-connection handling
guest/…/rpc.rsDefines guest frame decoding, encoding, and request parsing
app/…/control_plane.rsShows the local HTTP control-plane connection and graceful drain