Plan: Re-render notices with their program data; let USDA’s SNAP statement break between paragraphs (#2454, #3010)

Status: Done (2026-10-27) — !1817
Epic: none
Issues: #2454 (T1) → U1 · #3010 (T3) → U2 · follow-ups #3057, #3058
Branch: fix/notice-rerender-and-snap-statement: one branch, one MR, one commit per unit. The maintainer batches related issues to save a pre-push battery run.

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

Erratum (2026-10-27): D1’s created_at has no default: cargo xtask migrations-lint (#2589) refuses DEFAULT now() on a new table, so store::create_program_data copies the notice row’s own created_at in the same transaction (INSERT … SELECT id, $2, created_at FROM notices WHERE id = $1, exactly one row).

Erratum (2026-10-27): U2’s MIN_PAGE_BEFORE_STATEMENT applies only when the page before the statement is a continuation page; page 1’s letterhead and recipient block take height a character count cannot see, so seven letters per ruleset correctly open the statement on page 2. The pr-vcl and non-vacuity assertions stand.

Erratum (2026-10-27): FNS memo CRD 01-2026 (2026-03-03) tells State agencies to stop using FNS Instruction 113-1 for technical guidance and to cite the regulations instead, so U2’s header comment and CHANGELOG entry lead with 7 CFR 272.6; 113-1 IX.A.4, which has no sentence on pagination, is quoted on #3010.

Context

GET /v1/notices/{id}/pdf re-renders a notice when its stored PDF is missing or unreadable (services/canopy-notices/src/api/applicant_reads.rs:107-144). render_notice_on_demand (services/canopy-notices/src/generator.rs:657) builds its context in on_demand_context (:781). That context uses default_program_data (:866), the em-dash placeholder set overlaid only with the row’s effective date. So every reason, amount and program fact the mailed letter carried prints as "—". #2389 (letterhead columns, migrations/20261227000000_notice_letterhead.sql) and #2398 (the continued-benefits offer, from notice_appeal_rights and notices.cb_election_deadline) already persist what they print and read it back through store::get_stored_identity (store.rs:904). Program data is the remaining gap.

The notice store’s PII posture: canopy-notices has no sealing. It does not depend on canopy-crypto-shred, has no redaction_keys table, no KEK and no redaction route (ADR-036 sealing lives in canopy-persons and the program services). Notice rows are never deleted: retention is 7 CFR 272.1(f), and archive moves are operator-driven (data-models/canopy-notices.adoc § Retention). The routing contract forwards "ids, tokens, dates and decimal strings — never names or addresses" (api/canopy-notices.adoc § Event routing), and notice_work_items.request already holds that same program_data as plaintext JSONB. Two keys break the no-names rule:

  • regarding_name, the subject’s name, which the generator overlays (assembled_program_data, generator.rs:618);

  • representative_name, which the two rep-disqualification household routes forward (rulesets/*/notices/manifest.toml:1514,1534).

SNAP letters print USDA’s statement (rulesets//notices/components/civil-rights.typ) as one unbreakable block (:30-32). When it does not fit on the current page, it moves whole to the next and leaves a short page behind; georgia pr-vcl page 2 holds about 390 characters. #2464 made the HHS statements breakable, with unbreakable groups inside (rulesets//notices/components/hhs-nondiscrimination.typ), and pinned them with generator/hhs_statement_tests.rs. FNS Instruction 113-1 requires the USDA statement unaltered. DFCS’s TANF manual quotes its Section IX: the statement "must appear in all information materials" (compliance/policy-sources/civil-rights-manifest.toml docs."dfcs-tanf-1003"). The instruction itself is not in the repository.

Scope

In scope:

  • U1: an insert-only notice_program_data table written by persist and read by the re-render, with tests and docs.

  • U2: civil-rights.typ breaks only between paragraphs, in both rulesets. Includes the layout test, footer-aware verbatim checks, version bumps on every SNAP manifest entry, updated insta snapshots, and docs.

Out of scope:

  • Sealing the notice store (work items and snapshot) or adding a redaction path to canopy-notices. No PII class needs it once D2 holds. Not filed: it is a store-wide change the maintainer would have to want.

  • Printing the recipient’s name and address, the Regarding: line or the representative’s name on a re-render (that needs a canopy-persons read): #3057.

  • A re-render that compiles the recorded template_version instead of the current template (pre-existing): #3058.

  • USDA’s WIC statement, which is also one unbreakable block. Not filed: no WIC letter has shown a short page; file one if it does.

  • The 92.11(b) translations (#3011), and cutting CHANGELOG.adoc Unreleased, which is due (#3016).

Design

D1 — storage: a table, not a column. New migration services/canopy-notices/migrations/20270213000000_notice_program_data.sql (the next free timestamp if that one is taken):

  • notice_program_data (notice_id UUID PRIMARY KEY REFERENCES notices (id), program_data JSONB NOT NULL CHECK (jsonb_typeof(program_data) = 'object'), created_at TIMESTAMPTZ NOT NULL DEFAULT now()). created_at is a row-insert stamp, not a decision stamp, so its default stays (the #3007 rule).

  • Immutability: notice_program_data_insert_only_guard() raises insert-only violation: % on % is blocked (#2454) with ERRCODE = 'check_violation', wired as a BEFORE UPDATE OR DELETE …​ FOR EACH STATEMENT trigger, in the shape of services/canopy-caps/migrations/20270202000000_caps_authorization_notes.sql:47-70.

  • TRUNCATE is not guarded: the seed tool’s truncate(&mut s, &["notices", "notice_appeal_rights"]) (tools/canopy-seed/src/sql.rs:2679), which emits TRUNCATE TABLE … RESTART IDENTITY CASCADE (:691), must still reset it through the FK cascade.

  • The FK has no ON DELETE, so a notice with a snapshot cannot be deleted. That matches the retention rule.

  • A table rather than a notices column because: the 12 SELECT * / RETURNING * reads in store.rs (lists, dispatch claims) stay lean; the insert-only guard is the established append-only shape; the value can be NOT NULL, so a missing row is the only "no snapshot" state.

D2 — what is snapshotted. The program_data map exactly as the letter rendered it (AssembledNotice.context.program_data): placeholders, event values, worker enrichment and coverage presentation, minus the keys that name a person.

  • A new module, services/canopy-notices/src/program_data_snapshot.rs (registered in main.rs), holds the newtype ProgramDataSnapshot(serde_json::Map<String, serde_json::Value>), marked // STRUCTURAL-VALUE: the rendered Typst program_data (ADR-003 structural). The quality-budgets B3a lock does not move: the newtype is the one serde_json site, and tests use it, never a bare Value.

  • The newtype is the type invariant that no snapshot carries a name. Its only constructors: of_rendered(&serde_json::Value) → anyhow::Result<Self> drops NAMES_A_PERSON: [&str; 2] = ["regarding_name", "representative_name"] and refuses a non-object; from_stored(Map) serves the store read.

  • Agency strings (letterhead, interview location and contact) stay in the snapshot: they are agency data, not applicant data.

  • No API returns the snapshot, and there is no OpenAPI change.

D3 — writing it.

  • AssembledNotice::into_prepared (generator.rs:509) sets the new PreparedNotice.program_data: ProgramDataSnapshot from its context. It now returns anyhow::Result<PreparedNotice>, and prepare plus the three test call sites (generator.rs:8307, :8741, generator/wic_letter_tests.rs:769) add ? or .expect.

  • persist (:335) writes it with a new store::create_program_data(executor, NoticeId, &ProgramDataSnapshot) → Result<(), sqlx::Error>, binding sqlx::types::Json. The write goes inside the existing if let Some(pdf) arm: a snapshot exists exactly when a letter was rendered.

  • It shares the caller’s transaction, so a failed write rolls the notice back and the work item retries.

  • If persist exceeds the function budget, move the PDF-metadata and snapshot writes into one helper, record_rendering.

D4 — re-rendering from it.

  • store::StoredIdentity gains program_data: Option<ProgramDataSnapshot>, and its doc widens to "what a persisted notice recorded of what it printed".

  • get_stored_identity reads it with SELECT program_data FROM notice_program_data WHERE notice_id = $1. The struct literal at generator.rs:2614 adds program_data: None.

  • on_demand_context calls a new fn on_demand_program_data(primary, effective_date, Option<&ProgramDataSnapshot>) → Map: default_program_data, then every snapshot key written over it. A template key added after the notice was issued therefore keeps its placeholder instead of failing the Typst compile.

  • None (seed-loaded or pre-migration rows) is today’s placeholder render, plus tracing::info!(notice_id, "re-render without a program_data snapshot: placeholders").

  • Update the #2005 comments in on_demand_context and default_program_data that say the on-demand path keeps the em-dash.

  • A malformed stored value fails decode as a sqlx::Error, and the handler answers 500. That is fail-closed.

D5 — the #3010 layout rule. Best-effort reading (AGENTS.md: no SME gate before 1.0):

  • "Unaltered" governs the statement’s words, their order and its print size. A page break between two of USDA’s own paragraphs changes none of them; the pinned civil-rights.txt stays byte-identical.

  • U2 starts by fetching FNS Instruction 113-1 from fns.usda.gov and quoting on #3010, with the retrieval date, the sentences on the statement’s form. If those sentences forbid a break inside the statement, U2 stops with Status Blocked (FNS 113-1 forbids a split, #3010); U1 ships alone, and the layout becomes a maintainer decision.

The change in civil-rights.typ, identical in both rulesets: the outer block becomes breakable: true; the first and second paragraphs each go in a block(breakable: false); the complaint paragraph and the closing "USDA is an equal opportunity provider, employer, and lender." share one unbreakable block, so the closing line never stands alone at the top of a page; the header comment cites the 113-1 reading and 3010. Every [templates.snap.<key>] entry in both manifests bumps version, with comment #3010: USDA’s SNAP statement breaks between its paragraphs. The manifest records versions for exact reproduction, and pagination changes the PDF.

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

Weights: 1 trivial · 2 small · 3 medium · 5 large · 8 very large.

U1 (w3, #2454) — the program_data snapshot

Files: the D1 migration, services/canopy-notices/src/program_data_snapshot.rs (new), main.rs, store.rs, generator.rs, generator/wic_letter_tests.rs (the into_prepared call site, :769), generator/program_data_snapshot_tests.rs (new; register mod program_data_snapshot_tests; beside hhs_statement_tests), api/applicant_reads.rs (the :121 comment), docs/modules/ROOT/pages/api/canopy-notices.adoc, docs/modules/ROOT/pages/data-models/canopy-notices.adoc, CHANGELOG.adoc.

Tests. Infra tests guard on infrastructure_available() and run on an EphemeralSchema, as identity_infra_tests does. Make that module’s issue, Issued, georgia and rendered pub(super).

  • a_re_rendered_action_notice_prints_the_letter_as_issued (infra, regression): the #2398 termination request (generator.rs:8589-8640) with program_data carrying a distinctive action_reasons sentence and a current_benefit_amount. It issues the notice, runs UPDATE notices SET pdf_storage_path = NULL, reloads through store::get_notice and get_stored_identity, and asserts: pdf_storage_path is None; the issued text holds the sentence (non-vacuity); the re-render text, from on_demand_context through render_text, equals the issued text. Both render the placeholder addressee, so they must match exactly.

  • a_notice_without_a_snapshot_re_renders_with_placeholders (unit): with StoredIdentity::default(), the same notice prints "—" where the reasons were, and not the sentence.

  • the_snapshot_drops_the_names_and_keeps_the_rest (unit): assemble_notice with a ResolvedRecipient whose regarding is Some("Ada Okafor") and a payload carrying representative_name. The context holds both names; the snapshot equals the context map minus exactly those two keys.

  • every_routed_key_that_names_a_person_is_left_out_of_the_snapshot (unit, contract): load both rulesets' routing tables, as event_routing.rs:2923-2967 does. Every program_data_keys entry matching _name$, address, ssn or birth must be in NAMES_A_PERSON.

  • a_stored_snapshot_cannot_be_changed_or_removed (infra): UPDATE and DELETE on notice_program_data fail with SQLSTATE 23514 and the trigger message; TRUNCATE notices, notice_appeal_rights CASCADE still clears it.

  • a_snapshot_overlays_the_placeholders_it_lacks (unit): on_demand_program_data keeps a snapshot value over its default, and the placeholder for a key the snapshot lacks.

Docs: api/canopy-notices.adoc § Notice identity "Re-rendering reproduces what was stored" gains a program_data bullet covering the snapshot, the two omitted names (#3057) and the placeholder arm; the :67 PDF sentence and the ABAWD row’s "placeholder of an on-demand re-render" become "a re-render without a snapshot". data-models/canopy-notices.adoc: a notice_program_data Tables row (purpose, the insert-only guard, plaintext beside notice_work_items.request and why), the mermaid relationship, the Retention sentence (it follows its notice row, and the FK blocks deleting a notice with a snapshot), and the migration list. services.adoc names no tables: no change. CHANGELOG.adoc === Fixed: one entry.

U2 (w2, #3010) — USDA’s SNAP statement breaks between paragraphs

Files: rulesets/georgia/notices/components/civil-rights.typ, rulesets/default/notices/components/civil-rights.typ, both rulesets//notices/manifest.toml, generator/hhs_statement_tests.rs (make every_letter, USDA_MARKS and without_page_footers reachable as pub(super)), generator/wic_letter_tests.rs, generator/snap_statement_tests.rs (new; register it in generator.rs), src/snapshots/*snap_noa_approval_text_.snap, api/canopy-notices.adoc, CHANGELOG.adoc, this plan and nav.adoc (the close).

Tests (the #2464 pattern: every SNAP letter of both rulesets over the placeholder set, footers cut by without_page_footers, pages as text.lines()):

  • no_snap_letter_leaves_a_short_page_before_the_statement (regression): exactly one page holds the opening USDA_MARKS[0]. When that sentence opens its page, the page before holds at least MIN_PAGE_BEFORE_STATEMENT = 1500 characters. The pr-vcl short page held about 390, and a statement that breaks only opens a page when its first paragraph, about 620 characters, did not fit. Two extra assertions: non-vacuity, in each ruleset at least one letter’s opening and closing line fall on different pages; and the reported case, georgia pr-vcl's statement opens mid-page.

  • the_snap_complaint_paragraph_and_closing_line_share_a_page: the page holding "To file a program discrimination complaint" also holds the closing line (the the_notice_of_availability_stays_on_one_page pattern).

  • Verbatim: assert_prints_the_snap_statement (wic_letter_tests.rs:272) takes (label, ruleset, template_key, text) and cuts footers itself. Every caller passes its key: wic_letter_tests.rs:163, :245, :315, and hhs_statement_tests.rs:274-297.

  • civil-rights.txt and its text_sha256 test (wic_letter_tests.rs:320-341) stay unchanged, which proves the statement is byte-identical.

  • Snapshots: cargo insta test -p canopy-notices --review. Accept only diffs that move page breaks or footers.

Docs: api/canopy-notices.adoc § Nondiscrimination statement: "USDA’s SNAP and WIC statements print as one unbreakable block" becomes "USDA’s WIC statement prints as one unbreakable block; SNAP’s breaks only between its paragraphs, its complaint paragraph kept with its closing line (#3010)". CHANGELOG.adoc === Fixed: one entry, naming the 113-1 reading.

Risks

  • A seed-loaded or pre-migration notice has no snapshot. fail-open, visible: it prints today’s em-dashes, never invented values, and logs at INFO. Pre-1.0, only seed rows lack one.

  • A re-render omits the Regarding: line and the representative’s name. silent divergence from the mailed letter in those two fields, consistent with the placeholder addressee every re-render already prints. Mitigation: documented on the API page; #3057.

  • A future overlay or routed key names a person. A routed key is caught by the manifest guard test (fail-closed at test time). A new generator overlay is silent unless added to NAMES_A_PERSON; mitigation: the constant’s doc comment names the rule.

  • The snapshot write fails. fail-closed: the notice rolls back and the work item retries.

  • The current template meets an old snapshot. A renamed key keeps its placeholder; a key whose meaning changed may print differently. silent and pre-existing: #3058.

  • A SNAP letter’s page lacks the footer. fail-closed: without_page_footers panics, naming the page.

  • FNS 113-1 forbids a split. fail-closed: U2 stops at Blocked, and U1 ships alone.

  • persist or generator.rs exceeds a quality budget. fail-closed (cargo xtask quality-budgets). Mitigation: tests live in new files, and D3 names the helper.

Verification

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

  2. cargo xtask dev restart (schema change; it wipes data), then cargo xtask e2e.

  3. In the devstack, fetch a SNAP termination PDF, clear its pdf_storage_path, and fetch it again: the reasons print.

  4. Mutation checks, each made and reverted: persist skips the snapshot write (the re-render test prints placeholders); of_rendered keeps regarding_name (the names test fails); the trigger is dropped (the immutability test fails); civil-rights.typ back to one unbreakable block (the short-page test fails on pr-vcl).

  5. cargo xtask quality-budgets and cargo xtask compliance audit-data-tenancy are clean.

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

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

Documentation Updates

  • api/canopy-notices.adoc (U1 re-render; U2 statement) and data-models/canopy-notices.adoc (U1); services.adoc unchanged (it names no tables)

  • CHANGELOG.adoc == Unreleased === Fixed: one entry per unit; the cut is due (#3016)

  • The 113-1 citation as a comment on #3010 (U2)

Review log

round vendor resolved model verdict

1

Anthropic

claude-fable-5-1

FLAGS (1): cited files not supplied (every seam verified to hold), and D1 quoted the seed’s TRUNCATE text wrongly. Fixed in the draft.

2

Google

gemini-4-argon

FLAGS (1): cited files not supplied; every cited symbol and line verified to exist. Supplied on the second call.

Edit this page · default