Repository navigation
Description
- Author: @elezar
- State: draft
- Related: feat: move the desktop compute drivers to the ai-openshell/desktop repository #5200, feat: run compute drivers as launched child processes #5384, feat: pass launched drivers a versioned startup document #5385, WIP: Feat/5385 startup document/elezar #5838
Summary
The gateway launches the Docker, Podman and VM compute drivers as separate processes, all through one contract. That contract has three parts, separated by owner:
- Bootstrap: a fixed command line with the socket path, the expected peer PID and the log level.
- Driver table: the driver's own
[openshell.drivers.<name>]table, written to the process's stdin when it starts. - Gateway metadata: sent in a versioned
ConfigureRPC once the driver reports it is available.
serve validates its table and checks its backend before binding its socket, so starting it is also how the gateway detects whether a driver is usable. A preflight command runs the same table check without contacting the backend.
The outcome is a gateway that can launch drivers it doesn't link, built and released from another repository, without changing the ComputeDriver API, driver names, the detection order or operator config files.
Motivation
The desktop drivers are moving to ai-openshell/desktop so they can be developed and released independently of core (#5200). The gateway still has to launch and talk to them the same way. On main the three drivers run in two different ways:
- VM runs as a subprocess. The gateway passes every setting as a command-line flag:
vm.rsbuilds about 30 of them, plus the OTLP flags fromappend_otlp_args. - Podman and Docker are linked into the gateway and run in-process. The gateway builds their config structs itself and merges gateway-derived values into them: telemetry, gateway name, guest TLS CA and image overrides.
- Detection calls each linked driver's
is_available()in priority order. It ignores the operator's table, so a configuredsocket_pathdoesn't count. config preflightvalidates the Podman and Docker tables inside the gateway, because the gateway links those drivers.
None of this works once the drivers live in another repo:
- The gateway can't link crates from a repo that depends on core.
- It can't validate a table whose schema it doesn't own.
- Extending VM's flag approach to Podman and Docker means a flag for every key in their tables, plus gateway code to turn each table back into flags.
Driver-owned and gateway-owned settings are also mixed today. Driver config structs carry #[serde(skip)] runtime fields and keys the gateway fills in, which blurs who owns which schema.
Why implement the launcher before migrating
The launcher is the interface between the two repos. The bootstrap, the stdin table, the start-up result, Configure and preflight are what core and the desktop repo agree on. Settling them while both sides are in one repo means each change is one PR series, tested together.
Changing it after the split is expensive. A contract change would then take:
- a change in core and a core release;
- a dependency bump and driver change in desktop, then a desktop release;
- a packaging update in core.
Until all three are done, the gateway must support both behaviours, which needs version negotiation.
Podman and Docker have to stop running in-process anyway. Doing that in core first means the migration only moves code, CI and packaging, with no behaviour change at the same time.
It's off the critical path. What blocks the move is the drivers' remaining Rust dependencies on core (#5405, #5488). The launcher can be built in parallel with that work and land first.
Non-goals
- Changing the
ComputeDrivergRPC API or driver names. - Launching third-party or external drivers through this mechanism. They keep connecting through an existing socket endpoint.
- Negotiating versions between gateway and driver releases that aren't paired. Releases stay paired for now.
- Restarting a driver after it crashes. The gateway fails fast.
- Enforcing the expected peer PID in shared code. VM enforces it today; doing so for the others is a follow-up.
- Removing the drivers' Rust dependencies on core. That is tracked by refactor(driver-sdk): carve out the driver SDK and container-runtime crate #5405 and refactor(driver-contract): move the driver contract types into a contract crate #5488.
- Further hardening of OTLP endpoint handling.
- Changing the operator-run (standalone) drivers. A follow-up could have them share
settings_from_tableand accept gateway metadata throughConfigureinstead of flags, but they first needConfiguresupport.
Design questions
1. How does the gateway detect which driver to use?
By starting the driver. The gateway launches each candidate's serve in priority order, with that candidate's table on stdin. Before binding its socket, the driver:
- validates the table;
- checks its backend using the table, for example by resolving and pinging the configured
socket_path.
| Outcome | Driver | Gateway (auto-detection) | Gateway (driver named explicitly) |
|---|---|---|---|
| Available | Binds the socket and keeps running | Selects this driver | Same |
| Backend unavailable | Exits with EX_UNAVAILABLE (69) |
Tries the next candidate | Fails startup |
| Table invalid | Exits with EX_CONFIG (78) |
Logs a warning and tries the next candidate | Fails startup |
| Other failure | Exits with any other non-zero code | Fails startup | Fails startup |
The first available candidate is the one that serves, so detection never starts a process that it then has to stop. If no candidate is available, the startup error lists every candidate's reason.
Why not a separate detection command? The alternative is a short-lived command the gateway runs only to ask whether a driver's backend is usable:
- Without the table, it can give the wrong answer. It can report "available" for a backend the driver can't reach with its config, or the reverse.
- With the table, it duplicates the start of
serve, adding its own result format and its own copy of the backend check.
2. How is the driver configured at launch?
By splitting the inputs by owner instead of using flags or one combined document:
| Input | Owner | Channel | When |
|---|---|---|---|
| Bootstrap: socket path, expected peer PID, log level | Gateway | argv, frozen per protocol version |
Process start |
Driver table [openshell.drivers.<name>] |
Driver | stdin, raw TOML forwarded unparsed by the gateway |
Process start |
| Gateway metadata: gateway context, telemetry, network trust, image overrides | Gateway | Configure RPC (protobuf) |
After the driver reports it is available |
The operator still writes one gateway config file. The gateway removes any gateway-owned keys from the driver table (see Config split) and forwards the rest without parsing it.
Why this split:
- Each owner defines, validates and versions only its own input. The driver owns its table's schema; the gateway owns the protobuf.
- The command line never grows. New gateway settings go in
Configure, which carries a protocol version and a feature list, so it can evolve across repos. - No file to stage for config. The network-trust artifact is still staged as it is today.
- Secrets stay off
argvand out of the environment. For example, OTLP trace headers travel only inConfigure, over the private socket.
3. How is driver config validated?
The driver validates its own table, with one function used by every entry point. Each driver implements:
/// The only place the driver table is parsed and checked.
fn settings_from_table(table: &str) -> Result<DriverSettings, ConfigError>;The function rejects unknown keys, runs every check that needs neither the backend nor the gateway context, and has no side effects.
| Command | Steps |
|---|---|
preflight (stdin) |
settings_from_table -> exit 0 or EX_CONFIG |
serve (stdin) |
settings_from_table -> backend check -> bind -> Configure |
What this means in practice:
- Preflight covers every candidate.
config preflightruns each candidate driver'spreflightand rejects any invalid table, as onmain. preflightnever contacts the backend.- Startup and preflight always agree on whether a table is valid, because both call the same function.
Proposal
Launch sequence
sequenceDiagram
participant G as Gateway
participant FS as Gateway state dir
participant D as Driver process
participant B as Backend (Docker/Podman/libkrun)
Note over G,D: config preflight (no backend contact)
G->>D: spawn `preflight`, driver table on stdin
D->>D: settings_from_table
D-->>G: exit 0, or EX_CONFIG + reason
Note over G,D: Detection and launch (candidates in priority order)
G->>G: resolve binary, check trust
G->>D: spawn `serve --bind-socket --expected-peer-pid --log-level`, driver table on stdin
D->>D: settings_from_table, install stderr tracing
D->>B: check backend with the table (e.g. socket_path)
alt backend unavailable
D-->>G: EX_UNAVAILABLE + reason
G->>G: next candidate (fail if named explicitly)
else invalid table
D-->>G: EX_CONFIG + reason
G->>G: warn, next candidate (fail if named explicitly)
else other error
D-->>G: non-zero + reason
G->>G: fail startup
end
D->>D: bind socket, serve DriverLaunch + ComputeDriver (UNAVAILABLE)
G->>D: GetLaunchInfo
D-->>G: driver name, protocol versions, features
G->>FS: stage network trust artifact
G->>D: Configure(gateway ctx, telemetry, trust path/digest/count, image overrides)
D->>D: check version + features, enable OTLP export
D->>FS: verify trust artifact
D->>B: build driver
D-->>G: Configure OK
G->>D: ComputeDriver RPCs
D-->>G: exits unexpectedly
G->>G: log, exit nonzero
Commands
openshell-driver-<name> serve --bind-socket <path> --expected-peer-pid <pid> --log-level <level> < driver-table.toml
openshell-driver-<name> preflight < driver-table.toml- Empty stdin means the operator wrote no table, and the driver uses its defaults.
- Exit protocol: before exiting,
serveandpreflightwrite exactly one JSON line to stderr, for example{"result":"unavailable","reason":"..."}, which the gateway logs. The exit code decides what the gateway does next; the line explains why. - No state before
Configure.servecreates no persistent state, such as networks, volumes or state directories, untilConfiguresucceeds.
DriverLaunch service
syntax = "proto3";
package openshell.driver.launch.v1;
service DriverLaunch {
rpc GetLaunchInfo(GetLaunchInfoRequest) returns (GetLaunchInfoResponse);
rpc Configure(ConfigureRequest) returns (ConfigureResponse);
}
message GetLaunchInfoRequest {}
message GetLaunchInfoResponse {
string driver_name = 1;
string driver_version = 2;
repeated uint32 protocol_versions = 3;
repeated string features = 4;
}
message ConfigureRequest {
uint32 protocol_version = 1;
repeated string required_features = 2;
GatewayContext gateway = 3;
NetworkTrust network_trust = 4;
ImageOverrides image_overrides = 5;
Telemetry telemetry = 6;
}
message ConfigureResponse {}
message GatewayContext {
uint32 gateway_port = 1;
string tls_ca_path = 2;
string gateway_name = 3;
}
message NetworkTrust { // unset = no trust bundle
string artifact_path = 1;
string digest = 2;
uint32 certificate_count = 3;
}
message ImageOverrides {
optional string sandbox_runtime_image = 1;
optional string supervisor_image = 2;
}
message Telemetry {
OtlpExport traces = 1;
OtlpExport ocsf = 2;
OtlpExport agent = 3;
CollectorTls collector = 4;
string trace_headers = 5; // secret
}
message OtlpExport { string endpoint = 1; string protocol = 2; }
message CollectorTls { string ca_file = 1; string cert_file = 2; string key_file = 3; }Rules:
- Version check: a driver rejects an unsupported
protocol_versionor an unknown required feature withFAILED_PRECONDITION. - Configure once:
Configuresucceeds at most once. A call that fails leaves the driver running, and the gateway may retry. - Size limit: a
ConfigureRequestcan be at most 1 MiB. - Before
Configure: every other service the driver serves returnsUNAVAILABLEuntilConfiguresucceeds. One generic wrapper does this for all of them, including Docker'sComputeDriverConfigurationUpdates. - Network trust: the gateway still stages the trust bundle as a read-only file at a path that depends on its content.
Configurecarries only the path, digest and certificate count. Drivers verify the file before each sandbox create or start, and the container drivers bind-mount it.
Config split
Each driver separates the settings the operator writes from the context the gateway provides:
Driver::new(settings: DriverSettings, gateway: GatewayContext) -> Result<Self>DriverSettingsholds only operator keys and rejects unknown ones. The#[serde(skip)]runtime fields (supervisor_otlp,supervisor_gateway_name) move toGatewayContext.GatewayContextis one struct shared by all drivers, built fromConfigure.- Gateway-derived keys:
gateway_port,grpc_endpointandguest_tls_cadefault from the gateway context. See Open question 1 for whether operators can still override them in the table. - Image overrides: the table sets the image. A value in
ImageOverrides, which comes from the gateway's environment, takes precedence, asprefer_environmentdoes today. - Gateway-owned keys in driver tables: these are read and removed by the gateway before forwarding. Today that is VM's
driver_dir.
Telemetry
- At start: the driver installs tracing to stderr at
--log-level, plus an empty, reloadable OTLP export layer. - On
Configure: the driver fills that layer fromTelemetryandGatewayContext.gateway_name, before it builds the driver. A retriedConfiguredoesn't install a second exporter. - Supervisors get their trace, OCSF and agent endpoints from the same message.
In-process and operator-run drivers
- In-process mode goes away. Podman and Docker stop running inside the gateway, because the gateway in core can't link crates that live in the desktop repo.
- Operator-run drivers are unchanged. Today's standalone binaries, such as Docker's, are started by an operator or a service manager with
--config <file>and their existing flags. The gateway keeps connecting to them through a socket endpoint. This proposal doesn't change them; aligning them with the launch contract is a follow-up (see Non-goals).
Security
- Binary trust: the gateway resolves the driver binary from
driver_diror the packagedlibexecdirectory. It refuses a file that isn't owned by root or the gateway user, or that is writable by group or others. - Private socket: the socket lives in a directory created with mode
0700. VM also checks that the peer is the expected PID; the other drivers check that the caller runs as the same user until shared PID enforcement lands. - Secrets: no secret goes on
argvor into the environment. The driver table goes on stdin and gateway secrets go inConfigure.
Implementation plan
All of this lands in core before the drivers move. Each step builds and passes tests on its own.
- Deferred tracing in
openshell-otel: install stderr tracing first and enable OTLP export later. DriverLaunchprotocol and theopenshell-driver-launchcrate: the proto, aConfigurestate machine, theUNAVAILABLEwrapper and the size limit. The crate has no core dependencies.- Driver SDK:
- the stdin table reader;
- the start-up result (exit codes and the JSON line);
- the network-trust loader;
- conversion of
Telemetryinto OTLP settings; - the parent-death guard.
- VM:
settings_from_table,serveandpreflight. Then the gateway's generic launcher replaces VM's flag building. - Podman: the same driver-side changes, then gateway launch. Detection goes through
serve, and the gateway stops linking the Podman crate. - Docker: the same as Podman, with the wrapper also covering
ComputeDriverConfigurationUpdates. - Docs and packaging:
- update the gateway configuration and driver extensibility docs;
- ship each driver binary in the Debian, RPM and snap packages;
- add a packaging check that the binaries are present.
- Migration: move the driver crates, their CI and their release builds to
ai-openshell/desktoponce refactor(driver-sdk): carve out the driver SDK and container-runtime crate #5405 and refactor(driver-contract): move the driver contract types into a contract crate #5488 remove their core dependencies. Core packaging then takes the driver binaries from desktop releases.
Validation
Each driver gets integration tests against its real binary:
GetLaunchInfoanswers beforeConfigure;- other services return
UNAVAILABLEbeforeConfigure; Configurerejects unsupported versions and can be retried;- each start-up exit code;
preflightaccepts valid tables, rejects invalid ones and creates no state.
Gateway tests use fake driver binaries to cover:
- trust checks;
- exit-code mapping;
- detection order and fallback;
- reporting an unexpected exit.
Risks
- Detection behaviour changes. Honouring a configured
socket_pathcan select a different driver thanmainwould. An invalid table on an earlier candidate now logs a warning where it was silently ignored before. Mitigation:config preflightstill rejects invalid tables, and the startup log names the selected driver and why the others were skipped. - Unconfigured window. Between bind and
Configure, onlyDriverLaunchanswers. A bug in the wrapper could expose a half-built driver. Mitigation: one shared wrapper with tests, not per-driver code. - Early spans aren't exported. Spans from before
Configure, including the backend check, reach stderr but not OTLP. Configureuntil shared PID enforcement. For Podman and Docker, any process running as the gateway's user could callConfigurefirst. Mitigation: the socket is private (mode0700), and shared PID enforcement is a planned follow-up.- Exit-code collisions. A driver that exits with 69 or 78 for another reason would be misread. Mitigation: the SDK owns those exit paths, and the JSON line gives the reason.
- Packaging burden. Every package, including the snap, must ship driver binaries that were previously linked into the gateway. A missing binary fails startup. Mitigation: a packaging check in CI.
Alternatives
Command-line flags for every setting (extend VM's current approach)
This needs no new protocol. But each driver key needs a matching flag, the gateway has to turn each table back into flags, secrets end up on argv, and every new setting changes the command line. It doesn't scale to three drivers maintained in another repo.
Startup document (#5838)
The gateway writes a versioned TOML document holding both the gateway metadata and the driver table, and passes its path to the driver. The driver starts fully configured, so it has no unconfigured window and doesn't need deferred tracing. The costs:
- the gateway has to stage, permission and clean up a file for every launch and every preflight;
- gateway-owned and driver-owned settings share one document schema;
- detection still needs a separate detection command (
probe), which ignores the table.
Configure carrying the driver table, with a separate detection command
The gateway sends everything, including the driver table as an opaque field, in Configure. A separate probe command does detection without config. This has the clean versioned contract, but:
- detection ignores the operator's table;
- an invalid table only shows up after the driver has started and bound its socket;
- the driver-owned table travels inside the gateway-owned protobuf.
Keep Podman and Docker in-process
This needs no packaging or launcher work now, but it can't survive the migration: the gateway in core can't link crates from a repo that depends on core. Keeping both in-process and launched modes would also double testing, and keep two ways of building driver config.
Prior art
- HashiCorp Nomad task-driver plugins. Nomad starts plugin binaries as subprocesses, asks for plugin info, and then sends configuration through a
SetConfigRPC.GetLaunchInfoandConfigurefollow the same pattern. sysexits.h.EX_UNAVAILABLE(69) andEX_CONFIG(78) are the conventional exit codes for "service unavailable" and "configuration error".- RFC 0006 (driver config passthrough). It established that driver-specific settings are opaque to the gateway and owned by the driver. This proposal applies the same rule to the operator's driver tables.
- The VM driver on
main. It already runs as a subprocess with a private socket and checks the peer PID. This proposal generalises that model and replaces its command-line flags.
Open questions
- Gateway-derived keys (
gateway_port,grpc_endpoint,guest_tls_ca): should they stay valid in driver tables as optional operator overrides, or be removed? Proposed answer: keep them as overrides, so existing files keep working. - Admission policy (
allow_driver_config,resource_admission): should the gateway or the driver enforce it? Proposed answer: no change. It stays in the driver table, the driver enforces it, and the server keeps reading it. - Start-up result format: are exit codes plus one JSON line on stderr the right protocol, or should availability be reported over the socket instead?
- Gateway-owned table: should keys like
driver_dirmove to a gateway-owned table such as[openshell.compute.<name>], with the old location deprecated?
Activity