Plan: canopy-common splits by job, and the CLI stops linking sqlx (#3414)
Status: Done (2026-11-16) — four units; the shipped CLI links no sqlx
Closes: #3414
Epic: &170
Issues: #3414 (parent) · #3428 U1 (w5) · #3429 U2 (w3) · #3430 U3 (w5) · #3431 U4 (w3); relates to #3399, #1304
Branches: refactor/canopy-types-ids, refactor/canopy-types-vocabulary, refactor/common-db-modules-to-db, refactor/cli-without-sqlx
Erratum (2026-11-15): cargo xtask feature-builds runs clippy and rustdoc, not tests, and a lane that includes a redundant entry is refused, so U1 registers only canopy-types without sqlx; that build compiles the feature-off macro arm and its in-crate test, and the lanes run the crate's tests with the feature on.
Erratum (2026-11-16): the feature rule counts only a non-optional sqlx dependency, because canopy-common's own is optional and reaches canopy-types/sqlx through its sqlx feature rather than a declared one; and FEATURE_BUILDS gains no new entry for canopy-common, whose existing default-features entry (#3343) is already the build without sqlx and now says so.
Erratum (2026-11-16): the car job builds the workspace in one cargo invocation and dev start packages that build, so the separate CLI build line is added to the car job as well as the release job and the local build; the binary check therefore runs on every car. The check's markers are the symbol names sqlx_core and sqlx_postgres, not the source path sqlx-core, which the car profile's binaries do not contain.
This is a Design + Scope plan: GitLab owns tracking, the child issues carry the implementer brief, and the plan freezes when U1 starts.
Context
crates/canopy-common/Cargo.toml depends on sqlx with no feature gate. 54 workspace crates depend on canopy-common, and about 30 of them have no sqlx dependency of their own: every canopy-contracts-* crate, canopy-auth, canopy-signing, canopy-pack-check and tools/canopy-cli. ADR-007 makes the CLI an API-only tool, and its boundary test (tools/canopy-cli/src/dependency_boundary.rs) has to leave sqlx off its refused list for this reason.
sqlx is used in seven files of canopy-common. Four are database code: advisory_key.rs, fti_audit.rs, chain_append.rs and chain_verify.rs (about 5,800 lines with chain_verify/status.rs). Three are type glue: id.rs (the define_id! macro derives sqlx::Type on 111 id newtypes), identity.rs (manual Type/Encode/Decode for OidcSubject and ServicePrincipal) and error.rs (From<sqlx::Error> for ApiError and the database constructors).
Rust's orphan rule means only the crate that defines a type can implement sqlx's traits for it. Maintainer decisions (2026-11-15): three crates by job; the id types' database support is an optional sqlx feature that only server crates enable; ApiError's database conversion takes the same feature; and the canopy binary is built in its own cargo invocation so the feature stays off for it.
Scope
In scope:
-
A new crate
crates/canopy-types: ids, identities and the pure vocabulary and date modules, with no I/O. -
An optional
sqlxfeature on canopy-types and on canopy-common. -
The four database modules moved to
crates/canopy-db. -
The
canopybinary built apart from the services, and its boundary test refusing sqlx. -
Every import site updated; no re-export left behind.
Out of scope:
-
Splitting canopy-common further (telemetry, settings, http): it stays the server-plumbing crate.
-
canopy-admin and moving xtask's production verbs (#3399).
-
Rewriting the chain modules: #1304 deletes them, so they move as they are.
-
axum in canopy-common: the CLI may link it; only the database driver is the boundary.
Design
canopy-types
Dependencies: serde, serde_json, uuid, chrono, utoipa, thiserror, and sqlx as an optional dependency behind the feature sqlx. No tokio, axum, reqwest, tracing or canopy-config. Dev-dependencies are whatever the moved tests use today (proptest, serde_json_canonicalizer among them); the implementer copies them from canopy-common's manifest as the compiler asks.
Modules moved from canopy-common, files unchanged apart from their paths: id, identity, trigger, effective_date_basis, advisory, pagination, household, policy_target, recert, rep_disqualification, administrative_denial, au_composition, causal, date, workdays, filing, hex. Three seams are cut rather than moved whole, so the crate needs no toml, anyhow or configuration dependency:
-
bounded_excerptand its byte limit, fromerror.rstocanopy_types::text(it is whatpolicy_targetuses). -
PostponementDispatchandConversionDispatch, fromexpedited_postponement.rstocanopy_types::expedited_postponement; the table loader and the date arithmetic that reads configuration stay in canopy-common. -
workdays::load_from_jurisdiction_doc, which parses the pack's TOML withtomlandanyhow, stays in canopy-common ascanopy_common::workdays::load_from_jurisdiction_doc;WorkdayCalendarand its arithmetic move. A constructor the loader needs becomes public on the type.
The rule for anything else the compiler turns up: a function that reads configuration or needs a dependency outside the list above stays in canopy-common, and the type it builds moves.
The feature gate is decided inside canopy-types, never at the call site. define_id! is exported and also invoked from service crates (canopy-enrollment, canopy-notices), and a cfg written inside a macro body is evaluated in the invoking crate. So canopy-types defines the macro twice, under [cfg(feature = "sqlx")] (with sqlx::Type and [sqlx(transparent)]) and under [cfg(not(feature = "sqlx"))] (without). The manual impls in identity.rs sit under [cfg(feature = "sqlx")].
canopy-common
Gains the feature sqlx = ["dep:sqlx", "canopy-types/sqlx"]. error.rs puts From<sqlx::Error>, ApiError::database, ApiError::internal_database and the SQLSTATE classifier under it. After U3 no other production code in canopy-common uses the sqlx crate (a telemetry test names the log target string sqlx::query, which is text, not the crate). canopy-common depends on canopy-types and re-exports nothing from it. Both crates' feature combinations are registered in FEATURE_BUILDS (xtask/src/lanes.rs), which cargo xtask feature-builds requires of any new feature.
Who enables the feature
One rule: a workspace crate with a direct sqlx dependency (normal, not dev-only) declares canopy-types and, where it depends on it, canopy-common with features = ["sqlx"]. A crate with no sqlx dependency never does. A unit test in xtask reads every workspace manifest through cargo metadata --no-deps --offline and fails naming a crate that breaks either half.
canopy-db
The four modules move together, in one unit: chain_append uses fti_audit::FtiAuditEntry, and canopy-common cannot depend on canopy-db, so they cannot move apart. fti_audit, chain_append and chain_verify become canopy-db modules of the same names. advisory_key's two functions move into the existing canopy_db::advisory module, which re-exports them today and then owns them; there is no canopy_db::advisory_key. crates/canopy-db/Cargo.toml gains the dependencies the moved code uses (serde, serde_json, sha2, canopy-chain, utoipa, and the dev-dependencies of the moved tests). Importers are whatever rg "canopy_common::(advisory_key|fti_audit|chain_append|chain_verify)" lists across crates, services, tools and xtask (canopy-medicaid, canopy-security, canopy-tanf, canopy-snap, canopy-notices, canopy-api, canopy-mq, canopy-test-lib and xtask/src/cmd/perf/chain_verify.rs today); one that lacks a canopy-db dependency gains it.
The CLI build
build::binaries_argv (xtask/src/devstack_binaries/build.rs) builds every package of lanes::BINARY_PACKAGES in one cargo build, and cargo unifies features across the packages of one invocation, so the canopy binary would get sqlx from its neighbours. The change:
-
binaries_argvleaves canopy-cli out, and a newcli_argvbuilds-p canopy-cli --bin canopyalone, with the same profile and flags and its own--target-dir(target/car-cli), so a later workspace build cannot overwrite the binary with a unified one. -
container_script(xtask/src/devstack_binaries.rs) runs both; the copy step (copy_binaries) takescanopyfrom the CLI build's directory; andbuild_staleness, which runs before the copy and reads each build output astarget/car/<name>, readscanopyfrom the CLI build's directory instead, or every run would find it missing and rebuild. -
.gitlab-ci.ymlgains the second build line, andthe_pipelines_build_lines_are_the_sets_argvasserts it as it asserts the first. -
lanes::BINARY_PACKAGESandBINARY_NAMESkeep canopy-cli, soevery_selected_package_owns_the_binary_it_shipsis unchanged.
The car's test archive is a --workspace build and stays one: tests may link a unified canopy-cli. Only the shipped binary is held to the boundary.
The boundary test adds sqlx, sqlx-core and sqlx-postgres to its refused names. It must resolve features for canopy-cli alone, which cargo metadata's workspace-wide resolve does not do; it runs cargo tree -p canopy-cli -e normal --prefix none --offline --locked and parses package names. The parser is a function with a committed unit test over a fixture output that contains sqlx and one that does not, as the closure walk has today. If cargo tree -p proves to unify workspace features, the unit stops and reports rather than weakening the test. A second, committed check covers the binary itself: a step after the CLI build fails when the built canopy contains the byte string sqlx-core (cargo embeds dependency source paths in panic locations), and the unit confirms at implementation that today's binary does contain it, so the check can fail.
Units (weights by complexity) — U1 → U2 → U3 → U4
Weights: 1 trivial · 2 small · 3 medium · 5 large · 8 very large. One unit = one independently shippable MR = one child issue. Each unit is a move plus import rewrites; none changes behaviour. compliance/neutrality-gate.toml, compliance/ssn-reads-allowlist.toml and any other allowlist keyed by file path follow the files that move.
U1 (w5) — canopy-types with ids and identities
Files: crates/canopy-types/ (new), Cargo.toml (workspace member and dependency), crates/canopy-common/src/{id,identity}.rs (deleted), crates/canopy-common/src/lib.rs, every manifest under the feature rule, every file importing canopy_common::id or canopy_common::identity (about 2,400 import sites), the xtask manifest test.
Also xtask/src/lanes.rs (FEATURE_BUILDS). Tests: regression, the id and identity tests move with their modules and pass unchanged; contract, the serde and OpenAPI forms of an id are unchanged (the OpenAPI snapshots do not move); unit, the manifest rule test, with one fixture manifest breaking each half; build, canopy-types with and without the feature, through FEATURE_BUILDS; unit, a test inside canopy-types invokes define_id! on a test-only type, so the macro's arm for whichever feature set the test run has is compiled from inside the crate, and FEATURE_BUILDS runs the crate's tests both ways.
U2 (w3) — the vocabulary and date modules
Files: the fifteen remaining modules, bounded_excerpt, the two dispatch structs, their import sites; crates/canopy-contracts-*/Cargo.toml.
Acceptance: no canopy-contracts-* crate depends on canopy-common; the manifest test asserts it. Tests: regression, the moved tests pass unchanged.
U3 (w5) — the four database modules to canopy-db; the sqlx feature on canopy-common
Files: crates/canopy-common/src/{advisory_key.rs,fti_audit.rs,chain_append.rs,chain_verify.rs,chain_verify/} (moved), crates/canopy-common/{Cargo.toml,src/error.rs,src/lib.rs}, crates/canopy-db/{Cargo.toml,src/}, xtask/src/lanes.rs (FEATURE_BUILDS), every importer the Design names, and the allowlists under compliance/ keyed by the moved paths.
Tests: regression, the moved tests pass unchanged; build, canopy-common without the feature, through FEATURE_BUILDS; unit, the manifest test also asserts canopy-common's sqlx dependency is optional.
U4 (w3) — the CLI without sqlx; documentation and the close
Files: xtask/src/devstack_binaries/build.rs, xtask/src/devstack_binaries.rs, .gitlab-ci.yml, Dockerfile if its copy path changes, tools/canopy-cli/src/dependency_boundary.rs, docs/modules/ROOT/pages/adrs/adr-007-cli-api-ui-parity.adoc (Amendment 5's sqlx caveat removed), docs/modules/ROOT/pages/shared-crates.adoc, docs/modules/ROOT/pages/developer-guide.adoc. docs/modules/ROOT/pages/plans/config-check-cli.adoc is not edited (frozen).
Tests: unit, the cargo tree parser over a fixture with sqlx (refused) and one without; regression, the boundary test on the real tree; unit, the build-line test covers both argvs; build, the binary check for sqlx-core runs on the car.
Risks
-
A server crate forgets the feature and an id stops binding in a query — fail-closed. It does not compile; the manifest test names the crate before the build does.
-
Feature unification turns sqlx on for the CLI anyway — silent. The boundary test resolves canopy-cli alone and refuses sqlx; the separate build invocation is what makes the shipped binary match.
-
The macro's cfg is evaluated in the invoking crate — silent. The two-definition form decides in canopy-types; U1's in-crate macro test compiles each arm under its feature set.
-
An id's wire or schema form changes in the move — silent. The OpenAPI snapshots and the serde tests are unchanged files that must still pass.
-
A moved file loses an allowlist entry keyed by its path — fail-closed. The lint fails on the car; each unit moves the entries with the files.
-
A long-lived branch conflicts with 2,400 import rewrites — fail-closed. U1 lands as one mechanical change when the train is otherwise quiet, and open branches merge
mainafterwards. -
#1304 lands first and deletes the chain modules — fail-closed. U3 moves what is left; nothing else depends on its order.
-
A workspace build overwrites the separately built CLI — silent. The CLI build has its own target directory, and the binary check runs on the file the image copies.
Verification
-
cargo xtask test --unitpasses before each push; the merge train's pipeline is the gate (CI is the gate). -
After U2:
rg "^canopy-common" crates/canopy-contracts-*/Cargo.tomlfinds nothing. -
After U4: the boundary test passes with sqlx on its refused list; the car's binary check finds no
sqlx-corein the shippedcanopy; andcanopy config checkruns from that binary.
Documentation Updates
-
shared-crates.adoc— canopy-types, canopy-common's narrowed role, canopy-db's new modules (canonical page) -
ADR-007 — Amendment 5's caveat that the CLI links sqlx is removed
-
developer-guide.adoc— the feature rule in one paragraph -
CHANGELOG.adoc— an entry under== Unreleasedin each unit's MR -
Close: U4's MR says
Closes #3414; the Status is set to Done and the merge SHA noted on #3414
Review log
| round | vendor | resolved model | verdict |
|---|---|---|---|
1 |
anthropic |
claude-fable-5-2 |
FLAGS — the FTI audit could not move a unit before the chain modules that use it, and that unit's build test could not pass; the two units were merged before approval |
2 |
gemini-4-carbon |
FLAGS — the CLI build was described in the wrong file; a source grep an existing test string would fail; a macro check that could not compile the feature-off arm; a boundary check that did not inspect the shipped binary; corrected before approval |