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.
| Seam | 9, the driver contract |
| Requirement identifiers | DRV-<n>; the configuration requirements DRV-C<n> |
| Roles | orchestrator, driver |
| Machine schema | v1.schema.json, beside this document |
| Reference implementation | The 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 suite | driver-conformance, under conformance/driver/ in the same repository |
| Status | Unstable. 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
wardenitself, 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-outputsandcollector-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 must | Stated 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 channel | Seam 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 band | Seam 5, executor-initialize |
| Report the guest OS, which selects the bootstrap config | Seam 6, bootstrap-config |
| Make the relay the build's only network path | Seam 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:
- A path. The file is used as given and nothing else is searched.
PATH. Each entry inPATH's order is searched for the driver's file name, and the first candidate is the driver.- The directory of the orchestrator's own executable, symbolic links
resolved, when
PATHgave nothing. - 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:
- The
extform. 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. - 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.
- 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.--configis found by the same scan, in the same forms. - With no
--driver, the selection isWARDEN_DRIVER, else[runtime] driverfrom the config file the scan found, elsecontainer.
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:
| Commands | Names |
|---|---|
| Every command | driver, 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 |
doctor | build-link |
image-prepare | os, source |
clean | cache |
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:
| Code | Meaning |
|---|---|
| 0 | Done |
| 1 | Failed: the result (for run, the failed message) carries an error object |
| 2 | The request is not valid for this contract version |
| 3 | The command is not implemented by this driver |
| 4 | No 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
| Command | Required | Request | Result | Exit |
|---|---|---|---|---|
describe | yes | none | One JSON object on standard output (describe) | 0 |
run | yes | start on standard input, then messages | Messages on standard output (The build) | 0 after stopped, 1 after failed |
reap <build-id> | yes | reap | {removed} | 0, 1 |
doctor | no | doctor | {blocked} | 0, 1 |
setup | no | setup | {} | 0, 1 |
image-prepare | no | image-prepare | {path} | 0, 1 |
image-list | no | image-list | {count} | 0, 1 |
image-verify | no | image-verify | {checked, drift} | 0, 1 |
clean | no | clean | {removed} | 0, 1 |
attach <build-id> | when capabilities.shell | attach, in the request file | {}, or {error} | The shell's own |
ext <args...> | when describe.ext is not empty | ext, in the request file; the arguments in argv, as typed | none | The 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."}}
| Field | Meaning |
|---|---|
contract | The contract versions the driver speaks, as integers |
name | The driver's name (DRV-1, DRV-3) |
version, vendor, bug_url | The driver's own version, its vendor and where its bugs are reported, for the build's record and the text of a defect |
commands | The commands it implements, describe aside |
capabilities.vm | It 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.shell | run accepts mode: "shell", and attach is implemented |
capabilities.keep | What 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.exited | It sends exited when its relay or its environment stops on its own |
capabilities.containerfile | translate: 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_os | The guest OS values the orchestrator accepts for it; the first is sent when none is asked for |
capabilities.image_os, default_image_os | The OS values image-prepare takes, and the one it takes when none is given |
capabilities.reserved_ranges | Fixed address ranges it uses on the host, as CIDR prefixes; a build link must not overlap them |
flags | The flags it takes (DRV-C1) |
keys | The config keys it reads (DRV-C4) |
ext | Its own subcommands, each a path of words and a usage line |
help | A 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.
| From | type | Carries |
|---|---|---|
| orchestrator | start | The build (below) |
| driver | relay-started | claim, claim_values, guest_os, old_relay_fix |
| orchestrator | claimed | Nothing: the relay is configured and ready |
| driver | environment-started | Nothing |
| driver | exited (optional) | which (relay or build) and detail |
| orchestrator | stop | reason and detail |
| driver | stopped | kept: the paths and names left behind under keep |
| driver | failed | error |
{"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:
| Field | Meaning |
|---|---|
build_id | The build ID (Scope and roles) |
mode | build runs the build script. shell holds the environment after setup for attach; only for a driver with capabilities.shell |
claim_token | The 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_os | The guest OS asked for, or the first of the driver's capabilities.guest_os |
image | The image the user named, or empty |
base_image | The 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_script | The absolute path of the staged build script. The driver may read it to describe the environment; it never serves it (the collector does) |
context_dir | The build context, absolute |
tmpdir | Where work directories are made; empty means the system's |
diagnostics_dir | The build's output directory. The driver may write relay.log and console.log there, and nothing else |
state_file | The absolute path of the build's state file (The build record) |
keep | Leave what capabilities.keep names in place, and report it in kept. True only when capabilities.keep is not none |
verbose | The user asked for verbose output |
vm | For 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, args | The driver's configuration (Configuration) |
probe | A probe (DRV-32) |
collector | Reserved. 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.
- The orchestrator runs
describe, picks the contract version, parses the command line with the driver's flags, and probesrun. - The orchestrator makes the build ID, takes the build lock and writes the build record (The build lock).
- The orchestrator creates the output directory and stages the build
script; for
capabilities.containerfile: ignoreit drops the Containerfile first. - The orchestrator makes the claim token, starts
runand sendsstart. A build's time limit counts from here. - The driver writes its state file if it needs one, starts the relay with
the claim token, and sends
relay-started. - The orchestrator starts the collector, with the
guest_osthe driver reported, and claims the relay atclaim.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. - The orchestrator sends
claimed. The driver isolates the environment, delivers the executor, starts it, and sendsenvironment-started. - The collector takes the console output, heartbeats and completion. The driver's messages carry none of them.
- The orchestrator sends
stopwhen the build completes, fails, times out or is interrupted. The driver writes its diagnostics, tears down everything it created (underkeep, all but whatcapabilities.keepleaves), sendsstopped, 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 fails | When | Sent | What the orchestrator does |
|---|---|---|---|
| The driver refuses the build (its preflight, or the relay cannot start) | Before relay-started | The driver removes what it made, sends failed and exits 1 | Prints the error. Runs no reap. Removes the build's stage directory, record and lock |
| The orchestrator's claim fails or times out | After relay-started | stop with reason: failed and the claim's error as detail; the driver tears down and sends stopped | Prints the claim's error, with old_relay_fix when the relay refused a field; exits 1 |
| The relay exits | Any time after relay-started | The driver sends exited, which: relay | Cancels a claim in progress, or fails the build at once; then stop with reason: failed |
| The environment cannot be started | After claimed | The driver tears down, sends failed and exits 1 | Prints the error. Runs no reap |
| The environment exits before the build completes | After environment-started | The driver sends exited, which: build | Waits 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 wait | Any time | Nothing | Kills 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:
| File | Written by | Holds |
|---|---|---|
build-<name>-<id>.lock | The orchestrator | Nothing. 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>.json | The orchestrator, before it creates anything else | The build record (below) |
build-<name>-<id>.state | The driver, if it needs one | The 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.
| Field | Holds |
|---|---|
config_file | The 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 |
args | The 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)"}
| Field | Meaning |
|---|---|
name | The flag without its dashes, [a-z][a-z0-9-]*. There are no short forms |
value | True when the flag takes a value, false for a switch |
commands | The 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 |
usage | One 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:
| Table | Holds | Who 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 by | This 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 shape | This 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"}
| Field | Meaning |
|---|---|
key | The 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>. |
type | The TOML type of its value: string, integer, float, boolean, array, table, or any for a key whose shape the driver does not state |
aliases | The key's deprecated old names, each one this document lists for the driver's name (Old names) |
commands | The commands that read it |
usage | One line |
The common keys of version 1
| Key | Type | Meaning |
|---|---|---|
image_refresh_after | A 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_grace | A string holding an age | The 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:
- its flag, in
args; - its environment variable, where this document gives it one (DRV-C9);
[driver.<name>]in the config file;[driver]in the config file, for a common key;- 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"
| Driver | Setting | Value | Step |
|---|---|---|---|
| hyperv | image_refresh_after | 12h | 3: its own table. [driver]'s 3d is not reached |
| hyperv | image_min_grace | 1d | 5: nothing sets it for hyperv, so its default. [driver.qemu] is not hyperv's table |
| qemu | image_refresh_after | 3d | 4: [driver] |
| qemu | image_min_grace | 6h | 3: its own table |
| container | cli | podman | 3. With WARDEN_CTR_CLI=docker in the environment, docker (step 2); with --runtime finch as well, finch (step 1) |
| container | the two ages | not read | It 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 name | Old name | Key |
|---|---|---|
container | runtime.cli | driver.container.cli |
container | runtime.relay_image | driver.container.relay_image |
qemu | vm.image_refresh_after | driver.image_refresh_after |
qemu | vm.image_min_grace | driver.image_min_grace |
hyperv | vm.image_refresh_after | driver.image_refresh_after |
hyperv | vm.image_min_grace | driver.image_min_grace |
hyperv | vm.network | driver.hyperv.network |
hyperv | vm.windows_image | driver.hyperv.windows_image |
hyperv | vm.windows_image_update | driver.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:
code | Meaning | How the orchestrator reports it |
|---|---|---|
fixable | A known cause with a remedy, given in fix | The message and the fix, with no bug link |
busy | Another process already does this | The message |
invalid-request | The request was not valid (exit 2) | A defect of the orchestrator or the driver: bug text |
unsupported-command | The 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-contract | No contract version in common (exit 4) | An error the user can act on, naming both versions and which side to update |
internal | Anything else | The 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.
| Requirement | Why not |
|---|---|
| DRV-2 | Which 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-13 | Requirements 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-18 | Requirements on the orchestrator's files and arguments; the suite writes its own requests |
| DRV-19 | The 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-29 | How the orchestrator maps the attach result and an ext line; warden's tests hold them |
| DRV-35 | A process the driver starts itself is not visible to the suite |
| DRV-40 | What the orchestrator does with the driver's standard error is its own |
| DRV-41 | A 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-63 | Requirements 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-64 | A rule on later versions of this document |
| DRV-C8 | The 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-C9 | A 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 |