canopy-notices Data Model

Cross-link: canopy-notices API Reference · Source: migrations/

Tables

Table Purpose

notices

One row per generated notice. PDF is the canonical output; the schema deliberately omits body_text / body_html and stores only the S3 pointer + metadata. Carries the recipient pair (household_id, recipient_person_id), the notice_type (drives template selection), optional program / application_id / determination_id context (since #1662 application_id is the UPSTREAM canopy-applications id whenever the producer’s payload carries upstream_application_id — every determination.completed.snap does — else the legacy application_id, which for a SNAP NOA before #1662 was canopy-snap’s LOCAL id; no schema change, a routing-time precedence in the subscriber), the subject line, the templating pair (template_key, template_version) used for replay, the optional federal/state form_number, the locale (DEFAULT 'en-US'), the regulatory_basis (CFR / PAMMS cite carried for audit), date fields (effective_date, notice_date, advance_notice_days with advance_notice_adjusted recording whether the 10-day clock under 7 CFR 273.13 was extended for cause), and the storage sextet (pdf_storage_path — S3 key in the Garage / S3 bucket — plus pdf_size_bytes, page_count, and the #435 Pub 1075 §9 integrity trio: content_sha256 (SHA-256 of stored PDF bytes), content_type (magic-byte-verified at upload time, DEFAULT 'application/pdf'), scan_status (AV scanner result — the Scanner::name() of the wired backend; 'noop', because NoticeGenerator::new in services/canopy-notices/src/generator.rs wires canopy_store::NoopScanner and main.rs never swaps it)). Delivery tracking (#1091, reshaped by #1216): delivery_status (pending → dispatched, or terminally failed after bounded refused attempts — never a notice already mailed: a resent copy that exhausts its attempts, refused or parked by the crash-loop guard, returns to dispatched with its first dispatched_at and its failure is logged at ERROR (#2462) — or superseded — #1658: the superseded-notice consumer retracts a rendered-but-undispatched notice of expiration whose certification changed, but only one no dispatcher holds under a live lease (#2446: a leased notice may already be with the provider, so its dispatcher mails, stamps and reports it; a lease that expires unstamped is superseded by the next dispatch pass); every superseding path — arm 2, the pass’s retracted-notice sweep, a refused delivery of a retracted notice, the last look, and the legal-day fence’s retracted branch — also sets active = false (#2456, migration 20270101000000 retiring the rows written before), so a superseded notice leaves every read like a stale one; only a notice never dispatched is superseded: a pending notice with dispatched_at set is a resent copy of a letter already mailed, and each of those paths cancels just the copy — the notice returns to dispatched with its first dispatched_at, stays readable, and the copy is never handed over (the migration restores copies the old arm 2 had superseded); since #2457 the vocabulary is enforced by CHECK notices_delivery_status_check (pending, dispatched, failed, superseded, stale; migration 20270103000000, which first normalised seed-loaded delivered rows to dispatched); the claim scan reads only pending and skips a retracted letter, and the last look before a hand-off renews only a live lease, so a superseded row is never mailed), or stale — #2447, migration 20261231000000: the dispatch pass found a never-dispatched notice whose notice_date is earlier than today’s legal date in [jurisdiction].timezone (read from the service’s injected decision clock), so it was never handed to the provider; the notice is retired with active = false, and its work item is re-queued in the same transaction to regenerate the letter dated today (notice_regenerations); a notice from outside the work-item path (the direct POST /v1/notices) has nothing to regenerate from and is only retired, logged at ERROR and counted by the canopy_notices_stale_unregenerated gauge (#2460); a stale notice whose letter was retracted meanwhile goes superseded instead, and nothing is regenerated, dispatched_at (provider FIRST accepted the notice for delivery — the dispatch evidence and the mailing its legal windows count from; a resent copy never moves it, #2458), last_resent_at (TIMESTAMPTZ, nullable, #2458, migration 20270102000000: the provider accepted the latest resent copy of an already-dispatched notice; NULL until one is handed over), delivered_at (confirmed receipt; stays NULL until a receipt-capable production carrier exists — a tracked &72 production gap), and delivery_channel (DEFAULT 'test'). The #1216 dispatch ledger — dispatch_claimed_at / dispatch_claimed_by (the FOR UPDATE SKIP LOCKED lease that partitions the queue across replicas, the duplicate-physical-mail guard), dispatch_attempts (counted at claim), dispatch_next_attempt_at (exponential retry gate doubling from 60s, 30s · 2^attempts on the post-claim count, capped ~2.1h; NULLed on terminal park), dispatch_last_error (provider refusal, truncated to 1024 chars) — makes dispatch leased bounded-retry; the dispatcher renews a notice’s lease just before handing it to the provider, only while it is still live (#2446), so the lease covers one provider call rather than the whole batch; an operator resend (delivery_status → 'pending') resets the ledger. idx_notices_dispatch_due (created_at, id) partial over the dispatch-due predicate serves the claim scan. Read tracking (#721): read_at (nullable; first-read timestamp set when the recipient opens the notice in the applicant-portal Letters inbox — NULL means unread; mark-read is idempotent via COALESCE(read_at, now()) so the original read time survives repeat opens). Recipient-block provenance (#1188): acp_applied (BOOLEAN NOT NULL DEFAULT FALSE; TRUE iff the letter’s postal block was rendered with the jurisdiction’s [notices.acp] substitute address per the #1146 AcpOutcome::Applied swap, stamped by the render worker — the applicant portal suppresses inline PDF streaming for address_confidential/both households unless this is TRUE; DEFAULT FALSE is the fail-closed backfill: pre-#1188 letters have no provenance and are all treated as real-address — over-suppression is the safe direction). Since #1101 an action-bound notice also persists its adverse-action binding — adverse_action_id (the spine id), adverse_action_generation (source provenance), action_reason_code, exemption_authority — and the legal cb_election_deadline (Chart B2: notice_date + continued_benefits_election_days, INCLUSIVE, the same [appeals] window canopy-appeals enforces). subject_person_id (UUID, nullable; #1941, migration 20261226000000) records WHOM the notice is about when that differs from recipient_person_id — written only when a minor subject’s letter is addressed to someone else, the responsible adult (42 CFR 435.917) or the parent or caretaker (#2390); NULL = the recipient is the subject. The letterhead the notice printed (#2389, migration 20261227000000): agency_name, agency_address, agency_phone (TEXT, nullable, all three or none — CHECK notices_letterhead_complete), written by persist from the notice’s resolved identity (its program’s [notices.program.<p>] table, else [notices]) and read back by the on-demand re-render; NULL = no letterhead recorded by persist: a row persisted before this migration, which printed [notices], or one loaded outside the generator (the seed tool); both re-render with [notices] (notice identity). Every row persist writes carries all three. active (BOOLEAN NOT NULL DEFAULT true): every API read — the notice, its PDF, the lists, mark-read, the queue view, and so the appeal rights — loads a notice with active = true first, so false retires it from every read; the legal-day fence retires a stale notice this way (#2447), taking its appeal-rights row out of reach with it, so reads see only the regenerated letter’s deadline, and every superseding path retires a superseded one (#2456). Only a resend looks a retired notice up regardless: it regenerates a stale one and refuses a superseded one (409).

notice_work_items (#1091)

The event-routed generation queue: the subscriber persists one row per (source_event_id, notice_type) (UNIQUE — a redelivered/replayed event upserts into the same item, never a second notice) atomically with its inbox row, carrying the full typed GenerateNoticeRequest as JSONB request. The worker loop claims items via single-statement FOR UPDATE SKIP LOCKED + lease (claimed_at/claimed_by — also the completion FENCE: complete/fail match only the exact claim, so a lease stolen mid-render can never double-mint), performs recipient resolution + render + scan + upload OUTSIDE any transaction, then commits the fence flip + notice rows in one short transaction. status (pending → done / failed / skipped / superseded CHECK — superseded since #1658: the superseded-NOE consumer retracts a still-queued notice_of_expiration item, claimed or not; the claim-fenced complete/fail then miss and a mid-render worker discards its artifacts), attempts, last_error, due_at (exponential backoff, 30s·2^attempts capped 1h; terminal failed at 8 attempts), notice_id back-pointer once done. #1639: delivery_channel (CHECK (mail|sms) DEFAULT 'mail', stamped from the routing entry) splits the letter pipeline from the On-Demand side-channel text — an sms item renders no PDF and mints NO notice row (complete_without_notice closes it done with a NULL notice_id; the letter sibling is the binding artifact), and a household with no notify phone or no affirmative sms_opt_in closes skipped with the reason in last_error ("(if applicable)", PAMMS 3105:216). recipient_kind (#1665; household_member default | authorized_representative) selects the rep-letter pipeline; addressing (#1941, migration 20261225000000, widened by 20261229000000; CHECK NULL | subject | responsible_adult_for_minor | caretaker_for_minor) redirects only the envelope of a household-member letter, and only for a minor subject. responsible_adult_for_minor addresses the adult who applied, else an active individual authorized representative scoped to the notice’s program (CHIP under medicaid) (42 CFR 435.907(a)). caretaker_for_minor (#2390, the WIC advance notice of expiration) addresses the application’s filer when they are a member of the subject’s household, at any age (7 CFR 246.7(j)(8): participant, parent or caretaker), else that representative; a minor who applied for herself receives her own letter. NULL is the pre-#1941 backfill reading and reads as subject. The two columns compose; neither discriminates the other.

notice_appeal_rights

Per-notice appeal-rights companion under 7 CFR 273.13(a)(3). One row per notice whose letter prints the hearing-rights box: persist writes it only when the resolved template’s manifest entry sets hearing_rights (#2431), so a letter without the box has none. Carries hearing_request_deadline (the calendar date by which the household must request a hearing to preserve continued-benefits eligibility per 7 CFR 273.15(k)), continued_benefits_available + optional continued_benefits_request_deadline, and the contact strip (hearing_phone, optional hearing_address) rendered into the notice PDF and surfaced via the appeal-rights API.

notice_program_data (#2454)

The program_data each rendered letter printed, so an on-demand re-render prints it (notice identity).

  • One row per notice whose letter persist rendered: notice_id (PRIMARY KEY, FK notices), program_data (JSONB, CHECK notice_program_data_is_object) and created_at, which the insert copies from the notice row it is written with (store::create_program_data).

  • Insert-only: the statement-level trigger notice_program_data_insert_only refuses every UPDATE and DELETE with check_violation (23514). TRUNCATE is not guarded, so the seed tool’s TRUNCATE … CASCADE of the notice tables clears it.

  • Plaintext, like notice_work_items.request, which already holds the same routed values. The keys that name a person (regarding_name, representative_name, sanctioned_member_name, liable_adults) are dropped before the write (ProgramDataSnapshot::of_rendered), so the table holds no name.

notice_retractions (#2432, widened by #2446)

Every retraction the superseded-notice consumer received: one row per (source_event_id, notice_type) (the primary key) plus retracted_at (DEFAULT now()). The consumer writes it on every arm, whatever stage the letter reached (ON CONFLICT DO NOTHING, so a replay holds it once); before #2446 only the arm that finds no work item wrote it. Its readers: work_items::insert stages nothing for an event with a row for its notice type (the retraction overtook its due event on the other queue); and, reaching the row from a notice through its work item (notice_work_items.notice_id, idx_notice_work_items_notice), the dispatch claim and the crash-loop park skip the notice, the dispatcher’s last look before a hand-off (a lease renewal fenced on the live lease) supersedes one retracted since its claim, a refused delivery supersedes it instead of backing it off, each dispatch pass supersedes one whose lease is absent or expired, and a resend refuses it (409). The consumer and insert take a transaction-scoped advisory lock on the source event id (canopy-notices.notice-source:<uuid>, schema-folded) before reading, so a concurrent staging and retraction serialize.

notice_regenerations (#2447)

One row per stale notice whose work item the legal-day fence re-queued: stale_notice_id (PRIMARY KEY, FK notices), work_item_id (FK notice_work_items) and created_at. Written in the transaction that retires the notice and re-queues the item. The re-queue clears the item’s notice_id (the regenerated letter sets it again), so this row is the link a resend of the stale notice follows: it leaves a queued item be, and refuses (409) once the regeneration produced a live letter or failed terminally — that failure is announced as final (notice.stale, regenerating = false, #2459), so the resend never resumes it.

event_outbox, event_inbox

The generated ADR-018 / ADR-039 outbox and the generated consumer inbox (parked-state columns included), single-sourced in crates/canopy-mq/outbox-migrations/ — schema, indexes and migration files are described once in the data-models index. canopy-notices both publishes and subscribes (boot.subscriber.subscribe(…​) in services/canopy-notices/src/main.rs, with the #1658 retraction consumer in src/retractions.rs; the work-item insert commits with its inbox row), so event_inbox is live here.

idempotency_keys

The fleet-wide idempotent-POST cache (#434 / #1463), created outside this service’s migrations/ directory and described once in the data-models index.

Relationships

Intra-database foreign keys only (relationship-only; columns live in the Tables list):

Diagram

notice_work_items.notice_id back-points at notices without a FK (migration 20260721000000_notice_work_items.sql); the completion fence is the claim, not a constraint. notice_retractions shares notice_work_items' (source_event_id, notice_type) key without a FK: a retraction can be held before any work item exists.

Cross-service FKs (ADR-001 boundary)

Per ADR-001, canopy-notices holds no Postgres-level foreign keys to other services. Every UUID outside the intra-database FKs above is an application-level reference canopy-notices trusts the upstream services (the canopy-eligibility orchestrator, the program services and canopy-enrollment) to supply and never enforces in canopy_notices: household_id, recipient_person_id and subject_person_id (canopy-persons), application_id (canopy-applications, or the legacy program-local id before #1662), determination_id (the program service), adverse_action_id (canopy-enrollment) and source_event_id (the triggering envelope).

Address-confidentiality (ACP) mail routing (#1146)

Before anything renders, the work-item worker reads the household’s confidentiality election from canopy-applications (newest application, GET /v1/applications?household_id=…&limit=1) and fails closed: an unavailable signal is a retryable work-item error, never a mail-the-street-address fallback. An address_confidential / both election swaps the resolved postal block for the Address Confidentiality Program substitute address, in the form [notices.acp] in jurisdiction.toml states (#3439): form = "fixed" (the default) is one address for every participant, written in the table; form = "per_participant" is the addressee’s own substitute address, recorded on the person in canopy-persons, and the table then states no address lines. Under a per-participant program an addressee with no substitute address recorded is not mailed at home either: the item fails with a last_error that begins acp_substitute_unrecorded and stays on the retry ladder, because a worker can record the address. A pack without that table cannot mail an elected household at all (#3290): the worker renders nothing, warns, and closes the work item failed on the first attempt with a last_error that begins acp_substitute_unconfigured, for an operator to configure the substitute and requeue the item. Georgia’s ruleset omits the table until the SME-confirmed address lands (#1185), so its elected households' letters are held; case-confidential-only elections gate disclosure, not routing. The schema records only the outcome: notices.acp_applied (#1188) is TRUE iff the postal block was the substitute, and the applicant portal suppresses inline PDF streaming for confidential households unless it is. The per-participant ACP enrolment model that would supersede the config route is #1186.

Retention

Retention floors (eCFR, checked 2026-09-16): a rendered notice must stay retrievable for the case plus its appeal window. The PDFs are not in the database — they live in the S3-compatible object store (Garage in devstack) at pdf_storage_path, and their lifecycle is operator-driven on the bucket side; the DB holds the metadata and the pointer. Notice rows are SNAP program records under 7 CFR 272.1(f) — no less than 3 years from the month of origin — and outlive any open appeal that cites them (notice_id is held by canopy-appeals.appeal_requests). State series: Georgia Archives, DHS retention schedule (agency 144), series 1976-0110 "Food Stamp Administrative Files", 3 years — https://www.georgiaarchives.org/records/agencyprint/144 (checked 2026-09-18); it does not exceed the federal 3-year floor, so 7 CFR 272.1(f) governs. Rows are not deleted in production; archive moves are operator-driven, never migration-driven (ADR-016). A notice_program_data row follows its notice row: its FK has no ON DELETE, so a notice with a snapshot cannot be deleted while the snapshot stands, and the insert-only trigger refuses the snapshot’s own DELETE.

Indexes

  • idx_notices_household — household-scoped notice lookup

  • idx_notices_recipient — recipient-scoped notice lookup

  • idx_notices_type — list-by-type (worker portal filters)

  • idx_notices_program — program-scoped notice list

  • idx_notices_delivery (partial, WHERE active = true) — delivery-status work queue

  • idx_notices_active_created_at_id (partial, WHERE active = true, (created_at DESC, id DESC)) — the GET /v1/notices keyset page cursor (#1214); serves the newest-first list as an index scan with no top-N sort

  • idx_notices_date — notice-date scan for federal reporting / aging queries

  • idx_notices_application — notices-by-application lookup

  • idx_notices_determination — notices-by-determination lookup (appeal cross-link)

  • idx_notice_work_items_due (partial, WHERE status = 'pending') — the worker’s claim scan (#1091)

  • idx_notice_work_items_notice (partial, (notice_id) WHERE notice_id IS NOT NULL) — a notice’s work item, for the dispatch paths' retraction probe (#2446): the claim probes it per candidate instead of hash-joining every work item and retraction on each pass

  • idx_notice_appeal_rights_notice — appeal-rights companion lookup

  • idx_notices_adverse_action (partial, WHERE adverse_action_id IS NOT NULL) — the per-action evidence lookup (#1101)

  • idx_notices_stale_type (partial, (notice_type) WHERE delivery_status = 'stale') — the canopy_notices_stale_unregenerated gauge’s per-type count of stale notices retired with no regeneration (#2460); stale rows are inactive, outside idx_notices_delivery

  • idx_notices_dispatch_due (partial, (created_at, id) WHERE active AND delivery_status = 'pending' AND pdf_storage_path IS NOT NULL) — the dispatcher’s claim scan (#1216)

  • generated event_outbox_* / event_inbox_* indexes — described once in the data-models index

Migration files

The eight event_outbox / event_inbox files (20260508000000, 20260516000000, 20260518004851, 20260713000000, 20260720000000, 20260803000000, 20260815000000, 20260904000000) are generated copies of crates/canopy-mq/outbox-migrations/ (cargo xtask outbox-migrations --write, parity-gated by --check); they are described once in the data-models index. The service-owned files, in timestamp order:

  • 20260401000000_create_notices_tables.sql — original schema (notices, notice_appeal_rights; lookup + delivery indexes); deliberately omits body_text / body_html so PDF stays canonical

  • 20260515000000_add_notice_content_integrity.sql — #435 Pub 1075 §9 integrity columns (content_sha256, content_type, scan_status); forward-only with DEFAULTs so pre-migration rows survive

  • 20260608000000_add_notice_read_tracking.sql — #721 read/unread: adds notices.read_at (nullable, no backfill); forward-only additive per ADR-016

  • 20260721000000_notice_work_items.sql — #1091 work-item queue (notice_work_items + idx_notice_work_items_due) and notices.dispatched_at

  • 20260727000000_action_notice_binding.sql — #1101: the adverse-action binding columns + the Chart B2 cb_election_deadline + the per-action evidence index

  • 20260816000000_notices_list_keyset_idx.sql — #1214: the idx_notices_active_created_at_id partial index (created_at DESC, id DESC) WHERE active = true backing the GET /v1/notices keyset page cursor; transactional CREATE INDEX (not CONCURRENTLY — the sqlx migrator’s advisory lock deadlocks against CONCURRENTLY's snapshot wait)

  • 20260901000000_notices_dispatch_claims.sql — #1216: the dispatch claim-lease + bounded-retry ledger (dispatch_claimed_at / dispatch_claimed_by / dispatch_attempts / dispatch_next_attempt_at / dispatch_last_error) and idx_notices_dispatch_due over the dispatch-due predicate

  • 20261105000000_notices_acp_applied.sql — #1188 recipient-block provenance: adds notices.acp_applied (BOOLEAN NOT NULL DEFAULT FALSE); gates the applicant portal’s letter-PDF streaming for address-confidential households

  • 20261128000000_work_item_delivery_channel.sql — #1639: notice_work_items.delivery_channel (mail|sms CHECK, DEFAULT mail) + the skipped status for non-applicable texts

  • 20261217000000_work_item_recipient_kind.sql — #1665: notice_work_items.recipient_kind (household_member default \| authorized_representative — the rep-letter own-address path selector)

  • 20261224000000_work_item_superseded.sql — #1658: the notice_work_items.status CHECK widened with superseded (the 20261128000000 DROP + ADD shape); documents superseded as a notices.delivery_status value (no CHECK existed on that column until #2457 — a COMMENT ON COLUMN carried the vocabulary in-database)

  • 20261225000000_work_item_addressing.sql — #1941: notice_work_items.addressing (CHECK NULL \| subject \| responsible_adult_for_minor) — who a minor subject’s letter is addressed to (42 CFR 435.907(a)); additive, NULL = pre-migration rows

  • 20261226000000_notices_subject_person_id.sql — #1941: notices.subject_person_id — the person the notice is about when the addressee differs; NULL = the recipient is the subject

  • 20261227000000_notice_letterhead.sql — #2389: notices.agency_name / agency_address / agency_phone — the letterhead the notice printed, and the all-or-none CHECK notices_letterhead_complete; additive, NULL = no letterhead recorded by persist (a pre-migration row, which printed [notices], or a seed-loaded one; both re-render with [notices])

  • 20261228000000_notice_retractions.sql — #2432: notice_retractions (source_event_id, notice_type) PRIMARY KEY + retracted_at — a retraction held until its due event arrives, so the letter is never staged

  • 20261229000000_work_item_caretaker_addressing.sql — #2390: notice_work_items.addressing CHECK widened with caretaker_for_minor (the DROP + ADD shape)

  • 20261230000000_notice_retraction_dispatch_fence.sql — #2446: idx_notice_work_items_notice for the dispatch paths' retraction probe, and the notice_retractions table COMMENT widened to every retraction

  • 20261231000000_notice_stale_delivery.sql — #2447: notice_regenerations (stale notice → the work item re-queued to regenerate it), stale added to the notices.delivery_status COMMENT, and a COMMENT on notices.active. no CHECK on delivery_status yet, because the seed tool wrote delivered; #2457 (20270103000000) fixed the seed and added it

  • 20270101000000_notice_superseded_retired.sql — #2456: restores to dispatched the resent copies of mailed letters that the old arm 2 superseded (dispatched_at set), retires the other superseded rows written before (active = false, never dispatched), and re-comments notices.active and notices.delivery_status

  • 20270102000000_notice_last_resent_at.sql — #2458: notices.last_resent_at, the latest resent copy’s hand-off, so a resend no longer overwrites the first dispatched_at; additive, no backfill (an overwritten first instant cannot be recovered)

  • 20270103000000_notice_delivery_status_check.sql — #2457: normalises delivered rows (the old seed value) to dispatched, their NULL dispatched_at from delivered_at, else created_at, then adds CHECK notices_delivery_status_check over pending, dispatched, failed, superseded, stale

  • 20270104000000_notices_stale_type_idx.sql — #2460: idx_notices_stale_type, the partial index behind the unregenerated-stale gauge

  • 20270213000000_notice_program_data.sql — #2454: notice_program_data, the insert-only snapshot of the program_data each rendered letter printed, with no clock default on created_at (#2589); a notice without a row re-renders with the placeholders

All migrations are forward-only per ADR-016.

Edit this page · default