Plan: Test state residency for Medicaid and CHIP (#3068)
Status: Done (2026-10-29) — !1844
Epic: &63
Issues: #3068 (T2, parent) · #3094 U1 (w3) · #3095 U2 (w5) · follow-ups #3096 (F1), #3097 (F2), #3098 (F3), #3099–#3102 (F4)
Branches: feat/medicaid-state-residency
Erratum (2026-10-29): ruling Q2 (maintainer), inherit. A member without a residential address of their own takes the applicant’s residential state (D1). U1 found that the portal claims an address for the applicant alone and no worker path adds one per member, so D2 as written would have pended nearly every multi-member household. D2’s pend now fires only when neither the member nor the applicant has one, when a state is not a USPS code, or when the roster is empty. F3 (#3098) narrows to a child whose own address differs from where they live.
Erratum (2026-10-29): U1 also adds crates/canopy-test-lib/src/residence.rs and gives the shared mock persons applicant a residential address (mock.rs), and it touches the eligibility and medicaid test fixtures that build households (orchestrator_dispatch_test.rs, eligibility_test.rs, envelope_roundtrip_test.rs, member_wire_drift_test.rs, cmd_reeval_e2e_test.rs, medicaid_test.rs, cross_program_test.rs, determination_provenance_test.rs, canopy-medicaid/src/determine.rs and services/canopy-medicaid/src/api/handlers.rs tests). Their applicants had no residential address, so they would have pended. Fixtures change; no assertion does. eligibility.json is unchanged: eligibility's MemberContext is not in its OpenAPI schema.
Erratum (2026-10-29): D5 keeps the seed's StateName() draw and discards it, so the random stream stays the same and three seed tests pinned to it hold (forced_households_cover_all_paths and two wic_prior_period_* tests).
Erratum (2026-10-29): U2 implements D4's early denial as decide-then-seal: evaluate_member takes a SubjectVerdict from the residency gate or the cascade and seals it through the existing tail, because a denial must still be signed and snapshotted. The denial code comes from the ruleset's output, never a Rust literal. A second ruleset fixture asserts the denial. The persons binding is /persons/{id}/addresses/claims, as the TANF precedent writes it.
Erratum (2026-10-29): U2 also routes the whole-person denial_reason_codes on medicaid.determined when a denial has no per-COA pairs, and canopy-notices labels them (services/canopy-medicaid/src/events.rs, services/canopy-notices/src/generator.rs). Without that, the residency denial's notice of action would state no reason (42 CFR 431.210(b)). U2 further touches compliance/neutrality-gate.toml (the enum digest), the in-process test modules, the pin snapshot, tests/e2e/lib/fixtures.ts and nav.adoc.
Erratum (2026-10-29): D4's ruleset is an expression node, not a decision table. A decision table's firing names field-qualified inputs (input.state_of_residence), which dangle in canopy-medicaid's empty-provenance derivation graph; the medicaid snapshot tests caught it. Every other per-subject Medicaid ruleset is an expression node, whose firing names only the bare input root that the graph drops.
This is a Design + Scope plan: GitLab owns tracking, the child issues carry the implementer brief, and the plan freezes when U1 starts.
Context
Medicaid and CHIP never test state residency, which gates every Medicaid path (42 CFR 435.403; CHIP 42 CFR 457.320(a)(1)). The address is captured end to end: canopy-persons serves each member’s valid-time address versions (crates/canopy-contracts-persons/src/addresses.rs:71, Address { state, address_type, effective_date, end_date, … }), and GET /v1/households/{id}/full returns them per member (MemberFull.addresses, crates/canopy-contracts-persons/src/batch.rs:46) when the projection names addresses (batch.rs:127, BatchGetField::Addresses). primary_address (addresses.rs:57) prefers the residential address but falls back to any address, so it is not the selector here.
The orchestrator does not ask for them. fetch_household_context (services/canopy-eligibility/src/orchestrator.rs:385) projects income,assets,expenses,parent_child, and household_context_from_bundle (:420-500) builds each MemberContext (crates/canopy-contracts-eligibility/src/determine.rs:318) from the person core. canopy-medicaid’s MemberContext (crates/canopy-contracts-medicaid/src/determine.rs:30-57) mirrors it, every field Option with #[serde(default)]. map_context (services/canopy-eligibility/src/mappers/mod.rs:111) dispatches Medicaid and CHIP by stamping served_program on a clone, and returns ContextError::InputUnsatisfiable(Vec<MissingInput>) for CAPS and WIC, which the orchestrator reports as ProgramOutcome::InputUnsatisfiable (orchestrator.rs:2846).
canopy-medicaid determines every member (ADR-035 Slice 2, #860): build_subjects (services/canopy-medicaid/src/determine.rs:323) makes one Subject { person_id, age, disability_status, is_applicant } per ctx.members entry, or the single applicant from the top-level ctx.age and ctx.disability_status when members is empty (the direct-caller path; tests/medicaid_test.rs:249 baseline_context uses it). evaluate_member (:1095) runs each subject through the 38-COA cascade with three parallel provenance calls (rules_client.rs:569, evaluate_magi_with_provenance, all through evaluate_namespaced_with_provenance(name, &input, &thresholds, source)); each firing carries its own corpus hash and joins subject_firings (determine.rs:1166), while the snapshot’s top-level hash stays the cascade’s (resolve_priority_order, :605). A subject ends Approved or Denied (:1497-1525): the CHIP slot denies medicaid_eligible, an exhausted cascade no_eligible_coa. A malformed request is refused with ApiError::unprocessable_coded (:828).
SNAP already runs a bare federal ruleset per member before its cascade and short-circuits to a denial: run_alien_precheck (services/canopy-snap/src/determine.rs:1824) through canopy-snap/src/alien_eligibility.rs:38-120. That is the shape here (ADR-003: logic in rulesets, never Rust).
The jurisdiction names its state only as [jurisdiction].fips_state_code (rulesets/georgia/jurisdiction.toml:26, "13"; the default and test packs carry "74", "60" and "69", each one canopy_reference::fips::State::from_fips (fips.rs:385, Option<Self>) resolves). canopy-reporting derives the postal code from it (services/canopy-reporting/src/params.rs:412, load_state_postal_code). canopy-seed fakes every address’s state with StateName() (tools/canopy-seed/src/datagen.rs:647,973,4678), a random state name, so the seeded devstack would pend every Medicaid determination once residence is read.
Rulings (maintainer, 2026-10-29)
-
Q1, absent residence: pend, never deny. The orchestrator reports
input_unsatisfiablenamingmembers[].state_of_residence, as it does for the CAPS and WIC worker-fact gaps; canopy-medicaid itself refuses a request with a subject whose state is absent or unparseable with 422 (fail-closed for direct callers). A missing address is an intake gap, not a policy finding; a denial would mail an appealable NOA for the agency’s own omission, and 42 CFR 435.956(c) accepts the applicant’s attestation. Rejected: denying withnot_a_state_residenton no evidence.
Scope
In scope:
-
Each member’s
state_of_residence(the USPS code of their residential address as of the determination date) on the eligibility and medicaidMemberContexts, read from canopy-persons in the existing household bundle; the applicant’s on medicaid’sApplicationContextfor the direct-caller path. -
A federal ruleset
medicaid-residencyevaluated per subject before the cascade; a non-resident subject is denied under both served programs with reason codenot_a_state_resident, citing 435.403 and 457.320(a)(1). -
The pend (orchestrator) and the 422 (canopy-medicaid) when a subject’s state is absent or unparseable.
-
canopy-seed writes the pack’s own state on every address, with one non-resident household.
-
Both action-catalogue rows bound; a scenario-inventory row; docs; CHANGELOG.
Out of scope:
-
F1 (#3096) — intent to reside and temporary absence (435.403(h), (i), (j)(3)): no service captures intent or absence. Until then, residence is the address of record.
-
F2 (#3097) — individuals placed or institutionalised across state lines (435.403(e), (i)(3)): the placing state’s residency; no placement fact exists.
-
F3 (#3098) — a child’s residence following the parent or caretaker when it differs from the child’s own address (435.403(i)(1)): read from the member’s own address until a parent fact carries an address of record.
-
F4 — the residency tests of SNAP (7 CFR 273.3, #3099), TANF (45 CFR 233.40, #3100), CAPS (#3101) and WIC (#3102).
Design
D1 — The fact: each member’s residential address as of the determination date
fetch_household_context adds BatchGetField::Addresses to the projection. household_context_from_bundle sets MemberContext.state_of_residence: Option<String> from member.addresses.iter().find(|a| a.address_type == AddressType::Residential).map(|a| a.state.clone()): residential only, never primary_address's fallback to a mailing address. The bundle is read as_of the determination date, so the version is the one in force. The field is Option<String> with [serde(default)] on both member contracts. canopy-medicaid’s ApplicationContext also gains state_of_residence: Option<String> ([serde(default)]) beside age: the applicant’s state for the empty-members path.
D2 — Pend when any member’s state is absent or unparseable
In mappers::map_context, the Medicaid and Chip arms call require_member_states(ctx)? before serving(…): for every member, state_of_residence must be Some and parse with State::from_abbreviation (fips.rs:390); otherwise ContextError::InputUnsatisfiable(vec![MissingInput { field: "members[].state_of_residence", source_class: "persons", gap_issue: None }]). Every member is a subject, so one unknown state pends the household. An unparseable value is a persons data error and pends the same way; a wrong state must never read as "resident". The orchestrator’s InputUnsatisfiable arm needs no change.
D3 — Refuse when a subject’s state is absent (canopy-medicaid)
Subject gains state_of_residence: State. build_subjects resolves it as it resolves age: from member.state_of_residence on the members path, from ctx.state_of_residence on the empty-members path. None or unparseable → ApiError::unprocessable_coded("state_of_residence_missing", "subject {person_id} has no parseable state of residence"), before any rules call; the person id is an identifier, not PII. Nothing is persisted.
D4 — The residency ruleset and gate
rulesets/federal/medicaid-residency.json: a JDM decision table with inputs input.state_of_residence and input.jurisdiction_state and outputs resident: bool, denial_reason_code: string | null. Rows: equal → resident = true; otherwise resident = false, denial_reason_code = "not_a_state_resident". No numeric literal, so cargo xtask rules lint-inputs needs no ADR-011 entry. Cited in rulesets/federal/citations.toml (42 CFR 435.403(a); 42 CFR 457.320(a)(1); PAMMS Medicaid 2225) and indexed in rulesets/federal/indexing.toml, as tanf-work-activity-limits.json is. A jurisdiction may shadow it under rulesets/<jurisdiction>/medicaid-residency.json (engine scan order), where a reciprocal agreement (435.403(k)) would live.
MedicaidRulesClient::evaluate_residency_with_provenance(input: ResidencyInput, source) → Result<(ResidencyOutput, Option<Vec<RuleFiring>>), ApiError> calls evaluate_namespaced_with_provenance("medicaid-residency", &input, &serde_json::json!({}), source). ResidencyInput { state_of_residence: String, jurisdiction_state: String } and ResidencyOutput { resident: bool, denial_reason_code: Option<String> } live in services/canopy-medicaid/src/residency.rs (new). MedicaidParameterTable gains state_postal_code: String, loaded from [jurisdiction].fips_state_code as canopy-reporting/src/params.rs:412 does; an unknown FIPS refuses at startup.
In evaluate_member, before the three parallel calls: evaluate residency for the subject; push its firings onto subject_firings; when resident is false, return early with a Denied output: denial_reason = Some("not_a_state_resident"), denial_reason_codes = vec!["not_a_state_resident"], no CoaEvaluation rows, rationale "Not a resident of {state_postal_code} (42 CFR 435.403; 42 CFR 457.320(a)(1))". The slot never runs, so CHIP shares the gate and a non-resident child is never medicaid_eligible. The snapshot’s top-level corpus hash stays the cascade’s, as for every other per-subject ruleset. The rest of the pipeline (persist, envelope, seal, held events) is unchanged.
MedicaidDenialReasonCode (crates/canopy-reference/src/medicaid_labels.rs:49) gains NotAStateResident ("not_a_state_resident"), and services/canopy-web/src/api/case_detail/determination_wire.rs:49 humanises it as "Not a resident of the State". No migration: medicaid_determinations.denial_reason_codes TEXT[] already holds any code.
D5 — Seed
tools/canopy-seed/src/jurisdiction.rs resolves state_postal_code: String once in load (:156) from fips_state_code through State::from_fips, failing the seed with the pack path named when it is unknown. phase1_households_persons, push_residential_address and push_cast_address write that code instead of StateName(). The last generated non-cast household gets a different state on every member, so the seeded devstack holds one non-resident case for the worker UI and the e2e spec. StateName leaves the imports if nothing else uses it.
D6 — Compliance and docs
-
compliance/action-catalogue/medicaid.toml:1222chip.eligibility.apply-residency-standardbinds toservice = "medicaid",path = "/determine",verb = "post",operation_id = "post_determine",test_ref = "services/canopy-medicaid/tests/medicaid_test.rs::post_determine_denies_a_non_resident_child_for_chip"; its allowlist entry (compliance/action-coverage-allowlist.toml:437) is removed. -
medicaid.toml:1695medicaid.verification.record-residency-verificationre-binds to where residence is recorded:service = "persons",path = "/v1/persons/{id}/addresses/claims",verb = "post",operation_id = "claim_address"(docs/modules/ROOT/openapi/persons.json:3450),test_refan existing persons address-claim integration test. -
compliance/input-requirements/medicaid.toml:40membersnote namesstate_of_residence(persons-sourced, policy-material; D2/D3 enforce it), and afor the new top-levelstate_of_residence(optional,policy_material = true,source_class = "request", note: the applicant’s, direct-caller path only). -
compliance/scenario-inventory/medicaid.toml:medicaid.eligibility.non-resident-denial(universal; 42 CFR 435.403, 457.320(a)(1); bound to the jdm fixturemedicaid-residencyand U2’s integration test). -
docs/modules/ROOT/pages/federal-requirements.adoc: a 435.403 / 457.320(a)(1) row.api/canopy-eligibility.adocandapi/canopy-medicaid.adoc: the fields, the 422 and the reason code.services.adoc: the gate. Snapshotseligibility.jsonandmedicaid.jsonviacargo xtask api-docs --update.
Risks
| Risk | Mode | Mitigation |
|---|---|---|
A member with no residential address pends the whole household’s Medicaid and CHIP (D2), including a seeded or migrated household with addresses never claimed. |
fail-closed |
The pend names the field; the worker records the address and re-runs. The seed writes an address per person (D5). Verification step 2 proves the seeded households still determine. |
A wrong or stale state on file denies a resident. |
fail-closed, visible |
The denial carries the citation and the code; an address correction and re-determination settle it. Appeals are unchanged. |
|
silent |
D1 selects |
A ruleset edit that returns |
silent |
The rules-client fixture test and U2’s non-resident integration test both assert the denial; U2’s mutation (compare the state with itself) must fail. |
The gate’s firings dropped from the derivation graph. |
silent |
U2 asserts a firing from |
Units (weights by complexity) — U1 → U2
Weights: 1 trivial · 2 small · 3 medium · 5 large · 8 very large. One unit = one independently shippable MR = one child issue.
U1 (w3) — Thread state_of_residence and pend without it
Files: services/canopy-eligibility/src/orchestrator.rs, services/canopy-eligibility/src/mappers/mod.rs, crates/canopy-contracts-eligibility/src/determine.rs, crates/canopy-contracts-eligibility/tests/roundtrip.rs, crates/canopy-contracts-medicaid/src/determine.rs, crates/canopy-contracts-medicaid/tests/roundtrip.rs, tools/canopy-seed/src/jurisdiction.rs, tools/canopy-seed/src/datagen.rs, compliance/input-requirements/medicaid.toml, docs/modules/ROOT/openapi/{eligibility,medicaid}.json, docs/modules/ROOT/pages/api/canopy-eligibility.adoc, docs/modules/ROOT/pages/api/canopy-medicaid.adoc, CHANGELOG.adoc
D1, D2 and D5. canopy-medicaid parses and carries the fields in this unit without acting on them. Tests, by category:
-
Contract: the two
roundtrip.rssuites cover the new fields (present, absent, and the#[serde(default)]absence). -
Regression:
household_context_from_bundlesets the state from the residential address, leavesNonefor a member with none, and ignores a mailing-only address (unit tests besideorchestrator.rs:4155);map_context_medicaid_pends_without_a_members_state_of_residenceand…_with_an_unparseable_stateinmappers/mod.rs(mirror:265); anorchestrator_dispatch_testcase assertinginput_unsatisfiablenamingmembers[].state_of_residence(mirror the CAPS case). -
Seed: the seed’s integration test asserts every address carries the pack’s postal code except the one non-resident household.
Mutations: read the mailing address; treat an unparseable state as present; skip the check for one member.
U2 (w5) — The residency gate, the denial, the bindings
Files: rulesets/federal/medicaid-residency.json, rulesets/federal/citations.toml, rulesets/federal/indexing.toml, services/canopy-medicaid/src/residency.rs (new), services/canopy-medicaid/src/rules_client.rs, services/canopy-medicaid/src/determine.rs, services/canopy-medicaid/src/params.rs, crates/canopy-reference/src/medicaid_labels.rs, services/canopy-web/src/api/case_detail/determination_wire.rs, crates/canopy-rules-client/tests/ruleset_happy_path_test.rs, compliance/action-catalogue/medicaid.toml, compliance/action-coverage-allowlist.toml, compliance/scenario-inventory/medicaid.toml, docs/modules/ROOT/pages/federal-requirements.adoc, docs/modules/ROOT/pages/services.adoc, tests/e2e/specs/worker-portal-medicaid-actions.spec.ts, CHANGELOG.adoc
D3, D4 and D6. Tests, by category:
-
Integration (
services/canopy-medicaid/tests/medicaid_test.rs, Georgia pack):post_determine_denies_a_non_resident_citing_435_403(applicantAL:Denied,denial_reason_codes == ["not_a_state_resident"], no COA rows, rationale names both citations, amedicaid-residencyfiring in the derivation edges);post_determine_denies_a_non_resident_child_for_chip(served program Chip; nevermedicaid_eligible);post_determine_denies_only_the_non_resident_member(two members, oneAL: one denial, one determination unchanged);post_determine_refuses_a_subject_without_a_state_of_residence(422, codestate_of_residence_missing, nothing persisted).baseline_contextgainsstate_of_residence: Some("GA"), so the existing approvals still approve. -
Fixture:
ruleset_happy_path!(medicaid_residency_happy_path, "medicaid-residency"). -
Unit:
MedicaidParameterTablerefuses an unknown FIPS. -
E2E: the spec opens the seeded non-resident case and reads "Not a resident of the State" on the determination tab.
Mutations: compare the subject’s state with itself; skip the gate for a Chip subject; return no_eligible_coa instead of the residency code; drop the firing.
Verification
-
cargo xtask test— the unit and integration lanes pass (see Testing). -
cargo xtask dev restart(the seed changes), thencargo xtask e2e — specs/journey-medicaid-chip-screen-and-enroll-medicaid-first.spec.ts specs/worker-portal-medicaid-actions.spec.ts: the seeded Georgia households still determine; the one non-resident household denies. -
cargo xtask policy action-coverage,cargo xtask policy input-coverage,cargo xtask policy audit --source federal,cargo xtask scenarios audit,cargo xtask rules lint-inputs,cargo xtask api-docs. -
The mutations named in each unit each fail their test.
-
cargo xtask validate— the pre-push battery is green. -
Delivery: U1 and U2 each merge with
Closeson their child issue (#3094, #3095); U2’s MR also closes #3068 and this plan (StatusDone, moved toplans/archive/,plan-lint --done).
Documentation Updates
-
Antora canonical pages —
api/canopy-eligibility.adoc,api/canopy-medicaid.adoc,services.adoc; no table changes, so the data-model pages are untouched -
CHANGELOG.adoc— entry under== Unreleased -
federal-requirements.adoc— the 435.403 / 457.320(a)(1) row
Review log
| round | vendor | resolved model | verdict |
|---|---|---|---|
1 |
Anthropic |
claude-fable-5-1 (gadhs/pi’s plan review at exit_plan_mode) |
FLAGS — no Risks section, no test categories, no delivery step; files named but not supplied; |
2 |
gemini-4-argon |
FLAGS — #860 per-member determination is live, so the gate is per subject; canopy-medicaid’s provenance funnel and 422 idiom named wrongly; |