One WIC certification record per participant (epic &106, Plan A1)

Status: Done (2026-09-27) — !1522
Issues: #2359 (epic &106)
Branches: feat/2359-wic-certification-record (carries this page)

This is a Design + Scope plan. GitLab owns tracking. It freezes when U-A starts. One MR, one battery. Plan A2 (#2358, anchor-date periods) follows it.

Erratum (2026-09-27): D3 as built persists each participant’s whole output (determination, snapshot, record, events) in ascending person_id order through api/persist.rs persist_order, which a persist-level infra test pins; the 409 leaves no determination, snapshot or record, but the snapshot DEK minted before the transaction remains (pre-existing, #2367).

Erratum (2026-09-27): D5’s seeded prior determination is dated on the prior certification’s start (a certification starts on its determination date), with its assessment a week before; and two further catalogue GAP comments the new status and supersession falsified (above mid-certification-disqualification-notice and thirty-day-temporary-certification) are corrected.

Context

  • The record is not a record.

    • wic_participants has no link to a determination, application or household, and no uniqueness (services/canopy-wic/migrations/20260413000000_create_wic_tables.sql ~4-20).

    • Its status CHECK is active\|expired\|terminated\|transferred, but only active is ever written.

    • determine inserts a row on every approval (services/canopy-wic/src/determine.rs ~590-604), and nothing updates one. So a person can hold overlapping active certifications.

    • store::participants::list_active_by_person is dead code.

  • Nothing reaches it.

    • GET /v1/participants/{id} documents only a 403.

    • WicParticipant.status is a free String whose doc names a value the CHECK refuses (crates/canopy-contracts-wic/src/participants.rs ~16-39).

    • No response carries a participant id.

  • Dates. as_of is the caller’s value or legal_today (determine.rs ~237-239). Any as_of is accepted, including a future one (services/canopy-wic/src/api/handlers.rs ~39-63).

  • Precedents:

    • DeterminationStatus, the typed-vocabulary shape (crates/canopy-reference/src/enums.rs ~54-113);

    • a named-constraint violation mapped to a coded 409 (services/canopy-medicaid/src/determine.rs ~762-775);

    • a delete-cutover migration (services/canopy-wic/migrations/20270111000001_determination_status_check.sql). The latest WIC migration is 20270113000000.

  • Row: wic.certification.dual-participation-prevention (7 CFR 246.7(l)(1)) is unbound. Detection belongs to #837.

  • Reachability: the orchestrator refuses WIC (#2364), so this is exercised through direct service calls.

Rulings in force: pre-1.0, no shims; ADR-016 (forward-only migrations); neutrality N3 (no status token is in any pack); ADR-043 A1 (no actor column here; provenance is #2361).

Scope

In scope: D1–D5.

Out of scope:

  • #2358 (Plan A2): periods.

  • #2360: the writers of temporary, expired and terminated; ending a certification with notice.

  • #2361: provenance.

  • #837: detection.

  • #895: determination-level supersession.

  • #826: VOC transfer-in, which enrols without a new determination and will need its own record basis.

Pre-existing defects, each filed as a fix: issue:

  • WIC create routes answer 200, not 201.

  • Snapshot DEKs are minted outside the persist transaction, so a rollback, including the new 409, orphans one.

  • The seed’s terminated prior-period row can pick an infant and start its certification before the infant’s birth (tools/canopy-seed/src/datagen.rs ~3497-3533).

Design

# Decision

D1

Links and cutover. The migration is services/canopy-wic/migrations/20270114000000_wic_certification_record.sql, with one constraint per ALTER:

DELETE FROM wic_participants;  -- cutover: no row names its determination; devstacks reseed; nothing references the table
ALTER TABLE wic_determinations ADD CONSTRAINT wic_determinations_subject_key UNIQUE (id, application_id, household_id, person_id);
ALTER TABLE wic_participants ADD COLUMN determination_id UUID NOT NULL, ADD COLUMN application_id UUID NOT NULL,
    ADD COLUMN household_id UUID NOT NULL, ADD COLUMN superseded_by UUID;
ALTER TABLE wic_participants ADD CONSTRAINT wic_participants_determination_key UNIQUE (determination_id);
ALTER TABLE wic_participants ADD CONSTRAINT wic_participants_granting_determination_fkey
    FOREIGN KEY (determination_id, application_id, household_id, person_id)
    REFERENCES wic_determinations (id, application_id, household_id, person_id);
ALTER TABLE wic_participants ADD CONSTRAINT wic_participants_superseded_by_key UNIQUE (superseded_by);
ALTER TABLE wic_participants ADD CONSTRAINT wic_participants_superseded_by_fkey
    FOREIGN KEY (superseded_by) REFERENCES wic_participants (id) DEFERRABLE INITIALLY DEFERRED;
ALTER TABLE wic_participants DROP CONSTRAINT wic_participants_status_check;
ALTER TABLE wic_participants ADD CONSTRAINT wic_participants_status_check
    CHECK (status IN ('active', 'temporary', 'expired', 'terminated', 'superseded'));
ALTER TABLE wic_participants ADD CONSTRAINT wic_participants_supersession_check
    CHECK ((status = 'superseded') = (superseded_by IS NOT NULL) AND superseded_by IS DISTINCT FROM id);
CREATE UNIQUE INDEX wic_participants_one_current_per_person ON wic_participants (person_id) WHERE status IN ('active', 'temporary');
  • The composite foreign key makes the copied ids agree with the granting determination by construction.

  • wic_participants_status_check is PostgreSQL’s default name for the inline CHECK, and xtask/src/cmd/migration_checks.rs replays the new one.

D2

Typed status. WicCertificationStatus { Active, Temporary, Expired, Terminated, Superseded } is added to crates/canopy-contracts-wic/src/participants.rs, which gains a thiserror dependency.

  • It takes the DeterminationStatus shape: as_str; TryFrom<&str>, TryFrom<String> and FromStr, each with a typed unknown-token error; ALL; and CURRENT = [Active, Temporary] with is_current.

  • Its doc names each value’s writer: an approving determination, a re-determination, and #2360 for temporary, expired and terminated. The seed also writes terminated.

  • transferred is dropped: it has no writer in &106.

  • WicParticipant gains determination_id, application_id and household_id (typed ids, [schema(value_type = String)]) and superseded_by: Option<WicParticipantId> ([schema(value_type = Option<String>)], the crates/canopy-contracts-appeals/src/ipv.rs ~48 precedent).

  • WicParticipant.status becomes typed, and its stale docs are fixed.

  • The row mirror (services/canopy-wic/src/store/models.rs ~27-54) uses #[sqlx(try_from = "String")] status. The status is typed everywhere, so the determination-status lint discovers nothing.

D3

Supersession, inside the determine transaction. store::participants::persist_certification(tx, &part) → Result<Option<WicParticipantId>, sqlx::Error> replaces create_participant, and list_active_by_person is deleted. It returns the superseded row’s id, which the handler logs at info beside the new id. It runs two statements:

  1. UPDATE wic_participants SET status = 'superseded', superseded_by = $new, updated_at = now() WHERE person_id = $p AND status = ANY($current) AND certification_start ⇐ $new_start RETURNING id. The deferred self-FK admits the forward reference.

  2. The INSERT, binding status.as_str().

    • persist_outputs (handlers.rs ~108-161) persists the participant rows in ascending person_id order, in the one transaction that also writes the determination, snapshot and outbox events. Every request therefore takes row and index locks in the same order, and requests [A, B] and [B, A] cannot deadlock.

    • A violation of wic_participants_one_current_per_person (pub const ONE_CURRENT_PER_PERSON) maps to ApiError::conflict_coded("wic_current_certification_exists", …). It fires on a race: the loser’s UPDATE matches nothing after the lock, or two first certifications of one person collide on the INSERT. It also fires on a re-determination dated strictly before the current certification’s start, because that record would end before it began. Anything else is ApiError::internal_database.

    • A same-day re-determination supersedes: the prior record never took effect and is replaced outright.

    • No future-dated certification. A certification begins on the date the applicant is determined eligible, which is never later than the service’s legal today.

      • So determine refuses an as_of after canopy_common::clock::legal_today(wic_params.legal_timezone) with 422 wic_as_of_in_future before any write. The test clock steers that date.

      • A future successor can therefore never supersede today’s certification.

    • A denied re-determination leaves the current certification alone: ending one needs 15-day notice (246.7(j)(6), #2360).

    • A superseded row keeps its signed certification_end.

D4

Reachable and documented.

  • determine mints the WicParticipantId before signing and writes it to program_extension.participant_id on approval, through json!/.into() so that no new serde_json::Value constructor site is added (quality budget B3a).

  • GET /v1/participants/{id} documents its params and the responses 200 (WicParticipant), 403 and 404. post_determine adds 409 and the new 422.

  • WicParticipant and WicCertificationStatus are registered components (services/canopy-wic/src/api/mod.rs ~33-45).

  • crates/canopy-test-lib/src/clients/wic.rs gains get_participant, and loses its "intentionally not exposed" note.

  • The WicParticipantId route doc is fixed (crates/canopy-common/src/id.rs ~469-473).

  • handlers.rs stays at or under 500 lines (quality budget B1). If it would not, persist_outputs moves to api/persist.rs.

D5

Seed and compliance.

  • The seed (tools/canopy-seed, which gains a canopy-contracts-wic dependency):

    • links each participant to its determination;

    • gives the roughly 1-in-7 terminated prior-period row its own approved determination and assessment, both dated before the prior start and with an earlier created_at (datagen.rs ~3372, ~3497-3533). This keeps caps_wic_fixture_counts and the created_at DESC order true;

    • keeps at most one current row per person;

    • types WicParticipant.status (model.rs ~2047) as WicCertificationStatus;

    • updates sql.rs and manifest.rs.

  • xtask/src/cmd/seed_verify.rs gains the edges wic_participants.application_id → applications and wic_participants.household_id → households, also listed in PROGRAM_EDGES_1929 (~1046).

  • wic.certification.dual-participation-prevention (compliance/action-catalogue/wic.toml ~354-366):

    • its description narrows to in-system prevention;

    • its trigger becomes "7 CFR 246.7(l)(1)";

    • it keeps its manual_ref;

    • it binds to wic POST /determine post_determine with the test_ref services/canopy-wic/tests/wic_test.rs::wic_redetermination_supersedes_the_current_certification;

    • its allowlist entry is removed.

  • A new unbound row, wic.certification.dual-participation-detection, is allowlisted to #837: actor = "system", trigger "7 CFR 246.7(l)(1)-(2)", manual_ref "DPH WIC CT-860.02 (Rev Jun 2018)", covering identification across local agencies, states and CSFP.

  • The scenario wic.integrity.dual-participation-detected drops #825 from its blocked_by.

  • The comments the binding falsifies are updated: GAP comments at ~355-358 and ~1167-1171, and the scenario-inventory comment at ~725-726.

Invariants

  • A person holds at most one current (active or temporary) certification, and the database refuses a second.

  • Every record names the determination that granted it, and its person, application and household match that determination.

  • A re-determination supersedes the prior record in the transaction that writes it, and no certification starts after the service’s legal today.

Units — U-A → U-B, one MR

Commit 1: docs(plans): plan the one WIC certification record (#2359). Last: docs(plans): close the WIC certification record plan (#2359).

U-A (w5) — feat(wic): make wic_participants the one certification record (#2359)

Files:

  • the migration;

  • crates/canopy-contracts-wic/{Cargo.toml,src/participants.rs,tests/roundtrip.rs};

  • services/canopy-wic/src/{store/models.rs,store/participants.rs,determine.rs,api/handlers.rs,api/mod.rs};

  • services/canopy-wic/tests/wic_test.rs and the approved-pregnant insta snapshot (which redacts participant_id);

  • crates/canopy-test-lib/src/clients/wic.rs;

  • crates/canopy-common/src/id.rs;

  • tools/canopy-seed/{Cargo.toml,src/model.rs,src/datagen.rs,src/sql.rs,src/manifest.rs,tests/integration.rs};

  • xtask/src/cmd/seed_verify.rs;

  • compliance/{action-catalogue/wic.toml,action-coverage-allowlist.toml,scenario-inventory/wic.toml}, for the D5 rows only;

  • docs/modules/ROOT/openapi/wic.json.

Tests:

  • certification_status_tokens_round_trip (proptest).

  • Ephemeral-schema tests in a #[cfg(test)] mod infra_tests in store/participants.rs (the services/canopy-wic/src/store/determinations.rs ~141-226 pattern):

    • status_check_admits_exactly_the_certification_vocabulary;

    • a_second_current_certification_is_refused, for active and temporary holders;

    • persist_certification_supersedes_and_names_the_successor;

    • superseded_requires_a_successor;

    • participant_must_match_its_granting_determination;

    • concurrent_first_certifications_leave_one_current: two sessions via connect_raw;

    • reversed_order_batches_never_deadlock: two sessions persisting [A, B] and [B, A] through the ordered persist path. One succeeds and the other gets the 409; neither gets 40P01.

  • wic_test.rs (devstack):

    • wic_approved_determination_links_its_certification_record;

    • wic_redetermination_supersedes_the_current_certification;

    • wic_redetermination_dated_before_the_current_certification_is_409, which leaves no new determination, snapshot or participant row;

    • wic_future_dated_determination_is_refused, which writes nothing;

    • wic_denied_redetermination_leaves_the_current_certification;

    • wic_get_participant_unknown_is_404.

  • Seed invariants: every participant’s determination is an approved determination of the same person, and each person has at most one current row.

U-B (w1) — docs: document the WIC certification record (#2359)

Files:

  • docs/modules/ROOT/pages/api/canopy-wic.adoc: the GET, the 409, the future-date 422 and participant_id;

  • docs/modules/ROOT/pages/data-models/canopy-wic.adoc: the columns, constraints, index and relationships;

  • CHANGELOG.adoc:

    • Added: the documented GET, supersession and the 409;

    • Changed: the typed status, participant_id, and future as_of refused;

    • Removed: transferred, and pre-link rows at cutover.

Verification

  1. Per unit, in an isolated worktree: fmt, workspace clippy with the portal features, cargo doc with broken intra-doc links denied, the non-live nextest lanes, the infra tests filtered by name, quality-budgets, neutrality-lint, the policy gates, scenarios audit, test-lanes-lint and machete.

  2. cargo xtask dev restart, CANOPY_CARGO_FEATURES=canopy-api/test-clock cargo xtask dev reload, a reseed, cargo xtask api-docs --update (only the D2–D4 changes), then git push.

Documentation Updates

  • The pages in U-B.

  • GitLab: file the three pre-existing fix: issues, and add this plan’s link to epic &106.

Review log

round vendor resolved model verdict

1 (2026-09-27)

Anthropic

claude-opus-5-5

ship — no blockers; 14 observations folded in (seed ordering and typing, same-day supersession, return value, 409 scope, seed-verify edges, stale comments, detection-row fields, schema attributes, B3a, the infra_tests module, a race test, two scope lines).

2 (2026-09-27)

OpenAI

gpt-6-astra

no-ship — both findings fixed: participants persist in person_id order, with a reversed-order deadlock test; a future as_of is refused, so a future successor cannot supersede today’s certification.

Edit this page · default