Plan: Production operator tools leave xtask
Status
Done (2026-11-18) — all eleven steps merged; #2671 closed on the last. The operator image’s publication is unverified until the next tag, and xtask’s remaining craig-test-lib uses are #3135.
Closes: #2671, on the last step. Step 1 delivers its two acceptance items (the ADR, the child issues); it stays open as the tracker because release_artifact_gate.rs names it on two exceptions that only the last step can remove. Child issues are filed at approval, one per step.
Tree: written against main.
Ruling (maintainer, 2026-11-18): option 1 of #2671. API verbs go into craig; direct tools go into a new operator binary named craig-manage (in the sense of nova-manage), built, versioned and released with the services.
Erratum (2026-11-18): D1’s table starts with eleven Moving rows, not fourteen: the test reads the deployment guide, the CLI page and the runbooks, which name eleven of the moving verbs. seed-admin-units, reconcile and gen-client-keys are named on other pages and still move. rules is keyed with its sub-verb, since rules drift moves and rules check stays.
Erratum (2026-11-18): the credential kind is carried on the token (auth::Grant: password, device, fixed) and picks the re-login path; jobs::Credential keeps its one job, where a password comes from. The rotation verb takes the global --yes as its consent and no flag of its own.
Erratum (2026-11-18): craig rules promote needs the authority-evidence check, which evaluates through the rules engine and lived in xtask. It moves to a new crate, crates/craig-authority-evidence, that xtask’s gate and the promote command both call, so the recomputed-digest control is kept; craig-cli gains the engine in its dependency graph.
Erratum (2026-11-18): craig subsidy import reads the stage reply as its typed contract, so a record whose reply has another shape fails the run; the xtask tool wrote the outcome unknown and went on. The run report’s fields and names are unchanged.
Erratum (2026-11-18): craig backpay signs in through the profile like every other verb, so the per-act device grant and its stager and finalizer prompts are gone: the operator runs craig login --device first, and the deployment guide says the two roles sign in separately. abort takes the global --yes. The acts stay blocking code (the typed confirmation, the paced stage loop); each request is driven on the CLI runtime with its worker released.
Erratum (2026-11-18): craig-manage’s verbs are async functions that write to a writer the caller passes; the binary owns the runtime. `env_prefix (a service name to its CRAIG_<SERVICE> prefix) lives in craig_manage::target, where the database-URL rule also reads it, and xtask’s perf setup takes it from there. xtask drops its craig-store dependency with archive-fetch.
Erratum (2026-11-18): quarantine-drain keeps its own broker variable, CRAIG_QUARANTINE_DRAIN_AMQP_URL, and takes no URL flag: the URL carries a credential and a command line is readable by other local users. The no-default rule holds through that variable. xtask drops its direct craig-mq dependency with the verb.
Erratum (2026-11-18): backfill-assignments without --yes prints the four resolved targets as host/database and contacts nothing; it is not a dry run of the statements. The completion report is unchanged.
Erratum (2026-11-18): reconcile names one database per service by flag or variable and needs only those its --scope touches. caregiver-coverage labels its rows unknown without --jurisdiction; xtask passes the devstack’s jurisdiction when it calls the report. Both reports connect read-only through craig_manage::pg, which also holds the missing-table reading xtask’s invariants shared with the coverage report.
Erratum (2026-11-18): the catalog is embedded by a build script that writes one include_str! per file, not by an include_dir dependency. craig-manage invariants sweeps the nine stateful services by their own variables (one --database-url cannot name nine), and gains --database-url beside --service. The list of services lives in craig-manage; an xtask test holds it equal to xtask’s registry. D1’s Moving variant is deleted in this step, with its last row.
Erratum (2026-11-18): the craig-operator stage carries CMD ["craig", "--help"]: the hygiene lint requires an ENTRYPOINT or CMD on a runtime stage, and a CMD keeps docker run <image> craig-manage … working where an entrypoint would not. The operator’s unit is checked with no feature argument (its packages define no release feature). The image is no devstack image, so craig-cli and craig-manage stay in NON_IMAGE_PACKAGES and an edit to them does not mark a devstack stale. D5’s census found uses: 22 sites in 11 files, all test rigs, gates over test output and lints; they are listed on #3135, which the two exceptions now name.
Context
deployment-guide.adoc and the runbooks under operations/ tell a production operator to run cargo xtask <verb>. xtask is the developer task runner: it needs a checkout and a Rust toolchain, it is not versioned with a release, and it depends on craig-test-lib as a normal dependency (xtask/Cargo.toml:60), which puts test fixtures in the graph of tools that write production data.
The survey (line counts include in-file tests):
Verb (module under xtask/src/cmd/) |
Lines | Talks to | Goes to |
|---|---|---|---|
|
137 |
craig-exchange API |
|
|
219 |
craig-rules API |
|
|
864 |
craig-rules API, job poll |
|
|
— |
craig-rules API, ruleset files |
|
|
1,038 |
craig-financial API, job poll |
|
|
5,650 |
craig-financial API, job poll |
|
|
427 |
craig-security database |
|
|
202 |
a service database, the object store |
|
|
771 |
the broker |
|
|
1,980 |
four service databases |
|
|
1,209 |
every service database, read-only |
|
|
736 |
placement and cases databases, read-only |
|
|
1,019 |
every service database, read-only |
|
|
221 |
nothing (writes key files) |
|
Shared plumbing: operator_auth.rs (142 lines, the OAuth device-code grant) and job_poll.rs (196 lines), which services/craig-cli/src/jobs.rs (728 lines) duplicates.
Facts that shape the design, each read from the tree:
-
The issue’s lint claim is out of date: the crate-wide
#![allow]it cites is gone, and xtask is under[workspace.lints](xtask/src/main.rs:6-24). Thecraig-test-libdependency is what remains true. -
release_artifact_gate.rs:80-93carries twoXTASK_GRAPH_EXCEPTIONS(craig-auth/test-fixtures,craig-common/test-zones), each naming #2671, and the gate fails once the graph no longer carries a pair. -
craig-cli(packagecraig-cli, bincraig) hascraig-test-libonly under[dev-dependencies]. Itsmainis async; its login is a password grant cached per profile; service URLs and the identity provider come from theProfile(config.rs);--yesis a global flag. No Dockerfile stage builds it:cli.adocsayscargo install --path services/craig-cli. -
The xtask API tools use blocking
reqwest, take--rules-url/--api-baseflags with devstack defaults, and read the identity provider from per-tool environment pairs. -
xtask calls three of these itself:
validatecallscaregiver_coverageand readsinvariants::Debris;scenariosreadsinvariants::BLOCKING_INVARIANTS; the perf identity setup callsgen_client_keys. Nothing in xtask callsreconcilebut the dispatch arm (devstack.rsanddevstack_guard.rsusefield_key_reconcile, another module, which stays). -
invariantsloads its SQL catalog fromcrates/craig-test-lib/sql/invariants/throughcraig_test_lib::invariant_catalog; tests in craig-mq, craig-cases and craig-security read the same catalog. -
backfill-cross-service-assignmentconnects only as the devstack superuser (dsn::devstack_admin_dsn, line 846), yet the deployment guide says to run it once per environment. -
rules driftwalks ruleset files withrules::ruleset_files(rules.rs:262-293), which reads directories and parses JSON; it does not use the rules engine. -
The gate’s
unit_for(release_artifact_gate.rs:518-535) requires a copied/out/<bin>to be built by a unit whose-pnames a package called<bin>;RELEASE_BUILD_STAGESlists the stages it accepts. Thedockerfile-hygienelint requires a health check or an in-stage waiver line on every runtime stage.
Staying in xtask, on purpose: secrets (the repository’s SOPS store), identity (a conformance probe), rewrite-scheme and migrate (devstack rehearsals), rules check, config fetch, every gate. gen-actor-keys also stays: the issuer cutover deletes it with the actor keys (gen_client_keys.rs:18).
Design
D1. ADR-088 records the rule, and a test holds it
adrs/adr-088-operator-tools-outside-xtask.adoc: a tool an operator runs against a deployment is never an xtask verb; API work goes through craig, direct work through craig-manage; what stays and why.
The test no_operator_page_sends_an_operator_to_xtask (xtask, operator_docs_tests.rs) reads deployment-guide.adoc, cli.adoc and every page under operations/, collects each cargo xtask <verb> they name, and requires each verb to have a row in one table: Developer with a reason (a rehearsal on a devstack, a gate), or Moving with the step that moves it. Step 1 lists today’s fourteen as Moving; each step deletes its rows; the last step deletes the Moving variant. A verb with no row fails, so a new operator verb cannot be added to xtask and documented.
D2. craig gains the API verbs
| Today | Becomes |
|---|---|
|
|
|
|
|
|
|
|
The moved verbs become ordinary craig verbs, which fixes five things the two tools did differently:
-
Async. They are rewritten on craig-cli’s async clients; no blocking
reqwestenters craig-cli. Request method, path and body do not change. -
URLs and identity provider from the profile.
--rules-url,--api-baseand the per-tool issuer and client variables are dropped;--profileselects, as for everycraigverb. -
One credential, three kinds.
jobs::Session’s credential becomes `Password(today’s),Device(re-runs the device-code grant once per expiry) orFixed(cannot be re-minted; a 401 exits naming the job and the resume command,job_poll.rs’s behaviour). `craig login --deviceruns the device-code grant and caches the token with its kind. A global--bearer-token(envCRAIG_BEARER_TOKEN) gives aFixedsession and skips the cache;mainobtains the session through one function, so no moved verb callsload_cached_tokenitself.operator_auth.rsandjob_poll.rsare deleted when their last user leaves. -
--yes. A verb that had its own--yesreads the global flag. Its meaning is kept per verb: forssa invalidate-stale-cohortsandsubsidy import, absent is a dry run, never a prompt.rules promotekeeps--confirm-preview. -
One poll. The verbs wait through
jobs.rs, which already never re-POSTs and re-authenticates once per expiry.
rules drift takes --rulesets <dir>, the directory holding one directory per jurisdiction (in a checkout, target/config/layers). The walker (ruleset_dirs, ruleset_files_in, the fixture marker, is_decision) moves to craig_config::rulesets in crates/craig-config, which has no engine dependency; xtask’s rules check and craig rules drift both call it, so they still see one file set.
D3. craig-manage, a new crate at tools/craig-manage
A library and a binary. The binary is what an operator runs; the library is what xtask calls for its own uses.
-
No default target. Every verb takes its database URL, broker URL or store settings from a flag or the service’s own
CRAIG_<SERVICE>__DATABASE_URLvariable, and refuses to start when none is given. No devstack credential is compiled into the crate. The backfill gains the four URLs it never had, prints the database names it resolved, and writes only with--yes. -
xtask keeps its own uses by calling the library with devstack values:
validate(the caregiver report, the invariant debris),scenarios(the blocking-invariant list), perf (key generation). The xtask verbs are removed, with no alias. -
The invariant catalog moves.
crates/craig-test-lib/sql/invariants/andinvariant_catalog.rsmove to a new cratecrates/craig-invariants, compiled in withinclude_dir-style embedding so the binary needs no checkout. craig-test-lib and the tests that read the catalog depend on the new crate and name it directly; craig-test-lib re-exports nothing. -
Dependencies.
craig-test-libappears only under[dev-dependencies]. The crate is under[workspace.lints], with the test regime on its tests. -
Verbs keep their names, with one rename for length:
craig-manage backfill-assignments.
D4. Both binaries ship in one released image
-
A Dockerfile stage
operator-builder(FROM chef, its own cook and build, astools-builderis) builds-p craig-cli -p craig-manageand copiescraig-cli’s binary to `/out/craig-cliandcraig-manageto/out/craig-manage, so each/out/<name>is a package name, as the gate’sunit_forrequires. It is added toRELEASE_BUILD_STAGES. It is nottools-builder, which links the partner mocks. -
A stage
FROM runtime AS craig-operatorcopies them to/usr/local/bin/craigand/usr/local/bin/craig-manage, with the waiver line# dockerfile-hygiene: no-healthcheck — a one-shot tool container; it serves nothing and exits with its commandand no entrypoint. -
craig-operatorjoins the bake file’sreleasegroup, so it is built, smoke-tested and pushed at each tag at the services' version. Runbooks saydocker run -v <profiles>:/home/craig/.config/craig <registry>/craig-operator:<tag> craig ….
D5. xtask’s craig-test-lib dependency is measured, then the exceptions go or are re-pointed
After the last move, a census lists xtask’s remaining non-test uses of craig_test_lib.
-
None: the dependency moves to
[dev-dependencies], and bothXTASK_GRAPH_EXCEPTIONSare deleted in the same merge request (the gate fails on a stale one). -
Some: they are listed on a new issue, the two exceptions name that issue with a reason that says what still needs the dependency, and the plan claims no more.
Either way #2671 closes there.
Scope and order
One merge request per step, each green alone. Every step moves its tests with its code and updates every page that names the old command.
-
ADR-088; this plan page; D1’s test with fourteen
Movingrows. -
craig: the three-kind credential,login --device,--bearer-token; proved by movingssa invalidate-stale-cohorts. -
craig_config::rulesets;craig rules bootstrap,promote,drift. -
craig subsidy import. -
craig backpay;operator_auth.rsandjob_poll.rsdeleted. -
tools/craig-managewithseed-admin-units,archive-fetchandgen-client-keys. -
craig-manage quarantine-drain. -
craig-manage backfill-assignments. -
craig-manage reconcileandcaregiver-coverage. -
crates/craig-invariants;craig-manage invariants. -
The
craig-operatorimage in the release set;cli.adocand the deployment guide’s install section; D5; #2671 closes.
Out of scope: any change to what a tool does; a new tool; the verbs listed as staying.
Risks
| Risk | Mode | Mitigation |
|---|---|---|
A moved verb sends a different request or exits differently after the async rewrite. |
silent |
The HTTP-stub tests move with each verb; their assertions on method, path, body and exit are unchanged, and only their harness becomes async. A changed assertion is reported. |
A runbook still names |
fail-closed |
The command no longer exists; D1’s test fails a page that names a verb with no row. |
A new operator tool is added to xtask and documented. |
fail-closed |
D1’s test: the verb has no row. |
|
fail-closed |
No default exists; a test per verb asserts the refusal with no flag and no variable. |
|
silent |
It prints the four resolved database names and writes only with |
A |
silent |
Step 2 ports `job_poll.rs’s tests onto the credential kinds before deleting it, with a red proof for each. |
|
fail-closed |
One session function in |
Dropping |
fail-closed |
The connection is refused; the runbooks name |
A test-only feature reaches the released operator image. |
fail-closed |
|
|
fail-closed |
The released-image-set test in |
The catalog move breaks a test that reads the SQL by path. |
fail-closed |
Compile and test failures in the car; every reader is changed in step 10. |
The two graph exceptions go stale mid-plan and fail the gate. |
fail-closed |
They change only in step 11, with the dependency. |
Tests
-
Regression: every moved verb’s tests, moved with it. None is deleted. One that cannot hold (it asserts the
cargo xtaskname, a dropped flag or a blocking client) is reported in its merge request and rewritten for the new form. -
Contract (wire): the HTTP-stub tests of the API verbs pin method, path and body after the move.
-
Unit: the three credential kinds on a 401 (password re-login once, device re-grant once, fixed exits naming the job);
--bearer-tokenwith an empty cache;--yesabsent is a dry run for the two verbs; eachcraig-manageverb’s no-default refusal; the backfill’s--yes; the ruleset walker under--rulesets. -
Property: the walker returns the same file set for
rules checkandrules driftover generated directory trees. -
Contract (docs):
no_operator_page_sends_an_operator_to_xtask(D1), which pins the ADR’s "never". -
Contract (release): the released-set test with
craig-operator;release-artifact-gateoveroperator-builder;dockerfile-hygieneover the new stage; a parse test thatcraigandcraig-manageaccept each documented command line. -
Devstack-gated: the tools' integration tests (the drain against a scratch queue, the backfill’s lock tests, reconcile, invariants) keep
#[ignore = "requires devstack"]and run in the car; compiled, never run locally. -
Observed, live: the first tag after step 11 must publish
craig-operator:<tag>; until then "released with the services" is unverified.
Every new non-devstack test gets a red proof, recorded in its merge request.
Delivery
-
Canonical page:
docs/modules/ROOT/pages/cli.adoc(thecraigverbs and acraig-managesection);deployment-guide.adocand theoperations/runbooks carry the commands. -
CHANGELOG entry: one
changelog.d/<issue>.changed.adocper step that removes an xtask verb, itsOps:clause naming the new command. -
Close: each step closes its child issue with the merge SHA. Step 11 closes #2671; then Status
Done,cargo xtask plan-lint --done, the archive move.
Review log
| Round | Vendor | Resolved model | Verdict |
|---|---|---|---|
1 |
Anthropic |
claude-fable-5-2 |
FLAGS (1): |
2 |
gemini-4-carbon |
FLAGS (1): |