Plan: canopy-applications Is the One Writer of Its Determination State (#3202)
Status: Done (2026-11-05) — U1–U4 merged
Epic: none
Issues: #3202 (parent) · #3237 U1 (w2) · #3238 U2 (w5) · #3239 U3 (w5) · #3240 U4 (w2)
Branches: feat/3202-recorded-verdict-fields, fix/3202-applications-projects-determinations, refactor/3202-web-reads-not-writes, test/3202-determine-outlives-the-bff
Erratum (2026-11-04): Until U3 retires the route, U2 adds an optional eligibility_request_id to RecordDeterminationRequest and canopy-web sends DetermineResponse.request_id (both callers), so a gateway record and a verdict of one request agree on the sibling rule; without it a gateway row would carry no request id and a later sibling verdict would be judged as from another request.
Erratum (2026-11-05): U3 removed RecordDeterminationRequest with the route, so the eligibility_request_id field the erratum above added went with it; the verdict carries the request id.
Erratum (2026-11-05): projection_wait_ms defaults to 1_000, not 2_000, so determine_timeout_ms (8_000) plus it stays inside the 9 s bound the other htmx budgets keep.
Erratum (2026-11-05): hyper drops a request's future when its client disconnects, so a determine canopy-web stopped waiting for was cancelled rather than committed late, and a fault hold on canopy-eligibility's own router runs before its handler. U4 therefore also runs canopy-eligibility's admitted determine on its own task, and its regression holds canopy-snap in specs/fault-determine-outlives-the-bff.spec.ts, a fault-lane spec, not the default-project spec U4 names.
Erratum (2026-11-05): await_projection reads through canopy-web's applications client, not the scoped write clients (which have no read), and takes the wait as an argument.
This is a Design + Scope plan: GitLab owns tracking, the child issues carry the implementer brief, and the plan freezes when U1 starts.
Context
canopy-applications' application_programs.status and the parent applications.status (determined once every program is terminal) are durable facts. Inside the owning service, the postponement and reopen sagas dispatch their own determinations and record them in-process (record_and_settle and record_and_settle_conversion, services/canopy-applications/src/postponement_saga.rs; record_and_settle, src/reopen_saga.rs), settling their episode in the same transaction. Every other determination reaches the application only through canopy-web, a UI gateway, performing a cross-service dual write with no transaction around it. run_determination and approve_application (services/canopy-web/src/api/applications.rs) call POST /v1/eligibility/determine, then record_response_outcomes posts each program’s representative result (one_per_program, ranked by outranks: an approved sibling over a denied one, else the newer UUIDv7) to POST /v1/applications/{id}/programs/{program}/determination; the quarantine worklist’s promotion (services/canopy-web/src/api/ops_quarantine.rs, #2061) is a second caller of the same function. The endpoint (record_determination, services/canopy-applications/src/api/mod.rs) takes the SNAP household lock, runs gate_record_back (the #1707 refusal when a named postponement episode is not open, which stages determination.record_back_refused, #1822, api/postponement_record_back.rs), writes store::record_determination (UPDATE application_programs … WHERE determination_id IS NULL OR determination_id ⇐ $3, answering Recorded, NoRow or Superseded, the fallback read classifying a withdrawn or administratively denied row), settles a named reopen or postponement episode, and recomputes the parent (store::recompute_application_status). If canopy-web stops waiting (determine_timeout_ms, #3199) or fails between the two calls, canopy-eligibility still commits and signs the determination and the application never learns of it. The e2e library carries its own copy of the BFF logic for the same reason (recordDeterminationBack, tests/e2e/lib/given/determine.ts, whose comment notes that a determination alone leaves the application submitted).
The event that should drive this already exists. Since #2322 (ADR-002 Amendment 7), store::record_determination_on (services/canopy-eligibility/src/store/mod.rs) stages determination.recorded.<program> (DeterminationRecordedV1, crates/canopy-contracts-eligibility/src/verdicts.rs) in the transaction that records the determination of record, on every path: interactive, order, bulk, held adoption and quarantine promotion (#3119), and never for a disowned determination. The BFF record-back predates it. The per-program completion events are no substitute: only determination.completed.snap carries the record-back fields; tanf.determined and medicaid.determined carry no determination id, and caps.determined / wic.determination_completed no denial codes or provenance. The persisted ProgramDetermination row the verdict is built from (store/models.rs) holds the status, denial codes and provenance trio the determine response gives the BFF.
The maintainer ruled on 2026-11-04 (#3202, option A) that canopy-applications consumes the completion signal and records the outcome itself, and on the same day that the end state is one writer: the BFF record-back is retired, not kept as a fast path.
Scope
In scope:
-
The verdict carries the record-back fields and the request’s origin.
-
canopy-applications consumes
determination.recorded.*and projects each determination the BFF recorded today, with the #1707/#1822 guards, the sibling rule as a store rule, and a refusal kept as application state the reads expose. -
The record-back route, both canopy-web callers, the test-lib client method and the e2e helper go; canopy-web renders from a read of the application after a determine, with a bounded wait on the projection.
-
A regression test that a determine outliving the BFF’s budget still lands on the application.
Out of scope:
-
Projecting order-originated and bulk determinations onto the application (CMD and work-sanction orders, the COLA mass change). The BFF never recorded them, and they are the case’s continuation, not the application’s decision. If that changes, it is its own issue.
-
Making the determination request asynchronous end to end. The synchronous determine response stays: the sagas and the worker’s render use it, and the orchestrator commits whether or not the caller waits.
-
The per-program completion events' payloads (nothing new reads them).
Design
D1 — The verdict carries the record-back fields (canopy-contracts-eligibility)
DeterminationRecordedV1 gains, all from the persisted ProgramDetermination row (so a same-bytes re-land answers from the row of record, as the determine response does, 2061): status: DeterminationStatus, denial_reason_codes: Option<Vec<String>>, benefit_effective_date: Option<NaiveDate>, effective_date_basis: Option<EffectiveDateBasis>, operation_id: Option<DeterminationOperationId>, and origin: Option<RequestOrigin>. The origin lives on the request, not the determination (EligibilityRequest.origin_source/origin_ref, store/models.rs; ProgramDetermination carries only eligibility_request_id), so record_determination_on reads the request row by det.eligibility_request_id inside its transaction (one SELECT origin_source, origin_ref FROM eligibility_requests WHERE id = $1) and builds the origin as DeterminationCompletedV1.origin is built; its signature and five call paths are unchanged. An order’s request carries one; an interactive, bulk (bulk/admission.rs inserts none) or re-landed request carries none. The optional fields are [serde(default, skip_serializing_if = "Option::is_none")]; the type loses Copy (it holds a Vec), and its users clone. Pre-1.0, no compatibility shim: every program service’s verdict consumer deserializes the widened type and ignores the new fields.
D2 — What canopy-applications projects
A pure function fn projects(verdict: &DeterminationRecordedV1) → Option<ProgramDeterminationRecord> in a new services/canopy-applications/src/determination_subscriber.rs decides. It answers None (ack, write nothing) when the verdict has an origin (an order) or its basis kind is mass_change_cola (the bulk run, whose request carries no origin, which is why the basis is tested too). Otherwise it builds the record with the mapping the BFF holds today (record_back_outcome, determinations_to_record), moved into canopy-applications' domain: approved → Approved; denied → Denied; sanctioned → Denied with the sanctioned token first in the denial codes. The mapping is total over DeterminationStatus. RecordDeterminationRequest and RecordedProgramStatus leave canopy-contracts-applications with the route (D5); the record is a service-internal type.
D3 — The sibling rule becomes a store rule
A per-member program (Medicaid, CAPS, WIC: one determination per subject, ADR-035) yields several determinations per request, and the BFF recorded one: the approved sibling, else the newest. A consumer sees them one at a time, so the rule moves into store::record_determination. application_programs gains determination_request_id UUID NULL (forward migration), written from the verdict’s eligibility_request_id. The incoming determination replaces the recorded one when the row has none; when both are from the same request and the incoming one outranks it ((status = approved, determination_id) greater); or when they are from different requests and the incoming id is newer. Otherwise the store answers Superseded. One SQL predicate in the existing UPDATE, the fallback read classifying the miss as today.
D4 — The consumer, and a refusal as state (canopy-applications)
determination_subscriber::spawn binds queue canopy-applications.determinations to determination.recorded.snap, .tanf, .medicaid, .chip, .caps and .wic on canopy.events, through the same boot.subscriber.subscribe(queue, &keys, pool, prefetch, handler) call that mounts canopy-applications.notice-dispatched in main.rs, with the same canopy_mq inbox (event_inbox, processed in the handling transaction) and failure posture: a payload that does not parse is Err (nack, to the DLQ, #1014). The handler runs the record-back core lifted out of the HTTP handler into api::record_back::apply(tx, application_id, program, &record) → Result<ApplyOutcome, ApplyError>: the SNAP household lock, gate_record_back, the store write, the episode settles, the parent recompute. The consumer acks every ApplyOutcome (Recorded, Superseded, NoRow, Withdrawn, AdministrativelyDenied, Refused), logs the non-Recorded ones at INFO with ids only, and returns Err only for a database or broker failure (requeue). canopy-applications' read permission on canopy.events already admits .* (devstack/rabbitmq/definitions.json), and the queue name matches its configure pattern. cargo xtask mq-topology finds the binding by parsing the subscribe( call in-tree; the six keys already have consumers (the program services' verdict subscribers), so xtask/mq-topology-allow.toml is untouched.
The sagas keep their in-process record: it settles their episode in the step’s own transaction, and the saga’s next state depends on it. The consumer also sees those determinations' verdicts. When the saga lands first, apply is a replay: the store write is idempotent for the same id and the episode settle answers Replayed. When the consumer lands first, the saga finds its program row no longer owned by its episode and leaves it alone, the branch both sagas already take when another writer settles first (their household or row lock serializes the two).
A #1707 refusal is no longer a 409 a caller renders: gate_record_back records it on the program row, application_programs.record_back_refusal JSONB NULL ({ determination_id, code, refused_at }, the same migration as D3), cleared by the next Recorded, and stages determination.record_back_refused as today, once, since the row write is the only writer. ApplicationProgramRow (src/domain.rs) and the wire ApplicationProgram (crates/canopy-contracts-applications/src/applications.rs) gain record_back_refusal: Option<RecordBackRefusal>, so GET /v1/applications/{id} (ApplicationWithPrograms) tells a reader the determination the origin refused and why. determination_request_id stays a store column; nothing on the wire needs it.
D5 — canopy-web reads, never writes
POST /v1/applications/{id}/programs/{program}/determination, its contract types, record_determination's HTTP arm, the test-lib client method (crates/canopy-test-lib/src/clients/applications.rs), canopy-web’s record_response_outcomes, record_determination_outcomes, record_back_or_refuse, determinations_to_record, one_per_program, outranks, the record-back refusal copy and the quarantine mock’s record-back fixtures (api/mock_upstream/quarantine.rs) all go, with their tests and roster/authz inventory rows.
In their place, await_projection(scoped, application_id, &response) → Projection reads GET /v1/applications/{id} after a determine returns, until each program the response names a terminal determination for either carries one of that response’s determination ids in determination_id (the sibling rule, D3, picks which) or a record_back_refusal naming one, or the bounded wait ends: WebConfig.projection_wait_ms (CANOPY_WEB__PROJECTION_WAIT_MS, services/canopy-web/src/config.rs, beside determine_timeout_ms; default 2_000, and the pair bounded so determine plus projection stays inside the 10 s htmx response wait that bounds fragment_deadline_ms), re-reading at a fixed short interval. It is an operator setting, not pack data: nothing a jurisdiction’s policy tunes. The three outcomes render: projected (today’s success path), refused (the #1707 copy, now built from the row’s code), and pending (a new copy: the determination is recorded and the application will show it shortly). The quarantine promotion renders Reverified on projected, its 409 copy on refused, and ReverifiedUnrecorded on pending. DETERMINE_STILL_RUNNING (#3199) says the run may still finish and its outcome appears on the application when it does.
The e2e recordDeterminationBack helper and its callers (tests/e2e/lib/given/{determine,snap,index}.ts, flow-snap-certification-vocabulary.spec.ts, journey-snap-timely-recert.spec.ts) become awaitDetermined(applicationId, program, determinationId), a bounded poll on the application read naming the program.
Risks
-
The consumer projects a determination the BFF never recorded, an order’s or the COLA run’s, onto the application (silent: the status changes and no one is told). Mitigation: D2’s filter, with a unit test per excluded origin and basis, and an infra test that an order’s verdict leaves the application untouched.
-
Out-of-order delivery projects an older determination over a newer one (silent). Mitigation: D3’s predicate; an infra test delivering a newer request’s verdict before an older one’s, and the sibling rule in both arrival orders.
-
The worker’s render outruns the projection (fail-open: the page shows the pre-determination status for a moment, and the case clears on the next read). The consumer’s latency is the outbox tick plus one transaction, and the bounded wait covers it. Mitigation: the pending render says the outcome is being recorded rather than reporting failure; the U4 e2e regression; and the existing queue-lifecycle e2e assertion, which fails if a case does not leave the queue.
-
A consumer bug or a stopped consumer leaves every new determination unprojected (fail-closed: applications stay
submitted, cases stay in the queue, the determinations themselves are recorded and signed). Mitigation: the inbox requeues on a database or broker error and dead-letters a malformed payload (#1014), where the DLQ alarm names it; the U2 infra tests exercise the consumer end to end; and a stale queue shows as the U4 spec and the queue-lifecycle assertion failing, never as a wrong status. -
A caller that relied on the synchronous 409 misses the refusal (silent for that caller). Mitigation: U3 removes the route, so no caller can exist that the read-side refusal does not reach; the test-lib method and the e2e helper go in the same unit, and the two canopy-web callers' routed tests cover the refused render.
Units (weights by complexity) — U1 → U2 → U3 → U4
U1 (w2) — The verdict’s record-back fields
Files: crates/canopy-contracts-eligibility/src/verdicts.rs, services/canopy-eligibility/src/store/mod.rs, every program service’s src/verdict_subscriber.rs (compile only), docs/modules/ROOT/pages/api/canopy-eligibility.adoc.
D1. Tests: contract (the widened DeterminationRecordedV1 round-trips, and a payload without the optional fields still parses); regression (an infra test over record_determination_on: the staged verdict carries the persisted row’s status, codes, trio and the request’s origin).
U2 (w5) — canopy-applications projects determinations
Files: services/canopy-applications/src/determination_subscriber.rs (new), src/api/record_back.rs (new, lifted from api/mod.rs), src/api/postponement_record_back.rs, src/domain.rs (the mapping), src/store/mod.rs, src/main.rs, migrations/ (one forward migration: determination_request_id, record_back_refusal), crates/canopy-contracts-applications/src/applications.rs (the wire field), docs.
D2–D4, with the HTTP route still mounted on apply until U3 removes it, so U2 ships with every existing caller working. Tests: unit (projects for each excluded origin and basis and each status, the sanctioned token first); regression, infra over an ephemeral applications schema: a verdict projects the program and rolls the parent up with no HTTP call; the sibling rule in both arrival orders within one request; a newer request’s verdict before an older one’s; withdrawn, administratively denied and no-row verdicts ack and write nothing; the #1707 refusal on the consumer path writes the row’s refusal, stages record_back_refused once across a redelivery, and the next Recorded clears it; a malformed payload goes to the DLQ. Concurrency: two deliveries of one verdict at once leave one row and one settle; the consumer and each saga (postponement, conversion, reopen) recording the same determination, in either order, leave one row, one settle and the saga at its terminal state.
U3 (w5) — canopy-web reads, the route goes
Files: services/canopy-applications/src/api/mod.rs (the route and record_determination), crates/canopy-contracts-applications/src/applications.rs (RecordDeterminationRequest, RecordedProgramStatus), crates/canopy-test-lib/src/clients/applications.rs, services/canopy-web/src/api/applications.rs, src/api/ops_quarantine.rs, src/api/mock_upstream/quarantine.rs and the ops-quarantine tests, services/canopy-web/src/config.rs (projection_wait_ms), tests/e2e/lib/given/{determine,snap,index}.ts and the two specs, compliance/ inventories the route leaves, docs.
D5. Tests: regression (canopy-web routed tests with the mock upstream for projected, refused and pending on both callers; the quarantine notices per outcome); the ops-quarantine tests' write_paths lose the record-back path; the delegated-routes, route-authz and authorization-inventory counts move with the route; the e2e specs that used the helper pass on awaitDetermined.
U4 (w2) — The outlived-determine regression
Files: tests/e2e/specs/flow-determine-outlives-the-bff.spec.ts (new), docs.
Test (regression, e2e): with /test/fault latency on canopy-eligibility’s /v1 router above canopy-web’s determine_timeout_ms (tests/e2e/lib/fault.ts, withFaults; the devstack is a test-fault build), a worker’s determination run renders the #3199 copy, and the application’s program then reads determined with no further action (awaitDetermined). Closes #3202.
Verification
-
cargo xtask test; the canopy-applications, canopy-eligibility and canopy-web infra lanes. -
cargo xtask dev restartafter U2’s migration, thencargo xtask e2e(the whole suite in U3, which changes the helper every endpoint-first arrange uses; the new spec in U4). -
cargo xtask mq-topology,migrations-lint,route-authz audit,delegated-routes,api-docs,quality-budgets. -
cargo xtask validate— the pre-push battery is green per unit.
Documentation Updates
-
api/canopy-eligibility.adoc(the verdict’s fields, U1);api/canopy-applications.adoc(the consumer, the store rule, the refusal field, U2; the route removed, U3);data-models/canopy-applications.adoc(the two columns, U2);api/canopy-web.adoc(the read-after-determine, the three renders, U3);services.adoc(canopy-applications' events consumed; canopy-web no longer writes the application’s determination);authorization-inventory.adoc(the route gone, U3);configuration-reference.adoc(CANOPY_WEB__PROJECTION_WAIT_MS, U3) -
CHANGELOG.adoc— one entry per unit under== Unreleased
Review log
| round | vendor | resolved model | verdict |
|---|---|---|---|
1 |
anthropic |
claude-fable-5-1 (gadhs/pi plan review at exit_plan_mode) |
FLAGS (fixed): the Risks used |
2 |
gemini-4-argon (second-vendor review) |
FLAGS (fixed): the same two; D5 waited on |