Plan: county is required on a residential address (#3376)

Status: Done (2026-11-23) — two units; every writer sends a residential address's county, and canopy-persons and the database refuse one without
Closes: #3376 (by U2)
Issues: #3376 (parent) · U1 #3551 · U2 #3552

This is a Design + Scope plan: GitLab owns tracking, the unit issues carry the implementer brief, and the plan freezes when U1 starts.

Problem

county_fips is optional on a canopy-persons address. The finalize saga writes every applicant address with county_fips: None (services/canopy-applications/src/finalize_saga.rs, address_fact), the worker form offers a free-text "County FIPS" box that may be blank, and nothing derives it. Federal policy presumes the agency knows a household’s area: 7 CFR 273.24(f) waives the ABAWD time limit by area of residence, and 273.3(a) ties a household to a project area. #3331’s ABAWD waiver areas cannot be built on a county that may be absent.

Decisions (maintainer)

  1. 2026-11-11: county is required on every residential address, chosen from a list at intake and on the worker form. It is not derived from the ZIP. The ABAWD counter gets no unknown-county branch.

  2. 2026-11-23: the list is canopy-reference’s county table (admin_units_for_state) for the State the pack names in [jurisdiction].fips_state_code, narrowed by the pack’s existing [jurisdiction].fips_county_codes when that is non-empty. No new pack table.

  3. 2026-11-23: a residential address in another State still needs a county, validated against that State’s table. The jurisdiction’s narrowed list applies only when the address is in the jurisdiction’s State. The non-resident denial path is kept.

  4. 2026-11-23: existing rows are not migrated. No deployment holds real rows before 1.0; a database CHECK is added validated, and a database holding a residential row with no county must be re-seeded.

Design

The rule

The stored value stays the existing five-digit county_fips: the State’s two-digit FIPS code followed by the county’s three-digit code.

One pure function in canopy-reference, counties::residential_county(state: &str, county_fips: Option<&str>) → Result<&'static AdminUnit, CountyError>:

CountyError When

Required

No county, or an empty one.

UnknownState

state is not a USPS code canopy-reference knows.

NotInState

Not five digits, the first two are not the State’s FIPS code, or the last three name no unit of that State.

One loader in canopy-common beside load_jurisdiction_timezone, load_jurisdiction_counties(snapshot) → Result<JurisdictionCounties>: the jurisdiction’s State and its served units (the whole State’s table when fips_county_codes is empty). It refuses at load a fips_county_codes entry that names no unit of the State. JurisdictionCounties::admits(state, unit) is true for any unit of another State, and for a unit of the jurisdiction’s State only when it is served.

Mailing and substitute addresses are untouched: their county_fips stays optional and unchecked.

An application may still be filed with no address at all (7 CFR 273.2 does not condition filing on one; build_finalize_address in services/canopy-portal/src/pages/apply.rs sends null when every address field is blank). The rule binds an address that is given: a residential address always has a county.

U1: every writer sends a county

No reader refuses yet, so this unit changes no stored result.

  • Contracts: FinalizeAddress gains a required county_fips: String.

  • canopy-applications: loads JurisdictionCounties at boot (refusing to start when it does not load) and carries it to the finalize handler beside the pack lists it already holds. address_fact passes the county through; the finalize pre-check (check_fact_shape call site in api/mod.rs) runs residential_county and admits, so a bad county is 422 before any canopy-persons write: county_required, county_state_unknown, county_not_in_state, county_not_served.

  • canopy-portal: loads JurisdictionCounties and [jurisdiction].admin_unit_label at server boot (jurisdiction.rs load_strings). The apply wizard’s address step gains a "County" select, labelled by admin_unit_label, after State. The served list and the label reach the client as two new shell attributes, data-canopy-counties and data-canopy-admin-unit-label, as the document types do (jurisdiction.rs, csp.rs). build_finalize_address keeps its all-blank skip, with the county among the fields it reads: all blank sends null; a partly filled address, a missing county included, is the existing "finish your address" error; a complete one sends county_fips. When the State typed is another State, the client fetches that State’s list from a new portal server route, GET /reference/counties/{state} (public, static reference data, 404 for an unknown code). A saved draft without a county resumes with the field empty.

  • canopy-web: loads JurisdictionCounties at boot and hands it to the address tab. The address forms replace the free-text box with a select of the jurisdiction’s served counties plus an "Another State" choice that reveals a five-digit code box. parse_address_value refuses a residential address with no county inline, before any upstream call.

  • canopy-cli: address help says --county-fips is required for a residential address; the CLI stays a thin sender and canopy-persons refuses.

  • In-tree senders. The rule for U1: every site that sends a residential address claim to canopy-persons, or a finalize address, names a real county of the address’s State; a mailing or substitute sender is left alone; a site that only builds a read-shape Address for a consumer’s test is left alone. Found by searching main for county_fips: None, "county_fips": null and every caller of the claim route; the implementer re-runs both searches, since the list is a snapshot:

    • Residential claim senders to change: crates/canopy-test-lib/src/residence.rs (two sites); canopy-renewals src/pr_pipeline.rs (test seeder); canopy-persons tests/ (persons_test, finalize_control_test, finalize_receipt_test, fact_version_writes_test, fact_version_reads_test, batch_expansion_test, fact_event_emission_test) and src/store/dek_stamp_infra_tests.rs; canopy-notices tests/notices_test.rs (the two residential sites); tools/canopy-cli request-body and path tests and tests/cli_test.rs; tests/e2e/lib/given/snap.ts and tests/e2e/lib/helpers.ts; services/canopy-applications/tests/common/mod.rs and every finalize body in that crate’s tests.

    • persons_test.rs has a helper taking the address type as a parameter: it sends a county when the type is residential. Its insta snapshot is updated by hand.

    • Mailing senders, unchanged: canopy-applications' five *_http_test.rs files, canopy-appeals contested_union_test.rs, tests/e2e/lib/given/persons.ts, canopy-notices' mailing sites.

    • Read-shape builders, unchanged: canopy-eligibility orchestrator.rs tests, canopy-web case-detail tests, canopy-notices recipient.rs, subscriber.rs and worker.rs, the contracts crates' own tests.

  • canopy-seed: its three address sites write fips_state_code + "001"; they take the first served unit of load_jurisdiction_counties instead, so the code is a real unit in every pack.

U2: canopy-persons refuses, and the database holds it

  • claim_address (services/canopy-persons/src/api/mod.rs): after the shape validation, a claim whose value.address_type is residential must pass residential_county and admits. Refusals are 422 with the four codes above, each naming the field county_fips and not the value. A correction (fact_id present) is held to the same rule, and so is a finalize-tagged claim (a_finalize_tagged_claim_without_a_county_is_refused).

  • canopy-persons loads JurisdictionCounties at boot and refuses to start when it does not load.

  • Migration: a CHECK named address_versions_residential_county, added validated: the address type is not residential, or county_fips is five digits. The database cannot hold the county table, so it checks presence and shape; the handler checks membership.

  • Address.county_fips on the read shape stays optional (a mailing address has none).

U2 is stacked on U1 and closes #3376.

Config repositories

No pack changes. fips_county_codes gains its first reader: an entry naming no unit of the State now refuses boot. Georgia’s is empty; the agents are told on merge.

Tests

Category Tests

Unit (canopy-reference)

a_residential_county_is_a_unit_of_the_addresss_state (each CountyError, a valid Georgia and Alabama code, a three-digit code, another State’s code under this State). Property: every unit of every State passes under its own State and fails under any other.

Unit (canopy-common)

the_served_counties_are_the_states_or_the_packs_narrowed_list, a_served_county_naming_no_unit_refuses_to_load, another_states_county_is_admitted_whatever_the_narrowing.

Contract (wire)

FinalizeAddress round-trip and a body without county_fips refused; OpenAPI snapshots for canopy-applications and canopy-persons.

canopy-applications

a_finalize_address_without_a_county_is_422_before_any_persons_write, one case per code; the_finalize_address_fact_carries_the_county; a_finalize_with_no_address_still_files; boot: a_pack_whose_served_county_is_unknown_does_not_boot.

canopy-persons (postgres)

a_residential_claim_without_a_county_is_refused_naming_the_field, a_county_of_another_state_is_refused, an_out_of_state_address_needs_a_county_of_its_own_state, an_unserved_county_of_this_state_is_refused (a narrowed fixture), a_correction_is_held_to_the_same_rule, a_finalize_tagged_claim_without_a_county_is_refused, a_mailing_address_needs_no_county. Schema: a_residential_row_without_a_county_violates_the_check, a_mailing_row_without_a_county_is_stored.

Boot

a_pack_whose_served_county_is_unknown_does_not_boot (canopy-persons).

canopy-web

Form parse cases; routed: a residential form with no county is refused with no upstream call; the select lists the served counties; the "Another State" code reaches the typed body.

canopy-portal

The county and label attributes are stamped and decoded; build_finalize_address: all blank is null, an address without a county is the error, a complete one carries county_fips; the county route lists a State and 404s an unknown code; a step-1 form without a county does not advance.

canopy-seed

Every seeded residential address carries a served unit’s code.

Regression

the_finalize_address_fact_carries_the_county fails on today’s county_fips: None: the case that would have caught #3376.

Not run locally (the car’s): persons_test, the canopy-applications finalize stack tests, the e2e apply and address journeys.

Risks

Risk Mode Mitigation

A sender still writes a residential address with no county after U2.

fail-closed

canopy-persons answers 422 and the CHECK refuses the row; U1 changes every in-tree sender first, and the car’s stack tests exercise them.

A database with county-less residential rows meets the migration.

fail-closed

The migration fails and the service does not start; the changelog says to re-seed (decision 4).

A deployment that narrows fips_county_codes cannot record a resident of an unserved county.

fail-closed

That is decision 2; the refusal is coded county_not_served, and an_unserved_county_of_this_state_is_refused pins it. No shipped pack narrows.

An applicant picks the wrong county.

silent

A worker corrects it on the address form; the county is shown beside the address on the case.

The portal’s other-State fetch fails.

fail-closed

The select stays empty and the step does not advance; the applicant can retry.

canopy-reference’s table is out of date for a State.

fail-closed

A real county is refused until the table is corrected; the table is Census data in source, fixed by a release.

Scope

Unit Work Status

U1

The rule function and the loader; every writer sends a county: finalize contract and pre-check, portal select and route, worker form, CLI help, test and e2e senders, seed.

Done (2026-11-23)

U2

canopy-persons refusal and boot load, the CHECK migration; closes #3376.

Done (2026-11-23)

Out of scope: #3331’s ABAWD waiver areas, which this unblocks.

Delivery

  • Doc pages: api/canopy-persons.adoc, data-models/canopy-persons.adoc, api/canopy-applications.adoc, api/canopy-web.adoc, services.adoc, rulesets.adoc (fips_county_codes now read), authorization-inventory.adoc if the portal route is listed there.

  • CHANGELOG.adoc == Unreleased: one entry per unit; U2’s states the re-seed.

  • This plan page with its nav entry, merged before U1.

  • The close: U2’s MR closes #3376; the merge SHAs are noted on it and #3331 is told it is unblocked.

Errata

  • Erratum (2026-11-23): the loader lives in canopy-reference beside the rule (residence_county::JurisdictionCounties::load), not in canopy-common, so the table, the rule and the pack read are one module; its tests are there too.

  • Erratum (2026-11-23): the rule is JurisdictionCounties::check(state, county_fips), over the free function residence_county::residential_county; admits takes the unit alone.

  • Erratum (2026-11-23): the applicant portal and canopy-web refuse to boot on a pack with no [jurisdiction].admin_unit_label, since both label the choice with it.

  • Erratum (2026-11-23): the portal's wizard gates no step, so an address without a county is refused at submit by build_finalize_address, as any partly filled address is, not at step 1.

  • Erratum (2026-11-23): a service's main is not unit-tested; the boot refusal is pinned at the loader (a_served_county_naming_no_unit_refuses_to_load, the_loader_reads_the_packs_jurisdiction_table) and, for canopy-web, by a_pack_listing_an_unknown_county_refuses_the_load_by_name.

  • Erratum (2026-11-23): the CHECK tests county_fips IS NOT NULL beside the five-digit pattern, since a CHECK passes on NULL and the pattern alone admitted a county-less row.

  • Erratum (2026-11-23): canopy-persons' refusals are one table-driven test, a_residential_claim_without_a_usable_county_is_refused_naming_the_field, with a case for each name the plan listed; a_mailing_row_without_a_county_is_stored is the last assertion of a_residential_row_without_a_county_violates_the_check.

  • Erratum (2026-11-23): the worker form's other-State choice is the select's empty option beside an always-shown code box, with no script.

Edit this page · default