Plan: Downstream services act only on determinations of record (#2322)

Status: Done (2026-10-28) — !1826
Epic: none — the out-of-scope list of the quarantine plan (epic &86)
Issues: #2322 (T1, parent) · U1 → #3063 · U2 → #3064 · follow-ups F1 #3065, F2 #3066, F3 #3067
Branch: fix/determination-events-after-verification: one branch, two commits, ONE MR closing both child issues and the parent. This deviates from the template’s one-unit-one-MR rule on purpose: U1 alone is inert (its verdicts match no held rows) and U2 alone turns every program journey red (every event held forever), so main must never carry one without the other (see Rollout).

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

Erratum (2026-10-28): hold_for and DETERMINATION_HOLD_GENERATION live in canopy-mq (publisher.rs), not verdicts.rs: the contracts crate is pure data, and every producer and consumer already depends on canopy-mq.

Erratum (2026-10-28): D4’s dismissal stages disowned{dismissed} in quarantine_ops::apply, not record (a dismissal never reaches record, which persists a promotion); the dismiss arm gains the lock-free verified_claim signature check.

Erratum (2026-10-28): canopy-eligibility spells the twelve verdict keys as a match over the contract constants rather than calling recorded_key, the one shape mq-topology can resolve against the ACL; the contract also gains DeterminationVerdict::decode and VerdictKind so the five subscribers share one parser.

Erratum (2026-10-28): D7’s same-transaction lookup alone loses a concurrent interleaving (each transaction misses the other’s uncommitted rows), so the TANF and Medicaid staging and their verdict subscribers both take a transaction-scoped advisory lock on the determination id (class 2322); a concurrency test pins it.

Erratum (2026-10-28): four devstack tests that call canopy-tanf or canopy-snap directly (ruling Q3: a direct caller’s events stay held) now publish the verdict canopy-eligibility would have sent, through a new canopy_test_lib::verdicts helper.

Context

Each program service stages its completion events before it replies to canopy-eligibility, and before eligibility has verified anything. The keys are determination.completed.snap, tanf.determined, medicaid.determined, caps.determined and wic.determination_completed (crates/canopy-reference/src/cross_program.rs:51-71). Where they stage differs: canopy-snap inside the persist transaction in determine.rs (crate::events::publish_determination_completed(&mut tx, …) at :1251, beside application.approved and snap.case_closed); canopy-caps and canopy-wic inside their persist in services/canopy-{caps,wic}/src/api/persist.rs (CAPS with authorization.created; WIC with its supersession events); canopy-tanf and canopy-medicaid in services/canopy-{tanf,medicaid}/src/api/handlers.rs, in a second transaction opened after the determination’s own commit (tanf handlers.rs:82-174, medicaid handlers.rs:143). That second transaction is the pre-existing #477 gap: a staging failure after the commit loses the event. Downstream consumers act on those events: canopy-enrollment (auto-enroll and continuation, main.rs:270), canopy-notices (event_routing.rs, both rulesets' manifests), canopy-renewals (determination_subscriber.rs), canopy-medicaid’s ELE and TMA, and canopy-web’s live feed (sse_routing.rs).

canopy-eligibility verifies the returned envelope only afterwards. intake_envelope (orchestrator.rs:1417) records a verified, bound envelope through store::record_determination_on (store/mod.rs:247), or quarantines it: quarantine_envelope (:1582) writes quarantined_determinations through quarantine::quarantine_bytes (quarantine.rs:322), with QuarantineReason::ProvenanceRejected (:1558) for a verified envelope bound to the wrong application or operation. ADR-002 Amendment 5 says a quarantined envelope is never a determination of record and the program’s result stays pending. So an envelope that eligibility quarantines may already be enrolled, noticed and scheduled for renewal.

What already exists:

  • canopy-eligibility stages its own determination.completed (DETERMINATION_COMPLETED, crates/canopy-contracts-eligibility/src/events.rs:21) in its atomic completion commit (events.rs:7, ADR-002 A1 D10). It is per request and carries programs_approved and programs_denied as names, not determination ids. canopy-medicaid’s CMD settle already consumes it (main.rs:48-55). It stays as it is.

  • ADR-039’s event hold: Publisher::publish_tx_held, EventHold { operation_id, generation }, release_held and drop_held (crates/canopy-mq/src/publisher.rs:249-290). canopy-applications' finalize saga and canopy-persons use it (finalize_saga.rs:1038, persons/api/mod.rs:2640-2693).

  • The broker ACL in devstack/rabbitmq/definitions.json limits canopy-eligibility’s writes to ^(canopy\.events|canopy\.dlq|canopy-eligibility\..*)$; cargo xtask mq-topology lints publishers against it.

Governing decisions: ADR-001 (the program service owns its determination), ADR-002 (the signed black-box envelope; Amendment 5 quarantine; Amendment 6 CHIP binding), ADR-035 (per-member determinations), ADR-039 (single-source outbox and the hold).

Scope

In scope:

  • U1: the verdict contract and canopy-eligibility’s two verdict events, plus the consumer in each program service that releases or drops held rows.

  • U2: every program service stages its determination’s completion events held under the determination id.

Out of scope:

  • F1 (#3065): an operator path that releases a determination’s held events for a run that never recorded (an orchestrator timeout, an exhausted order, a direct caller). Fail-closed and signalled by ADR-039’s held-row gauge until then.

  • F2 (#3066): program-local derivative state written in the same transaction as the determination (for example canopy-medicaid’s ELE and TMA rows, canopy-caps authorizations). They are not events, so the hold does not reach them.

  • F3 (#3067): canopy-reporting and canopy-web reads that go to program rows directly, not through events.

  • Restricting direct callers of a program service’s determine route (today TANF, Medicaid, CAPS and WIC accept one); a determination with no eligibility request never publishes, which F1 covers.

  • canopy-eligibility’s existing determination.completed and its consumers: unchanged.

Design

D1 — the options.

  • A: consumers move to a verified-outcome event from eligibility. Rejected. The program events carry content the envelope lacks (SnapDeterminationCompleted: allotment, effective dates, postponed items, benefit-month prices, crates/canopy-contracts-snap/src/events.rs:40-191). Eligibility would have to author program semantics (ADR-001, ADR-035) or every consumer would read back from the program. Every consumer and both notice manifests change.

  • B: every consumer verifies the envelope itself. Rejected. Verification without binding misses provenance_rejected, so the acceptance test fails; every consumer needs every program’s keys; consumer and eligibility verdicts can disagree with nothing to reconcile them.

  • C: act provisionally, reverse on quarantine. Rejected. A mailed notice and an EBT issuance cannot be recalled; the compensations are corrective notices and overpayment claims, each racing the action it undoes.

  • D (recommended): the program holds; eligibility’s verdict releases or drops. Each program stages its completion events with ADR-039’s hold, keyed by the determination id. canopy-eligibility stages determination.recorded.<program> in the transaction that records a determination of record, and determination.disowned.<program> when it quarantines an envelope whose signature verified. Each program service consumes its own verdicts and calls release_held or drop_held. The gate is eligibility’s full decision, binding included; ADR-001 holds (the program still authors its events); the envelope, the consumers and the manifests are unchanged; keys stay with eligibility.

  • D′ (considered): carry determination ids on the existing request-level determination.completed instead of new per-program keys. Rejected: that event fires once per request, so an approved SNAP determination would wait on a sibling program’s pending member (#3012), and it has no disowned counterpart.

D2 — the verdict contract (crates/canopy-contracts-eligibility/src/verdicts.rs, new).

  • recorded_key(Program) → &'static str returns determination.recorded.{snap,tanf,medicaid,chip,caps,wic}; disowned_key the same under determination.disowned..

  • DeterminationRecordedV1 { determination_id, program, eligibility_request_id, application_id, household_id, person_id: Option<PersonId> }.

  • DeterminationDisownedV1 { determination_id, program, quarantined_id, reason: DisownReason }, DisownReason = provenance_rejected | dismissed (serde snake_case).

  • hold_for(DeterminationId) → EventHold { operation_id: the id, generation: 0 }. A determination id is minted once and never re-attempted, so the generation is constant.

  • Ids only, per ADR-004; envelopes carry .with_programs([program]).

D3 — recording stages the verdict (U1). store::record_determination_on takes &mut Transaction and, on Recorded, stages recorded_key(row.program) from the persisted row, so every path that records a determination emits the verdict by construction: interactive and order (record_determination), bulk, the #2673 read-back adoption, and a quarantine promotion on reverify or dismissal.

D4 — quarantine stages the disown (U1). quarantine::quarantine_bytes takes a transaction. When the reason is ProvenanceRejected (Amendment 5: the signature verified, the binding failed), it stages disowned_key with the new row’s id. On an operator dismissal, quarantine_ops::prepare today verifies the stored bytes only for a reverify (quarantine_ops.rs:6-15); U1 adds the same no-lock signature check to the dismiss arm, and record (which takes &mut PgConnection) stages disowned{dismissed} only when that check passed. An envelope whose signature never verified is untrusted: its claimed determination id is not acted on, and its events stay held (F1).

D5 — the verdict consumer (U1). Each program service gets services/canopy-{snap,tanf,medicaid,caps,wic}/src/verdict_subscriber.rs, mirroring services/canopy-persons/src/discrepancy_resolution_subscriber.rs: queue canopy-<svc>.determination-verdicts, bound to its programs' recorded and disowned keys (canopy-medicaid serves medicaid and chip). The payload is parsed typed; a program outside the service’s set is an Err (DLQ); an unknown key parks (#1131). Recorded calls release_held, disowned drop_held, both in the inbox transaction with hold_for(determination_id). It logs ids and row counts only. The broker ACL gains determination\.(recorded|disowned)\.(snap|tanf|medicaid|chip|caps|wic) for canopy-eligibility. mq-topology-allow.toml is NOT touched: it registers only keys with no in-tree consumer, and U1 lands the subscribers in the same commit as the producer (binding-first), which is what the lint requires.

D6 — holding (U2). Every outbox row a determination stages is held under hold_for(determination_id): the completion event and its companions (application.approved, snap.case_closed, CAPS authorization.created, WIC’s supersession events, and the TANF and Medicaid companions). The staging sites are: canopy-snap determine.rs:1251-1360; canopy-caps and canopy-wic services/canopy-{caps,wic}/src/api/persist.rs; canopy-tanf services/canopy-tanf/src/api/handlers.rs:82-174 and canopy-medicaid services/canopy-medicaid/src/api/handlers.rs:143, whose post-commit transactions must be threaded the determination id they do not receive today. The staging functions accept only the held form (publish_tx_held), and the unheld path is deleted. canopy_mq::stage_outbox_tx_held is added beside stage_outbox_tx for callers that stage without a Publisher. Moving TANF’s and Medicaid’s staging into the persist transaction itself (closing #477) is tempting but out of scope; U2 only holds what each site stages. F2’s rows are not events and are out of scope.

D7 — a later quarantine. Under D a quarantine always precedes release, and Amendment 5 never demotes a determination of record, so an action already taken never meets a later quarantine. The reverse happens: a reverify promotion records the determination and its events release late (superseding Amendment 5’s "the program service’s own events are left as they were"); a dismissal of a verifying envelope drops them; anything else stays held and the ADR-039 held-row gauge (canopy_mq_outbox_held_*, CANOPY_MQ_HELD_AGE_WARN_SECS) reports it. Ordering: a program replies to eligibility only after its persist commit, so for SNAP, CAPS and WIC the held rows exist before any verdict can. For TANF and Medicaid the post-commit staging (D6) can race a fast verdict; release_held on zero rows is idempotent, so U1’s subscriber must re-run the release when the staging commit lands after the verdict. U2 therefore makes those two staging sites release their own rows immediately if a recorded verdict for the id is already in the inbox (a determination_verdicts lookup in the same transaction), and a test pins that order.

D9 — pinned claims. hold_for uses generation 0 because a determination id is minted once per persist and never re-attempted under the same id (a retry mints a new id); U1’s contract test pins the constant, and U2’s hold test asserts every row of one determination carries the same (id, 0). The verdict-before-staging race is pinned by U2’s TANF and Medicaid order tests.

D8 — invariants.

  • A program completion event publishes only if canopy-eligibility recorded a verified, bound envelope with that determination id, or promoted one.

  • Only an envelope whose signature verified ever drops events.

  • Consumers, notice manifests and the ADR-002 envelope are unchanged.

Maintainer rulings (2026-10-28, recorded on #2322)

  1. Q1, the option: D. It is the only option that gates on binding and leaves consumers, manifests and the envelope untouched.

  2. Q2, when to drop: only when the signature verified (provenance_rejected at intake; a dismissal whose stored bytes verify). Bytes that do not verify name nothing trustworthy, so their holds stay held (F1).

  3. Q3, direct callers: hold all five programs the same way. A determination from a direct caller never publishes, because no determination of record exists. F1 is the operator path; restricting callers is a separate decision.

  4. Q4, where the decision lives: ADR-002 Amendment 7 (publication waits for verification), with an "Amended by" note on ADR-039 (a second hold owner). The envelope contract itself does not change, so no new ADR.

Units (weights by complexity) — U1 → U2, one branch, a commit each

Weights: 1 trivial · 2 small · 3 medium · 5 large · 8 very large. The MR carries Closes #2322.

U1 (w5) — the verdicts: contract, producer, consumers

Files: crates/canopy-contracts-eligibility/src/{verdicts.rs (new), lib.rs} and crates/canopy-contracts-eligibility/tests/roundtrip.rs; services/canopy-eligibility/src/{store/mod.rs, quarantine.rs, quarantine_ops.rs, orchestrator.rs, bulk/arm.rs, events.rs}; services/canopy-{snap,tanf,medicaid,caps,wic}/src/{verdict_subscriber.rs (new), main.rs} plus a determination_verdicts inbox table per program (one migration each, the D7 lookup); crates/canopy-mq/src/publisher.rs (stage_outbox_tx_held); devstack/rabbitmq/definitions.json; docs/modules/ROOT/pages/adrs/adr-002-black-box-determination-contract.adoc (Amendment 7), adr-039-single-source-outbox-schema-and-event-hold.adoc (the note); api/canopy-eligibility.adoc (Events Published), api/canopy-{snap,tanf,medicaid,caps,wic}.adoc (Events Consumed), data-models/canopy-{snap,tanf,medicaid,caps,wic}.adoc (the table); CHANGELOG.adoc.

Tests:

  • Contract (roundtrip proptest): both payloads and DisownReason; recorded_key/disowned_key pin the six keys; hold_for is the id with generation 0.

  • canopy-eligibility infra: recording an envelope stages exactly one recorded row naming the determination, on each path (interactive, order, bulk, read-back adoption, promotion); a provenance_rejected quarantine stages one disowned; a signature_invalid quarantine stages nothing; a dismissal of a verifying envelope stages disowned{dismissed}.

  • Each program’s subscriber (infra): a recorded verdict releases exactly the held rows of that determination and no other; a disowned drops them; a replay releases zero rows; a verdict for a program the service does not serve is an Err.

  • mq-topology is clean; the ACL test in the devstack suite admits the new keys for eligibility only.

Docs: ADR-002 Amendment 7 states D1–D8 and the rulings; the two API pages' event tables; CHANGELOG === Changed.

U2 (w5) — hold every determination’s events until its verdict

Files: services/canopy-snap/src/{determine.rs, events.rs}; services/canopy-{caps,wic}/src/{api/persist.rs, events.rs}; services/canopy-{tanf,medicaid}/src/{api/handlers.rs, events.rs} (threading the determination id into the post-commit staging, and the D7 immediate release); crates/canopy-test-lib journey helpers that await program events; tests/e2e/lib/* waits if any poll a program event; api/canopy-{snap,tanf,medicaid,caps,wic}.adoc (Events Published: "held until the determination is recorded, #2322"); CHANGELOG.adoc; this plan and nav.adoc (the close).

Tests:

  • Per program (infra): after determine, every outbox row of the determination carries hold_for(id) (the same (id, 0) on each) and published_at IS NULL; nothing publishes until a recorded verdict; after it, the drainer publishes them all.

  • TANF and Medicaid order (infra): a recorded verdict that lands before the post-commit staging still ends with the rows released (the staging site finds the verdict and releases its own rows), and one that lands after releases them through the subscriber.

  • The acceptance test (eligibility journey, infra): an envelope eligibility quarantines (a tampered signature, and a provenance_rejected binding) does not enrol, send a notice or schedule a renewal: the enrollment, notices and renewals tables hold no row for it after the drainers run, and the held rows are still held (signature) or gone (provenance).

  • The happy path end to end: the battery’s existing SNAP, TANF, Medicaid, CAPS and WIC e2e journeys still pass; their waits are the observed-condition polls they already use, now spanning two more outbox hops.

  • Mutation: a program staging unheld fails its hold test; eligibility recording without staging the verdict fails the end-to-end journey (nothing ever publishes).

Docs: the five API pages; CHANGELOG === Fixed (the #2322 entry); the close: Status Done (YYYY-MM-DD) — !N, archive, nav, plan-lint --done.

Risks

  • A genuine determination that is never recorded publishes nothing (orchestrator timeout, exhausted order, unresolved quarantine, direct caller). fail-closed; the held-row gauge signals it and the application stays pending for the worker. Mitigation: F1.

  • A down verdict drainer or subscriber delays enrollment and notices. fail-closed; at-least-once delivery resumes them.

  • Two extra outbox hops of latency in every journey. fail-closed for the battery: a journey that waited on a program event waits longer. Mitigation: U2 measures the e2e lane; if a journey’s wait budget is exceeded, raise that budget in the same commit, never poll faster.

  • Staging fails after the program’s commit (pre-existing, #477): the verdict releases zero rows. silent; the subscriber logs the count. Mitigation: unchanged scope, noted in Amendment 7.

  • F2 and F3 ignore the verdict. silent, named and filed.

  • A forged verdict. fail-open if the ACL were wrong. Mitigation: the ACL limits publishers to canopy-eligibility and mq-topology lints it.

  • U2 lands without U1. Every program event would stay held forever and the e2e lane turns red. fail-closed; the rollout order below prevents it.

Rollout

Pre-1.0, so no shims. U1 lands first: its verdicts match no held rows and release nothing. U2 then turns holding on in all five programs in one commit. Both ship in one MR so main never carries U2 alone. U1’s broker ACL needs cargo xtask dev reload (the broker reads definitions.json at boot), which the battery’s devstack refresh performs.

Verification

  1. cargo xtask test: the unit and integration lanes pass (see Testing).

  2. cargo xtask dev reload, then cargo xtask e2e: every program journey passes, and the e2e lane’s wall time is recorded in the MR against the previous battery.

  3. cargo xtask mq-topology and cargo xtask quality-budgets are clean.

  4. The acceptance test: a quarantined envelope leaves no enrollment, notice or renewal row.

  5. cargo xtask validate with CANOPY_CARGO_FEATURES=canopy-api/test-clock,canopy-api/test-fault.

  6. Close: U2 sets Status Done (YYYY-MM-DD) — !N, moves this plan and its nav entry under plans/archive/, and passes cargo xtask plan-lint --done.

Documentation Updates

  • ADR-002 Amendment 7 and the ADR-039 "Amended by" note (U1).

  • api/canopy-eligibility.adoc Events Published (U1); the five program pages' Events Consumed (U1) and Events Published (U2).

  • services.adoc: the eligibility row’s events (U1).

  • CHANGELOG.adoc == Unreleased: U1 === Changed, U2 === Fixed. A cut is due (#3016); making it is not this plan’s task.

Review log

round vendor resolved model verdict

1

Anthropic

claude-fable-5-1

FLAGS (2): no child issue per unit and the one-MR choice unexplained; the WIC key misnamed (wic.determination_completed), staging sites beyond determine.rs not named, and two claims with no pinning test. Fixed in the draft (child issues, the one-MR rationale, the staging inventory, D9).

2

Google

gemini-4-argon

FLAGS (1): TANF and Medicaid stage in a post-commit transaction (not the persist), quarantine_ops verifies only on reverify, and mq-topology-allow.toml is for unconsumed keys only. Fixed in the draft (D6, D7’s race and its test, D4’s dismiss check, D5).

Edit this page · default