ADR-040: Federal-Export Data Collection and Emit Architecture

Status

Accepted 2026-06-21. Sets the architecture for the NCANDS Child File export program (epic &55, plan NCANDS Child File Federal Export). The AFCARS file follows this shape with the deltas of § Amendment — #949 (Proposed 2026-09-20 with the program plan AFCARS 2020 Program (#949); Accepted at its close-out P-E, #1966). Distinct from ADR-032 (partner→federal-category routing), which is a different axis and is not used by case-level row emit.

Amended 2026-06-21 (D1, issue #651). During D1 implementation the original "app-layer decrypt of reports.children`" collection premise (Context fact 2 + Decision 2 below) was found to be unnecessary: the curated child demographics are plaintext structured columns on `persons (only ssn_last_four is encrypted), reachable via the non-null allegation.victim_id FK, and the report-level fields (reporter type, admin unit, receipt date) are plaintext on the referral. The collection is therefore a plaintext cross-entity assembly rooted on screened-in referrals — no decryption. Context fact 2 and Decision 2 are rewritten accordingly; the broader asymmetry (subject PII plaintext in the persons master index vs. encrypted at the intake edge) is captured as a separate posture review in issue #671, and the report-date-precision refinement (carrying the originating report’s received_at onto the referral) is issue #672.

Amended 2026-08-28 (#677/#678). The "no decryption" premise of Decision 2 narrowed when #677 (the #671 posture review’s outcome, ADR-041) encrypted persons.date_of_birth at rest: the collection endpoint now decrypts exactly ONE field — the victim DOB, via a DOB-narrowed registry walk that leaves the SSN family’s ciphertext untouched (services/craig-cases/src/api/ncands.rs). Everything else in Decision 2 stands: the assembly remains a plaintext cross-entity walk (demographics on persons; reporter type / admin unit / receipt date on the referral), rooted on screened-in referrals, and reports.children is still never read.

Amended 2026-09-10 (#648, parts 1 + 2). Disposition is re-cut to the seven NCANDS outcomes, #11 RptDisp / #27–33 Mal*Lev are total over it, and RptDisp is derived report-wide — see § Amendment — #648 (part 1) below. #10 RptSrc is a REQUIRED intake fact (craig_reference::ReportSource, captured on every channel, copied to the referral at conversion) and report_source_to_rptsrc is total — see § Amendment — #648 (part 2). The Decision 5 leave-unpopulated gap is therefore closed by parts 1 + 2 of NCANDS Report Source at Intake + Disposition Re-cut (#648); the leave-unpopulated POLICY itself stands for any future field.

Context

craig-reporting’s NCANDS/AFCARS generation is placeholder MVP: generate_ncands/generate_afcars write a submission row with record_count = 0; there is no per-row table and no cross-service data collection. A real federal case-level export must (a) obtain the source data, (b) map each domain value to the literal federal codebook code, and (c) emit a multi-row file.

Investigation of the real craig-cases model surfaced two structural facts that shape the architecture:

  1. The case-level source data is partly uncaptured. Child date-of-birth is not collected at intake (ChildEntry has no DOB → NCANDS age unsourceable); per-allegation disposition is never written (allegations.disposition always NULL → NCANDS maltreatment disposition unsourceable). Investigation-level disposition is captured.

  2. The curated child demographics are plaintext; only the raw intake snapshot is encrypted. The as-reported intake payload (reports.children, Plan B §D2) is application-layer-encrypted JSONB. But the curated person record — persons.sex/race/ethnicity/date_of_birth — is plaintext structured columns (only ssn_last_four is encrypted), and every allegation links to its victim via a non-null allegation.victim_id FK. So the authoritative demographics are reachable as a plaintext cross-entity assembly; decrypting the intake JSONB is unnecessary. (Original premise — corrected during D1; see the Status amendment + issue #671.)

Amended 2026-07-04 (#782, capture-complete reportability). ADR-040’s original "include every screened-in referral and leave incomplete rows flagged/unpopulated" rule (Decision 5, "leave-unpopulated fidelity policy"
the Consequences' "honestly partial pre-capture-completeness") was correct while per-allegation disposition was uncaptured (Context fact 1): every row was then a capture gap, so emitting them flagged-but-present was the honest partial file. Now that allegation- and investigation-level dispositions are captured, a report with no disposition is a pending case, not a capture gap — it is not yet reportable and must not appear in the annual Child File (ACF edit-checks reject a record with no disposition; a pending report is reported in the year it is disposed). The NCANDS mapper therefore now excludes (report, child) groups that carry no disposition, and validation_errors counts only genuine data-quality defects among reportable rows (e.g. >4 distinct maltreatment types). Consequently finalize_ncands_submission stamps validated only when the file has reportable records and zero validation errors, else validated_with_errors, a terminal state no transition leaves (the transmit_ncands route that also blocked a zero-record or errored file was retired in #2130: it only marked a submission transmitted). This supersedes the include-and-flag behavior for the "no disposition" case only; the leave-unpopulated policy for genuinely uncaptured coded fields (Decision 5) is unchanged.

CRAIG is pre-1.0 with no live federal submission, so correctness and not locking premature contracts matter more than speed.

Decision

  1. Capture-first sequencing. Add the missing data capture (intake child DOB; per-allegation disposition) before building the export. The export is the last phase, on real data — not the first. An export built on absent data would emit a mostly-empty file in exactly the fields that carry NCANDS value.

  2. Plaintext cross-entity assembly for collection (no decrypt). A purpose-built cases endpoint (GET /v1/cases/ncands-export?ffy=YYYY) assembles the export rows from the plaintext domain entities, rooted on screened-in referrals received in the FFY → their allegations + investigations → the victim persons record (via allegation.victim_id), returning a typed DTO. No decryption is required: the NCANDS fields are plaintext (demographics on persons; reporter type / admin unit / receipt date on the referral). Rooting on referrals (rather than reports) also captures referrals created directly, not only those converted from an intake report. Rejected: decrypting reports.children (unnecessary, and it reads the as-reported snapshot rather than the curated person record); a store-level SQL join across the encrypted JSONB; an event-sourced read model (premature for a yearly/periodic export). Report date is referrals.received_at, which carries the originating report’s receipt timestamp onto referrals converted from an intake report (#672) — so FFY bucketing uses the true report date, not the conversion instant. Directly-created referrals (no originating report) keep the column DEFAULT now().

  3. Per-row materialization with snapshot. generate writes one ncands_child_rows row per emitted child, materializing the jurisdiction/FFY-derived fields (#1 submission year, #2 state) into the row, so a later re-export is byte-stable even if the active bundle/jurisdiction changes. record_count and child_fatalities derive from the rows, never hardcoded.

  4. Literal federal codes as pure functions in craig-reference, returning Option. The enum→code mapping lives in craig-reference (mirroring the afcars codecs) as pure functions that return Option<u8> (or total u8). This keeps the verified, codebook-cited mapping in one tested place. The existing internal-mnemonic *to_ncands functions (ADR-precedent #640) remain; the new functions are named for the federal variable (*_to_rptsrc, *_to_chmal) to avoid confusion. _As-built (#1766): the remaining reporter-type and abuse-type mnemonics and their translate wrappers were retired too (no production caller), so only the federal-variable functions remain.

  5. Leave-unpopulated fidelity policy. Where a CRAIG domain value has no faithful federal code (e.g. ReporterType::Mandated is a legal status, not an NCANDS source category; Disposition::Inconclusive has no RptDisp equivalent), the mapping returns None → a NULL column → an empty cell. CRAIG never emits a guessed/wrong federal code. The faithful fix (capturing a finer source/disposition at intake) is a tracked follow-up, not an inline guess. No domain enum is enriched as a side effect of the export.

    Update (#649): #34 (Maltreatment Death) is now sourced from a real per-allegation child_fatality field captured in craig-cases — a true fatality emits 1, while a non-fatal (default-false) allegation is still left unpopulated rather than asserted as "No" (false is a default, not a recorded determination). The two remaining leave-unpopulated coded fields, #10 RptSrc / #11 RptDisp, were closed by #648 parts 1 + 2 (the two amendments below) — each by CAPTURING the faithful value, never by inferring it.

  6. FFY semantics + stable surrogate export IDs. reporting_year is the Federal Fiscal Year (Oct 1 – Sep 30). Federal record/child identifiers in the emitted file are stable surrogate keys, never raw internal UUIDs — internal join keys are not leaked into an external file.

Consequences

  • The export program is correctly ordered: data-capture MRs (intake DOB, allegation disposition) precede the export pipeline. Investigation disposition needs no capture work (already live).

  • The collection path is an HTTP call from craig-reporting’s service identity to a cases endpoint that assembles the plaintext entities. D1 gates it with require_service_caller() + an explicit service_id == "craig-reporting" allowlist (mirroring the jws_replay service-to-service pattern), not the per-row ruleset engine. The explicit CasesClient wiring into craig-reporting’s router state remains a D2 task (the authz-boot http_client is not in router state today).

  • The emitted Child File is honestly partial pre-capture-completeness: unfaithful/uncaptured coded fields are empty, documented in the CHANGELOG, and tracked as follow-ups — not presented as full ACF compliance.

  • The exact ACF fixed-width submission layout, field-level edit-checks, ACF transmission, and the AFCARS file are out of scope here; this ADR’s collection/emit shape is intended to carry them later.

Amendment — #648 (part 1, 2026-09-10): the Disposition re-cut; RptDisp is report-wide

Maintainer ruling on #648 (2026-09-03), ruling (2): Disposition is re-cut per the codebook — every variant maps to exactly ONE RptDisp code, Inconclusive is retired, no policy-guessed mapping; jurisdiction labels are renderings over the federal variants, never variants (that ruling — the code set is a federal reference value, not a per-jurisdiction knob). This amendment records what part 1 (MR-B, #1760) changed in this ADR’s terms. Part 2 (MR-A, #1761 — #10 RptSrc captured at intake) is the amendment that follows this one.

  1. Decision 5’s Disposition::Inconclusive example retires. craig_reference::Disposition is now the NDACAN Child File Codebook (rev 2025-09-12) vocabulary, one variant per code: substantiated (1), indicated (2), alternative_response_victim (3), alternative_response_nonvictim (4), unsubstantiated (5), unsubstantiated_false_report (6), closed_no_finding (7). disposition_to_rptdisp(Disposition) → u8 is TOTAL (bijective onto 1..=7) and serves #11 and #27/#29/#31/#33 — the Option<u8> is gone, so #11 leaves Decision 5’s leave-unpopulated list. Mal*Lev 8 has no variant and stays unemitted. The three internal disposition mnemonics (disposition_to_ncands / disposition_from_ncands / translate::disposition_str_to_ncands, zero production callers) are deleted. The retired token is refused everywhere (serde → 422 at the shared extractor; the two chk_*_disposition CHECKs re-created with the seven tokens by a refuse-on-data migration — no rewrite, no dual-accept).

  2. RptDisp is a REPORT fact (correction). craig-reporting computed #11 per (referral, victim) group — a defect this amendment corrects: RptDisp is derived ONCE per referral over every recorded allegation
    investigation disposition and stamped on every child row of that referral (a substantiated child and an unsubstantiated sibling both emit 1); Mal*Lev stay per child from the child’s own allegations.

  3. Precedence = the MIN codebook value (most_severe = min_by_key(disposition_to_rptdisp)) — a transparent CRAIG derivation over the federal list order, recorded ⁂ on #1073 as a best reading pending DFCS confirmation. NCANDS victim classification (codes 1 and 2 count as victims; code 3 excluded since FFY 2015) is a separate concept and is NOT the rationale.

  4. Alternative-response compatibility. Per the ACF codebook an alternative-response report carries only AR / no-allegation outcomes: if any disposition of a referral is 3 or 4, every recorded disposition of that referral must be 3 or 4, else every child row of the referral is row_valid = false with validation_notes naming alternative_response_mixed_outcomes (the slot-overflow reason’s shape). group_is_reportable is otherwise unchanged: a None code still means "no determination recorded yet" and the (referral, child) is excluded as not-yet-reportable, never emitted blank.

  5. "No domain enum is enriched as a side effect of the export" STANDS. This re-cut is the tracked capture-side fix Decision 5 pointed at, decided as a domain-vocabulary ruling (staff record the codebook outcome at determination time) — not an export-side inference over a coarser domain value. The seed draws dispositions per referral track so the fixtures are AR-coherent; the devstack wipes + reseeds through the -- devstack: wipe-before-apply migration annotation (local-dev.adoc).

Amendment — #648 (part 2, 2026-09-10): #10 RptSrc is a REQUIRED intake fact

Maintainer ruling on #648 (2026-09-03), ruling (1), + the user rulings of 2026-09-10 (the FULL RptSrc vocabulary on the public form; REQUIRED on every channel — no optional path, no NULL, no backfill guess): the report source is a fact captured at intake, distinct from the reporter STATUS (ReporterType, which stays). This amendment records what part 2 (MR-A, #1761) changed in this ADR’s terms; with it the Decision 5 leave-unpopulated list is empty.

  1. Decision 5’s ReporterType::Mandated example retires. craig_reference::ReportSource is the NDACAN Child File Codebook (rev 2025-09-12) #10 vocabulary, one variant per code: social_services_personnel (1), medical_personnel (2), mental_health_personnel (3), legal_law_enforcement_personnel (4), education_personnel (5), child_daycare_provider (6), substitute_care_provider (7), alleged_victim (8), parent (9), other_relative (10), friends_neighbors (11), alleged_perpetrator (12), anonymous_reporter (13), other (88), unknown (99). report_source_to_rptsrc(ReportSource) → u8 is TOTAL (injective onto {1..=13, 88, 99}) and REPLACES reporter_type_to_rptsrc (deleted — it was None for every mandated / professional reporter because a legal status names no source category). other keeps a REQUIRED answer from forcing a wrong category; unknown is the codebook’s own "unknown or missing" — a legitimate answer, distinct from blank = not collected, which a REQUIRED field never permits.

  2. Capture, not inference (the policy STANDS). The source is captured where the report is born — the public wizard (step 1, after the reporter type), the signed / partner API, the staff report entry, the three SDKs (the builders refuse to build without one), the CLI — as report_source on the intake DTO and CreateReportRequest, stored plaintext on reports.report_source (chk_reports_report_source, the 15 tokens), copied VERBATIM onto referrals.report_source at conversion (and captured directly on the direct referral create while #895 MR-D has not yet retired it), and read by the collection endpoint from the referral (NcandsExportRow.report_source replaces the dead reporter_type wire field). craig-reporting’s #10 cell is Some(report_source_to_rptsrc(..)) on every row. No status → source derivation exists anywhere in the product path: the refuse-on-data migration 20260913120000_report_source adds the NOT NULL columns WITHOUT a backfill (any recorded report / referral refuses the gate and names cargo xtask dev reseed), and the seed’s per-row derivation from the status + the row id is a fixture coherence, recorded as such in the generator, never a mapping.

  3. The standalone SHINES path keeps nothing, so the source needs an outbound representation. The mapped CpsRequest.reporterInfo gains reportSource via craig_reference::shines::report_source_to_shines_source — a PLACEHOLDER RefVal crosswalk in the exact shape of reporter_type_to_shines_rep_type (total, unique, pinned; each value is the codebook label) that #692’s authoritative RefVals replace before go-live (ADR-042’s conformer note). repType stays; the source is additional.

  4. Wire consequences (pre-1.0 BREAKING, CHANGELOG’d). report_source is REQUIRED on POST /public/v1/reports, the signed / partner routes, POST /v1/cases/reports and POST /v1/cases/referrals; a body without it is a 422 / typed 400 naming the field. The report’s ADR-062 LIFETIME identity is ReportIntentV3 (the V1 / V2 projections and the two-hash legacy replay retire — the guard empties reports, so no pre-cutover digest survives); schema_compat_floor = 20260913120000 (an N−1 cases INSERT without the column is 23502 on every write — the ADR-063 harm class; since #1765 the ADR-063 D3 lint demands that bump).

Amendment — #949 — The AFCARS file: federal codes from the federal ruleset, records with the CFR’s cardinality (Proposed, 2026-09-20)

Standing. Proposed 2026-09-20 with the approved program plan afcars-program (#949, epic &99; rev 4 after the maintainer’s gate). Accepted at the program’s close-out P-E (#1966), when the as-built notes replace the future tense here.

What changes. The Consequences bullet that left "the AFCARS file" out of scope is withdrawn: the AFCARS 2020 out-of-home care and assistance files (45 CFR 1355.41–1355.47) are built on this ADR’s collection / emit shape with four deltas. (1) Decision 5 is restated for AFCARS. Federal codes do NOT come from compiled craig-reference functions: the element dictionary, its value sets, applicability, exemptions, consistency and recurrence rows are the jurisdiction-invariant federal-afcars-2020 ruleset (rulesets/federal/, ADR-072 § Amendment — #949) and every state-vocabulary → federal-code mapping is a {j}-afcars-crosswalk table, both read through a verified surface (AfcarsSurfaceClient, the ADR-074 shape) that refuses a crosswalk that is not total over the fleet enum, emits a code outside the cited value set, or collapses two states without an embedded citation; craig_reference::afcars is DELETED when the surface lands (P-A). The leave-unpopulated policy of Decision 6 stands verbatim — a missing value is blank (§1355.43(d)), never defaulted, never guessed — and the capture-first sequencing of Decision 1 extends to craig-placement (episodes, arrangements, immutable response timestamps) and craig-financial (adoption assistance). (2) Decision 4 is restated for AFCARS. A submission is not one flat row set: afcars_child_records + per-removal, per-arrangement, per-event and ICWA child tables carry the CFR’s cardinality (§1355.43(b)(2): most recent AND all historical for §1355.44(d)–(i)); every generate creates a NEW submission row in a supersede chain per (period, file), each retaining its coverage snapshot and the IMMUTABLE policy identity (rule_set_id, revision, content_sha256) of both documents plus their canonical content, so a re-render never depends on a ruleset NAME (ADR-006 / #1188). (3) Validation is §1355.46 itself — exemptions, applicability, per-element classes, within-file recurrence, per-applicable-observation denominators, the 100 % / 10 % finalize — not a sourced-only completeness check. (4) The file is XML per the pinned ACF bulletin with a keyed, PINNED, never-rotated record number (§1355.44(a)(4)); readiness is bound to the winning export artifact and re-verified by the ready_for_transmission act; transmitted is written only by the separate ACF-delivery program (#1967) — the marking-only transmit stub is retired. The collection endpoints stay service-only, allowlisted and release-audited (Decision 3), take RESOLVED instants, never a period string, and the placement hop gains craig-placement’s first release-audit event. Design detail and the five child plans: AFCARS 2020 Program (#949).

Amendment — #2999 (2026-11-08): the configuration layers left CRAIG’s source

ADR-087 U4 (#2955) moved the configuration layers out of CRAIG’s source. A rulesets/<j>/<file> path above now names <file> in layer <j>: the federal, Georgia and Texas layers are the craig-config-{federal,georgia,texas} repositories, pinned in config-sources.lock and fetched to target/config/layers/<j>/ by cargo xtask config fetch, and the synthetic testonia layer is fixtures/config/testonia/. The decision above is unchanged.

Edit this page · latest