Plan: IEVS income stays inert until its resolution links it (#2546)

Status: Done (2026-10-23) — !1741
Issues: #2546 (one issue, one MR, five units)
Branches: fix/ievs-income-held-until-resolved

This is a Design + Scope plan: GitLab owns tracking, and the plan freezes when U1 starts.

Erratum (2026-10-23): the five units land as one commit. The persons claim route’s refusal of IEVS claims (D3) and its two consumers (D6, D7) must switch together, and U1’s contract docs describe U2’s behaviour. The accept’s landing is a dedicated redirect_to_case_ievs_accepted, not a parameterised redirect. event-delivery-protocol.adoc gains no row, having no per-consumer table; the consumer is documented on the canopy-persons API page. D5’s promotion takes the newest pending proposal of F that the resolving worker held, not any proposal of F: another worker’s proposal of the same fact, whose flip canopy-snap answers as the stored resolution, must not be applied under the resolver’s name. An accept resolved by a service promotes and consumes nothing; any other resolution consumes.

Context

An IEVS accept (canopy-web services/canopy-web/src/api/ievs.rs accept_discrepancy; canopy-cli verification accept) writes the worker-verified income to canopy-persons as accepted_verified. It then flips the canopy-snap discrepancy with that fact as resolved_fact_id. Only the flip is guarded (#2544), and it runs after the fact exists. A resolution that lands between the two leaves an accepted fact that no resolution links, and that fact changes eligibility.

A claim (lease) on the discrepancy cannot fence the persons write. The design review of 2026-10-23 found that each of these still lands an unlinked accepted fact:

  • a write that commits after the lease lapses;

  • a withdrawal mid-accept;

  • a twin releasing a shared claim;

  • an old client;

  • a retry lookup outside the fact’s validity window.

The maintainer ruled (2026-10-23): inert until linked. ADR-027 §2 already holds the shape. A proposed claim never feeds a determination, coexists with an accepted fact rather than superseding it, and "acceptance is what supersedes".

The design rests on these facts:

  • The income no-overlap constraint covers only claim_status LIKE 'accepted%', and snapshot_and_supersede touches only accepted rows (services/canopy-persons/src/store/income_versions.rs, migration 20260604000000).

  • Every determination read filters determination_statuses() (store/fact_versions.rs).

  • Of the service logins, only canopy-snap’s may publish ievs.discrepancy_resolved (devstack/rabbitmq/definitions.json). The administrator login is unrestricted there, as it is for every key (event-delivery-protocol.adoc). The payload (services/canopy-snap/src/events.rs) has eight fields: resolved_by (an Actor), discrepancy_id, application_id, person_id, resolution_status, income_type, resolved_fact_id (nullable) and program.

  • canopy-persons' bootstrap already builds a subscriber and inbox, and its broker user may consume canopy-persons.* queues.

Scope

In scope:

  • A worker-held proposed income version.

  • The proposal write and the pending-proposals read.

  • Refusal of direct IEVS claims.

  • Promotion on the resolution event.

  • The canopy-web and canopy-cli accepts moved onto proposals.

  • The Income tab’s "being recorded" row.

Out of scope:

  • Reject and manual resolve. They are unchanged: an unlinked proposal is inert, so they need no persons check.

  • The manual resolve’s status gap, and pending proposals of a withdrawn discrepancy. Both are follow-ups, listed under Verification.

Design

D1. A worker may hold a proposal

check_author_status (crates/canopy-contracts-facts/src/lib.rs) admits proposed with no author, as today for an automated lead, or with a Worker. The Worker case is an IEVS accept held until its resolution links it. feeds_determination is unchanged, so a held proposal never feeds a determination.

ADR-027 gets an as-built amendment for this, plus a §2 erratum line pointing to it. The ADR body is not edited.

D2. The proposal write

POST /v1/persons/{id}/income/proposals takes IncomeProposalRequest { value: IncomeFactValue, discrepancy_id: IevsDiscrepancyId, valid_from: NaiveDate, valid_to: Option<NaiveDate>, fact_id: Option<Uuid> }. The type is deny_unknown_fields and lives in crates/canopy-contracts-persons/src/income.rs. fact_id stays a Uuid, matching IncomeClaimRequest.

The route admits through a new delegated row in crates/canopy-auth/src/delegated.rs, PERSONS_POST_PERSONS_ID_INCOME_PROPOSALS: Admission::system().and_user_roles_via(&[WEB, CLI], CASEWORKER_WRITER_ROLES), the same admission as PERSONS_POST_PERSONS_ID_INCOME_CLAIMS. A system caller is admitted, so it reaches the author rule below and gets 422 rather than 403.

Persons fixes the provenance:

  • The source is ievs.

  • The origin is ievs:{discrepancy_id}, rendered from the parsed UUID, so no client spelling can miss a lookup.

  • The author is Author::worker(user.oidc_subject()?) from principal.user(). With no user (a system caller), the answer is 422 UnprocessableEntity. claim_author is not reused: its system branch trusts a body author, and this body has none.

The value passes the same checks as in claim_income: the validator, the non-negative amount check and require_amount_in_range. A supplied fact_id must be the person’s own fact (require_fact_ownership); otherwise persons mints one (Uuid::now_v7).

A new income_versions::append_income_proposal inserts one proposed row under the per-fact advisory lock. It never calls snapshot_and_supersede. It stages no income.claimed and no persons.income_changed, so canopy-renewals' frequency-shift minting and the Medicaid Express Lane re-evaluation never see a proposal.

The answer is 201 IncomeProposalResponse { fact_id, version_id }, under the platform idempotency middleware.

D3. Direct IEVS claims are refused

POST /v1/persons/{id}/income/claims with source: ievs gets 422 verified_income_is_proposed, before any write. An old canopy-web or canopy-cli, or a forged call, cannot author an accepted IEVS fact. Promotion (D5) is the only path to one.

D4. The pending-proposals read

GET /v1/persons/{id}/income/proposals?discrepancy_id= answers Vec<IncomeProposal { fact_id, version_id, value, valid_from, valid_to, recorded_at }>. It lists the person’s proposed, superseded_at IS NULL rows of origin ievs:{discrepancy_id}, in any validity window, newest first, with values opened as list_by_persons_as_of opens them. A missing discrepancy_id is a 400. A new delegated row, PERSONS_GET_PERSONS_ID_INCOME_PROPOSALS, copies the admission of PERSONS_GET_PERSONS_ID_INCOME.

D5. Promotion: an inbox consumer in canopy-persons

Queue canopy-persons.ievs-resolutions is bound to ievs.discrepancy_resolved. The consumer lives in a new module, services/canopy-persons/src/discrepancy_resolution_subscriber.rs, which has a QUEUE const, a KEYS literal slice, and handle(deps: &ResolutionDeps, envelope: &EventEnvelope, tx: &mut Transaction<'static, Postgres>) → anyhow::Result<()>. ResolutionDeps { publisher, kek, tz } is shared through an Arc. Wiring mirrors canopy-renewals' wire_continuation_consumer and ContinuationDeps (services/canopy-renewals/src/main.rs), called from canopy-persons' main.rs.

The payload is canopy_contracts_snap::events::IevsDiscrepancyResolvedV1, which carries the eight fields above, with discrepancy_id: IevsDiscrepancyId, person_id: PersonId and resolved_fact_id: Option<Uuid>. canopy-snap serializes that struct instead of json!, with unchanged JSON. canopy-persons gains a canopy-contracts-snap dependency.

The handler runs in the inbox transaction:

  1. If the status is not accepted_verified, or resolved_fact_id is null, it marks every pending proposal of that person and origin consumed (superseded_at) and acks. A reject, a manual resolve and a legacy unlinked accept promote nothing.

  2. Otherwise, with fact F, it takes the per-fact advisory lock of F first, which serialises it against a concurrent proposal write. It then reads, with FOR UPDATE, the newest pending proposed row with fact_id = F, person_id = person_id and that origin, through a new income_versions::read_pending_proposal(conn, kek, person_id, fact_id, origin) → Option<PendingProposal { version_id, value: IncomeFactValue, valid_from, valid_to }>. That opens the row as list_by_persons_as_of does (resolve_read_dek, open_money, open_text).

    • If there is none, it warns and acks. This covers a legacy accepted fact, or a link to another person’s or origin’s fact, which the predicates refuse.

    • If the fact’s key has been shredded (ReadDek::Redacted), it warns and acks. A redacted fact is never revived.

    • If resolved_by is not Actor::Human, it logs an error and acks, and the proposal stays inert (ADR-027 §1: System never authors a fact).

    • Otherwise it calls append_income_version with IncomeClaimRequest { value, source: Ievs, author: Author::worker(subject), origin: Some(origin), valid_from, valid_to, fact_id: Some(F) }, using the proposal’s value and window. A worker author derives accepted_verified. That supersedes overlapping accepted rows, as a correction does today. It then marks every pending proposal of the origin consumed. Finally it stages income.claimed and persons.income_changed in the same transaction, through the staging half of persist_and_publish_income_claim, extracted into a helper both callers share.

The inbox deduplicates a replay. A consumed proposal is never pending again, so a re-delivery finds nothing; this is the fenced-UPDATE pattern of canopy-medicaid’s CMD settle. A failing promotion retries, then dead-letters. The fact stays proposed, and so is never wrong, until an operator replays it.

Two config changes go with the consumer:

  • compliance/data-tenancy-authorisation.toml keeps [class.ievs].authorised_services unchanged. Widening it would need an ADR-004 revision, and persons holds no IEVS match data. New names avoid the ievs_ prefix. If cargo xtask compliance audit-data-tenancy still flags a canopy-persons file, a entry (class ievs, service canopy-persons, that file’s glob) records the reason: the event carries ids and a status, never a figure.

  • xtask/mq-topology-allow.toml drops the key’s no-consumer entry.

D6. canopy-web

The accept runs: bind, accept_target, choose the fact, write the proposal (D2) under the existing claim_key, then flip with that fact. The fact is:

  • the Correct plan’s self-report id;

  • otherwise the pending proposal’s fact, found by a new prior_proposal (D4) that replaces prior_fact;

  • otherwise none, so persons mints one.

A successful flip redirects with a new notice, ievs-accepted: "Accepted. The verified income applies once the resolution is processed. Refresh before running a determination."

A 409 from the flip names its code. For discrepancy_already_resolved: "another action resolved this discrepancy first; the income you entered was not applied". For discrepancy_withdrawn: "a verification re-run withdrew this discrepancy; the income you entered was not applied". The code is read through a new ServiceError::upstream_code() → Option<&str>, parsed from the problem+JSON code field when ServiceError::http is built (services/canopy-web/src/clients.rs). diagnostic() stays never-UI. flip_failed keeps its other-failure arm.

The notice rides a new redirect_to_case_with_notice(household, program, section, notice) beside redirect_to_case (api/fact_editor.rs), which hard-codes eligibility-changed. ievs-accepted joins the notice allowlist (api/case_detail/allowlists.rs). prior_ievs_fact_id goes with prior_fact. New helpers live in api/ievs/accept.rs, keeping services/canopy-web/src/api/ievs.rs under its line budget.

The Income tab changes too. canopy-web’s discrepancy type (api/case_detail/income_ievs.rs) gains resolved_fact_id. A discrepancy is being recorded when it is accepted_verified and no served IncomeRecord has id == resolved_fact_id with verification_source == Some("ievs"). That covers the correction path, whose linked fact is the self-report still served unverified, and a new fact not yet served at all. Both loops apply it:

  • the matched loop (income_ievs.rs) shows the paired self-report’s row as "Verified — being recorded" with the discrepancy’s verified figure, instead of marking the old figure verified;

  • the synthetic loop (income_tab.rs) renders the same row where today it renders nothing.

D7. canopy-cli

verification accept runs:

  1. Read GET /v1/verification/discrepancies/{id}. The subject is its person_id. --person-id is removed, and so is --author-sub: the author is the bearer.

  2. Find a pending proposal (D4).

  3. Write the proposal with fact_id set to --fact-id, else the pending one’s, else none.

  4. Flip with resolved_fact_id.

reject is unchanged.

Units (weights by complexity) — U1 → U2 → U3 → U4 ‖ U5

One branch carries one signed commit per unit, merged as one MR.

U1 (w2) — contracts and ADR

Files: crates/canopy-contracts-facts/src/lib.rs, crates/canopy-contracts-persons/src/income.rs, crates/canopy-contracts-snap/src/events.rs, docs/modules/ROOT/pages/adrs/adr-027-worker-fact-authoring-and-provenance.adoc.

Tests:

  • a_worker_may_hold_a_proposal_that_never_feeds_a_determination

  • roundtrip proptests of the new types

  • the_resolution_event_keeps_its_json_shape, a golden test against today’s payload

Two existing tests pin the old author table and change, as the commit explains: author_status_table_admits_exactly_the_adr_027_pairs gains the seventh pair, and provenance_error_names_the_author_kind_not_its_identity uses an applicant on proposed as its refused example.

U2 (w5) — canopy-persons

Files: services/canopy-persons/src/api/mod.rs (routes and the D3 refusal), src/store/income_versions.rs, a new src/discrepancy_resolution_subscriber.rs, services/canopy-persons/src/main.rs, Cargo.toml, crates/canopy-auth/src/delegated.rs (two rows), and the topology file (plus the compliance allowlist if the audit asks).

Infra tests:

  • a_proposal_coexists_with_the_self_report_and_feeds_nothing

  • an_ievs_claim_is_refused_before_any_write

  • a_resolution_promotes_only_the_proposal_it_links (two accepts)

  • a_rejection_leaves_every_proposal_inert (accept versus reject)

  • a_proposal_written_after_its_resolution_stays_inert

  • a_replayed_resolution_promotes_once

  • a_link_to_another_persons_fact_promotes_nothing

  • a_service_resolver_promotes_nothing

  • promotion_stages_the_income_events_and_a_proposal_stages_none

  • a_future_dated_proposal_is_found

Concurrency test: a_proposal_racing_its_promotion_never_feeds_unlinked. Two pools insert a second proposal while the handler promotes the first, and the as-of read serves only the linked fact.

The IEVS cases of tests/fact_version_writes_test.rs move onto the proposal route and a delivered resolution. The commit says why: direct IEVS claims are refused.

U3 (w1) — canopy-snap

Files: services/canopy-snap/src/events.rs.

The publisher serializes IevsDiscrepancyResolvedV1. The existing event tests, plus U1’s golden test, pin it.

U4 (w3) — canopy-web

Files: services/canopy-web/src/api/ievs.rs, api/ievs/accept.rs, services/canopy-web/src/clients.rs, api/fact_editor.rs, api/case_detail/allowlists.rs, api/case_detail/income_ievs.rs, api/case_detail/income_tab.rs, api/mock_upstream/ievs.rs. In the mock, twin_claim becomes the proposal route, and served_incomes serves accepted facts only.

Tests:

  • an_accept_proposes_then_flips_with_the_proposals_fact

  • a_retry_reuses_the_pending_proposal

  • a_refused_flip_says_the_income_was_not_applied (both codes)

  • an_accepted_discrepancy_awaiting_promotion_shows_being_recorded

The route tests pinning /income/claims for IEVS move to the proposal route. The commit says why.

U5 (w2) — canopy-cli and the journey

Files: tools/canopy-cli/src/cmd/verification.rs, tools/canopy-cli/src/main.rs, tests/e2e/specs/worker-ievs-resolution.spec.ts.

path_segment_tests.rs expects the discrepancy read and the proposal route, and a new test is added: a_cli_accept_takes_the_subject_from_the_discrepancy. The journey’s one-shot personsHasIevsFact becomes expect.poll, because promotion is asynchronous.

Verification

  1. Static gates: fmt, clippy -D warnings, quality-budgets, migrations-lint, mq-topology, delegated-routes, compliance audit-data-tenancy, test-lanes-lint --static, check-docs, api-docs and plan-lint.

  2. CANOPY_TEST_INFRA=required cargo nextest run over canopy-persons, canopy-snap, canopy-web, canopy-cli and canopy-contracts-facts, after cargo xtask dev reload for the new route and queue.

  3. Playwright worker-ievs-resolution.spec.ts against the real services.

  4. A mutation check per guard, each of which must fail its test:

    • a proposal write that supersedes;

    • promotion without its person or origin predicate;

    • promotion of a rejected resolution;

    • the claim route accepting source: ievs.

  5. The pre-push battery.

File these follow-ups and /relate them (search first):

  • The manual resolve forwards any status, so it can set accepted_verified with no fact.

  • A withdrawn discrepancy publishes no event, so its pending proposals stay pending (inert).

  • The stale snap_flip_client name in crates/canopy-auth/src/identity_policy/call_graph.rs.

Documentation Updates

  • api/canopy-persons.adoc (the routes, the refusal, the consumer) and data-models/canopy-persons.adoc (held proposals, consumed marking)

  • api/canopy-web.adoc (the accept flow and the IEVS row) and api/canopy-snap.adoc (the typed event)

  • tooling/canopy-cli.adoc (verification accept: the dropped flags and the proposal route) and the services.adoc persons row, which says facts are written only through */claims

  • event-delivery-protocol.adoc (the consumer, and the dead-letter replay line), authorization-inventory.adoc (two persons rows), docs/modules/ROOT/openapi/persons.json

  • CHANGELOG.adoc Fixed and Changed, with the deploy order: canopy-persons, then canopy-snap, then canopy-web and canopy-cli. In between, an old accept is refused at persons before any write.

  • The ADR-027 amendment (U1)

Review log

round vendor resolved model verdict

1

Anthropic

Claude Opus 5.5, a fresh subagent given only the plan and the rules

no-ship: eight blockers, all fixed in-plan. They were the ADR-004 tenancy matrix (scanner allowlist, not authorised services); the routes' delegated rows, author rule and validation; the consumer’s deps and sealed-value handling; canopy-web reading a 409’s code; the being-recorded rule on the correction path; the two contract tests the author table pins; the discrepancy-id newtype; and the CLI doc page.

Edit this page · default