Plan: Dated parent–child facts in canopy-persons (#3047)
Status: Done (2026-10-29) — !1833
Epic: none (prerequisite P1 of Plan: TANF work participation rate — weekly averages, the recorded young-child standard and family type (#2316, #2315, #2975); unblocks #3048, then #2975, the last open T1 item)
Issues: #3047 (T2, parent) · U1 → #3080 (w5) · U2 → #3081 (w3) · follow-up F1 → #3082
Branches: feat/persons-parent-child-facts
This is a Design + Scope plan: GitLab owns tracking, the child issues carry the implementer brief, and the plan freezes when U1 starts.
Erratum (2026-10-29): MemberFull gaining a required parent_child reaches beyond U1’s file list: struct literals and JSON fixtures in canopy-web, canopy-renewals, canopy-medicaid, canopy-applications and the persons client follow. Finalize compensation gains a parent–child arm, and a person a parent–child fact still references is not shredded on a cancelled finalize.
Erratum (2026-10-29): D8’s editor lives at services/canopy-web/src/api/members/parents.rs (with ensure_parent_and_child), not api/parents.rs and api/fact_editor.rs, to keep each route module within the B1 budget. The remove action binds only the child to the roster (the close names no parent, and a parent who moved out must still be closable), and a blank close date defaults to the legal day, as the address close does.
Erratum (2026-10-29): the EXPLAIN test seeds 40 pairs and runs ANALYZE before reading the plan, and asserts an index condition per column: on an empty, unanalysed table every index costs the same, so the plan cannot tell a probe from a walk.
Context
No canopy service records parenthood. The household roster’s relationship (crates/canopy-contracts-persons/src/households.rs:66, MemberFactValue.relationship at :107) is free text describing a member’s tie to the household or the applicant, in two vocabularies (crates/canopy-common/src/household.rs:58-75). The only code that reads it for parenthood is canopy-eligibility’s relationship_indicates_child (services/canopy-eligibility/src/orchestrator.rs:693), a string match that counts children when age is missing; nothing says which adult is a parent of which child.
Three programs need the pair. TANF’s assistance-unit composer (services/canopy-tanf/src/au_composition.rs:16-36, TanfMemberContext.is_parent_of_dependent and is_stepparent) is unwired because nothing supplies it (compliance/action-catalogue/tanf.toml:292), and the 45 CFR 261.24(c) two-parent rate (#2975) turns on two parents of the same minor child. MAGI’s budget-group composer was deleted until wired (compliance/action-catalogue/medicaid.toml:232, #864): 42 CFR 435.603(f) needs parent–child pairs and their kind. SNAP’s 7 CFR 273.1(b)(1)(ii) puts a child under 22 in the same unit as a natural, adoptive or step-parent, and canopy-snap sees only a flat member list.
canopy-persons already has one two-entity dated fact to mirror: household membership. Its table household_member_versions (services/canopy-persons/migrations/20260624000000_create_household_member_versions.sql) keys non-overlap on (household_id, person_id) with a btree_gist exclusion and carries the ADR-027 provenance columns; its store is services/canopy-persons/src/store/household_member_versions.rs over the shared substrate store/fact_versions.rs; its routes are POST /v1/households/{id}/members/claims and DELETE …/claims/{fact_id} (services/canopy-persons/src/api/mod.rs:1183, :1257); its events household.member_claimed and household.member_closed are program-neutral (services/canopy-persons/src/events.rs:205, :232); and canopy-web’s Persons tab records it (services/canopy-web/src/api/members.rs, templates/cases/tab_persons.html). Bulk reads go through POST /v1/persons:batchGet with a projection mask and an as-of date (crates/canopy-contracts-persons/src/batch.rs, BatchGetField; services/canopy-persons/src/store/batch.rs:44, expand_persons_as_of), capped at 500 ids (ADR-001 Amendment 1 §B4).
Rulings (maintainer, 2026-10-28)
-
The worker UI in v1 records a parent from the household roster only. The data model allows a parent outside the child’s household; recording one needs a person search canopy-web does not have, and is follow-up F1 (#3082). (Rejected: a pasted person-id field, error-prone and unconfirmable.)
Scope
In scope:
-
The fact: table, store, contract, claim and close routes, events.
-
The read: a
parent_childprojection onpersons:batchGetand onGET /v1/households/{id}/full. -
The worker UI: a Parents row per household member in the Persons tab, with add, correct and close, picking the parent from the roster.
-
Docs and the CHANGELOG.
Out of scope:
-
Consuming the fact: TANF (#3048), MAGI (#864) and SNAP mandatory members are their own issues.
-
Applicant-portal intake capture of parenthood (a follow-up when #858’s intake work reaches it).
-
Recording a parent outside the child’s household (F1).
-
Changing or retiring the roster’s free-text
relationship.
Design
D1 — the fact. A parent–child fact is a directed pair (parent_person_id, child_person_id) with a value kind ∈ {natural, adoptive, step} and an ADR-027 valid-time window. One pair holds one kind at a time: a step-parent who adopts gets a second window after the first closes. The fact is keyed by fact_id for corrections, and a correction may not reassign either person (422, as membership refuses a reassigned person_id). parent_person_id <> child_person_id is a CHECK. Nothing limits the number of parents per child or children per parent: the regulations differ by program, and that is a consumer’s rule.
D2 — the table. Migration services/canopy-persons/migrations/<stamp>_create_parent_child_versions.sql creates parent_child_versions with membership’s column shape (version_id, fact_id, valid_from, valid_to, recorded_at, superseded_at, author_type, author_id, claim_source, claim_status, origin, proposed_value_sealed), the two person columns referencing persons(id), and kind TEXT NOT NULL CHECK (kind IN ('natural','adoptive','step')). The exclusion is EXCLUDE USING gist (parent_person_id WITH =, child_person_id WITH =, daterange(valid_from, valid_to, '[)') WITH &&) WHERE (superseded_at IS NULL AND claim_status LIKE 'accepted%'), immediate, as membership’s. Indexes: fact_id; (child_person_id) WHERE superseded_at IS NULL; (parent_person_id) WHERE superseded_at IS NULL, since the read looks up by either end. The recorded_at default follows the existing version tables; migrations-lint decides whether it is a database-owned stamp.
D3 — the contract. crates/canopy-contracts-persons/src/parent_child.rs (new, exported from lib.rs): ParentChildKind (closed, snake_case, with strum like BatchGetField), ParentChildFactValue { kind }, ParentChildClaimRequest mirroring MemberClaimRequest (households.rs:133) with parent_person_id in the body in place of person_id (the URL names the child), and ParentChildRelation { fact_id, parent_person_id, child_person_id, kind, valid_from, valid_to } for reads. paths.rs gains CLAIM_PARENT = "/v1/persons/{id}/parents/claims" and CLOSE_PARENT_CLAIM = "/v1/persons/{id}/parents/claims/{fact_id}", where {id} is the child. events.rs gains ParentChildClaimedEvent and ParentChildClosedEvent with membership’s attribution fields (MemberClaimedEvent, events.rs:523), both persons, before windows and the after value; the kind is not PII, so the event carries it whole.
D4 — the store. services/canopy-persons/src/store/parent_child_versions.rs mirrors household_member_versions.rs: append_parent_child_version (claim or correction under fact_versions::lock_fact, snapshot-and-supersede, remnants), close_parent_child_version (the idempotent valid-time close), and list_by_persons_as_of(pool, person_ids, as_of) → Vec<ParentChildRelation> returning every accepted current window touching any listed person as parent or child. The registration in services/canopy-persons/src/store/mod.rs follows.
D5 — the routes. In services/canopy-persons/src/api/mod.rs, claim_parent and close_parent_claim mirror claim_household_member (:1183) and close_household_member_claim (:1257): the principal admits two new constants in crates/canopy-auth/src/delegated.rs beside PERSONS_POST_HOUSEHOLDS_ID_MEMBERS_CLAIMS (:107), PERSONS_POST_PERSONS_ID_PARENTS_CLAIMS and PERSONS_DELETE_PERSONS_ID_PARENTS_CLAIMS_FACT_ID; the finalize-step and idempotency-key guards (#2707) apply; author must be Worker or Applicant; both persons must exist (foreign_key_violation → 422); parent_person_id == child → 422; two accepted windows overlapping for one pair → 409 exclusion_violation, whether sequential or concurrent (the exclusion constraint is immediate, so the second of two racing inserts fails at its statement). The claim answers 201 Created with ClaimResponse; the close takes CloseClaimParams (as_of, author_sub) as the membership close does. The authorization inventory and the route-authz gate gain the two routes.
D6 — the read. BatchGetField gains ParentChild; BatchProjection (store/batch.rs:96) gains parent_child: bool; MemberFull (batch.rs:30) gains parent_child: Vec<ParentChildRelation>, always serialised and empty unless projected (no serde default: pre-1.0 surfaces carry no tolerance scaffolding). expand_persons_as_of fills it with one list_by_persons_as_of call over the whole id set, so a bulk read stays one query per family. GET /v1/households/{id}/full (api/mod.rs:933) includes it as one more fact group: with no projection every group comes back, so the orchestrator (#3048), which reads the roster there, gets it without a change; a caller naming groups adds parent_child. The 500-id cap and the as-of anchor are unchanged.
D7 — events. services/canopy-persons/src/events.rs gains publish_parent_child_claimed and publish_parent_child_closed, program-neutral like membership’s (events.rs:188, :223), staged in the write transaction. Keys person.parent_child_claimed and person.parent_child_closed; canopy-persons' write ACL in devstack/rabbitmq/definitions.json (:370) gains them, and xtask/mq-topology-allow.toml gains the two entries with the wording the other persons fact events carry (:52-53: "persons fact-stream event; audit-consumed only; domain change-detection consumers pending").
D8 — the worker UI. In canopy-web, services/canopy-web/src/api/members/parents.rs (new; the erratum moved it from api/) adds /actions/parent/add, /actions/parent/edit and /actions/parent/remove beside the member actions (api/members.rs:61), each under AuthenticatedWorker and WritePermission. Each handler follows edit_member (api/members.rs:224-236): authorize_household_fact_write (api/fact_editor.rs:158, the #632 gate) first, then both the child and the posted parent bound to the household’s roster through ProvenPerson::on_roster (services/canopy-web/src/persons_write.rs) before any parse, so a parent off the roster 403s uniformly (#1523) and the ruling holds; the write path is PersonsWritePath::person(child, "/parents/claims"), the close PersonsWritePath::person(child, "/parents/claims/{fact_id}") with CloseClaimParams. The Persons tab reads GET /v1/households/{id}/full?projection=person_ssn into HouseholdFullView (api/case_detail/household_full.rs:56-77, persons_tab.rs:99-103), not persons:batchGet; the tab adds parent_child to that projection query, and MemberView gains parent_child: Vec<ParentChildRelationView> under the view’s existing lenient deserialisation. The template (templates/cases/tab_persons.html) gets a Parents row per member listing current parents with kind and window, an add form (a <select> of the other roster members, a kind <select>, a valid-from date), a correct form per parent (kind and dates, a correction on the same fact_id), and a close form.
D9 — docs. canopy-persons API Reference (the two routes, the projection, the two events), canopy-persons Data Model (the table), Canopy Service Catalog (events published), Fleet authorization inventory (the routes), canopy-web API Reference (the Persons tab’s actions), and the CHANGELOG. ADR-027 §3 already names time-varying facts; no ADR change.
Units (weights by complexity) — U1 → U2, one MR
Weights: 1 trivial · 2 small · 3 medium · 5 large · 8 very large. One unit = one child issue. Both land in one MR, one commit per unit, under the maintainer’s standing direction to batch issues touching the same code onto one branch; U2 has no value without U1’s routes.
U1 (w5) — the fact in canopy-persons
Files: services/canopy-persons/migrations/<stamp>_create_parent_child_versions.sql; services/canopy-persons/src/store/{parent_child_versions.rs (new), mod.rs, batch.rs}; services/canopy-persons/src/{api/mod.rs, events.rs}; crates/canopy-contracts-persons/src/{parent_child.rs (new), lib.rs, paths.rs, events.rs, batch.rs}; devstack/rabbitmq/definitions.json; xtask/mq-topology-allow.toml; the delegated-route and authorization-inventory registrations; docs/modules/ROOT/pages/{api/canopy-persons.adoc, data-models/canopy-persons.adoc, services.adoc, authorization-inventory.adoc}; CHANGELOG.adoc.
D1 to D7 and D9’s persons pages. Tests, infra-guarded as the siblings in services/canopy-persons/tests/ are (fact_version_writes_test.rs, fact_version_reads_test.rs, batch_expansion_test.rs, fact_event_emission_test.rs):
-
Claim and read: a worker claims
naturalfor (A, C) from 2027-01-01;persons:batchGetfor C with the projection as of 2027-06-01 returns one relation, and for A returns the same relation; as of 2026-12-31 returns none. -
Correction: a correction to
adoptiveover[2027-06-01, ∞)on the samefact_idleavesnaturalfor[2027-01-01, 2027-06-01)andadoptiveafter; the superseded version is gone from reads. -
Close: a close as of 2027-09-01 ends the window; a read as of 2027-08-31 sees it and as of 2027-09-01 does not; a second close changes nothing and emits nothing.
-
Refusals: a reassigned parent on a correction → 422;
parent == child→ 422; an unknown person → 422foreign_key_violation; a System author → 422; a new claim with no idempotency key and no finalize tag → 400; a second accepted window overlapping the first for one pair → 409. -
Concurrency: two new claims for the same pair and window, started together (the two-task pattern of
two_concurrent_corrections_to_one_fact_serializeinfact_version_writes_test.rs:540, which races corrections; this races creates): exactly one201and one409, and one accepted window after both return. -
Events: a claim stages
person.parent_child_claimedwith both persons, the kind and the attribution; a close stagesperson.parent_child_closed; a no-op close stages nothing. -
Batch: 501 ids → 422; the projection absent →
parent_childempty with no query (a counted-queries assertion, if the harness has one; otherwise the empty vector). -
Contract:
ParentChildKindround-trips and rejects an unknown token; the requestdeny_unknown_fields.
Mutations named in the child issue: the exclusion’s WHERE dropped (the overlap test passes twice); the parent index dropped (the read-by-parent EXPLAIN); the reassign check dropped; the close emitting on a no-op.
U2 (w3) — the worker records and corrects a parent
Files: services/canopy-web/src/api/{parents.rs (new), mod.rs, fact_editor.rs}; services/canopy-web/src/api/case_detail/{persons_tab.rs, household_full.rs}; services/canopy-web/templates/cases/tab_persons.html; services/canopy-web/src/persons_write.rs; docs/modules/ROOT/pages/api/canopy-web.adoc; CHANGELOG.adoc.
D8 and D9’s web page. Tests:
-
Unit (canopy-web): the add handler builds a claim body naming the proven child in the path and the proven parent in the body, attributed to the worker; a parent not on the roster is refused before any upstream call; the edit handler sends a correction on the given
fact_id; the remove handler sends the close. -
Infra (canopy-web, devstack): the Persons tab renders a member’s parents from the projection; add, correct and close round-trip through canopy-persons and the tab shows each state.
-
e2e: one journey in
tests/e2e/specs/records a natural parent from the roster, corrects it to adoptive, and closes it, asserting the tab after each step by observed condition.
Mutations: the roster check dropped (the refusal test); the path built from the parent instead of the child (the body test).
Verification
-
cargo xtask test— the unit and integration lanes pass (see Testing); canopy-persons' and canopy-web’s integration lanes run the new infra tests on the devstack. -
cargo xtask dev restart(the U1 migration), thencargo xtask e2e, including the new journey. -
cargo xtask migrations-lint,cargo xtask mq-topology, the route-authz gate, andcargo xtask api-docs --updatefor canopy-persons' OpenAPI snapshot (the two routes and the projection). -
cargo xtask validate— the pre-push battery is green. -
Close: the MR carries
Closes #3047and both children; the close note names the merge SHA and F1.
Documentation Updates
-
Antora canonical pages —
api/canopy-persons.adoc(routes, projection, events),data-models/canopy-persons.adoc(table), Service Catalog (events),authorization-inventory.adoc,api/canopy-web.adoc(the Persons tab’s actions) -
CHANGELOG.adoc— entries under== Unreleased(U1 Added, U2 Added) -
No ADR change (ADR-027 §3 covers a new time-varying fact)
Risks
-
A parent outside the household. Fail-closed: the UI cannot record one, so a program reading the fact may miss a non-custodial parent who is a canopy person. Mitigation: F1, and the data model needs no change when the UI arrives.
-
Two vocabularies for the same truth. The roster’s
relationship = "child"and a parent–child fact can disagree. Fail-open and silent for a consumer that reads only the roster. Mitigation: the consumers (#3048, #864, SNAP) read the fact;relationship_indicates_childstays a fallback the orchestrator uses only when age is missing, and its retirement is #3048’s. -
Bulk-read cost. One extra query per
batchGetonly when projected. Fail-open and silent if the indexes are missed: the read still answers, slowly, and nothing reports it. Mitigation: the two partial indexes, and an EXPLAIN test (sequential scans off) that pins the parent-side index.
Review log
| round | vendor | resolved model | verdict |
|---|---|---|---|
1 |
Anthropic |
claude-fable-5-1 |
FLAGS (3): the bulk-read risk named no fail mode; the delegated-route constants' home ( |
2 |
gemini-4-argon |
FLAGS (2): the Persons tab reads |