driver-contract, version 1

How an orchestrator runs a driver binary: how it finds the driver, the commands it runs on it, the messages of a build, the files they share, and how a driver reads its own configuration.

Seam9, the driver contract
Requirement identifiersDRV-<n>; the configuration requirements DRV-C<n>
Rolesorchestrator, driver
Machine schemav1.schema.json, beside this document
Reference implementationThe orchestrator warden (cmd/warden); the drivers under driver/, the kit driver/drivercmd, and the container driver's binary warden-driver-container, in buildwarden/buildwarden
Conformance suitedriver-conformance, under conformance/driver/ in the same repository
StatusUnstable. Version 1 may change in any release before BuildWarden 1.0 (Versions)

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY" and "OPTIONAL" in this document are to be interpreted as described in BCP 14 (RFC 2119, RFC 8174) when, and only when, they appear in all capitals. A requirement is a paragraph or list item that starts with its identifier in bold. Text that is not a requirement is informative.

Every JSON example in this document is a code block whose info string names the definition of v1.schema.json it is an instance of ( ```json describe); the schema is checked against every example (specs/specs_test.go).

Scope and roles

A driver creates the isolated environment of a build, starts the relay that is the build's only network path, and makes that relay claimable. An orchestrator finds the driver, runs its commands, claims the relay, serves the relay its collector, waits for the build and reports it. warden is the orchestrator of this repository; the conformance suite is a second one.

Two roles take part:

  • The orchestrator starts the driver's process for each command, writes its requests and reads its output.
  • The driver is an executable file, named for the driver, that answers the commands of this document. It is written in any language. A driver written in Go may use the kit (driver/drivercmd); nothing in this document depends on it.

Terms:

  • A build ID is eight lowercase letters and digits, made by the orchestrator for one build. A driver names everything it creates for a build from it.
  • A probe is a request that asks a driver to check what it would check before doing any work, and to do nothing else (Probes).
  • A linked driver is a driver compiled into warden itself, reached through the same sequence as Go calls. It is an implementation detail of the reference orchestrator while the bundled drivers become binaries; a requirement of this document on "a driver" is a requirement on a driver binary.

Outside this document:

  • The claim and the tunnel the orchestrator opens on the relay: seam 1, the specification relay-claim. This document says only where the claim is sent and which of its fields the driver supplies.
  • What the relay and the collector exchange: collector-outputs and collector-inputs.
  • The executor's initialize, the bootstrap config and what the build environment is served: executor-initialize, bootstrap-config, relay-guest-api.
  • The orchestrator's own command line, configuration and output, beyond what this document requires of them.

What a driver needs besides this contract

This contract says how an orchestrator runs a driver. A driver that is to run real builds also has to start the project's relay and executor correctly, and those are other seams, not all of them written yet:

A driver mustStated by
Launch the project's relay in one of its release forms, and give it its pre-claim values (the claim token and the address it accepts the claim on) on its boot channelSeam 8 (relay release forms), not yet written; seam 1, relay-claim, for the pre-claim values
Report an environment record for the claim (claim_values.environment)Seam 4, metadata-environment
Deliver the executor and start it once (warden-io initialize), and nothing else out of bandSeam 5, executor-initialize
Report the guest OS, which selects the bootstrap configSeam 6, bootstrap-config
Make the relay the build's only network pathSeam 7, the build-link contract, not yet written

Until each exists, the reference for it is the bundled drivers' source. The conformance suite checks none of them: it tests the commands and the build's lifecycle.

Finding a driver

Names and files

DRV-1. A driver's name MUST match [a-z][a-z0-9]{0,31} and MUST NOT be the name of a command of the orchestrator. The name is used as a TOML table ([driver.<name>]), in lock and record file names and as the orchestrator's subcommand that reaches the driver's own commands (ext).

DRV-2. A driver's file MUST be named warden-driver-<name>, and on Windows warden-driver-<name>.exe. On Windows a file of another extension (.bat, .cmd) MUST NOT be taken for a driver: a batch file runs under cmd.exe, whose quoting no other program's matches, and the process the orchestrator starts and stops would be cmd.exe and not the driver.

DRV-3. The name a driver reports in describe MUST be the name the orchestrator looked up, and the base name of its file without .exe MUST be warden-driver- followed by it. The orchestrator MUST refuse a driver whose describe reports another name.

warden's commands, the names no driver may take: build, shell, doctor, setup, image, clean, inspect, driver, help, completion. While the Hyper-V driver is linked into warden, hyperv is also a warden command (warden hyperv service ...).

Selection

The orchestrator selects one driver by its first source that is set: its --driver flag, the variable WARDEN_DRIVER, [runtime] driver in the config file, else the name container.

DRV-4. A selection that contains a path separator (/, and \ on Windows) is a path; anything else is a name. A path MAY come from --driver or WARDEN_DRIVER, and a relative one is taken against the working directory. A config file MUST NOT name a driver by path: the orchestrator MUST refuse a path in [runtime] driver, naming the file, with the two places a path may come from as the fix. It MAY select any driver by name.

DRV-5. There is no auto-detection, and a name that is not found MUST be an error that says where the orchestrator looked. It MUST NOT be replaced by another driver.

Lookup

DRV-6. A selection is resolved once per invocation to an absolute path, which every later command of that invocation runs. The first match wins:

  1. A path. The file is used as given and nothing else is searched.
  2. PATH. Each entry in PATH's order is searched for the driver's file name, and the first candidate is the driver.
  3. The directory of the orchestrator's own executable, symbolic links resolved, when PATH gave nothing.
  4. A driver linked into the orchestrator, when the name is one.

DRV-7. A file named by path MUST exist and, after symbolic links are resolved, be a regular file the user may execute; otherwise the orchestrator MUST refuse it with an error that names the file and what is wrong with it.

DRV-8. On PATH and in the orchestrator's directory, a directory, or a file without execute permission, is not a candidate, and the search goes on. The orchestrator SHOULD show a file it passed over this way, with the reason, where it lists drivers and in its not-found error.

DRV-9. A candidate reached through a relative PATH entry, or on Unix an empty one, MUST NOT be run, and the lookup MUST stop there with an error that names the entry and the file. On Windows the orchestrator MUST NOT search the current directory before PATH, and it skips an empty entry.

DRV-10. Candidates are compared by identity after symbolic links are resolved. A candidate that is the same file as the driver's file in the orchestrator's own directory is the bundled copy, whichever step met it. Two candidates that are one file are one candidate.

Nothing in the lookup compares owners, modes or directory permissions: what is on PATH is the user's to arrange, and a file earlier on PATH replaces a driver the orchestrator ships. warden shows the result (warden driver list) and records it in the build's output (driver.json).

Finding the driver before the command line is parsed

The orchestrator cannot parse a command line before it knows the driver's flags, and it knows them only from the driver's describe. So it finds the driver from the raw arguments first.

DRV-11. The orchestrator MUST find the driver by this scan, which needs the arity of no flag but its own:

  1. The ext form. When the argument right after the orchestrator's name is not a flag and not one of its commands, the line is <orchestrator> <name> <args...>: the driver is <name>, and nothing after it is the orchestrator's.
  2. Otherwise, the command. The orchestrator's own persistent flags are skipped from the left; the first argument after them that is not a flag names the command. A command that selects no driver stops here.
  3. Then --driver. The arguments are scanned left to right, up to a -- argument or the end. --driver <value> takes the next argument as its value, whatever it looks like; --driver=<value> holds its own; the last wins. --config is found by the same scan, in the same forms.
  4. With no --driver, the selection is WARDEN_DRIVER, else [runtime] driver from the config file the scan found, else container.

DRV-12. After describe, the orchestrator MUST parse the line with the flags the driver declares (DRV-C1), and MUST refuse a line whose parsed --driver or --config is not the one its scan found (as in build --network --driver hyperv, where a flag that takes a value took --driver as it), naming the flag that took it.

DRV-13. The orchestrator MUST refuse, before it runs any driver command but describe, a flag that neither it nor the selected driver declares for the command.

Reserved flag names

A flag of the orchestrator's on a command is a name a driver cannot declare for that command (DRV-C1). warden's, without their dashes:

CommandsNames
Every commanddriver, config, verbose, color, help, version
run (warden build, warden shell)capture, output, no-compress, timeout, tmpdir, quiet, guest-os, script, image, cpus, memory, keep-vms, build-link
doctorbuild-link
image-prepareos, source
cleancache

Commands

Invocation

DRV-14. The command is the driver's first argument (argv[1]). describe takes no request. Every other command takes one request, a JSON object that carries contract, the version the orchestrator chose (Versions).

DRV-15. The request MUST be written on the driver's standard input, except for attach and ext, which inherit the terminal's standard input: for those two the orchestrator writes the request to a file and names it in the environment variable WARDEN_DRIVER_REQUEST.

DRV-16. describe and run own their standard output: every byte a driver writes there MUST be the command's output as this document gives it. Every other command inherits the terminal for standard output and standard error, prints its own lines there, and MUST write its result as one JSON object to the file the environment variable WARDEN_DRIVER_RESULT names.

DRV-17. The orchestrator MUST create the request and result files with mode 0600 in its own temporary directory, and MUST remove them when the command has ended.

DRV-18. A secret travels only in a request on standard input. The orchestrator MUST NOT put a secret in a driver's arguments, its environment or a file, and a driver SHOULD declare no flag that takes one (a build's args are kept in its record).

DRV-19. Paths in requests are UTF-8 strings. The orchestrator MUST refuse, before it starts the driver, a context, output or temporary path that is not valid UTF-8, with an error the user can act on.

DRV-20. An orchestrator and a driver MUST each ignore a field of a JSON object that they do not know, in describe, a request, a result and a message, and a message whose type they do not know.

Exit codes

DRV-21. For every command but attach and ext, a driver MUST exit with one of these codes:

CodeMeaning
0Done
1Failed: the result (for run, the failed message) carries an error object
2The request is not valid for this contract version
3The command is not implemented by this driver
4No contract version in common

DRV-22. Another exit code, a result file that is missing or not one JSON object, or output that is not what the command owes, is a defect of the driver; the orchestrator MUST report it as one (Errors), and MUST NOT take it for success.

The commands and their requests

CommandRequiredRequestResultExit
describeyesnoneOne JSON object on standard output (describe)0
runyesstart on standard input, then messagesMessages on standard output (The build)0 after stopped, 1 after failed
reap <build-id>yesreap{removed}0, 1
doctornodoctor{blocked}0, 1
setupnosetup{}0, 1
image-preparenoimage-prepare{path}0, 1
image-listnoimage-list{count}0, 1
image-verifynoimage-verify{checked, drift}0, 1
cleannoclean{removed}0, 1
attach <build-id>when capabilities.shellattach, in the request file{}, or {error}The shell's own
ext <args...>when describe.ext is not emptyext, in the request file; the arguments in argv, as typednoneThe driver's own

DRV-23. A driver MUST implement describe, run and reap. Every command it implements but describe MUST be listed in describe.commands, and a command of this table that it does not list MUST exit 3 with an unsupported-command error.

DRV-24. reap <build-id> removes whatever the build of that ID left. Exit 0 MUST mean that nothing of that build is left; reap MAY be repeated, and a reap of an ID that never existed exits 0 with removed: 0. When the driver cannot look where the build's leftovers would be (its runtime does not answer, it is on another host), it MUST exit 1 with a fixable error; it MUST NOT report success for a place it could not look in. reap is sent the values the build was started with (The build record), and works from the state file (DRV-C10).

DRV-25. doctor reports on standard output whether this host can run the driver's builds, and MUST change nothing on the host. Its result's blocked is true when a build could not run.

DRV-26. setup makes the one-time host changes the driver needs, and MAY be repeated. image-prepare prepares a base image for os from source, with progress on standard error, and returns its path, or an empty path when it has already reported the outcome. image-list prints one line per prepared image and returns their count. image-verify prints one line per cached layer and returns how many it checked and how many showed drift. doctor and image-list MUST change nothing under the temporary directory they are given.

DRV-27. clean removes the driver's leftovers of every build whose ID is not in keep_ids, printing a Removing ... line on standard error for each, and its own cache when cache is true. It returns how many it removed. A driver whose resources are shared between users SHOULD keep a liveness check of its own beside keep_ids, which holds only the builds whose locks this user's orchestrator can see (The build lock).

DRV-28. attach <build-id> enters the shell of a build started with mode: shell, on the inherited terminal, and exits with the shell's own exit code. When the attach itself failed, the driver MUST write an error object to its result. The orchestrator MUST exit with the shell's code when the result holds no error, and MUST print the error and exit 1 when it does.

DRV-29. ext <args...> runs the driver's own subcommands, which describe.ext lists, with the arguments as typed. The orchestrator MUST run a line <orchestrator> <name> <args...> (DRV-11) as ext <args...> on the driver <name>.

Probes

DRV-30. Any request MAY carry "probe": true. A driver given a probe MUST check contract, read and check its own flags and keys from args and config_file (DRV-C7), make the checks it would make before doing any work, create nothing, and exit 0 or with its refusal.

DRV-31. A driver MUST answer a probe within 30 s.

DRV-32. A probe of run is a start message with probe: true and without build_id, claim_token, build_script, diagnostics_dir and state_file. The driver answers it with one message, stopped or failed, and exits.

DRV-33. The orchestrator MUST probe run before it takes the build's lock, creates its output directory or stages anything, so that a bad value of a driver's flag or key, or a host that cannot run the build, is refused before anything is left behind. The orchestrator SHOULD likewise probe clean before it reaps any dead build in its clean command.

Commands not started by the orchestrator

DRV-34. A driver's ext started with no WARDEN_DRIVER_REQUEST (a process the operating system starts, such as a registered service) MUST run with no config file and the driver's defaults. It MUST NOT exit 2 for the missing request, and MUST NOT look for a config file by itself (DRV-C3).

DRV-35. A driver that starts one of its own commands as a process (a detached refresh) MUST write that command's request itself, as the orchestrator would.

describe

DRV-36. describe MUST exit 0 within 10 s, print exactly one JSON object on standard output and nothing else, have no side effects, and print the same object each time it is run.

{"contract": [1],
 "name": "qemu", "version": "0.9.0", "vendor": "buildwarden",
 "bug_url": "https://github.com/buildwarden/buildwarden/issues/new",
 "commands": ["run", "reap", "doctor", "image-prepare", "image-list", "image-verify"],
 "capabilities": {"vm": true, "shell": false, "keep": "stopped", "exited": false,
   "containerfile": "translate", "guest_os": ["linux", "windows"],
   "image_os": ["linux", "windows"], "default_image_os": "linux",
   "reserved_ranges": ["10.0.2.0/24"]},
 "flags": [{"name": "edition", "value": true, "commands": ["image-prepare"],
   "usage": "Windows edition / install.wim image name (qemu windows)"},
  {"name": "force", "value": false, "commands": ["image-prepare"],
   "usage": "re-acquire even if a valid cached copy exists"}],
 "keys": [{"key": "driver.image_refresh_after", "type": "string",
   "aliases": ["vm.image_refresh_after"], "commands": ["run"],
   "usage": "age after which a prepared Windows layer is refreshed"}],
 "ext": [],
 "help": {"doctor": "Checks qemu-system and qemu-img on PATH."}}
FieldMeaning
contractThe contract versions the driver speaks, as integers
nameThe driver's name (DRV-1, DRV-3)
version, vendor, bug_urlThe driver's own version, its vendor and where its bugs are reported, for the build's record and the text of a defect
commandsThe commands it implements, describe aside
capabilities.vmIt boots a separate build machine: it takes the shared VM settings (start.vm) and builds a script or a Containerfile. Without it, it builds a Containerfile only, and the orchestrator refuses its VM flags
capabilities.shellrun accepts mode: "shell", and attach is implemented
capabilities.keepWhat the orchestrator's keep request (warden --keep-vms) leaves: running (the machines), stopped (the work directory only) or none, for which the orchestrator refuses the request
capabilities.exitedIt sends exited when its relay or its environment stops on its own
capabilities.containerfiletranslate: the orchestrator translates a Containerfile to the build script and sends its base image. ignore: the guest cannot run one, and the orchestrator drops it and records nothing
capabilities.guest_osThe guest OS values the orchestrator accepts for it; the first is sent when none is asked for
capabilities.image_os, default_image_osThe OS values image-prepare takes, and the one it takes when none is given
capabilities.reserved_rangesFixed address ranges it uses on the host, as CIDR prefixes; a build link must not overlap them
flagsThe flags it takes (DRV-C1)
keysThe config keys it reads (DRV-C4)
extIts own subcommands, each a path of words and a usage line
helpA paragraph of its own for a command's long help, keyed by command

DRV-37. describe MUST be consistent with itself: run and reap are in commands; attach is listed exactly when capabilities.shell is true; ext exactly when the ext list is not empty; and capabilities.image_os is present exactly when image-prepare is listed.

DRV-38. The orchestrator MUST run describe on the selected driver only, once per invocation, and MUST refuse a describe that does not match the schema, lists no contract version it speaks, lacks run or reap, reports a name other than the one looked up, declares a flag whose name it uses on the same command, or declares a key outside the driver's place in the config file (DRV-C4). Each refusal names the field it is about.

The build

Messages

run is one process per build. The orchestrator writes messages to the driver's standard input and reads the driver's from its standard output.

DRV-39. A message is one JSON object on one line, UTF-8, ending with a newline, at most 1 MiB long, and has a type. A driver's standard output in run MUST hold nothing but messages.

DRV-40. A driver's standard error in run is its human-readable log. The orchestrator MUST read it, pass it on to its own standard error, and keep its tail for an error report.

FromtypeCarries
orchestratorstartThe build (below)
driverrelay-startedclaim, claim_values, guest_os, old_relay_fix
orchestratorclaimedNothing: the relay is configured and ready
driverenvironment-startedNothing
driverexited (optional)which (relay or build) and detail
orchestratorstopreason and detail
driverstoppedkept: the paths and names left behind under keep
driverfailederror
{"type": "start", "contract": 1, "build_id": "k3v9x2ab", "mode": "build",
 "claim_token": "c2VjcmV0LXRva2Vu", "guest_os": "linux", "image": "",
 "base_image": "alpine:3.21",
 "build_script": "/tmp/warden-stage-k3v9x2ab/build.sh",
 "context_dir": "/home/ana/project", "tmpdir": "",
 "diagnostics_dir": "/home/ana/project/warden-output",
 "state_file": "/home/ana/.cache/buildwarden/locks/build-qemu-k3v9x2ab.state",
 "keep": false, "verbose": false,
 "vm": {"cpus": 8, "memory_mb": 0, "build_link": "", "build_link_source": "default",
   "dns": []},
 "config_file": "/home/ana/project/warden.toml",
 "args": ["--network=warden-ci"]}

The fields of start:

FieldMeaning
build_idThe build ID (Scope and roles)
modebuild runs the build script. shell holds the environment after setup for attach; only for a driver with capabilities.shell
claim_tokenThe claim token. The driver puts it on the relay's boot channel, where it is one of the relay's pre-claim values. It is the only secret a driver is given
guest_osThe guest OS asked for, or the first of the driver's capabilities.guest_os
imageThe image the user named, or empty
base_imageThe FROM image of the build's Containerfile, as written there, whenever the build has a Containerfile and the driver's capabilities.containerfile is translate, whether or not the build script was translated from it. Empty when there is no Containerfile, when it cannot be parsed, or when its FROM is scratch. The driver resolves it to what it boots or runs
build_scriptThe absolute path of the staged build script. The driver may read it to describe the environment; it never serves it (the collector does)
context_dirThe build context, absolute
tmpdirWhere work directories are made; empty means the system's
diagnostics_dirThe build's output directory. The driver may write relay.log and console.log there, and nothing else
state_fileThe absolute path of the build's state file (The build record)
keepLeave what capabilities.keep names in place, and report it in kept. True only when capabilities.keep is not none
verboseThe user asked for verbose output
vmFor a driver with capabilities.vm: {cpus, memory_mb, build_link, build_link_source, dns}. Zero or empty means "not set", and the driver applies its default
config_file, argsThe driver's configuration (Configuration)
probeA probe (DRV-32)
collectorReserved. Never sent in version 1

DRV-41. The orchestrator MUST send collector in no message of version 1.

{"type": "relay-started",
 "claim": {"network": "tcp", "address": "127.0.0.1:41233"},
 "claim_values": {
   "environment": {"type": "vm-disk-chain/v1", "payload": "eyJ0eXBlIjoidm0tZGlzay1jaGFpbi92MSJ9",
     "metadata": null},
   "build_link": {"prefix": "10.9.0.0/30", "relay": "10.9.0.1", "guest": "10.9.0.2"},
   "upstream_dns": ["10.20.0.53"]},
 "guest_os": "linux",
 "old_relay_fix": "reinstall warden so its relay binary matches it"}

DRV-42. claim.address is where the relay accepts its claim, and MUST be reachable from the orchestrator's process as the user it runs as. claim.network is an enumeration whose only value in version 1 is tcp.

DRV-43. The orchestrator MUST copy claim_values into the claim unchanged, as its environment, build_link and upstream_dns fields; their shape is the claim protocol's (relay-claim), not this document's. A driver supplies no other claim field: collector_url, collector_token, capture_mode and the upstream CA fields are the orchestrator's.

DRV-44. relay-started's guest_os is the guest the environment really runs, and selects the bootstrap config the collector serves; it MAY differ from the one asked for. old_relay_fix is the fix the orchestrator shows if the relay refuses a claim field as unknown.

{"type": "claimed"}
{"type": "environment-started"}
{"type": "exited", "which": "build", "detail": "the build VM powered off"}
{"type": "stop", "reason": "completed", "detail": "the build script exited 0"}

reason is one of completed, failed, interrupted, timeout and shell-exited; detail is a sentence for the driver's log (for failed, what failed, such as the claim's error).

{"type": "stopped", "kept": ["/tmp/warden-qemu-k3v9x2ab"]}
{"type": "failed", "error": {"code": "fixable",
  "msg": "qemu-system-aarch64 not found on PATH",
  "fix": "install qemu (brew install qemu)"}}

The sequence

DRV-45. A build follows this order. The actor is named at each step.

  1. The orchestrator runs describe, picks the contract version, parses the command line with the driver's flags, and probes run.
  2. The orchestrator makes the build ID, takes the build lock and writes the build record (The build lock).
  3. The orchestrator creates the output directory and stages the build script; for capabilities.containerfile: ignore it drops the Containerfile first.
  4. The orchestrator makes the claim token, starts run and sends start. A build's time limit counts from here.
  5. The driver writes its state file if it needs one, starts the relay with the claim token, and sends relay-started.
  6. The orchestrator starts the collector, with the guest_os the driver reported, and claims the relay at claim.address: it opens the tunnel, sends the claim, and waits for the relay's ready, at most 90 s from the start of the claim.
  7. The orchestrator sends claimed. The driver isolates the environment, delivers the executor, starts it, and sends environment-started.
  8. The collector takes the console output, heartbeats and completion. The driver's messages carry none of them.
  9. The orchestrator sends stop when the build completes, fails, times out or is interrupted. The driver writes its diagnostics, tears down everything it created (under keep, all but what capabilities.keep leaves), sends stopped, and exits 0.

DRV-46. A driver MUST send relay-started before it starts the build environment, and MUST NOT start the build environment before it has read claimed: the relay is claimed and configured before the environment exists.

DRV-47. A driver MUST send environment-started only after claimed, and at most once.

DRV-48. A driver MAY send exited at any time after relay-started. On which: relay the orchestrator MUST cancel a claim in progress, or fail the build at once. On which: build it MUST give the build 10 s to deliver a completion already on its way, and then fail it.

DRV-49. A driver's last message MUST be exactly one of stopped and failed, sent after it has torn down. stopped answers stop or the end of its input. failed MAY be sent at any time, without waiting for stop, when the driver itself cannot go on.

DRV-50. A driver MUST treat the end of its standard input as it treats stop: tear down, then exit. A run whose input ends before start MUST exit without writing anything to standard output.

DRV-51. After the end of its input a driver MUST complete its teardown whether or not it can still write to its standard output and standard error, itself or through a child. (On Unix, a process that writes to a closed pipe is killed by SIGPIPE unless it ignores it.)

DRV-52. The orchestrator MUST start run in its own process group, so that the terminal's signals reach the orchestrator only. On the first interrupt or termination signal it MUST send stop (reason: interrupted), close the driver's input, and wait for stopped or failed for its teardown wait. A second signal, or the wait passing, MUST kill the driver's process group (on Windows, its process) and run reap <build-id>.

The teardown wait is the orchestrator's own setting; warden's is [build] teardown_timeout, 60 s unless set. warden bounds the reap it runs after a kill by the same wait, and an interrupted build exits 130.

DRV-53. In shell mode the driver sends environment-started once the shell can be entered. The orchestrator then runs attach <build-id> and, when it ends, sends stop with reason: shell-exited.

When something fails

DRV-54. Each failure has one outcome:

What failsWhenSentWhat the orchestrator does
The driver refuses the build (its preflight, or the relay cannot start)Before relay-startedThe driver removes what it made, sends failed and exits 1Prints the error. Runs no reap. Removes the build's stage directory, record and lock
The orchestrator's claim fails or times outAfter relay-startedstop with reason: failed and the claim's error as detail; the driver tears down and sends stoppedPrints the claim's error, with old_relay_fix when the relay refused a field; exits 1
The relay exitsAny time after relay-startedThe driver sends exited, which: relayCancels a claim in progress, or fails the build at once; then stop with reason: failed
The environment cannot be startedAfter claimedThe driver tears down, sends failed and exits 1Prints the error. Runs no reap
The environment exits before the build completesAfter environment-startedThe driver sends exited, which: buildWaits 10 s for a completion, then fails the build; stop with reason: failed
The driver's process ends with neither stopped nor failed, writes a line that is not a JSON object, or does not stop within the teardown waitAny timeNothingKills the driver's process group, shows the tail of its standard error as a driver defect, and runs reap <build-id> with the record's values. A completion the collector already holds stands, with the defect reported beside it; otherwise the build fails. When that reap fails or does not finish, the record and lock stay

failed and stopped both promise that the driver has torn down, so the orchestrator runs reap only when it got neither.

The build lock

The convention below is how an orchestrator says which builds are alive. Every orchestrator that runs builds on a driver follows it, the conformance suite included.

DRV-55. The lock directory is <user cache directory>/buildwarden/locks, mode 0700 (on Linux $XDG_CACHE_HOME, else ~/.cache; on macOS ~/Library/Caches; on Windows %LocalAppData%). For a build of the driver <name> with the ID <id>, the orchestrator keeps three files there:

FileWritten byHolds
build-<name>-<id>.lockThe orchestratorNothing. The orchestrator holds an exclusive OS file lock on it for the life of the build, released by the operating system if the orchestrator dies. A held lock means the build is live
build-<name>-<id>.jsonThe orchestrator, before it creates anything elseThe build record (below)
build-<name>-<id>.stateThe driver, if it needs oneThe state file (below)

DRV-56. The orchestrator MUST take the lock before it writes the record and before it creates anything else for the build. After it holds the lock it MUST check that the path still names the file it locked, and start again with a new file when it does not.

DRV-57. An orchestrator MUST remove a lock file only while it holds that lock, after the same check. It removes the three files when the build ends cleanly, and otherwise only after a reap of the build that exited 0.

DRV-58. keep_ids in a clean request MUST be the IDs of the driver's build locks that are held when the request is made.

The build record

DRV-59. The record holds the driver's name, the path and SHA-256 digest of its file (or that it is linked), the contract version, the build's temporary directory and stage directory, and the config_file and args that run was started with. It MUST hold no secret: the claim token is not in it.

DRV-60. reap and attach MUST be sent the record's tmpdir, config_file and args and the state file's path, whoever runs them and whenever, and not those of the invocation that runs them.

DRV-61. The state file is the driver's to write for one build: whatever it needs to find the build again that the ID does not give, and everything it resolved from its configuration that attach or reap depends on. It MUST be at most 64 KiB, and the driver MUST write it before it creates the thing its content describes. It is opaque to the orchestrator.

The record names the config file and repeats the flags; it does not freeze what the file said. A value reap or attach depends on therefore belongs in the state file (DRV-C10).

Configuration

A driver reads its own configuration, in its own process: its flags from the request's args, and its keys from the one config file the request names. The orchestrator reads its own flags and keys, looks at none of the driver's values, and sends the driver none of its own beyond the fields of the requests.

DRV-62. Every request MUST carry config_file when the orchestrator has a config file for the invocation, and every request of a command that takes flags MUST carry args.

FieldHolds
config_fileThe absolute path of the one config file the orchestrator read, or would read, for this invocation: for warden, the file --config names, else the one WARDEN_CONFIG names, else ./warden.toml when it exists. Absent when there is none. Never a list, and it says nothing of how the file was found. The file is TOML v1.1.0
argsThe driver's flags from the command line. A flag declared with a value: one element per occurrence, in the order typed, as --name=value, whether it was typed --name value or --name=value; the value's bytes unchanged, an empty value included. A switch (a flag declared without a value): --name, once, when the switch is on, and nothing when it is off. Empty when the user gave none

DRV-63. The orchestrator MUST settle a switch itself: it MUST NOT send --name=false or --name=true, and a switch that is off is absent.

A driver is not told whether its file is the defaulted ./warden.toml, which may have come with a build context someone else wrote, or a file the user named. A driver whose key names a program or a host path SHOULD take the file for the first, and the safe form of such a key is a closed list of names.

Flags

{"name": "network", "value": true, "commands": ["run", "doctor", "setup"],
 "usage": "durable build switch name (default: [driver.hyperv] network, then warden-dev)"}
FieldMeaning
nameThe flag without its dashes, [a-z][a-z0-9-]*. There are no short forms
valueTrue when the flag takes a value, false for a switch
commandsThe commands that take it, each one the driver lists: run, doctor, setup, image-prepare, clean. image-list and image-verify take none. Everything after <orchestrator> <name> is ext's, in its argv
usageOne line for help

The orchestrator places a declared flag and does nothing else with it: it does not know its type, read its value or apply a default. A driver's flag is accepted after the subcommand's name; one declared for every command the driver lists is also accepted before it.

Keys and their two tables

A driver's keys have two tables in the config file:

TableHoldsWho says what a key means
[driver]The common keys: a short list of keys that more than one driver reads and means the same thing byThis document (The common keys of version 1)
[driver.<name>]That driver's overrides of the common keys it honours, each under the common key's own name; and the driver's own keys, in any shapeThis document for an override; the driver for its own keys

The orchestrator reads neither table. [runtime] driver selects the driver and is the orchestrator's; [driver] configures drivers and selects nothing.

{"key": "driver.hyperv.network", "type": "string", "aliases": ["vm.network"],
 "commands": ["run", "doctor", "setup"], "usage": "durable build switch name"}
FieldMeaning
keyThe key as a dotted path: a common key the driver honours as driver.<key>, which also stands for its override driver.<name>.<key>; a key of its own under driver.<name>.
typeThe TOML type of its value: string, integer, float, boolean, array, table, or any for a key whose shape the driver does not state
aliasesThe key's deprecated old names, each one this document lists for the driver's name (Old names)
commandsThe commands that read it
usageOne line

The common keys of version 1

KeyTypeMeaning
image_refresh_afterA string holding an age, such as "7d" or "36h"The age at which a prepared base image is prepared again in the background; the build goes on with the image it has
image_min_graceA string holding an ageThe least evaluation grace a prepared image must still have; a build on an image with less is refused

An age is a Go duration ("90m", "36h"), or a whole or fractional number of days followed by d ("7d", "1.5d"). The value a driver uses when nobody sets a key is the driver's to state.

DRV-64. A common key's name matches [a-z][a-z0-9_]*. A later version that names a common key without an underscore MUST also refuse that name for a driver, since [driver] <key> and a driver of that name would claim one place in the file.

The precedence

For one setting of the driver <name>, the first of these that sets it is the value:

  1. its flag, in args;
  2. its environment variable, where this document gives it one (DRV-C9);
  3. [driver.<name>] in the config file;
  4. [driver] in the config file, for a common key;
  5. nothing: the driver's default.

A key of the driver's own has no place in [driver], so for it step 4 does not exist. In words: the flag, then the variable, then the file, and in the file the driver's own table before [driver]. Nothing is merged, and no step is a fallback: a value found at one step that the driver cannot use is an error that names where it was found, and the next step is not tried.

A worked example, with drivers named hyperv, qemu and container whose defaults for the two ages are 7d and 1d:

# warden.toml
[driver]
image_refresh_after = "3d"

[driver.hyperv]
image_refresh_after = "12h"

[driver.qemu]
image_min_grace = "6h"

[driver.container]
cli = "podman"
DriverSettingValueStep
hypervimage_refresh_after12h3: its own table. [driver]'s 3d is not reached
hypervimage_min_grace1d5: nothing sets it for hyperv, so its default. [driver.qemu] is not hyperv's table
qemuimage_refresh_after3d4: [driver]
qemuimage_min_grace6h3: its own table
containerclipodman3. With WARDEN_CTR_CLI=docker in the environment, docker (step 2); with --runtime finch as well, finch (step 1)
containerthe two agesnot readIt lists neither key

Old names

Seven keys of the bundled drivers had other names before this contract. Each old name is a deprecated second name for the same key, read as the key itself until BuildWarden 1.0, and only by a driver of that name:

Driver nameOld nameKey
containerruntime.clidriver.container.cli
containerruntime.relay_imagedriver.container.relay_image
qemuvm.image_refresh_afterdriver.image_refresh_after
qemuvm.image_min_gracedriver.image_min_grace
hypervvm.image_refresh_afterdriver.image_refresh_after
hypervvm.image_min_gracedriver.image_min_grace
hypervvm.networkdriver.hyperv.network
hypervvm.windows_imagedriver.hyperv.windows_image
hypervvm.windows_image_updatedriver.hyperv.windows_image_update

An old name stands where its key stands: [vm] image_refresh_after is step 4, below the driver's own table; [runtime] cli is step 3. An old name in another letter case, such as [Runtime] CLI, is refused as DRV-C12 says, and the key to write is the new name.

The environment variables of version 1 are the container driver's two: WARDEN_CTR_CLI for driver.container.cli and WARDEN_IMAGE for driver.container.relay_image.

The configuration requirements

DRV-C1. A driver MUST declare every flag it takes in describe.flags, with its arity and its commands, and MUST use no name the orchestrator uses on the same command (Reserved flag names). Each command a flag names MUST be one the driver lists.

DRV-C2. A driver MUST take each declared flag from args: a flag with a value as --name=value (for a flag that holds one value, the last occurrence wins), a switch as --name, on when present and off when absent. It MUST refuse an element it did not declare for the command with a fixable error that names it.

DRV-C3. A driver MUST read configuration only from the file named in config_file. It MUST NOT look for a warden.toml by itself, in its working directory or through WARDEN_CONFIG, which it inherits from the orchestrator. Sent no config_file, or started with no request, it reads no file and uses its defaults.

DRV-C4. A driver MUST list the keys it reads in describe.keys, each in its place in the config file and with the commands that read it: a common key it honours as driver.<key>, with the type this document gives it; a key of its own under driver.<name>., with the TOML type of its value (or any) and a name that is no common key's. Listing a common key is also listing its override, driver.<name>.<key>. It MUST read nothing in [driver] that it did not list, and no override of a common key it did not list. No two places where a driver's listed keys may be written (each key's name, the override of each common key it lists, and each old name) may be equal when ASCII letters are folded.

DRV-C5. A driver MUST ignore every table and key it does not own: the orchestrator's tables, another driver's table, and a common key it does not list, in [driver] and in its own table, except as DRV-C12 says. It MUST read any file the orchestrator reads: the file is TOML v1.1.0.

DRV-C6. When it lists a key, a driver MUST refuse a config_file that does not exist, cannot be read or cannot be parsed, and a key of its own whose value has the wrong type, with a fixable error that names the file, and the key where there is one (not in reap and attach: DRV-C10). A file that was named and is missing MUST NOT be read as if none had been named, and no other file is tried in its place.

DRV-C7. A driver MUST read and check all of its configuration before any work: in the probe of run, and first in every other command but reap and attach (DRV-C10).

DRV-C8. A driver MUST apply the precedence: a flag, else the setting's environment variable where this document gives it one (DRV-C9), else the key in config_file, else its default. A common key is read from the driver's own table, and from [driver] only when that table does not set it. A flag given with an empty value, and a variable that is set but empty, are not set, and the next place is read. The place that sets a value is the value, not merged with another, and an unusable value is an error, never replaced by a lower place's value or by the default. What an empty string in the file means is the driver's.

DRV-C9. A driver MUST take its settings as flags and keys, not as environment variables of its own. The two that exist, WARDEN_CTR_CLI and WARDEN_IMAGE, stay the container driver's.

DRV-C10. In reap and attach, a driver MUST take from the state file what it holds, and MUST NOT resolve it again from args and config_file. It MUST read a config_file that no longer exists as if none had been named, saying so on standard error, and MUST NOT fail the command for it. When a state file exists, it MUST NOT fail because a recorded file cannot be parsed or holds a value it would refuse. When no state file exists, a driver that still wants a setting resolves it from the record's args and the recorded file if it exists; a file that is there and cannot be used is a fixable error that names it.

DRV-C11. A driver MUST read a key under an old name only where this document lists that name for the driver's own name, and then as the same key. It MUST refuse a file that sets a key under both names, with a fixable error that names the file and both names. It MUST say on standard error, once per old name the file sets, that the name is deprecated and what the new one is: when it answers a probe, and in a request that is not a probe only for a command the orchestrator does not probe first (doctor, setup, the image commands, ext); so not in a run or clean that is not a probe, nor in reap or attach. A driver whose name has no old names reads none.

DRV-C12. A driver MUST refuse a config_file that holds, at a key path equal, when ASCII letters are folded, to a place where one of its listed keys may be written (the key's name, the override driver.<name>.<key> of a common key it lists, an old name this document lists for it), a key that is not spelt as that place, with a fixable error that names the file, each spelling found and the key to write. It MUST do so at the points DRV-C7 gives, before it reads the value or applies DRV-C11; in reap and attach, only where DRV-C10 has it resolve a setting from the recorded file because no state file exists. A key that equals no listed place ignoring letter case is ignored (DRV-C5).

Requests and results

Every request carries contract, and MAY carry probe.

{"contract": 1, "build_id": "k3v9x2ab", "tmpdir": "",
 "config_file": "/home/ana/project/warden.toml", "args": ["--runtime=docker"],
 "state_file": "/home/ana/.cache/buildwarden/locks/build-container-k3v9x2ab.state"}
{"contract": 1, "vm": {"build_link": "", "build_link_source": "default"},
 "config_file": "/home/ana/project/warden.toml", "args": [], "verbose": false}
{"contract": 1, "vm": {}, "args": ["--slots=2"], "verbose": true}
{"contract": 1, "os": "windows", "source": "/isos/win.iso",
 "args": ["--force", "--edition=Windows Server 2025 Datacenter"], "verbose": false}
{"contract": 1, "config_file": "/home/ana/project/warden.toml"}
{"contract": 1}
{"contract": 1, "keep_ids": ["k3v9x2ab"], "cache": false, "tmpdir": "",
 "args": [], "probe": true}
{"contract": 1, "build_id": "k3v9x2ab", "args": [],
 "state_file": "/home/ana/.cache/buildwarden/locks/build-container-k3v9x2ab.state"}
{"contract": 1, "config_file": "/home/ana/project/warden.toml"}

The results:

{"removed": 4}
{"blocked": false}
{}
{"path": "/home/ana/.cache/warden/images/windows-server-2025.qcow2"}
{"count": 2}
{"checked": 3, "drift": 1}
{"removed": 0}
{"error": {"code": "fixable", "msg": "no build k3v9x2ab is held for a shell",
  "fix": "start one with warden shell"}}

DRV-65. A command that exits 1 MUST put an error object in its result (for run, in its failed message).

Errors

{"code": "internal", "msg": "relay container exited: exit status 125",
 "details": {"container": "warden-relay-k3v9x2ab"}}

DRV-66. An error object has a code, a msg, and MAY have a fix and details. code is one of:

codeMeaningHow the orchestrator reports it
fixableA known cause with a remedy, given in fixThe message and the fix, with no bug link
busyAnother process already does thisThe message
invalid-requestThe request was not valid (exit 2)A defect of the orchestrator or the driver: bug text
unsupported-commandThe command is not implemented (exit 3)For an optional command the driver did not list, the orchestrator never calls it; if returned anyway, a driver defect
unsupported-contractNo contract version in common (exit 4)An error the user can act on, naming both versions and which side to update
internalAnything elseThe message, the tail of the driver's standard error, and bug text that names the driver, its version and its bug_url

DRV-67. A driver defect (an exit code outside the table, a missing result, a line on run's output that is not a JSON object) MUST be reported as internal is, naming the driver and its bug_url, and not with the orchestrator's own bug link.

DRV-68. A value of a driver's flag or key that it cannot use MUST be a fixable error that names where the value came from: the flag as typed, the variable, or the file with the table and key as written there. It is reported at the points DRV-33 and DRV-C7 give, and exits 1, never 2.

Versions

DRV-69. describe.contract lists the versions a driver speaks. The orchestrator MUST pick the highest version it also speaks and send it in every request. With none in common, it MUST refuse the driver with an unsupported-contract error, and a driver sent a version it does not list MUST exit 4.

DRV-70. A request that is not a JSON object, or that is not valid for the contract version, MUST make the driver exit 2 with an invalid-request error.

Adding a field, a command, a capability or a message type does not change the contract version. Removing one, changing its meaning, or adding a common key does: a driver and an orchestrator that agree on a version agree on what [driver] holds. Version 1 is unstable until BuildWarden 1.0, and may change in any release, its list of common keys with it. A driver's own version is independent of the orchestrator's.

Requirements that are not machine-checked

Each requirement below is not checked by a case of the conformance suite, for the reason given; every other requirement is checked by a case that names it.

RequirementWhy not
DRV-2Which files the orchestrator takes on Windows is the orchestrator's lookup, which the suite does not exercise; warden's own tests hold it
DRV-4, DRV-5, DRV-6, DRV-7, DRV-8, DRV-9, DRV-10, DRV-11, DRV-12, DRV-13Requirements on the orchestrator's lookup and command line, which the suite, playing the orchestrator, does not exercise; warden's own tests hold them
DRV-17, DRV-18Requirements on the orchestrator's files and arguments; the suite writes its own requests
DRV-19The orchestrator's refusal of a path before it starts a driver; warden's tests hold it
DRV-22, DRV-38, DRV-67, DRV-69 (the orchestrator's half)How the orchestrator reports a defect or refuses a describe is its own; warden's tests hold them
DRV-26 (setup, image-prepare, image-verify)Their effects are host- and driver-specific and can take hours; only their exit codes and results are checked
DRV-28 (the orchestrator's half), DRV-29How the orchestrator maps the attach result and an ext line; warden's tests hold them
DRV-35A process the driver starts itself is not visible to the suite
DRV-40What the orchestrator does with the driver's standard error is its own
DRV-41A requirement on the orchestrator's messages
DRV-42 (reachability as the user)The suite runs as one user, the one it checks from
DRV-43 (no other claim field)The driver supplies claim_values only; what it cannot send is not observable beyond the schema
DRV-44 (guest_os is the real guest)The suite cannot see which guest runs
DRV-46 (the environment not started before claimed)The suite sees the order of the messages, not when the environment really started; the build-link suite holds isolation
DRV-52, DRV-54 (the orchestrator's column), DRV-56, DRV-57, DRV-59, DRV-60, DRV-62, DRV-63Requirements on the orchestrator; warden's tests hold them
DRV-61 (written before what it describes)The suite sees the state file only after the fact
DRV-64A rule on later versions of this document
DRV-C8The suite does not know what a value means to a driver, so it cannot see which place won. The kit's tests hold it for a driver built on the kit, and the suite's self-test for the reference fake, which echoes its values and their places in a probe
DRV-C9A process may read any variable
DRV-C11 (the value used, both names refused, when the warning is printed)The suite cannot make a value a driver accepts; the kit's tests hold it for each of the seven old names. That the old names in describe.keys are this document's, and that a wrong type under an old name is refused, is checked