Local Development

Prerequisites

  • Hardware: at least 4 cores and 16 GB of RAM (the minimum developer machine, ruled on #1977); on Docker Desktop the VM’s allocation is what counts. Every host runs the same battery settings; see Battery threads and the nextest environment below

  • Rust 1.97.0 (edition 2024): rust-toolchain.toml pins the exact version, so rustup installs the right one automatically, with the wasm32-unknown-unknown target a partner module is built for (ADR-090; the tests build the partner specification and the fixture modules for it, the fixture modules)

  • cargo-nextest and cargo-machete: cargo install --locked cargo-nextest cargo-machete

  • Docker Desktop (Windows/macOS) or Docker Engine (Linux), with Compose v2

  • glab CLI for GitLab issue and MR management: install from the GitLab CLI releases

  • Git hooks: git config core.hooksPath .githooks (runs fmt, clippy, build, and nextest before push)

  • mold linker (Linux only, optional, #1371): a per-machine opt-in that speeds up cargo build/check/test; see Linux + mold linker below

Windows host prerequisites (#2823, #2828)

CRAIG builds and runs cargo xtask natively on Windows (x86_64-pc-windows-msvc):

  • Visual Studio 2022 Build Tools (or Community/Professional) with the *Desktop development with C* workload: MSVC v143 C/C compiler (cl.exe, link.exe) and the Windows 10/11 SDK (required by ring, aws-lc-sys, psm, stacker, and rquickjs-sys).

  • Rust MSVC toolchain: rustup toolchain install 1.97.0-x86_64-pc-windows-msvc (selected automatically by rust-toolchain.toml).

  • Docker Desktop for Windows with the WSL 2 backend enabled and Compose v2 (docker compose version): verified end to end on Windows (#2828) for the full 23-container devstack (cargo xtask dev start), cargo xtask validate (including all devstack integration suites), cargo xtask e2e (all 523 Playwright specs and post-journey sweeps), cargo xtask perf --profile smoke, cargo xtask security --skip-zap --skip-fuzz, cargo xtask sdk-test, craig-devtools (sops + age), and craig-gitleaks.

  • Docker Desktop file sharing (Docker VMM backend): before the first run, add the checkout root (for example D:\src) and %LOCALAPPDATA% (tests bind-mount tempfile directories under %TEMP%) to Settings > Resources > File sharing. Docker Desktop otherwise adds a root the first time a container bind-mounts under it and restarts the VM to apply it, which stops every running container: observed on 2026-10-31 as a whole devstack exiting 0 in the middle of a test run (FilesharingDirectories changed settings update requires VM restart in com.docker.backend.exe.log). The WSL 2 backend shares all drives and has no such step.

  • Run the devtools container tests under nextest (2829): xtask’s docker_* tests in xtask/src/devtools.rs (docker_age_keygen_round_trips_through_the_captured_runner and its siblings) are [ignore = "requires docker"], and several of them bind-mount a temporary directory; run at once they can wedge container creation in Created on Docker Desktop with VirtioFS file sharing. Every nextest profile serializes them in the docker-secrets test group (.config/nextest.toml), so run them as cargo nextest run -p xtask --run-ignored all -E 'test(/docker_/)' or through cargo xtask validate (which runs ignored tests too), never as cargo test -p xtask — --include-ignored, which runs them concurrently.

  • Checkout location and endpoint security: prefer a ReFS Dev Drive for the checkout and for TEMP. On an NTFS volume with an on-close scanning minifilter attached (CrowdStrike Falcon on the agency image), a file that object_store’s local `PutMode::Create just published is held by the scanner for up to about two seconds, and a rename over it in that window fails with ERROR_ACCESS_DENIED (OS error 5). Production never overwrites a published object; the one in-tree writer that does, the AFCARS tamper fixtures, goes through craig_test_lib::overwrite_stored (an unlink, then a fresh write; #2828). A Dev Drive detaches such filters, and the same sequence never failed there.

  • Git for Windows with git-lfs: .gitattributes enforces LF line endings (* text=auto eol=lf) so shell scripts and Dockerfiles bind-mounted into Linux containers never acquire CRLF line endings.

  • Age identity location: DevtoolsPaths::resolve resolves $XDG_CONFIG_HOME/sops/age when set, falling back to %USERPROFILE%\.config\sops\age on Windows ($HOME/.config/sops/age on Unix). On Windows cargo xtask secrets init verifies before and after generation that the identity path resolves inside USERPROFILE (relying on the default user-profile ACL; not read or modified at runtime) and refuses any path outside USERPROFILE.

First-Run Setup

  1. Clone: git clone git@gitlab.com:gadhs/application/ccwis/craig.git && cd craig

  2. Set hooks path: git config core.hooksPath .githooks

  3. Copy env template: cp .env.example .env (edit if needed — defaults work for devstack)

  4. Build workspace: cargo build --workspace --locked

  5. Fetch the configuration layers: cargo xtask config fetch (see Configuration layers (ADR-087, #2955))

  6. Start devstack: cargo xtask dev reload

Configuration layers (ADR-087, #2955)

The rule sets and jurisdiction data live in their own repositories (craig-config-federal, craig-config-georgia, craig-config-texas), each pinned to a signed commit by config-sources.lock; only the synthetic testonia fixture stays in source (fixtures/config/testonia/). cargo xtask config fetch runs craig-config-fetch sync over the lock into target/config/<name>/current, verified against ci/config-trust/<name>.openpgp (the fetcher imports <name>.openpgp.asc into its own throwaway keyring, so it needs git and gpg on PATH but reads no keyring of yours), then builds target/config/layers/<name>, the tree the ruleset lints, twin parity, the scenarios audit and the tests read. The view is swapped in atomically (a symlink renamed onto a fresh layers.<nonce>/ directory, and left untouched when it already matches the lock), so a test reading it while a fetch runs never finds it missing (#3038). A layer already at its pin is not fetched again, so a repeat run needs no network; the ci stages that read configuration run it first. --layer-path <name>=<dir> publishes a working copy of a config repository as that layer instead (unverified), to run CRAIG’s checks against a change before it merges. A ci stage’s fetch (so cargo xtask validate) keeps that working copy and prints a kept working copy … (unverified …) line for it; a bare cargo xtask config fetch restores the layer to its pin. The writing commands (policy sync-cache, rules afcars-manifest, rules afcars-attest) refuse a fetched layer and write only into a working copy published that way. Where rule sets live has the change flow.

The devstack fetches the same pins itself: docker-compose.yml reads the lock’s source lists from the committed files under devstack/config-sources/, which cargo xtask config env regenerates from the lock (a pin bump commits both; cargo xtask config env --check, a validate gate, fails until it does, and dev start and the other bring-up verbs refuse to start on stale files, #3143), and the craig-config-fetch one-shot publishes them into the craig-config volume before any service that loads configuration, or the seed, starts (Devstack § Config fetch). Every service loads its jurisdiction and its reference data from those layers at boot.

A host-free devstack: no host ports, dev exec, the dev profile

The devstack publishes no host port (plan merge-trains-gate design 3, #2922). Every service is reached on the compose project network by its container name and port: http://keycloak:8080 (also the OIDC issuer, http://keycloak:8080/realms/craig), http://craig-web:8080, postgres:5432, and so on (DevStack Guide § Services and Ports). No /etc/hosts entry and no firewall rule is needed on any host.

  • Processes that talk to the stack run on its network. cargo xtask dev exec — <cmd> runs a command in the craig-tools container (a Dockerfile target: the pinned Rust toolchain, cargo-nextest, cargo-mutants, Playwright’s browsers, node, python, k6 and the Docker CLI). The checkout is mounted at its own host path, target/craig-tools is the cargo target (its own glibc and toolchain paths never invalidate the host’s target/; dev start’s one compile lands in its `x86_64-unknown-linux-musl/devstack/ (dev start compiles once (plan ci-dev-loop D1, #3044)), and after each battery inventory build xtask deletes from that profile’s deps the test executables, with their .d and .dwp, that the build did not list and that are more than 60 minutes old (a younger one may be another selection’s build about to run), so a dev exec build under another cargo selection rebuilds next time, #3013), the host’s cargo registry is reused, CRAIG_* variables pass through by name, and the host’s Docker daemon is passed through, so compose works inside too. For example: cargo xtask dev exec — cargo xtask dev sql craig_cases "SELECT 1".

  • Devstack verbs re-execute themselves there. Started on the host, cargo xtask e2e, perf, security, test --integration (with or without --package), verify-seed, fault-preflight, diag inbox-latency and diag pg-sample print =⇒ running … in craig-tools and run inside it. cargo xtask validate brings the stack up on the host (dev start), and its battery, e2e and aux lines re-execute in craig-tools the same way. The operator tools that dial the stack (reconcile, rules-*, backpay, seed-admin-units, the backfills) default to container addresses: run them through dev exec. cargo xtask test --unit runs its --lib tests in craig-tools too, off the stack’s network, from dev start’s one compile (dev start compiles once (plan ci-dev-loop D1, #3044)); `cargo xtask test with no lane flag, clippy and the doc gates stay on the host.

  • A browser uses the dev profile. cargo xtask dev start --profile dev layers docker-compose.dev.yml, which publishes Keycloak on http://localhost:8180, craig-web on http://localhost:8080, craig-portal on http://localhost:8081, craig-intake on http://localhost:8008 and the SHINES intake on http://localhost:8011, all on loopback, and switches the issuer and the two BFF redirect URIs to those localhost URLs so a host browser can log in. Every later cargo xtask dev … keeps the profile while the running stack carries it; a plain cargo xtask dev start converges back to no host ports. Under the profile cargo xtask e2e refuses (its in-network browser cannot reach localhost:8180); the nextest battery still runs (dev exec hands it the profile’s issuer).

  • One stack per checkout. The compose project name is the checkout directory’s normalized name plus the first eight hex digits of the SHA-256 of its canonical path (cargo xtask dev project prints it, e.g. craig-1a2b3c4d). A worktree therefore names its own stack, and with no host ports two stacks run side by side.

One-time teardown after #2922

The primary checkout’s stack used to be the compose project craig. xtask no longer knows that name, so retire the old stack once, from the checkout: docker compose -p craig --profile fault down -v --remove-orphans, then cargo xtask dev start. The seed recreates the data.

Linux + mold linker

The mold linker (-fuse-ld=mold) is several times faster than the platform-default ld.bfd on this 66-crate workspace, which matters most on the link-time tail of every incremental cargo build/check/test. It is an optional local speedup, not a requirement: .cargo/config.toml deliberately commits no target.*.rustflags for it.

Leaving it uncommitted is a deliberate choice (#1371, from the MR !1310 review), not an oversight. Cargo picks ONE rustflags source, first found wins: CARGO_ENCODED_RUSTFLAGS, then RUSTFLAGS, then target.<triple>.rustflags, then build.rustflags. But when the same array key appears in multiple config files, the values join rather than replace, and higher-precedence entries land last. A committed target.<triple>.rustflags = […​-fuse-ld=mold] therefore could not be cleanly reverted by a personal ~/.cargo/config.toml override: the project’s entry would always land last in the merged array, and because the linker driver honours the last -fuse-ld flag it sees, mold would win no matter what a personal config tried to set. Committing the flag would have made mold a de facto mandate for every Linux machine, with no working opt-out.

Opt in locally

Add it to your own (gitignored, outside the repo) ~/.cargo/config.toml:

# Debian/Ubuntu
sudo apt install mold

# Arch
sudo pacman -S mold

# Fedora
sudo dnf install mold
# ~/.cargo/config.toml
[target.x86_64-unknown-linux-gnu]
rustflags = ["-C", "link-arg=-fuse-ld=mold"]

[target.aarch64-unknown-linux-gnu]
rustflags = ["-C", "link-arg=-fuse-ld=mold"]

This works cleanly (unlike the reverse case above) precisely because the project contributes no rustflags of its own to join with: your personal config is the only source. Add the musl triples too if you cross-build for Alpine targets locally.

Alternatively, per-invocation via the env var (which replaces config rustflags wholesale rather than joining):

RUSTFLAGS="-C link-arg=-fuse-ld=mold" cargo build

Docker: always on

The devstack’s one musl compile (dev start compiles once (plan ci-dev-loop D1, #3044)) runs in craig-tools and links with the toolchain’s own rust-lld, which linked the workspace faster than mold there (#3044). The Alpine/musl Docker builder stage (Dockerfile), which builds the release images, forces mold unconditionally: apk add mold plus ENV RUSTFLAGS="-C link-arg=-fuse-ld=mold" on the shared chef base stage, so both the cargo chef cook layer and the final build see identical rustflags (a mismatch would invalidate the ADR-039 dependency cache). No local install or opt-in is needed to build images. This is also where the win matters most: CI on RUNNER_SMALL was the original out-of-memory pressure that motivated #1371.

Debug info in local builds

The workspace Cargo.toml sets how much debug info a local build carries (#3209). A test executable links every crate it uses, so with full debug info most of each one was debug sections.

  • A test build (cargo test, cargo nextest run, the pre-push unit lane) has line tables only for workspace crates: a failing test’s backtrace keeps file and line for workspace code. The repository sets this, so it holds whatever a developer’s own cargo configuration gives the dev profile.

  • Dependencies have no debug info in dev, test or devstack builds. A backtrace still names their functions.

  • cargo build and cargo run leave workspace crates at the dev profile’s setting: cargo’s default, full debug info, unless the developer’s cargo configuration lowers it.

For a debugger session on a test, build it under the test-debug profile, which gives workspace crates full debug info again: cargo nextest run --cargo-profile test-debug -p <crate> <filter>, or cargo test --profile test-debug. It builds into its own directory, target/test-debug.

Keeping target/ in check

Nothing collects stale build artifacts (#3210). Every state of every branch leaves its own hashed files in a deps directory, and cargo never removes them; the devstack compile also keeps incremental state. On the build host target/ reached 284 GB about a day and a half after a clean that had left it at 141 GB (2026-12-02), most of it in three places:

Directory Size What it is

target/debug

68 GB

the host’s unit-lane and clippy artifacts

target/craig-tools/x86_64-unknown-linux-musl/devstack/deps

101 GB

the devstack compile’s artifacts

target/craig-tools/x86_64-unknown-linux-musl/devstack/incremental

50 GB

the devstack compile’s incremental state

A full disk fails a build with an error that does not name the disk, so look at du -sh target and df -h . from time to time and clean well before the disk fills. Each step below costs only the next build, and none touches the devstack’s data. Run them when no build and no cargo xtask dev command is running.

cargo clean --profile dev                                                # the host's artifacts (target/debug)
rm -rf target/craig-tools/x86_64-unknown-linux-musl/devstack/incremental # the devstack compile's incremental state
rm -rf target/craig-tools/x86_64-unknown-linux-musl/devstack             # all of the devstack compile's artifacts

Measured on the build host: the first two brought 284 GB to 168 GB, and the third to 66 GB. The next pre-push battery (cargo xtask validate --profile fast) then took three and a half minutes and the next cargo xtask dev start six, after which target/ was 112 GB: the two builds need about 50 GB between them. The second line alone keeps the compiled dependencies, so only the workspace crates are compiled again.

cargo clean with --profile devstack --target x86_64-unknown-linux-musl --target-dir target/craig-tools does not reach the devstack compile’s artifacts (a dry run reports 3 GB of about 150), which is why the last two lines name the directories.

Running Locally

  • Start/rebuild all containers: cargo xtask dev reload (builds images, starts containers, initializes Garage, waits for health)

  • Restart services only (no rebuild): cargo xtask dev restart

  • Smart minimum rebuild: cargo xtask dev refresh (reads SHA-256 markers; rebuilds only what changed)

  • Read one devstack table for diagnosis: cargo xtask dev sql <database> "<statement>" (#1874). It runs ONE SELECT / WITH … SELECT / EXPLAIN through the devstack postgres container’s psql and prints the rows, e.g. cargo xtask dev sql craig_exchange "SELECT status, last_error FROM exchange_send_jobs ORDER BY created_at DESC LIMIT 5". It never writes. The statement is classified before docker runs, its strings, comments and quote continuations (E'…' continued across lines keeps its backslash escapes) read as postgres’s lexer reads them: a second statement, a write or lock word (INSERT, UPDATE, DELETE, MERGE, INTO, SHARE, CREATE, EXECUTE, DECLARE), or a backend-signal or advisory-lock function is refused with the reason. The session is read-only (default_transaction_read_only=on; refusing a chained second statement is what keeps a SET …; COMMIT from lifting it), and it connects as the database’s runtime role craig_<svc>_app, which is no superuser and runs no DDL. The database must be one of the stateful-service registry’s (an unknown name lists them). An unquoted column named like a write word must be double-quoted. A statement that starts with - (e.g. a leading -- comment) goes after a -- separator: cargo xtask dev sql <database> — "<statement>". Devstack only: there is no production equivalent.

  • Reproduce inbox commit latency: cargo xtask diag inbox-latency (#2699) drives envelopes through the inbox attempt machine on scratch databases on the durable devstack Postgres and writes a report to test-results/diag/. Never during a battery; see Diagnostics: inbox latency probe.

  • Sample the durable Postgres beside a battery: cargo xtask diag pg-sample (#2699) records WAL positions, wait events, the WAL, checkpointer and database statistics and host pressure every 250 ms to test-results/diag/, until SIGINT or SIGTERM; cargo xtask diag pg-sample-report <file> lists its stall candidates with the battery’s overlapping tests. It runs alongside a battery, never as part of it; see Diagnostics: durable Postgres sampler.

  • Run E2E tests: cargo xtask e2e (checks health, starts if needed, rebuilds Playwright container, runs tests). Since #937 the craig-e2e container runs as the checkout’s owner on Unix (xtask derives CRAIG_E2E_UID/GID from the workspace root) and as 1000:1000 on Windows (#2820; Docker Desktop maps container writes back to the host user), so SCREENSHOTS=1 and --update-snapshots regenerate the tracked LFS baselines owned like the rest of the worktree — no more root-owned files blocking git checkout. Root-owned leftovers from earlier runs on Unix are reclaimed once, automatically, on the next cargo xtask e2e (a chown through the e2e image as root, only when such entries exist).

  • Commands are idempotent: safe to re-run at any time

Never invoke docker compose …​ directly to bring up, rebuild, or restart devstack services; always go through cargo xtask dev …​. The dev subcommands pass compose the checkout’s project name and its layered files (docker-compose.yml, plus docker-compose.dev.yml under the dev profile); a bare docker compose names a different project (the directory name) and drops the profile. Use dev reload (whole stack, always correct), dev restart-service <name> (fast, but does not pick up new images), dev reseed (wipe data and recreate with cached images), or dev start (cold start) instead.

Read-only docker commands (docker logs, docker exec, docker ps, docker port) are fine; they do not mutate compose state.

Bring-up retries

The stack publishes no host port, so a bring-up never collides with a host listener. Image builds the devstack runs carry no provenance or SBOM attestation (--provenance=false --sbom=false, and BUILDX_NO_DEFAULT_ATTESTATIONS=1 on compose), so an unchanged image keeps its ID and up recreates nothing for it. A container that vanishes between compose’s listing and its recreate (No such container: <id>) tears nothing down: the same up re-runs, volumes kept, up to five attempts (#2170). Any other failure that is not a dependency still settling (#1799) is terminal: it is printed as-is, with a note that the stack may be left half-recreated and that cargo xtask dev start re-runs the converge once the cause is fixed (cargo xtask dev reload if it reports the stack current).

When to use reload vs restart vs refresh

dev refresh (Plan K F-043 / Step 4) is the daily-driver third lifecycle command, alongside reload and restart. It reads the same .devstack/*.sha256 markers that dev start writes, works out what actually changed, and dispatches the cheapest compose action that covers the drift. reload and restart stay available as escape hatches.

Situation Command Why

I edited source (.rs, .toml, .html, .ftl, .json, .sql, .js, .css) in services/, crates/, tools/ or plugins/

dev refresh

Cached rebuild of changed images only. An edit no image compiles marks nothing stale (#2679): a package’s tests/, benches/ or examples/, or a package outside every image’s dependency closure (NON_IMAGE_PACKAGES in xtask/src/devstack_guard.rs: craig-test-lib, craig-cli, craig-intake-sdk, craig-policy, craig-partner-test-harness; a contract test keeps the list exact)

I edited static assets (crates/craig-bff/static/, services/craig-web/static/, services/craig-intake/static/)

dev refresh

Cached rebuild; baked into image via Dockerfile COPY

I changed Cargo.toml / Cargo.lock

dev refresh

Cached rebuild; the cargo cache mounts are kept, so cargo recompiles only what the change moved (#2136)

I changed Dockerfile

dev refresh

Cached rebuild; the cargo cache mounts are emptied first only when the builder environment (the chef stage builder inherits) changed (#2136)

I changed docker-compose.yml or devstack/ configs

dev refresh

Cached rebuild + compose down first (forces re-create)

I added a new migration .sql (no edits to existing)

dev refresh

Cached rebuild (the service’s build.rs recompiles it, #2220); new migration applies on startup

I edited or deleted an existing migration .sql

dev refresh

Wipes volumes + rebuilds + reseeds (destructive migration)

I bumped a pin in config-sources.lock (and ran cargo xtask config env, #3143)

dev refresh

Cached rebuild; the recreated config fetch and seed one-shots re-run against the new commits and the convergent rules phase creates/updates rule sets in place (#1118 — no data wipe)

I changed tools/craig-seed/src/, tests/fixtures/ or devstack/seed/seed.sh only

dev refresh

Triggers dev reseed (data wipe + seed) under the hood; a generator or seed.sh edit rebuilds the images first; a fixtures-only edit is the reseed alone (#2072)

I changed a crate the seed generator links, an AFCARS ruleset it compiles in, or CRAIG_FAMILIES / CRAIG_SEED / CRAIG_SCENARIOS

dev refresh

Cached rebuild, plus the reseed only when the rendered seed identity moved (#2376)

Nothing changed; I just want to check state

dev refresh

Reports "already up to date"; no Docker action

The .devstack/ markers are gone (a failed reseed/converge left them cleared, dev clean ran, or a concurrent cargo xtask dev run clobbered them)

dev refresh

Prints a [refresh] WARN, then a conservative cached rebuild of all services — data volumes preserved, no reseed, no port churn — and rewrites the markers so the next refresh is incremental again

I want to force a full rebuild regardless of markers

dev reload

Cached compose down + compose up --build

I want a clean slate (wipe data AND images)

dev restart

Full teardown + cold no-cache rebuild

I only want to restart one service

dev restart-service <name>

compose restart <svc> + health-wait

Every lifecycle verb that converges the stack rewrites the markers: dev start, dev refresh, dev reload, dev restart, and dev reseed. The blessing lives in bring_up’s success arm, after the health wait and seed verification, so a written marker always describes the running stack (#1405). `dev status shows what refresh would do without acting, and dev start --force bypasses the staleness check entirely. When the markers are absent, dev refresh no longer aborts (#955); it degrades to the conservative cached rebuild described above rather than forcing you back to a heavyweight dev start, which would reseed and churn the allocated ports. The fingerprints a marker records are captured BEFORE the image build they describe (#1726): an edit you save while a build is running is not in the image, and the marker says so — the next dev refresh reports source code changed and rebuilds. The capture prints a Fingerprinted the source tree line; anything saved after that line is not in this build.

A converge up recreates only the containers whose image or configuration changed. When it recreates RabbitMQ (its image was rebuilt to a new ID) but not a service whose image did not move, that service’s publisher channel dies with the old broker and lapin never re-creates it. Since #2826 the service then fails fast (ADR-061): its mq-publisher-channel monitor dies, the process exits nonzero, and the devstack’s restart: "no" keeps it down. Before #2826 it kept running unhealthy, and compose never restarts a running dependent, so compose failed everything that waits on it. Both converge up`s (`bring_up’s, which every `dev start/reload/restart/reseed runs, and dev refresh’s) therefore check, once the `up has succeeded or has failed on an unhealthy dependency: every running service with a depends_on: rabbitmq edge that started before the running broker is stopped, and the same up runs once more, so compose starts it again behind its healthy-broker gate. The log names the services it stops (#1892). A service that has already exited while the broker runs (it failed fast before the check) is named too, and the same re-run starts it; the check also runs when the up failed because such a service exited while a dependent waited (compose reports dependency failed to start: container <name> exited (1), reading exit state before health); if one is still down after the converge, cargo xtask dev restart-service <name> starts it. The check compares start times, so a stack an earlier failed converge left with an unhealthy service and created dependents heals on the next dev refresh or dev start. Source: xtask/src/devstack_broker.rs.

Source: xtask/src/devstack_guard.rs::auto_refresh (refresh dispatch), xtask/src/devstack.rs::ensure_ready (start dispatch).

Seed integrity works in two layers. First, cargo xtask dev start/refresh (and the pre-push validate battery) poll the craig-seed one-shot to a clean exit; the check is state-aware, so a still-running seed is never misread as success. Second, the battery runs cargo xtask verify-seed --expect keyed to assert the seeded PII is genuinely encrypted at rest. The devstack has run field encryption end-to-end since epic &66 C7: the devstack/field-key.env key is mounted into craig-cases and craig-seed (only those two), both with ENCRYPTION_MODE: required. Since #2138 a second key, devstack/reporting-field-key.env, is mounted into craig-reporting only (also required); it is never the cases key. A key change or a missing .devstack/field-key.kcv marker forces the full-volume wipe and keyed reseed automatically, and since ADR-064 the key itself is adopted from the repo-committed encrypted store for recipients, so a committed rotation drives the same wipe-and-reseed on the next mutating command. See the quality-gates "Field-encryption seed verification gate" for the gate detail and how to run verify-seed manually.

A field-scheme change keeps the same posture (#1399, plan field-scheme-rewrite D8): the devstack never runs the craig-cases rewrite-scheme process mode against the seeded volume — a scheme flip is a jurisdiction flip (a bundle’s search_schemes() declaration, ADR-049), and the seed identity would strand the next dev start — so a change of the config layers the stack is seeded from is the same full-volume wipe + keyed reseed (the config-layers marker, #1025), and cargo xtask rewrite-scheme rehearses the tool’s round trip (GA → the Texas layer’s Opaque declaration → GA, the migrate gate + verify-seed --expect keyed after each) on a throwaway craig_cases_rehearsal clone instead, stopping craig-cases for the TEMPLATE copy and restoring it — and dropping the clone — under a guard on every exit path; both directions run the cases image the devstack runs (#2268). The verb is described in the CLI reference.

Multi-backend identity stack (Authentik + ZITADEL + Kanidm)

Opt-in stack for the IdP-neutral integration tests: Authentik 2026.2.2 + ZITADEL 4.15.0 + Kanidm 1.11.2 + a Redis dep + their own postgres. Default cargo xtask dev start is unchanged — these containers are heavy and only needed when verifying the cargo xtask identity render output against real backends.

Since #1415 the stack is the separate fixed compose project craigidp (docker-compose.idp.yml), with its own lifecycle:

  • the battery-managed devstack’s down -v --remove-orphans (reseed, refresh escalations, cargo xtask e2e) can never wipe IdP databases or remove the IdP containers again — the IdPs stay running through battery cycles, which is what the 120 s multibackend probes need;

  • it binds its compose defaults (Authentik 9000/9443, ZITADEL 8089, Kanidm 8443/3636, Redis 6379), not a devstack-block port: cargo xtask dev start knows nothing of it, so the multibackend probes dial those defaults unless you export a CRAIG_PORT_<SERVICE>_<PORT> override for both the project and the tests (#2597);

  • multibackend-down removes the containers but keeps the state volumes (craigidp_idp-postgres-data, craigidp_kanidm-data); the next multibackend-up comes back with data intact and no ~90 s Authentik blueprint re-apply surprise;

  • a full wipe is a deliberate act: docker compose -f docker-compose.idp.yml down -v, then re-run the bootstraps (zitadel-bootstrap, kanidm-bootstrap) because the host-side secrets files (devstack/zitadel-secrets.env, devstack/kanidm-secrets.env, devstack/zitadel-bootstrap/firstinstance-pat.txt) go stale against a re-inited IdP.

Migration from the pre-#1415 shape (IdP state inside the shared devstack postgres): nothing to move — the old databases were wiped by every battery reseed anyway, so there is no live state worth carrying. Run cargo xtask dev multibackend-up once (fresh craigidp volumes; its postgres creates the authentik/zitadel DBs from devstack/idp-postgres-init.sql), then re-run both bootstraps to regenerate the secrets files.

cargo xtask dev multibackend-up
# first boot only: wait ~90s for Authentik's blueprint apply (ZITADEL ~30s)
cargo xtask dev zitadel-bootstrap
cargo xtask dev kanidm-bootstrap
cargo nextest run -p craig-test-lib --profile identity-multibackend --run-ignored only
cargo xtask dev multibackend-down   # state kept

Per coding-conventions.md § Docker & DevStack, always activate through cargo xtask dev — never invoke docker compose on the file directly (the wipe command above is the one sanctioned exception). See docs/modules/ROOT/pages/plans/archive/idp-multibackend-tests.adoc for the plan + devstack/authentik/README.md + devstack/zitadel/README.md for backend-specific notes (Authentik applies a declarative blueprint at boot; ZITADEL requires a one-time operator-side Terraform apply with a PAT extracted from the Console).

One stack per checkout

Each checkout names its own compose project from its path (A host-free devstack: no host ports, dev exec, the dev profile), so a git worktree or a second clone runs its own stack when asked, side by side with the primary one: nothing is published, so nothing collides. The devstack-starting entry points — cargo xtask dev start|reseed|reload|restart|refresh, cargo xtask validate without --skip-devstack, cargo xtask e2e — refuse only an exported COMPOSE_PROJECT_NAME, which would make compose and xtask name the stack differently (#1636). Each stack costs a full set of containers and volumes, so retire a worktree’s with cargo xtask dev clean --confirm from that worktree.

One battery per devstack, too (#2361): two batteries on one stack share its databases, queues and fault records and read each other’s writes. A cargo xtask validate without --skip-devstack therefore takes an exclusive lease at start, an OS file lock (flock) on target/xtask-state/<project>-battery.lease beside the lifecycle lock, and holds it to the end. Both live under the checkout, so a host validate and the battery it hands to craig-tools (the checkout is mounted at the same path) see the same files. A second battery refuses at once, naming the holder’s PID, start time and branch; it never waits. The kernel drops the lock when its holder exits, however it exits (SIGKILL included), so a dead holder never blocks: the next battery takes the lock, prints [lease] reclaimed a stale battery lease (…) with the line the dead holder left, and overwrites it. A clean exit clears the line. Source: xtask/src/battery_lease.rs.

The lifecycle verbs are profile-complete since #1636: dev stop, dev clean and dev reseed’s wipe take the `fault sidecar (Toxiproxy) down with the stack, every bring-up carries the profile so --remove-orphans never evicts it, and dev status lists it under "Profile sidecars" — you never need docker ps.

Devstack Staleness Guard

cargo xtask dev start and dev status run a staleness check backed by SHA-256 marker files in .devstack/ (gitignored). The guard hashes inputs at several granularities and picks the minimum rebuild action needed:

Category Paths hashed Action on change

Source code

services/, crates/, tools/, plugins/ (.rs, .toml, .html, .ftl, .json, .sql, .js, .css)

Cached rebuild

Dependencies

Cargo.toml, Cargo.lock

Cached rebuild; cargo cache mounts kept (#2136)

Dockerfile

Dockerfile

Cached rebuild; the cargo cache mounts are emptied first only when the builder environment changed since they were filled (.devstack/builder_env.sha256, #2136)

Compose config

docker-compose.yml

Cached rebuild + compose down

Infrastructure

devstack/

Cached rebuild + compose down

Config pins

config-sources.lock

Cached rebuild; the config fetch and seed re-run, and the seed converges the rules phase (no wipe, #1118)

Static assets

crates/craig-bff/static/, services/craig-web/static/, services/craig-intake/static/

Cached rebuild

Migrations (additive)

new .sql files

Cached rebuild (the service’s build.rs recompiles it, #2220; applied on start)

Migrations (refuse-on-data)

a new .sql whose header carries -- devstack: wipe-before-apply — <reason>

Volume wipe + reseed BEFORE the migration gates start

Migrations (destructive)

modified/deleted .sql

Volume wipe + reseed

Seed

tools/craig-seed/src/, tests/fixtures/, devstack/seed/seed.sh

Reseed (a generator or seed.sh edit also matches Source code / Infrastructure: cached rebuild, then the reseed)

Seed identity

the identity the host-built craig-seed renders for the seed’s compose env vs .devstack/seed-identity (absent or changed; #2376)

Cached rebuild + reseed

Field-encryption key

devstack/field-key.env KCV vs .devstack/field-key.kcv (absent or changed)

Volume wipe + keyed reseed

Reporting field-encryption key

devstack/reporting-field-key.env KCV vs .devstack/reporting-field-key.kcv (absent or changed; #2138)

Volume wipe + keyed reseed

Seeded config layers

the names of the layers the stack is seeded from (federal,georgia) vs .devstack/config-layers (absent or changed; #1025). Names only: a pin bump is the Config pins row

Volume wipe + reseed

Ciphertext envelope format

the linked craig_crypto::FORMAT_VERSION (v2 since #1007 MR-1) vs .devstack/envelope-format (absent or changed)

Volume wipe + keyed reseed

Committed secrets store

secrets/dev.yaml key SET vs the local key files (ADR-064; store v2 since #2138; consulted BEFORE this table)

Adoption: teardown → publish the new keys → cold start + reseed

The envelope-format marker is the wipe-before-start class for a ciphertext format bump (#1007): a rebuilt image linking a new format cannot read the seeded cells, so the guard wipes the volumes BEFORE the image starts instead of letting craig-cases refuse boot against them. Landing the marker itself costs ONE wipe + keyed reseed per existing stack (the same self-binding as the config-layers marker); the format bump that follows costs a second. dev status prints the blessed vs linked format. The whole-.devstack/-absent cold start is unchanged (no staleness arm runs — see the keyed-devstack entry in Known Issues & Lessons Learned).

The -- devstack: wipe-before-apply — <reason> header annotation (#648) is the wipe-before-start class for a refuse-on-data migration — one whose DO $$ … RAISE EXCEPTION guard refuses to run against populated tables because the rows cannot be rewritten without a policy guess (the 20260828120000 DOB shape). A plain new migration is only a cached rebuild, and dev refresh starts the ADR-063 migration gates and waits for health BEFORE its reseed step, so such a guard would abort the refresh in a loop it can never leave. When the guard sees the annotation on a migration file that is NEW relative to the blessed manifest (within the first 20 lines; the reason is surfaced verbatim by dev status), it escalates dev start and dev refresh to the volume wipe + reseed before any gate runs; an annotation with no reason still wipes (the safe direction for a devstack) and says so. Use it on every refuse-on-data migration, alongside the guard’s own remedy text — cargo xtask dev reseed remains the explicit remedy for a stack whose markers are absent or already blessed. Once the manifest is blessed the annotation is inert (no repeated wipes).

Markers are (re)written by every lifecycle verb that converges the stack (dev start/reload/restart/reseed via bring_up’s success arm, `dev refresh via auto_refresh — #1405). Use cargo xtask dev status to see what would happen on the next dev start without acting. Use cargo xtask dev start --force to skip the staleness check and do a full rebuild. The values written are a snapshot taken before the build (#1726), so a marker never claims an edit made mid-build was built.

Devstack lifecycle logic lives in xtask/src/devstack.rs (bring_up, tear_down, reseed, wait_for_health, verify_seed, ensure_ready). Garage bootstrap is NOT an xtask concern: it runs as the in-graph garage-init compose one-shot (devstack/garage-init/, C4-gate #1012), which every docker compose up path executes before the gated seed. devstack_guard owns only the staleness detection and marker files. Non-CLI callers (pre-push validate, etc.) that need a ready devstack should call devstack::ensure_ready(false). The cargo xtask dev CLI in cmd::dev is a thin shell that dispatches into devstack::*.

Postgres data volume + seed idempotency (ADR-048 §D1/§D2)

Postgres persists in a named postgres-data volume (mounted at /var/lib/postgresql, the path postgres:18-alpine declares). A plain docker compose down && up KEEPS the data; only dev clean / dev reseed / dev restart (which pass down -v) wipe it.

One-time transition (pre-1.0 break). If your devstack predates this change, its data lives in the image’s anonymous volume. Run cargo xtask dev clean --confirm once before the next dev start to drop it cleanly. A bare dev start also works (it re-migrates and re-seeds onto the fresh named volume) but leaves the old anonymous volume dangling; reclaim that with docker volume prune. Note that dev clean, like every down -v path, clears the .devstack/ staleness markers but PRESERVES .devstack/snapshots/ (#1013), so your migrate snapshot pg_dump backups survive every lifecycle command. The wiped data volumes are a separate matter: restore a snapshot with cargo xtask migrate rollback after the reseed if you want the old data back.

Idempotent, fail-loud seed. The one-shot craig-seed container writes a per-database public._seed_marker (a content-fingerprint identity covering the generated SQL, the seed and family counts, the active seed scenario variants (#667), and the on-disk tests/fixtures/ and seed.sh) and runs psql under ON_ERROR_STOP. A re-run against a current fixture therefore skips cleanly, while a genuine SQL error or duplicate key fails loud instead of silently rolling back.

If you edit tools/craig-seed/src/, seed.sh, or tests/fixtures/, StalenessReport.seed flips to Reseed. Both dev start (via decide_action’s `StartAction::SeedOnlyReseed, #1374) and dev refresh (via auto_refresh) detect this and drive a tear_down(false) + bring_up reseed cycle themselves, wiping just the data volumes so the rebuilt seed image converges against a clean slate in one call; no manual cargo xtask dev reseed is needed. (Before #1374, dev start consulted only .volume and .rebuild, so seed-only drift reused the stale volume and craig-seed’s identity guard refused with "run cargo xtask dev reseed`", looping forever under `cargo xtask e2e’s start-and-retry fallback. `dev refresh consulted .seed but, when the same change also rebuilt images, ran a plain up before its reseed and hit the same refusal; since #2063 it builds the images, then reseeds, with no bring-up in between.)

The guard’s seed list is the generator’s source plus every on-disk path seed.sh hashes into the identity (tests/fixtures/ and seed.sh itself); a unit test derives the latter from seed.sh and the Dockerfile, so a path added to the EXTRA_FP block without joining the list fails the test (#2072). Everything else the identity hashes (the workspace crates the generator links, the two AFCARS documents it reads at start, the seed’s compose env CRAIG_FAMILIES, CRAIG_SEED and CRAIG_SCENARIOS, and the current month the subsidy history anchors on) is checked by rendering the identity itself (#2376): the guard builds craig-seed on the host in $CARGO_TARGET_DIR/seed-identity and runs it, keyless and without a database, for the env compose resolves for the one-shot, over the federal and Georgia layers of the fetched view target/config/layers/ as a working copy (#2955; the one-shot reads the same bytes from the verified trees in /config), then compares the result with the .devstack/seed-identity marker. A different identity is a reseed; an edit to a linked crate that leaves the seed unchanged stays a cached rebuild. The first build is cold (about 50 s, 1.8 GB on disk); after that a no-op build plus the render takes about a second, and an edit to craig-common about 4 s. dev status, dev start and dev refresh therefore fail, naming the cargo error, while craig-seed does not compile. A stack blessed before #2376 has no seed-identity marker and reseeds once.

The rule sets (the fetched config layers) are the exception (#1118). The rules phase carries its own fingerprint in the craig_rules rules marker and is convergent: the re-run creates or updates each rule set via the craig-rules API (JDM-validated, cache-swapped, change-notified) to the fixture’s (name, version), verifies a per-fixture receipt — (name, version) and canonical content through the craig-rules by-name API read, with the direct-DB rule_sets snapshot kept as an independent witness that re-reads and logs the row it holds on any disagreement — a snapshot-only miss whose re-read shows the active row at the wanted version is a logged WARNING: #1691, not a failure (#1691) — and only then rewrites its marker. A ruleset version bump therefore lands on dev refresh with no volume wipe. A rules-phase failure is fatal — the seed exits non-zero and the C4 gate refuses the stack — never a silently kept stale version.

Every local path that runs the seed checks its exit code: dev start/reload/reseed/restart and validate via bring_up, and dev refresh via auto_refresh. Since the C4 gate (#1012) the compose graph itself enforces the same thing declaratively: craig-web gates on craig-seed: service_completed_successfully, and the seed gates on the in-graph garage-init one-shot. So even a raw docker compose up — CI’s path, with no xtask involved — fails loud on a bad seed, and the seed’s attachment upload can never race an uninitialized bucket on a first start.

Source: xtask/src/devstack_guard.rs (guard — unit-tested per dimension), xtask/src/devstack.rs (lifecycle).

Storage layer (#1125, rescoped by #1148)

The devstack postgres runs with synchronous_commit on — the default, set explicitly in the command: list since 2026-09-19 and pinned by the main-instance durability test — plus modest shared-buffer and checkpoint easing (shared_buffers 512MB since #1952 — headroom for growth on an instance holding ~190 MiB, not a fix for anything measured; checkpoint_timeout 15 min, max_wal_size 2 GB). Since #2699 it also runs with track_wal_io_timing and track_io_timing on, so pg_stat_io times WAL and data-file I/O (PostgreSQL 18 reports WAL timing there, no longer in pg_stat_wal); the cost is a clock read around each timed write or fsync, and cargo xtask diag pg-sample records the result. This applies to the devstack and CI only; production deployments own their own postgres tuning. vacuum_truncate deliberately stays at its default (on) — the reasoning is recorded next to the knob in docker-compose.yml; the decision is re-measured after the host’s storage move below.

The history behind that default is worth knowing. #1125 originally set synchronous_commit=off after measuring one WAL fdatasync at 1.1 ms idle but 5,068 ms under concurrent I/O (k6 create_referral p95: 8 ms idle rising to 9.5 s loaded). The #1129 root-cause analysis then reframed that measurement: fsync on this box is ~718 µs/op even at load average 25 (pg_test_fsync, 2026-07-26), and the multi-second events are episodic host page-cache transients from co-tenant memory pressure, not a chronic function of load. #1148 restored the default: muting a durability semantic in a system-of-record test environment to absorb a minutes-per-day transient was the wrong trade, and it masked exactly the commit-path behavior the battery exists to observe. The transient class is absorbed where it belongs, in the e2e retry policy (retries: 1, unconditional since the #1129 analysis).

Connection ceiling (#1160): the devstack postgres also raises max_connections to 250. The stock 100 was under water for this stack — 8 services with pool size 10 each, around 14 detached advisory-lease sessions outside pool accounting, plus the api suites' live-DB read pools — which surfaced as 5-second acquire-timeout cliffs during the pre-push battery. Since #1403 the battery’s scratch-DB churn pools live on the dedicated postgres-test instance instead (with its own 150-connection floor). The full arithmetic is recorded next to the knob in docker-compose.yml; the floor is pinned by crates/craig-db/tests/connection_budget.rs, and the production sizing formula lives in the deployment guide’s "Database connection budget" section.

Optional host-side mitigation for btrfs boxes: Docker named volumes live under /var/lib/docker/volumes and inherit COW + compression, which amplifies database fsync cost. The standard exemption (the same technique commonly applied to build-artifact dirs like a cargo target/): make volumes/ a dedicated subvolume marked chattr +C (NoCOW — applies to newly created files only, so recreate volumes after flipping it; note NoCOW also disables btrfs data checksums for those files). This is a per-machine choice, not repo state. As of 2026-09-19 the maintainer’s dev box runs the Docker volumes on XFS on a dedicated volume instead of this chattr +C workaround (with byte-sized dirty-page limits on the host); the workaround stays documented for btrfs boxes that keep the volumes in place.

Healthchecks and resource limits (#1135): every devstack healthcheck carries a start_period (probes during it don’t count toward unhealthy) sized for build-saturated cold starts — keycloak’s is 120 s because --import-realm under concurrent image-build I/O routinely exceeds its JVM-boot window. Compose-level CPU/memory limits were considered and REJECTED for now: dev boxes vary too widely for one set of numbers, limits would slow the builds that share the box, and the async-commit change above removed the sensitivity that made contention visible. Revisit if healthcheck flakes return.

Secrets: the repo-committed encrypted store + the field-encryption key (ADR-064, ADR-048 §D5)

The devstack field-encryption keys — since #2138 a key SET of two, the cases key in devstack/field-key.env and the craig-reporting column key in devstack/reporting-field-key.env (store v2, ADR-064 § Amendment — #2138) — have TWO sources, resolved in this order on every mutating lifecycle command (dev start/reseed/refresh/reload/restart/restart-service, plus e2e’s and validate’s ensure_ready):

  1. The repo-committed encrypted store (secrets/dev.yaml, sops + age, policy in .sops.yaml) — for store recipients (maintainers + CI). If your age identity (~/.config/sops/age/keys.txt) decrypts the store, the store’s key SET is adopted into the gitignored devstack/field-key.env and devstack/reporting-field-key.env automatically, as one unit; if either store key CHANGES (a rotation commit), the next mutating command tears the stack down (volumes wiped FIRST), publishes the new keys atomically, and cold-starts + reseeds under them. A missing reporting file alone is materialized from the store without an adoption. Rotation is a git commit — no manual key handling.

  2. Generate-once fallback — for contributors WITHOUT an identity (positively classified: no keys.txt), and for identities in the joining window (not yet added as a recipient): each key is generated independently, once-if-absent, written atomically, hardened to 0600 (best-effort
    a warning on native Windows — use WSL2). An existing file is validated and reused, never re-keyed; symlinks and loose permissions are refused/repaired. Contributor devstacks are fully functional on this path — the store only ADDS shared-key semantics.

The key is live (epic &66 C7): compose env_file-mounts it into craig-cases + craig-seed — only those two — and both run ENCRYPTION_MODE: required; since #2138 the reporting key is env_file-mounted into craig-reporting only, also required, so every devstack seed and every cases write path is genuinely encrypted, and a missing key file fails docker compose up outright. At boot, craig-cases verifies the mounted key against the seeded data’s crypto_key_lineage anchor and refuses to start on a mismatch (ADR-048 §D3; the refusal names the remedy). The KCV fingerprint (never key material) rides .devstack/field-key.kcv, and the reporting key’s rides .devstack/reporting-field-key.kcv; an absent/changed KCV on either escalates to the volume wipe
keyed reseed, exactly as before.

One-time, after pulling #2138: the first cargo xtask dev start after U1 materializes the devstack/reporting-field-key.env file and wipes + reseeds once (the new reporting KCV marker is absent; the additive migration itself applies on start). Until then a raw docker compose … or cargo xtask dev stop fails to load the project, because the craig-reporting env_file is missing. cargo xtask dev status reports store drift and in-flight adoptions read-only (no docker/sops invocation).

Workflows

  • First run (recipient): nothing extra — the first dev start adopts the store key. If your identity is not yet a recipient, you get the fallback path plus the joining handoff below.

  • First run (contributor, no identity): nothing extra — generate-once, exactly as always.

  • Daily: nothing — the warm-path marker (.devstack/secrets-adoption.v2.json, both KCVs; a leftover v1 marker is a stale cache nothing reads) makes the check hash-cheap; sops runs only when the store or your key actually changed.

  • Joining (becoming a recipient): run cargo xtask secrets init and post the printed PUBLIC key; an existing recipient runs cargo xtask secrets add-recipient <age1…​> and commits. Until then your devstack uses the fallback key (and the seed data differs from store-keyed boxes — expected).

  • Leaving (revoking a recipient): another recipient runs cargo xtask secrets remove-recipient <age1…​> — this is REAL revocation: the store re-encrypts from scratch (fresh sops data key) AND both field-encryption key values rotate in the same pass. Git history remains readable to the removed identity forever (removal protects only future values). Self-removal is refused; the recipient floor is 3.

  • Rotating the secret: cargo xtask secrets edit → commit → any mutating devstack command consumes the transition (CI picks it up on its next pipeline via CRAIG_CI_AGE_KEY). A crash mid-adoption resumes from the root-level .craig-pending-adoption.v2.json record at the next mutating command.

  • Adding a store entry: cargo xtask secrets mint-missing mints every entry the store lacks (never re-mints a present one) → commit. New entries are minted, never typed.

  • Edit limits: secrets edit opens $EDITOR INSIDE the devtools container (terminal editors only — vi is the in-container fallback; GUI editors do not work). A no-change close is a clean no-op.

  • Forks: a fork can never rewrap the upstream store — run cargo xtask secrets fork-rebootstrap --force once and mint fork-own identities.

Hygiene

  • Never paste an AGE-SECRET-KEY-1…​ line into a shell command (argv + history leak) — the tooling only ever reads identities from files. Keep ~/.config/sops/age/ at 0700/0600.

  • CI logs never carry key material by design (the store tooling prints KCVs — HKDF-derived check values — and paths only); treat any plaintext key sighting in a log as an incident.

  • The dev identity is SHARED with canopy (keys.txt is one file) — compromise or rotation of that identity couples both projects (accepted threat model, ADR-064; ratified on #1031).

Source: xtask/src/field_key.rs (generate-once provisioning, hardened load), xtask/src/field_key_reconcile.rs (store adoption: warm marker, pending record, fail-closed matrix), xtask/src/devstack.rs::consume_store_transition (lifecycle wiring), xtask/src/cmd/secrets.rs (the operator command family), xtask/src/devstack_guard.rs (KCV staleness). Decision record: ADR-064.

Local DB snapshot/rollback (Plan K F-045)

cargo xtask migrate wraps pg_dump/pg_restore for the 8 stateful CRAIG service databases: craig_cases, craig_composition, craig_exchange, craig_financial, craig_placement, craig_reporting, craig_rules, and craig_security. The list derives from the ONE typed registry in xtask/src/registry.rs (since #1308, which also fixed craig_composition having been silently skipped); craig_intake is the stateless edge per ADR-017 and is excluded. The postgres binaries run inside the devstack postgres container via docker exec, so the host does not need a matching pg_dump installed. Since #1276 the same command family carries cargo xtask migrate apply [--service <name>], which builds and runs the ADR-063 one-shot migration gates with per-service reporting.

Subcommand What it does When to use

cargo xtask migrate snapshot

pg_dump -F c --no-owner --no-privileges of each DB into .devstack/snapshots/<UTC-timestamp>/. Writes manifest.json with git HEAD SHA + each DB’s latest _sqlx_migrations.version.

Before applying a risky/experimental migration locally.

cargo xtask migrate rollback [--id <ts>] [--db <name>…​] [--force]

pg_restore --clean --if-exists from the most recent snapshot (or --id <ts> for a specific one), connecting as the service’s MIGRATION-OWNER role (#1310 — with --no-owner, restored objects belong to the connecting role, so they keep the runtime role’s default-privilege DML grants and stay alterable by future gates). --db restores a subset. Bails if the live schema is ahead of the snapshot’s recorded _sqlx_migrations head (override with --force).

When a migration breaks something and you want your data back.

cargo xtask migrate list

Prints available snapshots: timestamp, entry count, total bytes, git short SHA, per-DB schema version.

Inventory between sessions.

Since #1310 the devstack runs the ADR-063 privilege boundary: each service database is owned by craig_<svc>_owner (which the migration gates connect as) while serving containers connect as craig_<svc>_app, which can run DML only — DDL refuses with error 42501. devstack/postgres/init.sql provisions the 16 roles on a FRESH data directory only, so upgrading an existing devstack across #1310 requires cargo xtask dev reseed. The craig superuser stays the devstack admin principal for the seed, the test-plane scratch/template databases, and xtask tooling.

The schema-version-ahead bail (Plan K cross-cutting invariant #4) catches the silent-corruption case where the local devstack has applied a migration after the snapshot was taken — restoring older data against a newer schema can violate freshly-added CHECK constraints or NOT-NULL columns. --force overrides for the "I know my migration just broke and want the old data back" case; the operator owns the consequences.

Snapshots live under .devstack/snapshots/ (gitignored) and SURVIVE dev clean/reseed/restart (#1013: clear_markers preserves the snapshots/ subdirectory while clearing the staleness markers around it). pg_dump/pg_restore invocations are gated by the same exclusive xtask lock as dev start/dev reload/etc., so a concurrent rebuild can’t race a snapshot.

Source: xtask/src/cmd/migrate.rs (port of canopy xtask/src/cmd/migrate.rs, with single-shared-postgres adaptation + CRAIG-side schema-version invariant; 11 unit tests).

Container Management

Bring-up retries (a host-port collision, a container gone mid-recreate, #2170) and the half-recreated-stack recovery are described in [Host port allocation and collisions].

Infrastructure Services

Service Image Ports Healthcheck

postgres

postgres:18-alpine (custom Dockerfile)

5432

pg_isready -U craig

rabbitmq

rabbitmq:4.2-management-alpine (custom)

5672, 15672

bash /dev/tcp: Prometheus GET /metrics 200 + the AMQP acceptor bound (#1799 — never a RabbitMQ CLI: each boots an Erlang VM)

keycloak

quay.io/keycloak/keycloak:26.5 (custom)

8080 (container; localhost:8180 under the dev profile)

HTTP GET /realms/craig

garage

dxflrs/garage:v2.2.0 (custom)

3900 (S3), 3903 (Admin)

/garage status

Devstack image run-as users (#1646)

The #1646 audit (2026-09-03) of every non-CRAIG image the devstack runs, keyed to the run-as user the upstream image establishes. Each row cites the source actually read (the vendor Dockerfile at the pinned tag, or the entrypoint script where the drop happens at runtime). Each CRAIG overlay (devstack/*/Dockerfile) carries the same attestation as an inherits-user <user> <source URL> (or root-residue <reason>) marker; the dockerfile-hygiene lint checks the marker’s PRESENCE, that a source URL is given, and that the declared user is not root — the fact itself is the cited vendor source in this table (quality-gates § Dockerfile hygiene gate). "Compose posture" is what docker-compose.yml / docker-compose.idp.yml add on top (user: / cap_drop / read_only). "ps" marks rows confirmed host-side with ps -eo user,uid,comm,args against the running stack on 2026-09-03; the IdP overlay was not running on the audit box, so its rows rest on the sources alone.

Service (file / profile) Image Upstream default user — source Compose posture Volumes Verdict

postgres, postgres-test (docker-compose.yml)

postgres:18-alpine via devstack/postgres/Dockerfile

No image USER. The entrypoint starts as root, chown`s `$PGDATA, then exec gosu postgres; the user is adduser -u 70 … postgres — https://github.com/docker-library/postgres/blob/master/18/alpine3.23/Dockerfile and docker-entrypoint.sh beside it (the 18-alpine tag floats across the 18/alpine3.* variants; uid 70 in each)

none

postgres-data:/var/lib/postgresql (postgres-test: tmpfs)

non-root by upstream entrypoint drop (ps: uid 70)

rabbitmq (docker-compose.yml)

rabbitmq:4.2.9-management-alpine@sha256:b774118f… via devstack/rabbitmq/Dockerfile

No image USER. The entrypoint, when uid 0 and $1 is rabbitmq*, chown`s `/var/lib/rabbitmq and exec su-exec rabbitmq; the alpine variant creates adduser -u 100 … rabbitmq (the Debian variant’s 999 does NOT apply) — https://github.com/docker-library/rabbitmq/blob/master/4.2/alpine/Dockerfile and docker-entrypoint.sh beside it

none

none (pinned volume-less by devstack_guard)

non-root by upstream entrypoint drop (ps: uid 100)

keycloak (docker-compose.yml)

quay.io/keycloak/keycloak:26.5 via devstack/keycloak/Dockerfile

USER 1000 (keycloak:x:1000:0, /opt/keycloak chowned 1000:0) — https://github.com/keycloak/keycloak/blob/26.5.0/quarkus/container/Dockerfile

none

none

non-root by default (ps: uid 1000)

garage (docker-compose.yml)

dxflrs/garage:v2.2.0 via devstack/garage/Dockerfile

FROM scratch, no USER, CMD ["/garage", "server"], and NO pre-created /var/lib/garage/{meta,data} in the image — https://git.deuxfleurs.fr/Deuxfleurs/garage/src/tag/v2.2.0/Dockerfile

the overlay bakes /var/lib/garage/{meta,data} at uid 10001 (COPY --from=builder --chown) and sets USER 10001:10001 (#1653)

garage-meta:/var/lib/garage/meta, garage-data:/var/lib/garage/data — fresh volumes inherit the baked ownership

non-root (ps: uid 10001)

garage-init (docker-compose.yml, one-shot)

alpine:3.23 + curl/jq — CRAIG-authored devstack/garage-init/Dockerfile

alpine sets no USER (FROM scratch + minirootfs + CMD ["/bin/sh"]) — https://github.com/alpinelinux/docker-alpine/blob/v3.23/x86_64/Dockerfile. Our Dockerfile now adds adduser -D -u 10001 craig + USER craig (#1646; it was root before)

none

none

non-root by CRAIG Dockerfile (ps: uid 10001, proof below)

toxiproxy (docker-compose.yml, profile fault)

ghcr.io/shopify/toxiproxy@sha256:9378ed5… (2.12.0)

FROM scratch, no USER (root by default) — https://github.com/Shopify/toxiproxy/blob/v2.12.0/Dockerfile

user: 65534:65534, read_only: true, cap_drop: [ALL], no-new-privileges, CPU/memory caps

none

non-root by compose (ps: nobody/65534)

jaeger (docker-compose.yml, profile observability)

jaegertracing/jaeger:2.17.0

USER ${USER_UID} with ARG USER_UID=10001 — https://github.com/jaegertracing/jaeger/blob/v2.17.0/cmd/jaeger/Dockerfile

none

none (image VOLUME /tmp, anonymous)

non-root by default

prometheus (docker-compose.yml, profile observability)

prom/prometheus:v2.53.0

USER nobody (65534) after chown -R nobody:nobody /etc/prometheus /prometheus — https://github.com/prometheus/prometheus/blob/v2.53.0/Dockerfile

none

bind ./devstack/prometheus/prometheus.yml:ro; image VOLUME /prometheus, anonymous

non-root by default

grafana (docker-compose.yml, profile observability)

grafana/grafana:11.1.0

USER "$GF_UID" with ARG GF_UID="472" (GF_GID="0") — https://github.com/grafana/grafana/blob/v11.1.0/Dockerfile

none

bind ./devstack/grafana/provisioning:ro

non-root by default

craig-e2e (docker-compose.yml, profile e2e)

tests/e2e/Dockerfile (Playwright base) — CRAIG-authored

not audited here (not an infra image)

user: ${CRAIG_E2E_UID:-1000}:${CRAIG_E2E_GID:-1000} (#937)

bind mounts of the checkout

non-root by compose (#937)

idp-postgres (docker-compose.idp.yml)

postgres:18-alpine (raw, no overlay)

as the postgres row

none

idp-postgres-data:/var/lib/postgresql; bind idp-postgres-init.sql:ro

non-root by upstream entrypoint drop

redis (docker-compose.idp.yml)

redis:7-alpine

No image USER; adduser -u 999 redis. The entrypoint drops ONLY when $1 = redis-server and uid 0 (find . ! -user redis -exec chown … then exec gosu redis); compose sets no command:, so the image’s default redis-server applies and the drop happens — https://github.com/docker-library/redis/blob/master/7.4/alpine/Dockerfile and docker-entrypoint.sh beside it (the 7-alpine tag resolves to the 7.4/alpine directory)

none

none (image VOLUME /data, anonymous)

non-root by upstream entrypoint drop

authentik-server, authentik-worker (docker-compose.idp.yml)

ghcr.io/goauthentik/server:2026.2.2

adduser --system --uid 1000 … authentik, chown authentik of /data, /media, /certs, then USER 1000 (image also ships a HEALTHCHECK) — https://github.com/goauthentik/authentik/blob/version/2026.2.2/lifecycle/container/Dockerfile (the Dockerfile moved off the repo root; this is the server image’s)

none

bind ./devstack/authentik/blueprints:ro

non-root by default

zitadel (docker-compose.idp.yml)

ghcr.io/zitadel/zitadel:v4.15.0

useradd -s "" --home / zitadel on the Debian builder (uid allocated by useradd, not pinned), /etc/passwd copied into the FROM scratch final stage, USER zitadel, HEALTHCHECK NONE — https://github.com/zitadel/zitadel/blob/v4.15.0/apps/api/Dockerfile

none

bind ./devstack/zitadel-bootstrap (host dir pre-chmodded world-writable for exactly this non-root uid)

non-root by default

kanidm (docker-compose.idp.yml)

kanidm/server:1.11.2

FROM scratch, no USER, WORKDIR /data, CMD ["/sbin/kanidmd", "server"] — https://github.com/kanidm/kanidm/blob/v1.11.2/server/Dockerfile (the Kanidm book makes no run-as statement; grep of the whole printed book, 2026-09-03)

none

kanidm-data:/data; bind server.toml:ro

ROOT — upstream default, recorded (probe-only slot, separate craigidp project; CRAIG builds no overlay for it, so it has no marker)

Live proof for the garage-init fix (2026-09-03): a host-side ps sampler ran during the cached cargo xtask dev start that rebuilt the image (RUN apk add --no-cache curl jq && adduser -D -u 10001 craig in the build log); the recreated one-shot ran as uid 10001, exited 0, the seed it gates re-ran, and cargo xtask verify-seed --expect keyed passed on the converged stack:

$ ps -eo user,uid,comm,args | grep -E 'init\.sh'
10001    10001 sh              /bin/sh /init.sh
garage is non-root since #1653 — how the volume-ownership migration works

The dxflrs/garage:v2.2.0 image is FROM scratch with no USER and no pre-created /var/lib/garage/{meta,data} (only /garage and its CMD), so a bare compose user: would land on Docker-created ROOT-owned mount points and fail garage’s first write. The overlay (devstack/garage/Dockerfile) instead bakes the two data directories INTO the image at uid 10001 via a throwaway builder stage + COPY --from=builder --chown=10001:10001, sets USER 10001:10001, and restates upstream’s CMD. Docker populates a FRESH named volume from the image’s content at the mount path — ownership included — so garage-meta / garage-data are born writable by 10001. What a rebuild cannot do is rewrite a volume Docker already populated: the pre-#1653 volumes on every developer box are root-owned. That one-time migration is the xtask staleness guard’s job — check_garage_volume_stale hashes devstack/garage/Dockerfile (the ownership-bearing artifact; garage.toml edits need only the rebuild+recreate the infra sweep already gives) and escalates a change to the volume wipe + reseed, the same class as devstack/postgres/ (see Infrastructure Dockerfiles). Not a bolt-on root init container, and no chown runs as root at RUNTIME — the only chown is the throwaway builder stage’s build-time step, discarded with the stage. With garage retired, the dockerfile-hygiene lint’s recorded root-residue set is EMPTY and a unit test pins it there — adding one is a conscious edit of that pin, never a drive-by. Exposure bound: garage publishes 3900/3903 on the host with committed devstack-only fixtures (rpc_secret, admin_token, the GKdeadbeef… key) — never production values.

The FIRST cargo xtask dev start/refresh after pulling #1653 escalates to the check_garage_volume_stale volume wipe + reseed (the garage_volume.sha256 marker is new, so it mismatches once on every box). That IS the migration: the root-owned garage-meta / garage-data volumes are dropped and recreated from the uid-10001 image directories, and the seed re-uploads the attachment fixtures. One-time.
The inherits-user / no-healthcheck marker lines added to devstack/postgres/Dockerfile by #1646 change that directory’s hash, so the FIRST cargo xtask dev start/refresh after pulling #1646 escalates to the documented check_postgres_init_stale volume wipe + reseed (see Infrastructure Dockerfiles) — a one-time, comment-only cause; nothing about the image’s runtime changed.

Application Services

Each stateful service depends on its ADR-063 migration gate (service_completed_successfully) plus postgres, rabbitmq, and keycloak (service_healthy). The rules, cases, exchange, reporting, and security services also depend on garage, and everything but craig-rules depends on craig-rules itself, whose authz engine must be up first. craig-intake is the exception: as the stateless edge (ADR-017) it has no postgres, rabbitmq, or garage edges, and depends only on keycloak, craig-cases, and craig-security. docker-compose.yml is authoritative.

Service Port Database Extra Env

craig-rules

8001

craig_rules

JURISDICTION=georgia

craig-cases

8002

craig_cases

RULES_ENGINE_URL, CRAIG_STORE__*

craig-placement

8003

craig_placement

RULES_ENGINE_URL=http://craig-rules:8001

craig-exchange

8004

craig_exchange

CRAIG_STORE__*

craig-financial

8005

craig_financial

JURISDICTION=georgia

craig-reporting

8006

craig_reporting

—

craig-security

8007

craig_security

—

craig-intake

8008

— (stateless, ADR-017; the pre-created craig_intake DB is never populated)

CASES_URL, SECURITY_URL, CLIENT_ID/SECRET, IP_HASH_SECRET, TRUSTED_PROXIES

craig-composition

8009

craig_composition

composition layer engine (ADR-035; Plan X)

craig-intake-standalone

8010 (container 8009)

—

MODE=standalone, forwards to craig-intake:8008

craig-intake-standalone-shines

8011 (container 8009)

—

MODE=standalone, BACKEND_PROFILE=shines, drops each CpsRequest into the Garage craig-dev bucket (ADR-042 § "Amendment 2026-08-31")

craig-intake-tx

8014 (container 8008)

—

integrated mode on the Texas config layers (the plain craig-intake image with CRAIG_CONFIG_SOURCE set to the federal and texas layers) — the deliberately distinct palette the #902 non-default-palette accessibility sweep audits; shares the georgia cases/security backends (a Texas-county report lands as a georgia report row — cases stores admin_unit without re-validating it)

Keycloak URL Pattern

Object Storage (Garage)

  • The Garage image is distroless: no shell, just the binary at /garage. Healthcheck: ["CMD", "/garage", "status"]

  • Config: devstack/garage/garage.toml is baked into the image via the Dockerfile (project convention: no bind mounts)

    • db_engine = "lmdb", compression_level = 2, replication_factor = 1 (single-node devstack)

  • Init is the in-graph garage-init compose one-shot (devstack/garage-init/, the C4 gate from #1012), NOT xtask

    • alpine + curl/jq against the Garage admin API on garage:3903 (bearer token from the committed devstack garage.toml); the distroless garage container is never exec’d

    • runs as its own non-root user craig (uid 10001; adduser + USER craig in devstack/garage-init/Dockerfile, #1646) — the script writes nothing to disk and binds no port, so root was never needed; see Devstack image run-as users (#1646) for the whole-stack audit

    • Idempotent per step: layout applied only at layoutVersion == 0, key imported only when GetKeyInfo 404s, bucket created only when GetBucketInfo 404s, and AllowBucketKey ALWAYS re-granted (it is idempotent), so any partial state repairs on re-run

    • craig-seed gates on it (service_completed_successfully), so the bucket exists before the seed’s attachment upload on every path

  • Devstack credentials: access key GKdeadbeefdeadbeefdeadbeef, secret 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef

    • Access key format: GK + 24 hex chars (12 bytes). Non-hex chars are rejected by Garage v2.

  • Bucket: craig-dev, region: garage

  • Volumes: garage-meta, garage-data (named Docker volumes, ephemeral with docker compose down -v)

  • Services receive CRAIG_STORE__* env vars; no BODY_LIMIT override any more (#974) — the attachment routes derive their own cap from the store’s MAX_UPLOAD_BYTES (deployment guide § Upload limits), every other route keeps the 2 MiB default

    • CRAIG_STORE__BACKEND is explicit-required (#1362) — compose sets s3 via the x-garage-credentials anchor for every store-consuming service; a service booted outside compose without it refuses startup with the remedy (there is no silent local fallback; local is an explicit dev/test opt-in)

Volumes

  • garage-meta: Garage metadata

  • garage-data: Garage object data

Multi-replica devstack

cargo xtask dev start --replicas SERVICE=N[,SERVICE=N…] brings up the devstack with the named CRAIG application services scaled to N containers each. Loads docker-compose.scale.yml (replica-specific settings; nothing is published, so there are no host-port pins to drop).

# 2 craig-cases replicas + 2 craig-exchange replicas; rest scale=1.
cargo xtask dev start --replicas craig-cases=2,craig-exchange=2

Reaching scaled replicas:

  • From inside the compose network: by Docker DNS — craig-cases-1, craig-cases-2.

  • From a shell: through cargo xtask dev exec, by the same names (the replicas publish no host port).

Limitations:

  • Postgres / RabbitMQ / Keycloak / Garage stay scale=1 — sharing state requires external replication this devstack doesn’t model.

  • Scaled replicas are reached by their container names (<project>-craig-cases-1, -2) from the project network (cargo xtask dev exec); tests that need per-replica URLs use MultiReplicaCluster (see testing.md).

MultiReplicaCluster (in craig-test-lib) is the test-side analogue — it spawns a dedicated cluster with a unique compose project name so its stop() cannot wipe the developer’s persistent devstack volumes.

Seed Data

  • Generated by craig-seed, the deterministic seed generator (tools/craig-seed/)

  • Pinned defaults: CRAIG_SEED=42, CRAIG_FAMILIES=12 (pinned in docker-compose.yml; CI inherits 12 through compose’s :-12 fallback — there is no separate .gitlab-ci.yml pin). The generator binary’s OWN default stays --families 9 — the reproducibility baseline pinned by the seed42/families9 byte-identity fixture. The 12-vs-9 split is intentional two-tier layering (#1006): operational dataset vs baseline corpus; the compose env line carries the authoritative comment. --families is at least 4 (craig_seed::MIN_FAMILIES, #2793) because the base subsidy fixtures anchor to the first four generated cases and each family yields at most one, and a seed whose families still generate fewer cases than its fixtures and active scenario variants need is refused rather than seeded with orphaned rows.

  • SQL: auto-generated at container startup, seeded via craig-seed binary in Docker

  • TypeScript manifest: tests/e2e/lib/seed.ts — auto-generated via craig-seed --manifest

  • Seed scenario variants (#667): cargo xtask dev reseed --scenario <slug> layers a named background state over the base families (subsidy-generator-backlog, foster-home-at-capacity); the slugs join the seed identity, so changing them is a dev reseed (a non-wiping up against the old volume is refused, naming dev reseed). cargo xtask e2e --scenario <slug> regenerates the base manifest when it ends, so tests/e2e/lib/seed.ts is left as committed; the stack keeps the variants until the next reseed.

  • With seed=42, families=12: 50 persons, 15 referrals, 12 investigations, 10 cases, 6 plans, 6 contacts, 5 court orders, 3 foster homes, 12 placements, 5 partners, 6 agreements, 2 ICPC (one a pinned overdue received exemplar), 5 rate tables, ~36 payments, 1 claiming record

Common Tasks

Task Command

Build workspace

cargo build --workspace --locked

Unit tests

cargo nextest run --workspace --lib

All tests (needs devstack)

cargo nextest run --workspace --locked --profile integration

E2E tests

cargo xtask e2e

Reseed DB (wipe volumes, keep images)

cargo xtask dev reseed

Format check

cargo fmt --check --all

Lint

cargo clippy --workspace --locked — -D warnings

License/advisory check

cargo deny check

Stop containers (keep data)

cargo xtask dev stop

Wipe containers + data

cargo xtask dev clean --confirm

CI’s docs job checks the docs' external links (testing-reference § The docs checks). The same run needs only the Antora image, so a local run is one docker run from the checkout root. The xref gate’s build needs a full clone (.git a directory, not a worktree’s .git file) and what CI’s craig-docs image adds (ci/Dockerfile.docs: chromium, mermaid-cli, the lunr extension). The extension’s tests need neither, and they make no request beyond 127.0.0.1:

docker run --rm -v "$PWD:/antora:ro" -w /antora --entrypoint node antora/antora:3.1.14 \
  docs/extensions/link-check.test.js

The check itself is off unless CRAIG_LINK_CHECK=1: a plain antora antora-playbook.yml never touches the network for links. To run it as CI does, set the switch for the build and run the prose and verdict scripts after it. node docs/extensions/link-check-prose.js [file.adoc …​] checks the named root files, by default README, CONTRIBUTING, CHANGELOG, SECURITY and the *.adoc files in changelog/ and changelog.d/. node docs/extensions/link-check-verdict.js --expect antora,prose reads build/link-check.json and exits 42 on a dead link.

Battery timing (#1977)

cargo xtask validate prints === validate timing === just before its terminal line — one row per step (seconds, share of wall, [N] label), slowest first, the ten slowest by default and every step with --timing, then Σ steps, total and the gap between them; a red run prints it too, before the error, and target/validate-phases.log carries the same per-step durations. The devstack refresh (the staleness guard’s verdict plus any cold start, rebuild, restart or reseed) is a step of its own, so a rebuild’s time is not credited to the api-docs gate before it, and the scoped cargo xtask test --package <crate> --integration run journals it under the same label (#2134). The fast pre-push hook prints only validate’s breakdown (the former full hook added its own === pre-push timing === table, one row per stage), and cargo xtask e2e prints the five slowest specs after each Playwright phase from test-results/e2e/junit.xml (the final attempt’s time per spec; a phase that never wrote the file says so). Read the breakdown before blaming load: a stage that grew is a stage to look at, and Σ far below total means time is being spent between steps.

Battery threads and the nextest environment (#1977)

Every host runs the integration profile’s 8 nextest threads (.config/nextest.toml). The ruled minimum machine is 4 cores and 16 GB of RAM; on Docker Desktop the VM’s allocation (Settings → Resources) is what counts. The per-host row the battery used to detect and print (floor, large, the CRAIG_BATTERY_ROW override) was removed in #2668: both rows ran the profile’s 8, so it only printed a line.

The nextest environment. The battery removes NEXTEST_TEST_THREADS and NEXTEST_RETRIES from nextest’s environment, on the pre-push and CI paths alike, so a shell export can neither change the thread count nor retry a failure. CI’s tracked configuration and project variables set neither variable. A plain cargo nextest run still honours both.

Operating range. No row carries a thread count of its own. On the reference host (32 CPUs / 94 GiB), 16 threads cut the nextest step by 31 % against its paired floor run (295.9 s against 429.6 s), but two of three 16-thread runs redded in craig-exchange’s `outbound_triggers suite (#2243). #2244 gave a failed cases read its own short retry schedule, which shipped and stays. The 16-thread re-measure still redded the same suite on its first run, with no retry of any kind in the window, on the global CPRS partner slot: while a suite’s CPRS partner is active, every concurrent test’s case and investigation events are admitted as trigger work, so the trigger lane resolved about 1,000 foreign jobs at its concurrency cap and the suite’s own jobs queued past the 45 s settle window. The thread pursuit closed won’t-do on 2026-10-11 (#2244): a suite-owned admission scope would be a production capability built only to speed the battery. The battery runs the profile’s 8, and its thread plumbing is gone.

Dockerfile (Multi-Stage Build)

  • Build stage: rust:1.97-alpine, pinned to the toolchain in rust-toolchain.toml. It installs musl-dev, pkgconfig, and curl; cargo chef cooks the dependency layer, then a single cargo build invocation builds every workspace binary in one pass

  • 15 named runtime targets (all alpine:3.23 base): craig-rules, craig-cases, craig-placement, craig-exchange, craig-financial, craig-reporting, craig-security, craig-composition, craig-intake, craig-intake-keyring, craig-web (includes craig-bff’s shared static/ + its own static/), craig-portal (includes craig-bff’s shared static/ + its own static/ + locales/), craig-mock-server, craig-seed (includes tests/fixtures/, psql client, jq; no configuration since U4 — the seed reads the fetched layers at /config); and craig-operator, the released operator image (craig and craig-manage, built by their own operator-builder stage; no devstack runs it)

  • Jurisdiction data: no image carries any. Each service loads its jurisdiction and bundle at boot from the layers CRAIG_CONFIG_SOURCE names, read from the craig-config volume; the devstack hands every service the federal and georgia layers, and craig-intake-tx the federal and texas layers.

  • Build a single target: docker build --target craig-rules -t craig-rules:tag .

  • CI builds + pushes to GitLab Container Registry with tags $CI_COMMIT_SHORT_SHA and latest

  • Each of those 14 targets has a copy-only twin, <target>-devstack, on the shared devstack-runtime base, which cargo xtask dev start builds (dev start compiles once (plan ci-dev-loop D1, #3044))

dev start compiles once (plan ci-dev-loop D1, #3044)

cargo xtask dev start (and every verb that rebuilds the devstack images: dev refresh, reload, restart, reseed, migrate apply, validate’s images stage) compiles the whole workspace ONCE, in craig-tools on Docker’s default bridge, as one invocation (`xtask/src/lanes.rs):

cargo build --locked --workspace --all-targets --target x86_64-unknown-linux-musl --profile devstack \
  --features authz-witness,craig-web/plugin-example,craig-web/plugin-ssa-screening,craig-composition/plugin-example,craig-composition/plugin-ssa-screening,craig-intake/self-signed-tls
  • The musl target. craig-tools carries x86_64-unknown-linux-musl, musl-gcc (Ubuntu’s musl-tools) for the C in ring, aws-lc-sys and psm, and links with the toolchain’s rust-lld through gcc (-fuse-ld=lld and -B to the toolchain’s gcc-ld wrapper directory, set as CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_RUSTFLAGS in the image). The binaries are static, so the Alpine images, craig-tools and a CI job container all run them unchanged.

  • Where the binaries land. target/craig-tools/x86_64-unknown-linux-musl/devstack/ (the host side of the build, its build scripts and proc macros, in target/craig-tools/devstack/). [profile.devstack] keeps line tables, so a backtrace has file and line.

  • The images only copy. xtask hard-links the fourteen binaries into target/craig-tools/devstack-bins/ and builds each image’s <target>-devstack stage with --build-context devstack-bins=target/craig-tools/devstack-bins: the stage COPY`s its binary from that context onto the same `runtime base as production, with the production stage’s user, assets, probe and entrypoint (pinned by xtask/src/docker.rs tests, which also refuse cargo under devstack-runtime). The main build context and its .dockerignore, which keeps target/ out, are unchanged. Fifteen tags: the TLS SHINES instance runs the plain intake binary, since self-signed-tls changes nothing until an instance sets CRAIG_INTAKE__SELF_SIGNED_TLS.

  • The config fetcher’s image copies too (#3000). craig-config-fetch is a workspace member, so the one compile builds it. xtask stages it beside the fourteen and builds tools/craig-config-fetch/Dockerfile’s `craig-config-fetch-devstack stage with the same devstack-bins context, tagged craig/craig-config-fetch:local, the image compose resolves for the one-shot, before up. That file’s runtime stage (git, ssh-keygen, gpg, uid 10001, /config) is the base of both the devstack stage and the deployed craig-config-fetch stage, which still compiles the fetcher from source in release mode; xtask/src/docker.rs tests pin that the two differ only in where the binary comes from. Compose’s build: block names the compiling stage, so a dev start --release stack, whose tag no devstack build carries, builds the fetcher from source. An edit under tools/craig-config-fetch now marks the devstack stale like any service’s.

  • Nothing compiles after it. The battery’s inventory and nextest run (test --integration, with or without --package, which narrows by the filterset package(=<crate>) rather than by cargo’s selection), the C24 gate’s test inventory and test --unit select the same target, profile and features, so cargo finds every unit fresh. A lane that selected other features or targets would compile the shared dependencies again under other hashes (resolver 2 unifies features over the whole invocation). api-docs and the coverage matrix run --print-openapi on the same binaries while the compile’s stamp says they are current for the tree, and build the services with cargo otherwise (testing-reference, #3049).

  • The partner mocks. A devstack’s partner mocks are the simulators of its configuration layer, which the mock server loads (ADR-090), so no build compiles one in. The one partner crate in the tree, the reference partner, and the conformance kit are development dependencies only; a test pins over the battery’s cargo tree that no binary links either.

  • dev start --no-cache removes both target directories above before the compile and builds the images with --no-cache; --force skips only the staleness check.

  • dev start --release compiles nothing: it runs the release images docker buildx bake --file docker-bake.hcl built under CRAIG_IMAGE_TAG (the deployable release group, pulled when missing, and the local release-stack side images, refused when missing), wipes any running stack first and blesses no staleness marker, so the next plain dev start cold-starts. deployment-guide § Release images has the commands (#3045). --bake builds those images from the checkout first, with release-build’s two bake lines, and `--replicas scales the release stack as it scales a devstack (#3166): CRAIG_IMAGE_TAG=$(git rev-parse --short=8 HEAD) cargo xtask dev start --release --bake --replicas craig-security-issuer=3.

The chef stages build only the release images (docker-bake.hcl); a CI car runs dev start like a developer (plan ci-dev-loop U4, #3046).

Serial chef image builds — cache-key grouping (#1347)

Since #3044 this section describes the `Dockerfile’s chef builder stages, which CI’s image builds still use; the devstack verbs build by copy (dev start compiles once (plan ci-dev-loop D1, #3044)).

docker-compose.yml declares 17 build: blocks across those 13 targets — one target, craig-intake, is built for FIVE services: craig-intake, craig-intake-standalone, craig-intake-standalone-shines and craig-intake-tx share identical build args and image tag (one real build satisfies all four; craig-intake-tx differs only in its runtime CRAIG_CONFIG_SOURCE, the Texas layers), while craig-intake-standalone-shines-tls builds the same target with a distinct build arg (CRAIG_INTAKE_FEATURES=self-signed-tls) and a distinct image tag, so it needs its own build. The service targets share the SAME builder stage, which compiles every service binary in ONE cargo chef cook + cargo build invocation; since #2646 craig-mock-server and craig-seed share the tools-builder stage, which compiles the two tools in their own, so their test-only features never unify into a service. The layer a build stage produces is a pure function of its build args, not of which final target you asked for. Stage plus args boil down to four distinct recipes across the whole compose file:

Recipe Build args Targets

1

builder, CARGO_PROFILE=devstack

craig-rules, craig-cases, craig-placement, craig-exchange, craig-financial, craig-reporting, craig-security, craig-intake (plain), craig-intake-keyring, craig-portal

2

tools-builder, CARGO_PROFILE=devstack

craig-mock-server, craig-seed

3

builder, + CRAIG_WEB_FEATURES=plugin-example,plugin-ssa-screening

craig-web, craig-composition

4

builder, + CRAIG_INTAKE_FEATURES=self-signed-tls

craig-intake (the TLS SHINES instance, distinct -tls image tag)

docker compose build and up --build schedule all requested targets CONCURRENTLY by default, and BuildKit only commits a layer to its cache once the build that produced it finishes. So when two same-recipe targets start close together, the second starts before the first’s cargo chef cook and cargo build layer has landed in the cache, sees nothing to reuse, and redundantly re-runs the full-workspace cargo build itself. In the worst case this stacks up to N concurrent full-workspace builds, each with its own set of rustc and linker processes, instead of 1 real build plus N-1 cache hits. That multiplication lands at the exact moment memory is already highest (musl static-linking ring/aws-lc-sys for rustls is a heavy step on its own), and it is a confirmed source of OOM-killed builds on memory-constrained dev machines and the smaller self-hosted CI runners (RUNNER_SMALL).

The fix: xtask/src/docker.rs’s `build_devstack_images_serial (backing BUILD_SPECS, the table above encoded in Rust) issues one docker build --target <X> per distinct (target, build-args, image-tag) tuple, ONE AT A TIME, ordered so every recipe’s builds run back-to-back — group 1’s targets first, then group 2’s, 3’s and 4’s. Every xtask call site that could trigger a docker compose build/up --build goes through this instead and drops --build from its subsequent up: cargo xtask dev (start/reload/restart/reseed), dev refresh’s auto-rebuild path, `cargo xtask migrate apply, and cargo xtask validate’s Docker build phase (CI-covered). Building via `docker compose directly (as the raw-compose CI jobs still do — out of scope for #1347) reintroduces the race.

Since #1977 A3 the build stages' cook and build RUNs share three BuildKit cache mounts (craig-cargo-registry, craig-cargo-git, craig-target; sharing=locked; ADR-039 § Amendment — #1977 A3). Recipes 3–4 therefore compile only their feature-changed crates on top of recipe 1’s artifacts (recipe 2, tools-builder, reuses any unit recipe 1 built and compiles the two tool crates plus the dependencies, or dependency feature sets, only they need), and a source-only rebuild recompiles only the crates whose fingerprints moved — fewer rustc / linker processes at the musl-link moment, so the per-recipe peak is not raised (recipe 1 of a cold build is the same workload as before; no pre-change baseline was measured — #1977 asks other machines for theirs), and the last builder layer is /out alone. The serial loop above is UNCHANGED: one build at a time, grouped by recipe. A from-scratch build is now two things — the layer bypass AND emptying the mounts — and cargo xtask dev start --no-cache does both (it runs docker builder prune --force --filter type=exec.cachemount once before the loop); dev restart empties them too, right after down --rmi local. dev clean and dev reseed keep them. dev start --force is a cold start WITH the caches.

The automatic triggers keep the mounts (#2136, ADR-039 § Amendment — #2136): a Cargo.toml / Cargo.lock change, a Dockerfile edit outside the builder environment, and dev start’s volume wipe (a migration, key, envelope-format or bundle verdict) all take a cached rebuild over them. Every app-image build empties them first only when the builder environment — the stages `builder inherits, chef today — differs from the one .devstack/builder_env.sha256 records; that marker survives dev clean / dev reseed, as the mounts do.

Adding a 14th image target: add its BuildSpec entry to the group matching its (CARGO_PROFILE, CRAIG_WEB_FEATURES, CRAIG_INTAKE_FEATURES) build args — inside that group’s contiguous run, not appended after a different group — and do NOT reach for docker compose build/up --build as a shortcut; that is exactly the scheduling this section fixed.

Infra images are a separate, disjoint set. BUILD_SPECS only covers the 13 targets sharing the root cargo-chef Dockerfile — it deliberately excludes postgres, rabbitmq, keycloak, garage, and garage-init, which each declare build: as a bare string pointing at their own standalone devstack/<x>/Dockerfile (no shared layer, so no race to serialize around). Dropping --build from up without also covering these left them frozen at whatever image was last built — editing devstack/postgres/init.sql (or any other infra Dockerfile/config) silently had no effect, since up alone never rebuilds a service’s image. xtask/src/docker.rs’s `infra_build_services discovers this set dynamically (services whose build: value is a plain string, not a mapping — the same signal build_specs_match_docker_compose_yml uses to rule them OUT of BUILD_SPECS, so the two lists can never silently overlap or gap) and build_infra_images hands them to a single docker compose build <services> call — concurrent scheduling is fine here since there’s no cargo-chef layer to race. Every call site above runs it alongside (never instead of) build_devstack_images_serial. A name-based filter (e.g. a craig- prefix) was considered and rejected: mock-server is a BUILD_SPECS target with no craig- prefix, and compose’s own default image naming makes the unrelated craig-postgres/craig-rabbitmq/etc. images ALSO start with craig- — the heuristic is wrong in both directions on this exact compose file.

Infrastructure Dockerfiles

devstack/postgres

  • Dockerfile: FROM postgres:18-alpine, COPY init.sql

  • init.sql creates 9 CRAIG databases (craig_rules, craig_cases, craig_placement, craig_exchange, craig_financial, craig_reporting, craig_security, craig_composition, and craig_intake — the last pre-created but never populated; stateless edge per ADR-017), the multibackend-profile IdP stores (authentik, zitadel), and the per-service migration-owner/runtime role pairs (#1310, ADR-063)

  • init.sql only ever runs once, against a FRESH/empty data directory — upstream Postgres entrypoint behavior, not a CRAIG choice. The devstack’s postgres-data volume is a persistent named volume that survives a plain down/up (ADR-048 §D1), so a rebuilt image alone does nothing: editing init.sql on an already-initialized volume silently has no effect until the volume is wiped. xtask/src/devstack_guard.rs’s `check_postgres_init_stale hashes devstack/postgres/ separately from the rest of devstack/ for exactly this reason — a change there escalates straight to VolumeAction::Wipe (+ reseed) instead of the plain cached rebuild the rest of devstack/ gets. Same escalation mechanism as a modified migration file or a rotated field-encryption key.

devstack/rabbitmq

  • Dockerfile: copies definitions.json + rabbitmq.conf

  • rabbitmq.conf: management.load_definitions = /etc/rabbitmq/definitions.json

  • definitions.json (#1202) declares 10 users with SHA-256 password hashes: craig (the admin/operator), craig-test (the broad AMQP test identity), and 8 per-service least-privilege accounts (craig-<svc>, password equal to the account name — a public dev ACL fixture). It also declares the / vhost and the two durable topic exchanges craig.events and craig.dlx, which are operator-owned; services no longer declare them

  • WARNING: RABBITMQ_DEFAULT_USER env var does NOT work when rabbitmq.conf is COPYed (overrides entrypoint config)

devstack/keycloak

  • Dockerfile: FROM quay.io/keycloak/keycloak:26.5, COPY craig-realm.json

  • Command: start-dev --import-realm

  • Bootstrap admin: admin/admin (Keycloak admin console)

  • See DevStack Guide § Test Users (Keycloak) for realm users/roles/clients

CI vs Local Differences

The pre-push hook runs the fast battery, cargo xtask validate --profile fast: fmt, the locked config layers published (cargo xtask config fetch for the pins, so a fresh checkout pushes; #3014), the static lints, machete, clippy and the ci unit nextest, with no Docker and no devstack, in about five minutes warm (plan merge-trains-gate U1). Its published text is devstack/hooks/pre-push; install it with cp devstack/hooks/pre-push .githooks/pre-push && chmod +x .githooks/pre-push (the_installed_hook_is_the_published_hook fails until the two match). The hook verifies the commit signatures first and runs git lfs pre-push last. The full battery runs on the merge train, which is the merge gate (ADR-086; Known Issues § Landing an MR).

The battery is the car’s lines (plan ci-dev-loop D2, #3046). cargo xtask validate (--profile full, the default) runs the CI car’s lines in its order on this host, each one step of one table, labelled with the line: fmt, the config layers, every precompilation gate, the .dockerignore canary and gitleaks; dev start; then the lanes (test --unit, test --clippy, lints source-ownership, test --doc, test --integration --profile ci-integration, api-docs --check, e2e, e2e --scenario … --grep @seed-variant (the seed scenario variant legs, which leaves tests/e2e/lib/seed.ts as committed), e2e --degraded, sdk-test, security --skip-zap --skip-fuzz, perf --profile smoke) (Quality Gates § CI: the car). Off CI it skips the car’s dev clean --any-project (the stack is yours) and adds the battery’s --pre-push debris clear. Every line is a command of its own: rerun a red one alone, for example cargo xtask test --integration --profile ci-integration. --profile fast is the pre-push hook’s subset. cargo xtask doctor checks this machine’s setup (repository visibility, commit signing), which validate no longer does.

CI runs the same lines in one car job (blocking on a merge train and on a plain MR that changes code), plus the security/supply-chain scans, the secrets/docs policy jobs, the release build, Pages, and the scheduled pentest/perf/cluster jobs.

Aspect Local (pre-push) CI

Lint/clippy/tests

The hook: cargo xtask validate --profile fast; by hand: cargo xtask validate (every car line) or one line’s command

car (the gates, dev start, the lanes)

E2E (Playwright)

cargo xtask e2e, then the seed scenario variant legs (Testing Reference (CRAIG) § Seed Data) and cargo xtask e2e --degraded (the C22 matrix)

car

Security scans

The security regression, cargo xtask security --skip-zap --skip-fuzz (auth boundary, injection and infrastructure phases; ZAP and fuzzing are not run); cargo deny check when installed, and validate’s gitleaks scan (required, from its pinned image; #2649) (the hook’s stages)

SAST, secret detection, dep scanning, cargo-deny

Docker images

cargo xtask dev start (the one compile, images by copy)

the car’s dev start (pushes nothing); release-build (docker buildx bake) on tags, the schedule and by hand

Docs

Not built

Antora review apps + Pages

CI Field Keys and the Retired devstack/ci/ Scripts

  • cargo xtask secrets write-field-key (the scheduled stack jobs' first step) materializes devstack/field-key.env by DECRYPTING the repo-committed store (secrets/dev.yaml) with the CI age identity CRAIG_CI_AGE_KEY, inside the pinned devtools container (ADR-048 §D5 as amended by ADR-064 U7, #1385). Since #2138 it writes both files, devstack/field-key.env and devstack/reporting-field-key.env, and validates both decrypted keys before writing either. Each file is published atomically at 0600 (a symlinked target is refused), and the prior files are retained on failure. An unset variable is a hard error on a protected ref, and wherever the ref’s protection is unknown: a CI devstack must never come up keyless, and a store rotation reaches CI on the next run. On an unprotected ref (GitLab’s CI_COMMIT_REF_PROTECTED is false) the protected identity is never there, so the verb says so and writes nothing, and dev start mints a throwaway key, as on every MR car; that is how a perf measurement runs on a branch (#3185, Measurement pipelines). The identity reaches sops only as a read-only file mount, staged under the checkout (.cikey.*, removed after the decrypt) so the /builds alias covers it. The test seams CRAIG_SECRETS_FILE, CRAIG_SOPS_CONFIG, CRAIG_FIELD_KEY_OUT, CRAIG_REPORTING_FIELD_KEY_OUT and CRAIG_DEVTOOLS_CONTEXT override the inputs and outputs. It was devstack/ci/write-field-key.sh until #2936: that script’s sibling sops container bind-mounted checkout paths a /builds-volume runner’s daemon cannot see.

  • Two scripts were retired by the C4 gate (#1012): garage-init.sh, because Garage bootstrap now runs as the in-graph garage-init compose one-shot on every path, and wait-healthy.sh, because the CI jobs use docker compose up -d --wait --wait-timeout 900, which the seed and garage-init completion gates make fail-loud.

Edit this page · latest