Plan: Adopt or drop a determination’s held events after operator review (#3065)
Status: Done (2026-10-30) — U1–U5 (#3123–#3127) merged
Epic: none (follow-up F1 of Plan: Downstream services act only on determinations of record (#2322), #2322)
Issues: #3065 (T2, parent) · #3123 U1 (w3) · #3124 U2 (w5) · #3125 U3 (w5) · #3126 U4 (w2) · #3127 U5 (w5) · #3116 (TANF operation signing, a precondition for TANF adopt) · #3117, #3118, #3119 (filed during planning)
Branches: feat/held-determination-events
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-30): the delegated rows use Admission::user_roles_via(&[ELIGIBILITY], DETERMINATION_OPERATOR_ROLES) with no system arm. The cited delegated.rs:237 shape carries Admission::system(), which admits the bare system token D1’s authz contract test requires to be 403.
Erratum (2026-10-30): the program services held no MqTuning, so canopy-api’s bootstrap now returns it and each program’s main.rs injects it. HeldQuery also carries an optional operation, so the single lookup uses the hold index.
Erratum (2026-10-30): U2 adds HeldResolutionId to canopy-common and the open-quarantine read to store/quarantine.rs, beside that file’s derived-state SQL. Promote answers a dropped id with its own Refusal::Dropped, 409 envelope_conflict.
Erratum (2026-10-30): D6’s unit test pins the adopt set as the conjunction, exactly {SNAP, Medicaid, CHIP}. It does not assert that the two predicates agree, because #3116 puts TANF in signs_its_operation alone; its mutation adds TANF to both. U3’s superseded means a newer row for the household, program and subject on a request admitted after the operation’s, by (requested_at, id). Adopt lives in held_ops/adopt.rs.
Context
Since #2322 a program’s completion events stay held in its outbox until canopy-eligibility records the determination (ADR-039; crates/canopy-mq/src/publisher.rs:262-319, hold_for keys the hold on the determination id at generation 0; release_held :292, drop_held :311). canopy-eligibility releases them by staging determination.recorded.<program> from record_determination_on (services/canopy-eligibility/src/store/mod.rs:268), and drops them by staging determination.disowned.<program> (DeterminationDisownedV1, crates/canopy-contracts-eligibility/src/verdicts.rs:112-125), whose quarantined_id is required but read by no production consumer: each program’s verdict subscriber keys on the determination id alone (services/canopy-snap/src/verdict_subscriber.rs:69-96). A determination never recorded publishes nothing: an orchestrator timeout, an order that exhausted its retries, an unresolved quarantine, or a direct caller. The canopy_mq_outbox_held_* gauges signal it (crates/canopy-mq/src/outbox_drainer.rs:961-1065, the warning age held_age_warn_secs, default 7200), but nothing settles it, and the only read of the held set is that aggregate.
The quarantine resolution path is the precedent (services/canopy-eligibility/src/api/quarantine.rs, quarantine_ops.rs): user-only DETERMINATION_OPERATOR_ROLES (crates/canopy-auth/src/roles.rs:67), a ResolutionNote of 1..=500 characters (quarantine_ops.rs:79), an append-only ledger (quarantine_resolutions, migration 20270112000000), and an audit event canopy-security’s wildcard subscriber attributes (services/canopy-security/src/event_parsing.rs:464-578). Its promote (quarantine_ops.rs:786-821) verifies the stored envelope, binds it with routing_mismatch (quarantine.rs:218), builds the row with record_row (:261), records it, and reconciles the combined result. canopy-web’s /ops/quarantined-determinations worklist (services/canopy-web/src/api/ops_quarantine.rs) is the UI precedent. canopy-cli has no quarantine command (#3117).
canopy-eligibility already reads a program’s signed envelopes by its own operation id: read_operation (services/canopy-eligibility/src/orchestrator.rs:2133) calls canopy-snap’s GET /v1/determination-operations/{operation_id}/envelope and canopy-medicaid’s …/envelopes, both admitting eligibility’s system token. The interactive path admits the eligibility request before it dispatches (orchestrator.rs:2514, then claim_operations :2778), and a timed-out dispatch leaves a pending result with no determination id (:3238): eligibility knows only its DeterminationOperationId. The claim ledger determination_operations (migrations/20261204000000) has no eligibility_request_id. Only SNAP and canopy-medicaid sign the operation back (signs_its_operation, quarantine.rs:246); TANF does not (#3116), and CAPS and WIC are never dispatched (mappers/mod.rs:129-130).
Rulings (maintainer, 2026-10-29)
-
Q1, release is adopt. canopy-eligibility fetches the program’s signed envelope, verifies the signature and its binding to the original order, and records it as the determination of record; the existing verdict subscriber releases the events. Rejected: drop and re-run, which makes a second determination whose date and inputs can differ.
-
Q2, no order means drop only. A direct caller’s determination has no order to bind to; adopting it would record an unbound determination. An envelope whose signature never verified is drop-only too.
-
Q3, operation signing is a precondition of dispatch (#3116). Adopt covers every dispatched program whose envelope signs its operation: SNAP and Medicaid/CHIP now, TANF when #3116 lands. CAPS and WIC holds come only from direct callers.
-
Q4, ADR-007 parity. The operations ship on the API, as
canopy eligibility held …and as a canopy-web/ops/held-determinationsworklist. -
Q5, a dropped determination is never recordable.
record_determination_ontakes an advisory lock on the determination id and refuses an id the ledger dropped; the drop takes the same lock first.
Scope
In scope:
-
A per-program held-determination list, read through canopy-mq, and an eligibility operator list that annotates each hold with its disposition.
-
drop: a ledger row,determination.disowned.<program>with an operator basis, and the audit event. The guard of Q5. -
adopt: by eligibility’s own operation id, throughread_operation, verified and bound, recorded, reconciled; the ledger row and the audit event. -
canopy eligibility held list|adopt|drop; a canopy-web worklist with both actions. -
ADR-002 Amendment 8; the runbook page; the API, data-model and catalog pages; CHANGELOG.
Out of scope:
-
TANF adopt before #3116; CAPS and WIC adopt (never dispatched).
-
Bulk-arm determinations: Amendment 5’s cohort re-arm is their remedy.
-
Re-emitting
determination.completedfor a promoted or adopted determination (#3119); the actor onquarantine_resolved(#3118); quarantine CLI commands (#3117).
Design
D1 — Discovery
canopy-mq gains list_held(exec, HeldQuery { cutoff, after: Option<(DateTime<Utc>, Uuid)>, limit }) → Vec<HeldOperation { hold: EventHold, held_since: DateTime<Utc>, rows: u32 }>: GROUP BY (hold_operation_id, hold_generation) over unpublished rows, HAVING min(enqueued_at) < cutoff, ordered by (held_since, hold_operation_id), keyset-paged, on the ADR-039 partial index. MqTuning exposes held_age_warn().
Each program service mounts GET /v1/held-determinations?after=&limit= (canopy_contracts_eligibility::paths::HELD_DETERMINATIONS, beside REDACT_DETERMINATION). The cutoff is always the service’s own warning age, so "listed" means "warned about". Each item is enriched from the program’s own determination row: program (CHIP vs Medicaid) and operation_id where the service stores one. Limit 1..=200, default 50; an optional determination_id filter for the single lookup. Admission: a canopy-eligibility delegation at the operator bar through a new delegated::<SVC>_GET_HELD_DETERMINATIONS row per service (crates/canopy-auth/src/delegated.rs:237 shape), so the read is attributed to the operator and adds no system edge.
GET /v1/eligibility/held-determinations?program=&after=&limit= (user-only OPERATOR) passes the page through and annotates each item from eligibility’s tables with one = ANY read each: disposition ∈ recorded (an anomaly), resolved (a verdict in flight), quarantine_open, adoptable (the program is in the adopt set and the reported operation is in determination_operations), else drop_only. An unreachable program is 502 program_unavailable.
D2 — Drop
POST /v1/eligibility/held-determinations/{determination_id}/drops { program, note } → 201 HeldResolution. One program lookup (D1’s filter), then one transaction under pg_advisory_xact_lock(3065, hashtext(determination_id)):
refuse not_held (the named program does not report the id past its warning age), recorded, quarantine_open (resolve it there), already_resolved, determination_in_flight (the reported operation has a live claim, or its order or cohort case is non-terminal), 422 invalid_note. No signature check (Q2): a drop only suppresses events, and a re-determination recovers. It writes the ledger row, stages determination.disowned.<program> with the operator basis, and stages determination.held_resolved.
DeterminationDisownedV1 { determination_id, program, #[serde(flatten)] basis: DisownBasis }, with DisownBasis tagged by reason: provenance_rejected { quarantined_id }, dismissed { quarantined_id }, operator_dropped { resolution_id }. It replaces DisownReason; the illegal combinations become unrepresentable; no new routing key, no ACL change. Producers (quarantine.rs:369, quarantine_ops::apply), the canopy-test-lib verdict helper and the subscriber infra tests change; subscriber production code does not. No compatibility shim.
D3 — The guard (Q5)
record_determination_on takes the same advisory lock, then refuses an id in held_determination_resolutions with action = 'drop': a new RecordOutcome::Dropped, surfaced as the pending refusal envelope_conflict with detail determination_dropped (no new wire code). Every recording path (intake, order replay, promote, adopt) passes through it.
D4 — Adopt
POST /v1/eligibility/determination-operations/{operation_id}/adoptions { note } → 201 HeldResolutions (one per determination; Medicaid signs one envelope per subject). Keyed by eligibility’s own operation, so routing comes from the ledger, never from an envelope’s claim. read_operation, reads_operations and signs_its_operation are private today and widen to pub(crate) for held_ops.rs.
determination_operations gains eligibility_request_id UUID NULL, set by claim_fresh (through claim_operations, store/operations.rs:69,116) and overwritten by claim_pinned's re-open, so it names the newest execution’s request. TrustedRouting is built from the operation row (program, application_id), the request (eligibility_request_id, household_id) and operation: Some(op); owner is unused (adopt never quarantines).
Phase one, no transaction: read the operation; refuse 404 (unknown: a direct caller or the bulk arm), 409 operation_unsigned (program outside the adopt set: signs_its_operation ∧ reads_operations), request_unknown (a row claimed before the migration), order_retrying (the owning order is non-terminal: its re-execution adopts by replay), determination_in_flight; fetch with read_operation (502 program_unavailable; operation_not_determined when the program has nothing); from_signed_bytes (envelope_malformed); verify each envelope under key_program (signature_unverified with the reason token); bind each with routing_mismatch (provenance_rejected with the field); refuse quarantined when any quarantine row claims an envelope id.
Phase two, one transaction, D3’s lock per id in id order: operation_in_flight, superseded (a newer row for the household, program and subject in either table), already_resolved, already_recorded (nothing unrecorded remains); then record each unrecorded envelope with dispatch_anchor unchanged, one adopt_pending reconcile (every pending entry naming the program removed, one entry per adopted envelope appended, under promote_pending's total-benefit and Medicaid-group rules), a ledger row and a held_resolved event per determination. A refusal writes nothing; the operator then drops (Q2). As with promote, the request’s status and determination.completed are left alone (#3119).
D5 — Ledger and audit
held_determination_resolutions (migration 20270301000000_held_determination_resolutions.sql): id UUID (v7), action TEXT CHECK (action IN ('adopt','drop')), program TEXT CHECK (the six slugs), determination_id UUID UNIQUE, operation_id UUID, eligibility_request_id UUID (both NOT NULL exactly when action = 'adopt', one CHECK), actor TEXT, authz_basis TEXT, note TEXT, created_at TIMESTAMPTZ NOT NULL stamped from the decision clock with no default (#2589). The quarantine append-only trigger is copied; the table joins the seed’s maintenance truncation list (tools/canopy-seed/src/sql.rs:710,2257).
determination.held_resolved carries DeterminationHeldResolvedV1 { resolution_id, action, program, determination_id, operation_id, eligibility_request_id, resolved_by: Actor } from Principal::actor(), one per ledger row in the same transaction; devstack/rabbitmq/definitions.json (the quarantine_resolved pattern at :335) and xtask/mq-topology-allow.toml admit it; canopy-security’s # binding audits it with the operator attributed.
D6 — Auth and coverage
Eligibility routes: OPERATOR, user-only; authz_basis from operator_basis (api/quarantine.rs:60). Program list routes: the D1 delegated rows. Adopt’s envelope read: eligibility’s system token on the existing routes. The adopt set is signs_its_operation ∧ reads_operations (orchestrator.rs:1222), pinned by a unit test that the two predicates agree, so #3116 cannot enable TANF adopt without TANF’s operation read (a note on #3116).
D7 — CLI and worker portal (Q4)
canopy eligibility held list --program <p> [--after <cursor>] [--limit n], held adopt <operation_id> --note, held drop <determination_id> --program <p> --note, under EligibilityAction (tools/canopy-cli/src/main.rs:1476), calling the D1/D2/D4 routes with the operator’s token, --format table|json.
canopy-web /ops/held-determinations mirrors the quarantine worklist (ops_quarantine.rs, routes at api/mod.rs:433-437): a program selector, the paged list with each disposition, and per row an Adopt (when adoptable) or Drop form with the note, posting to /ops/held-determinations/adopt and /drop, which delegate to the eligibility routes with the worker’s Bound session; the same operator roles; the shared copy table for each refusal code.
Risks
| Risk | Mode | Mitigation |
|---|---|---|
An adopt records a stale verdict, and downstream acts on it. |
fail-open |
|
An operator drops a genuine determination. |
fail-closed |
The application stays pending; the ledger and the audit record who and why; re-run recovers. |
A drop and a late record race. |
silent |
D3’s lock and guard; U2’s concurrency test. |
A wrong |
silent |
D2’s |
An adopt re-emits no |
silent |
The same gap promote has today, tracked as #3119; the runbook’s adopt section names it, and the ledger row shows which determinations were adopted. |
The new routing key missing from the ACL. |
fail-closed |
The outbox row parks and the held gauge shows it; |
A program is down during list or adopt. |
fail-closed |
502 |
Units (weights by complexity) — U1 → U2 → U3 → U4 → U5
Weights: 1 trivial · 2 small · 3 medium · 5 large · 8 very large. One unit = one independently shippable MR = one child issue.
U1 (w3) — Program-side discovery
Files: crates/canopy-mq/src/{held.rs (new), tuning.rs, lib.rs}, crates/canopy-contracts-eligibility/src/{paths.rs, held.rs (new)}, crates/canopy-auth/src/delegated.rs, services/canopy-{snap,tanf,medicaid,caps,wic}/src/api/{mod.rs, held.rs (new)} and one store read each, docs/modules/ROOT/pages/api/canopy-{snap,tanf,medicaid,caps,wic}.adoc, shared-crates.adoc, authorization-inventory.adoc, services.adoc, CHANGELOG.adoc
D1’s program half. Tests, by category: infra (canopy-mq), each hold past the cutoff listed once with its row count, oldest first, young and released holds absent (mutation: drop the HAVING); infra, keyset paging with no repeat and no skip (mutation: > to >=); infra per service, a held determination listed with its program and, for SNAP and Medicaid, its operation, a CHIP hold only under program=chip (mutation: return the id unenriched); authz contract per service, a delegation below the bar, a direct user and a system token all 403, and cargo xtask delegated-routes check passes (mutation: widen the admission); contract, a roundtrip proptest of the page types.
U2 (w5) — Eligibility list, drop, ledger, audit, the guard
Files: crates/canopy-contracts-eligibility/src/{verdicts.rs, events.rs, held.rs}, services/canopy-eligibility/migrations/20270301000000_held_determination_resolutions.sql, services/canopy-eligibility/src/{held_ops.rs (new), api/held.rs (new), api/mod.rs, store/held.rs (new), store/mod.rs, events.rs, quarantine.rs, quarantine_ops.rs}, the five subscriber infra tests, crates/canopy-test-lib verdict helper, devstack/rabbitmq/definitions.json, xtask/mq-topology-allow.toml, tools/canopy-seed/src/sql.rs, docs/modules/ROOT/pages/adrs/adr-002-*.adoc, api/canopy-eligibility.adoc, data-models/canopy-eligibility.adoc, runbooks/held-determination-events.adoc (new) and nav.adoc, services.adoc, authorization-inventory.adoc, CHANGELOG.adoc
D1’s eligibility half, D2, D3, D5, D6, D8, and the runbook (alert, list, decide, verify). Tests, by category: contract, a DisownBasis proptest and a wire golden for operator_dropped (mutation: rename the variant); subscribers, operator_dropped drops exactly that determination’s rows (mutation: skip drop_held); eligibility infra, a drop writes one ledger row, one disowned{operator_dropped} and one held_resolved naming resolved_by (mutation: skip the staging), one test per refusal asserting nothing written (mutation: delete that check), each list disposition (mutation: misclassify), the guard, an envelope whose id was dropped is pending determination_dropped with no row (mutation: remove the guard); concurrency, a drop and a record of one id behind a barrier, exactly one commits (mutation: remove the lock); producer-to-parser, the audit row’s actor is the operator with role human (mutation: rename resolved_by); the devstack ACL test admits held_resolved for eligibility alone; a devstack journey, a direct /v1/determine on canopy-snap is listed, dropped, then absent.
U3 (w5) — Adopt
Files: services/canopy-eligibility/migrations/20270302000000_determination_operations_request.sql, services/canopy-eligibility/src/{store/operations.rs, orchestrator.rs, held_ops.rs, api/held.rs, quarantine_ops.rs, quarantine.rs}, crates/canopy-contracts-eligibility/src/held.rs, api/canopy-eligibility.adoc, data-models/canopy-eligibility.adoc, runbooks/held-determination-events.adoc, services.adoc, CHANGELOG.adoc
D4. record, dispatch_anchor, program_result and the promotion types move to a crate-private module shared with promote, with no behaviour change. Tests, by category: infra with a mocked canopy-snap signing under the test key, adopting a timed-out operation records it, stages exactly one recorded.snap, moves SNAP out of pending, writes one ledger row and one event (mutation: skip the reconcile); infra, Medicaid with two subjects, both recorded, one pending entry removed and two added (mutation: reconcile per envelope); regression, one test per D4 refusal (mutation: delete that check); concurrency, two concurrent adopts, one 201 and one 409 (mutation: drop the UNIQUE); infra, the claim stores the request and a pinned re-open overwrites it (mutation: leave it on re-open); unit, the D6 predicate test (mutation: add TANF to one side).
U4 (w2) — CLI
Files: tools/canopy-cli/src/{main.rs, cmd/eligibility.rs, cmd/path_segment_tests.rs, cmd/request_body_tests.rs}, docs/modules/ROOT/pages/tooling/canopy-cli.adoc, CHANGELOG.adoc
D7’s CLI. Tests, by category: contract, the request-body and path-segment tests of the three commands (mutation: drop --program from the drop body); unit, the table rendering of a page.
U5 (w5) — Worker-portal worklist
Files: services/canopy-web/src/api/{ops_held.rs (new), mod.rs}, services/canopy-web/templates/ops/held_determinations.html (new), services/canopy-web/src/session.rs, services/canopy-web/src/api/ops_held/route_tests.rs (new), tests/e2e/specs/worker-portal-held-determinations.spec.ts (new), docs/modules/ROOT/pages/api/canopy-web.adoc, authorization-inventory.adoc, CHANGELOG.adoc
D7’s worklist. Tests, by category: route (through the harness), the list renders each disposition with its action, an adopt and a drop post the operator’s note and household-free bodies to eligibility and land back on the list, each refusal code renders its copy (mutation: misroute the drop to adopt); e2e, a spec that drops a seeded direct-caller determination and sees it leave the list.
Verification
-
cargo xtask test— the unit and integration lanes pass (see Testing). -
cargo xtask dev restartafter U2 and U3 (migrations), thencargo xtask e2e — specs/worker-portal-held-determinations.spec.ts specs/worker-portal-quarantined-determinations.spec.ts. -
cargo xtask delegated-routes check,cargo xtask call-graph,cargo xtask mq-topology,cargo xtask route-authz audit,cargo xtask web-paths audit,cargo xtask api-docs,cargo xtask migrations-lint. -
The mutations named in each unit each fail their test.
-
cargo xtask validate— the pre-push battery is green. -
Delivery: each unit merges with
Closeson its child issue (#3123–#3127); U5’s MR also closes #3065 and this plan (StatusDone, archived,plan-lint --done).
Documentation Updates
-
Antora canonical pages — the five program
api/canopy-*.adocpages,api/canopy-eligibility.adoc,api/canopy-web.adoc,data-models/canopy-eligibility.adoc,services.adoc,authorization-inventory.adoc,shared-crates.adoc,tooling/canopy-cli.adoc -
CHANGELOG.adoc— an entry per unit under== Unreleased -
ADR-002 Amendment 8; the new runbook page
runbooks/held-determination-events.adoc
Review log
| round | vendor | resolved model | verdict |
|---|---|---|---|
1 |
Anthropic |
claude-fable-5-1 (gadhs/pi’s plan review at exit_plan_mode) |
FLAGS — a risk mode outside the vocabulary; cited files not supplied (the citations held on the reviewer’s own read); three private helpers to widen. Fixed. |
2 |
gemini-4-argon |
FLAGS — the same two, plus |