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

ssa-invalidate-stale-cohorts (ssa_rotation.rs)

137

craig-exchange API

craig

rules-bootstrap (rules_bootstrap.rs)

219

craig-rules API

craig

rules-promote (rules_promote.rs)

864

craig-rules API, job poll

craig

rules drift (rules_drift.rs)

—

craig-rules API, ruleset files

craig

import-subsidy-history

1,038

craig-financial API, job poll

craig

backpay (backpay/, 12 files)

5,650

craig-financial API, job poll

craig

seed-admin-units

427

craig-security database

craig-manage

archive-fetch

202

a service database, the object store

craig-manage

quarantine-drain

771

the broker

craig-manage

backfill-cross-service-assignment

1,980

four service databases

craig-manage

reconcile

1,209

every service database, read-only

craig-manage

caregiver-coverage

736

placement and cases databases, read-only

craig-manage

invariants

1,019

every service database, read-only

craig-manage

gen-client-keys

221

nothing (writes key files)

craig-manage

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). The craig-test-lib dependency is what remains true.

  • release_artifact_gate.rs:80-93 carries two XTASK_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 (package craig-cli, bin craig) has craig-test-lib only under [dev-dependencies]. Its main is async; its login is a password grant cached per profile; service URLs and the identity provider come from the Profile (config.rs); --yes is a global flag. No Dockerfile stage builds it: cli.adoc says cargo install --path services/craig-cli.

  • The xtask API tools use blocking reqwest, take --rules-url / --api-base flags with devstack defaults, and read the identity provider from per-tool environment pairs.

  • xtask calls three of these itself: validate calls caregiver_coverage and reads invariants::Debris; scenarios reads invariants::BLOCKING_INVARIANTS; the perf identity setup calls gen_client_keys. Nothing in xtask calls reconcile but the dispatch arm (devstack.rs and devstack_guard.rs use field_key_reconcile, another module, which stays).

  • invariants loads its SQL catalog from crates/craig-test-lib/sql/invariants/ through craig_test_lib::invariant_catalog; tests in craig-mq, craig-cases and craig-security read the same catalog.

  • backfill-cross-service-assignment connects only as the devstack superuser (dsn::devstack_admin_dsn, line 846), yet the deployment guide says to run it once per environment.

  • rules drift walks ruleset files with rules::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 -p names a package called <bin>; RELEASE_BUILD_STAGES lists the stages it accepts. The dockerfile-hygiene lint 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

cargo xtask ssa-invalidate-stale-cohorts

craig ssa invalidate-stale-cohorts

cargo xtask rules-bootstrap, rules-promote, rules drift

craig rules bootstrap, craig rules promote, craig rules drift

cargo xtask import-subsidy-history

craig subsidy import

cargo xtask backpay stage|show|finalize|supersede|abort

craig backpay … (the same sub-verbs)

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 reqwest enters craig-cli. Request method, path and body do not change.

  • URLs and identity provider from the profile. --rules-url, --api-base and the per-tool issuer and client variables are dropped; --profile selects, as for every craig verb.

  • One credential, three kinds. jobs::Session’s credential becomes `Password (today’s), Device (re-runs the device-code grant once per expiry) or Fixed (cannot be re-minted; a 401 exits naming the job and the resume command, job_poll.rs’s behaviour). `craig login --device runs the device-code grant and caches the token with its kind. A global --bearer-token (env CRAIG_BEARER_TOKEN) gives a Fixed session and skips the cache; main obtains the session through one function, so no moved verb calls load_cached_token itself. operator_auth.rs and job_poll.rs are deleted when their last user leaves.

  • --yes. A verb that had its own --yes reads the global flag. Its meaning is kept per verb: for ssa invalidate-stale-cohorts and subsidy import, absent is a dry run, never a prompt. rules promote keeps --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_URL variable, 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/ and invariant_catalog.rs move to a new crate crates/craig-invariants, compiled in with include_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-lib appears 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, as tools-builder is) builds -p craig-cli -p craig-manage and copies craig-cli’s binary to `/out/craig-cli and craig-manage to /out/craig-manage, so each /out/<name> is a package name, as the gate’s unit_for requires. It is added to RELEASE_BUILD_STAGES. It is not tools-builder, which links the partner mocks.

  • A stage FROM runtime AS craig-operator copies them to /usr/local/bin/craig and /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 command and no entrypoint.

  • craig-operator joins the bake file’s release group, so it is built, smoke-tested and pushed at each tag at the services' version. Runbooks say docker 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 both XTASK_GRAPH_EXCEPTIONS are 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.

  1. ADR-088; this plan page; D1’s test with fourteen Moving rows.

  2. craig: the three-kind credential, login --device, --bearer-token; proved by moving ssa invalidate-stale-cohorts.

  3. craig_config::rulesets; craig rules bootstrap, promote, drift.

  4. craig subsidy import.

  5. craig backpay; operator_auth.rs and job_poll.rs deleted.

  6. tools/craig-manage with seed-admin-units, archive-fetch and gen-client-keys.

  7. craig-manage quarantine-drain.

  8. craig-manage backfill-assignments.

  9. craig-manage reconcile and caregiver-coverage.

  10. crates/craig-invariants; craig-manage invariants.

  11. The craig-operator image in the release set; cli.adoc and 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 cargo xtask <verb> after the verb is gone.

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.

craig-manage run with no URL acts on a devstack by default.

fail-closed

No default exists; a test per verb asserts the refusal with no flag and no variable.

backfill-assignments pointed at the wrong database.

silent

It prints the four resolved database names and writes only with --yes; pinned by test.

A Fixed bearer is re-minted, or a Device session re-prompts without bound.

silent

Step 2 ports `job_poll.rs’s tests onto the credential kinds before deleting it, with a red proof for each.

--bearer-token is ignored because a verb reads the token cache itself.

fail-closed

One session function in main; a test runs each moved verb with the flag and an empty cache.

Dropping --rules-url / --api-base sends a tool to the default profile’s localhost.

fail-closed

The connection is refused; the runbooks name --profile, and D4 mounts the profile file.

A test-only feature reaches the released operator image.

fail-closed

release-artifact-gate reads `operator-builder’s unit and fails the car.

craig-operator is left out of the release group, or the reverse.

fail-closed

The released-image-set test in ci_changes.rs compares the two.

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 xtask name, 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-token with an empty cache; --yes absent is a dry run for the two verbs; each craig-manage verb’s no-default refusal; the backfill’s --yes; the ruleset walker under --rulesets.

  • Property: the walker returns the same file set for rules check and rules drift over 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-gate over operator-builder; dockerfile-hygiene over the new stage; a parse test that craig and craig-manage accept 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 (the craig verbs and a craig-manage section); deployment-guide.adoc and the operations/ runbooks carry the commands.

  • CHANGELOG entry: one changelog.d/<issue>.changed.adoc per step that removes an xtask verb, its Ops: 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): reconcile has no caller in xtask (the hits were another module); the #2671 graph exceptions and the missing craig-cli build unit were unaddressed; folded.

2

Google

gemini-4-carbon

FLAGS (1): rules drift deferred a decision; the async, URL, credential and --yes differences from craig-cli were unresolved; the gate’s package-name rule and the health-check waiver; no test for "never"; invariants unaccounted; folded. Approved by the maintainer in plan mode, 2026-11-18.

Edit this page · latest