Plan: Custody Episodes and the DOE-SLDS Bind — legal status as a first-class fact (#1804, #1806, #1821)

Archive record

Merge requests: !1904 (U0 plan page + ADR-081, Relates #1804) + !1906 (U1, Closes #2341) + !1909 (U2, Closes #2342) + !1912 (U3, Closes #1804) + !1918 (U4, Closes #1806) + !1921 (U5, Closes #2343) + !1925 (U7, Closes #2344); the close-out !1926 (U6, Closes #1821)

2026-10-15 — approved in plan mode after a contextless round 1 (no-ship, 6 blockers fixed) and the maintainer’s round 2 on GPT Astra (no-ship, 13 findings fixed). What landed: the 24-code legal-status vocabulary as bundle data (U1); custody episodes and the legal-status ledger, five events, the case-close trigger (U2); court orders write the children’s custody rows (U3); the GTID as an encrypted person identifier, demographics first, with an audited reveal (U4); the custody stage in the outbound projection (U5); the six DOE-SLDS legs: the GTID pin, per-child order, the predecessor wait, the reentry skip, per-type wire validation, the GTID-free acknowledgement store, the consent knob default off (U6); the web legal-status panel and person identifiers (U7). Follow-ups stay open: #1073 (the DFCS readings), #1813, #2345-#2348.

Status

Done (2026-10-15) — !1926

Erratum (2026-10-13): before the live episodes' FOR UPDATE, each act takes a transaction-scoped advisory lock per named child in child-id order, so two cases' acts on one child serialize (a child with no live episode has no row to lock).

Erratum (2026-10-13): a court-order update that names a child again with its live order row’s own token and date leaves that row as is (no successor, no event).

Erratum (2026-10-14): the reveal’s case.person_pii_exported wrapper names the revealing worker as user_id (an #2211 actor key), not requested_by, which the census holds as CONTEXT for a service release; under it a human reveal would audit with no actor.

Erratum (2026-10-14): a custody read whose identifier names no GTID row of the child serves no GTID; "else" applies only when identifier is absent.

Erratum (2026-10-15): exchange’s custody and stage reads did not take U5’s identifier; U6 adds it to all four custody and stage read functions and to read, not to OutboundReads::stage_principal alone.

Erratum (2026-10-15): the INC’s spent wait is held predecessor-unsettled inside its resolve transaction, under the child lock, not at the worker’s last attempt; the worker’s after-dispatch hold skips that class. Likewise an occurrence skipped as superseded-by-reentry leaves its admission dismissed with that reason.

Erratum (2026-10-15): impl TriggerRuntime stays at its 16-method cap and the resolve, close, record, supersede and release bodies do not grow, so the DOE passes are free functions (services/craig-exchange/src/triggers/doe_passes.rs, services/craig-exchange/src/triggers/legs/doe_slds.rs).

Erratum (2026-10-15): exchange had no read for D6’s person → open-episode arm; U6 adds OutboundReads::person_custody_stages. A catch-up or custody-keyed DOE admission takes its child from the custody stage’s principal; subject_person_id is required only for the identifier legs.

Erratum (2026-10-15): AckOutcome::Accepted carries the body to store, and the stored DOE acknowledgement is transaction_id, status and received_at only.

Erratum (2026-10-15): craig-exchange gains a direct dependency on craig-partner-doe-slds (it reached the adapter only through the bundle registry) and a mock-featured dev-dependency for its in-crate DOE tests.

Erratum (2026-10-15): an INC re-stages at assembly only behind a live DOE record of the child on an OLDER stage (episode ids are uuidv7(), so < is creation order), not on any other stage: matching a newer stage let two episodes' live INCs re-stage behind each other forever.

Erratum (2026-10-15): "errors classify as CPRS’s" is one generic classifier over the transport’s PartnerFailureView, not a copy; a DOE bad status carries no body digest.

Erratum (2026-10-15): "requires `gtid`" is a minimum length of one; the wire type validated only a maximum, so an empty GTID passed.

Erratum (2026-10-15): the entry also requires the Out-of-Care date (legal_status_end_date) on an OUC, per the catalogue’s OUC row (cat/:492).

Erratum (2026-10-15): the devstack DOE partner row already existed and the seed links no partner to an agreement, so U6 adds no seed row; each devstack test installs its own partner and agreement (the DSA chain is per test).

Erratum (2026-10-15): the two devstack DOE tests need no nextest filter change (the existing outbound_triggers:: clause matches them); only the in-crate triggers::doe_legs_tests module gains a clause.

Erratum (2026-10-15): the coverage matrix is a generated snapshot; U6 adds its two devstack tests to the untagged list rather than regenerating it.

Erratum (2026-10-15): U6 also amends ADR-075 decision 9 (the DOE key is the child) and updates ADR-003 and the implementation guide’s custody rows, which the diff would otherwise make false.

Erratum (2026-11-06): #2353, ruled Option A. D2’s in-day order is (effective_on, chain_seq), not chain_root_id (F9’s "ids being v7" no longer orders a day). A v7 is monotonic only within one process, so under replica clock skew a same-day close recorded after a change could sort first and be refused. chain_seq is a per-child number: an original takes the next one under D2’s per-child advisory lock, and a correction keeps its root’s. Migration 20261106140000_legal_status_chain_seq back-fills existing rows in chain_root_id order and bumps the floor.

Glossary. This page is docs/modules/ROOT/pages/plans/archive/custody-episodes-doe-slds.adoc. ⁂ marks a reading DFCS may rule otherwise, logged on #1073 (it confirms a reading, it does not gate the build). D = design, F = fork, U = merge request, AC = a restated criterion. "The fix lane" = #1815, #1837, #1838. "Same-partner recipient" = a row of exchange_outbound_recipients for the same DOE partner. :line prefixes: cases/ = services/craig-cases/src/, cc/ = crates/craig-cases-contracts/src/, ex/ = services/craig-exchange/src/, doe/ = crates/craig-partner-doe-slds/src/types.rs, cat/ = docs/modules/ROOT/pages/interfaces/doe-slds-interface.adoc, otp/ = docs/modules/ROOT/pages/plans/archive/outbound-trigger-parity.adoc, …recut.sql = services/craig-placement/migrations/20260925130000_removal_episodes_recut.sql.

Anchor What binds here

#1804 (P2, W8), #1806 (P2, W3), #1821 (P2, W3)

one program; #1804 is the spine of four binds (ADR-075 :177, :208), #1821 is its first consumer

Removal episodes (ADR-079 D2, adrs/adr-079-afcars-placement-capture.adoc:93-126)

the identity row: stable id, owning case for life, deferred instants, EXCLUDE

The D1 ledgers (ADR-078 :40-45, :75; crates/craig-ledger-contracts/src/lib.rs:247-276)

event ledger, supersedes_id, retire, ids-only events

The trigger substrate (ADR-075 :129-169; otp/ :102-221)

matrix rows, admission + recipient ledgers, knob, projection, catch-up, rollout

The DOE wire (doe/:36-53, :109-207, :221-290, :300-317) and catalogue (cat/:474-500)

INC / OUC / RMV, status NEW, 24 CLEGSTAT codes; per-type mandatory fields (RMV: In-Care date and GTID only); gtid "FERPA-protected; host service encrypts at rest"; the ack echoes transaction_id and gtid

Context (census 2026-10-12 on main)

  • No legal status anywhere. Only the partner wire crates carry one. The catalogue’s trigger is "a GTID number has been validated and the child’s most recent, active Legal Status is In-DFCS custody" (cat/:393). DOE’s code table has no class column (cat/:247-325); the WIC catalogue lists the in-custody statuses: Permanent Court, Permanent Voluntary, Short Term Emergency Care, Temporary Court, Temporary Voluntary and the two Joint Commitments with DJJ (interfaces/wic-referral-ies.adoc:53, :953).

  • The nearest facts do not fit. court_orders is case-scoped, has no child and emits no custody fact (crates/craig-reference/src/enums.rs:1043). Removal episodes hold placement-and-care; custody is "a separate craig-cases fact" and an in-agency move is a reassignment on the same case (data-model-placement.adoc:1040-1042, #2028).

  • The substrate is stage-shaped. Recipients are UNIQUE (interface, partner_id, stage_kind, stage_id, person_id), insert-once, with no record of the identifier a person was listed under (services/craig-exchange/migrations/20260913150000_outbound_triggers.sql:47-69); record jobs order per stage (ex/triggers/dispatch.rs:815-818, ex/store/send_jobs.rs:267-272), and closed_sent_at is stamped at staging, not at send (ex/store/trigger_ledgers.rs:294-298). OutboundStageKind has Case and Investigation only (cc/outbound_principals.rs:31-36). A re-entry must send INC again under a new stage_id: the custody episode needs a stable id of its own. Only CPRS is bound (crates/craig-state-ga/src/outbound.rs:28-48); doe_slds is registered (crates/craig-state-ga/src/lib.rs:115); the knob struct has only cprs (crates/craig-common/src/settings.rs:493-511).

Scope

In: D1–D8. Out: the DOE GTIDLookup adapter (cat/:516; F7, #2345); the weekly DOE inbound; other identifier kinds (EMPI later); the WIC, IES and STARS binds; a status change inside custody reaching DOE (no such request type); a second GTID inside one episode (#2346); a custody-expiration date (DOE-2.1.15; optional on the wire); a person-wide custody read (#1804 asks for the case); education_records; AFCARS use of custody; the removal-episode cross-check (F5, #2347); a pause for staged outbound jobs (#2348); a same-day exit and re-entry (F9); the production DOE endpoint, DSA and credentials (#1813).

Restated acceptance

#1804 (stale: craig-reference; Placement.removal_date, dropped by #2018, …recut.sql:306; one event key). AC1. GA’s 24 CLEGSTAT codes are StateBundle data with D1’s classes (F1), pinned to DoeSldsLegalStatus by a test; ⁂ #1073 confirms both. AC2. Per-child legal-status history with effective dates, each in-custody run under a custody-episode identity row with a stable id, readable on the case. AC3. Manual acts stating their intent and court-order-driven writes (F4) set it; corrections keep the episode id; case closure follows F11. AC4. case.custody_opened, _closed, _retracted, _close_corrected and case.legal_status_changed (F3), ids-only, in ADR-003 and the security parser in the same MR.

#1806 (re-homed by F6: it puts the GTID on EducationRecord, services/craig-placement/src/store/models.rs:389; the catalogue reads it from Person Identifiers, cat/:57, :385, :401). AC5. A cases person_identifiers ledger holds the GTID (kind gtid) encrypted under BlindIndex (F8), only for a person with a DOB and names; a malformed value or date is a typed 422, a GTID live on another person a typed 409; end and retract acts; case.person_identifier_recorded / _ended, catalogued with security arms, replace #1806’s proposed (never emitted) placement.education.gtid_validated; an audited reveal; the person’s authorization. "Validated" = format-checked and worker-attested (F7).

#1821 (blocked on the above; its "NEW" is the interface status, INC the request type, doe/:36-41). AC6. GA matrix rows citing cat/:67-73: INC on an open episode with a live GTID, never before an earlier episode’s removal unless its closing admission was dismissed; OUC on its close and on a corrected close of the child’s latest stage (F12); RMV on the GTID’s end or retraction, or the retraction of the child’s latest stage, each reaching only recipients listed under that GTID or stage; per-type validation; one record per job; categorical settlement; CRAIG_EXCHANGETRIGGERSDOE_SLDS__ENABLED (default off) + the DSA chain; the devstack partner row and mock capture; contested legs by name; the deployment-guide row. No placement read (F6).

Design

D1 — Vocabulary as bundle data (U1)

StateBundle::legal_statuses() → Vec<LegalStatusSpec>, default empty (the uas_codes() doctrine, crates/craig-state-bundle/src/bundle.rs:61-66; ADR-072 :55). LegalStatusSpec { token, label, custody_class: CustodyClass }, CustodyClass { InCustody, NotInCustody }, a closed neutral enum. GA contributes the 24 codes (doe/:109-207) with these classes, the readings U0 logs on #1073:

Class Tokens Source

InCustody (7)

PCT, PVL, STE, TCT, TVL, JCP, JCT

the catalogue’s "In DFCS Custody" list (Context), read as DOE’s too ⁂

NotInCustody (17)

NAF, NCT, NCD, NCO, NTT, NCE, NGP, NPC, NPR, NOT, NCS, NCR ("Not In DFCS Custody – …"); AFS, CTD, ILP, NDJ, DJA (aftercare, DJJ commitment)

the twelve by name; the five because that list omits them ⁂

Cases resolves the list at boot: a duplicate or malformed token (not 1–16 ASCII uppercase letters or digits) refuses boot; an empty list (the TX stub) answers every custody act with a typed 422 legal-status-vocabulary-missing, never a guess.

D2 — The episode and the history (U2; F2 A, F9)

  • custody_episodes: id (v7), child_id, case_id (one owning case for life), custody_from DATE, custody_until DATE NULL, recorded / retired columns as removal_episodes (…recut.sql:127-148), EXCLUDE USING gist (child_id WITH =, daterange(custody_from, custody_until, '[]') WITH &&) WHERE retired_at IS NULL (inclusive: a one-day episode is a one-day range, and a re-entry opens the day after an exit at the earliest), a row guard admitting only the instants update and a retire (:102-120).

  • legal_status_facts: a craig-ledger EVENT ledger keyed by the shared CaseChildKey (person_id = the child, case_id; cases/store/ledger_codecs.rs:24-47): status_token, custody_class (stamped at write, so a reclassification never rewrites history), effective_on, chain_root_id (the row’s own id on an original), episode_id NULL and court_order_id NULL, all fact columns corrections inherit (the court_order_id precedent, services/craig-cases/migrations/20260923180000_permanency_ledgers.sql:115, cases/store/child_review_events.rs:38, :75-78), note, supersedes_id, retire columns; its retired-reason CHECK and LedgerRetiredReason (cc/ledger.rs:97-133) gain episode_retracted. Rows order by (effective_on, chain_root_id), ids being v7; the status in force on a day is the last live row on or before it.

  • An act states its intent. An in-custody row without episode_id opens an episode (409 custody-episode-overlap if it overlaps any live episode of the child, this case or another); with one, it is a change in that open episode. A not-in-custody row with episode_id closes that episode; without one it is a history row, refused while the child has an open episode in this case (409 custody-episode-open, naming it) or when dated inside a live episode’s span (409 custody-row-out-of-order). A named episode that is closed, retired or another case’s is 409 custody-not-open.

  • Episode rule, after every act. An episode’s live rows are its in-custody rows, then at most one closing row, ordered after each of them (else 409 custody-row-out-of-order); custody_from = the earliest in-custody date, custody_until = the closing date; every date is on or before today (jurisdiction clock). A correction supersedes within its class (a flip is 422) and keeps its episode; the instants follow. A one-day episode, and a change then a close on one day, are both representable.

  • Retiring a row (the row retract, or D4’s sweep): (i) another live in-custody row remains: the instants follow; (ii) it was the last live in-custody row: the episode retires as in an episode retract, this row included; (iii) it is the closing row: 409 custody-close-not-retirable. A closed episode never reopens, because DOE has been sent OUC; correct the close (F12) or retract the episode.

  • Episode retract retires the episode and, in the same transaction, every live row of it as episode_retracted, the triggering row of rule (ii) too. Those rows are the snapshot D6 serves for RMV; D4’s sweep retires live rows only (child_review_events.rs:128-143), so it never touches them.

  • Each act takes one lock order (ADR-079 :103-106): claim → the case row (require_case_open, FOR UPDATE, cases/store/cases.rs:202-216, on open / change / close; else FOR KEY SHARE) → the live episodes of every child the act names, in every case, in one FOR UPDATE statement ordered by id; it ends with SET CONSTRAINTS ck_custody_episode_current_instants IMMEDIATE (ADR-079 :121-126): the EXCLUDE answers a typed 409 custody-episode-overlap; the deferred trigger (live episodes only) stays an internal invariant no request can trip.

D3 — Acts, reads, events, lifecycle (U2; F11 A)

  • Routes under /v1/cases/cases/{case_id}/children/{child_id}/ (the P-C shape, cases/api/ledgers/child_facts.rs:3-17), ADR-062 idempotent: POST legal-statuses {client_request_id, status_token, effective_on, episode_id?, note?, until?: {status_token, effective_on}} (until without episode_id records a closed historical episode in one act); POST legal-statuses/{row_id}/corrections {client_request_id, status_token, effective_on, note?}; POST legal-statuses/{row_id}/retract and POST custody-episodes/{id}/retract {client_request_id, note} (crates/craig-ledger-contracts/src/lib.rs:101-110). Reads: GET /v1/cases/cases/{case_id}/custody-episodes[?child_id=] and GET …/children/{child_id}/legal-statuses.

  • Authz on the case resource (case: read / update, ledgers/child_facts.rs:95-101), no new authz file; the child holds a child-role household row of the case (400 child-not-in-case). Field specs crates/craig-cases-fields/src/{custody_episodes,legal_status_facts}.rs.

  • Lifecycle (F11 A). Open, change and close take require_case_open (409 case-closed); history rows, corrections and retractions pass on a closed or transferred case (data-model-cases.adoc:8-25). A BEFORE UPDATE OF status trigger on cases refuses closed / transferred while a case episode is open (the cross-table trigger precedent: ck_arrangement_in_episode, …recut.sql:297-302); U2 maps its error to 409 custody-open, and a pre-U2 replica still serving gets it as a 500, never a closed case with open custody. The case row lock serializes a close with a racing open.

  • Events, ids-only (ADR-078 :75), on the placement.episode_exited model (ADR-003 :61): {episode_id?, child_id, case_id, row_id, act, act_id, act_at, user_id}. case.custody_opened / closed / _retracted on those transitions (an until act emits _opened then _closed, each with its row’s id); case.custody_close_corrected on an act that changes a closed episode’s instants or closing token (a correction, or rule (i)); case.legal_status_changed on every other act (a change, a correction or rule (i) on an open episode, a history row). ADR-003 rows; craig-security arms and families: case.custody → episode_id (resource custody_episode; opened a create, the rest an update), case.legal_status → case_id (resource case, an update) (services/craig-security/src/event_parsing.rs:77-123; the count pin at :3275 becomes 34).

D4 — Court-order writes (U3; F4)

  • CreateCourtOrderRequest.custody: Option<CourtOrderCustody {children, status_token, effective_on}> (cc/court_orders.rs:47) writes one D2 row per child in the order’s transaction, with court_order_id, under D2’s rules; child-role members only, at most HEARING_CHILDREN_MAX (:16). An order row takes the intent the child’s state in this case implies: an open episode makes it a change or a close, none an open or a history row.

  • Idempotency. CourtOrderIntentV3 (cases/api/intents/casework.rs:257-271) adds custody, an explicit null when absent (crates/craig-api/src/request_claims.rs:42-44); every court-order create hash moves once with the schema key (the V2 precedent, casework.rs:17-23), so a create retry spanning the U3 deploy answers 409 idempotency-conflict (pre-1.0, no dual decode; a CHANGELOG ops note). The update is If-Match-versioned (cases/api/court_orders.rs:363, :390), not hashed.

  • UpdateCourtOrderRequest.custody follows the hearing rule (:120-125): absent = unchanged, so a judge-name fix touches no custody row. A value restates per child: named again, the order’s live row is corrected (same class, the episode id stays; a flip is 422); no longer named, its row is retired; newly named, a new row. An order delete retires every live row it wrote.

  • Retirement runs D2’s rules through the sweep (order_corrected / order_deleted): (i) emits case.legal_status_changed or case.custody_close_corrected; (ii) case.custody_retracted (DOE RMV), every row episode_retracted; (iii) refuses the whole order act with 409 custody-close-not-retirable, nothing written. No order-type → status derivation.

D5 — Person identifiers and the GTID (U4; F6 G-a, F7, F8)

  • person_identifiers: id, person_id, kind (StateBundle::identifier_kinds() → Vec<IdentifierKindSpec {token, label, format}>, default empty, boot-resolved as D1; GA gtid, IdentifierFormat::Digits(10) ⁂; an undeclared kind, so every TX act, is a typed 422 identifier-kind-unknown), value (CGEF) + value_hmac (BlindIndex, field_domain = "person_identifier", Canon::AsIs: the value is format-checked, never trimmed, a malformed one 422 identifier-format-invalid; the crates/craig-cases-fields/src/persons.rs:134-147 shape), effective_from (on or before today), effective_until (from effective_from to today; else 422 identifier-dates-invalid), provenance = worker_attested, retire columns. Live = neither retired nor ended. Partial UNIQUEs over live rows: one per (person, kind); one per (kind, value_hmac), a violation 409 person-identifier-duplicate naming no one. The second BlindIndex entity (crates/craig-cases-fields/src/lib.rs:11-12): the seeder, xtask verify-seed and the key lineage cover it.

  • Demographics. Record takes the person row with lock_person (cases/store/persons.rs:286-295) and refuses a person with no DOB or a blank first or last name (422 person-demographics-incomplete). A DOB cannot be cleared (date_of_birth = COALESCE(…), store/persons.rs:215), and a person update that would blank a name of a person holding a live identifier is 409 person-identifier-live, checked under the same lock. So every GTID holder carries the INC demographics (D7); supplying a DOB, then recording the GTID, is the path to the INC.

  • Acts, ADR-062 idempotent: record {client_request_id, kind, value, effective_from}, end {client_request_id, effective_until}, retract {client_request_id, note}. Events {identifier_id, person_id, kind, act, act_id, user_id}: case.person_identifier_recorded on record, case.person_identifier_ended on end and retract (act says which; DOE scenario 3 is "end-dated / marked invalid", cat/:494-498). ADR-003 rows; craig-security arms file both under resource person through the existing case.person_ family (the #2032 posture, ADR-003 :97), since a case.person_identifier_ family would fail resource_id_families_are_prefix_disjoint (event_parsing.rs:3273).

  • Reveal stages a fourth case.person_pii_exported wrapper before the body (purpose = person_identifier_reveal, {person_ids, identifier_id, kind, requested_by}; cases/events.rs:463-480), Cache-Control: no-store; an export, so the data_export detection rule sees each one.

  • Routes: POST /v1/cases/persons/{id}/identifiers, …/{identifier_id}/end, …/retract, …/reveal; GET …/identifiers (masked to the last four). Authz inherits the person’s exactly, through PersonPath::authorize (cases/api/ledgers/mod.rs:89-99): the list = Person read; record, end, retract = Person update; reveal = Person approve (GA: Admin and Supervisor, rulesets/georgia/georgia-authz-person.json:128, :143; the SSN verification posture, cases/api/persons_ssn.rs:60-66). deny_pure_service precedes every identifier route, the list included, as on every ledger route (ledgers/mod.rs:11-12); exchange reads a GTID only through D6. No new resource type or ruleset file; each jurisdiction’s person ruleset (georgia-, texas-authz-person.json) applies unchanged.

D6 — The custody stage in the projection (U5)

  • ADR-075 amendment: OutboundStageKind::CustodyEpisode (custody_episode). The wire extends in place (one exchange resolve and dispatch path): OutboundStage.custody: Option<OutboundCustody {custody_from, custody_until, retracted, rows: [{status_token, custody_class, effective_on}]}>, OutboundPrincipal.gtid: Option<OutboundGtid {identifier_id, value, ended_on, retracted}> (live = neither; both skipped when None: CPRS bytes unchanged) and OutboundReadQuery.identifier: Option<Uuid>. The contract (cc/outbound_principals.rs:3-8, "No SSN …") gains "the GTID, custody arms only" (Changed).

  • An episode stage: stage_id = episode id; partner_case_id, case_number, admin_unit, county_fips, assigned_worker from the owning case; status open / closed / retracted; opened_at = the episode’s recorded_at; closed_at = the closing row’s recorded_at or the retire instant. rows are the episode’s live rows, or for a retracted episode its episode_retracted rows (D2). The principal is the child (role child); its source_version covers the person row, the served GTID row and the served rows.

  • Arms behind the allowlist (cases/api/outbound_principals.rs:41): set and single-record GET /v1/cases/custody-episodes/{id}/outbound-principals[/{person_id}], serving closed and retracted episodes (404 only for an unknown id), with the GTID identifier names (that person’s, live or not), else the live one, else the latest ended or retracted; a person → open-episode id arm GET /v1/cases/persons/{id}/outbound-custody-stages (the report arm’s shape); the open-stages arm (cases/api/outbound_stages.rs:89-100): open episodes whose child has a live GTID. Each read stages the existing outbound release wrapper (stage_kind = custody_episode, cases/events.rs:772-797); no case.outbound_principals_released exists (ADR-075 :14-17).

  • Exchange learns the kind: ex/triggers/cases_reads.rs:144, :162 route it; triggers/dispatch.rs:903 parses it; cprs_stage_type (triggers/legs.rs:472-477) returns Option, None refusing assembly (a CPRS leg never meets a custody stage). No exchange migration in U5.

D7 — The DOE-SLDS legs (U6; F12)

  • Matrix (GA), one leg per event, as a leg fixes its admission key (ex/triggers/admission.rs:159-194): case.custody_opened → doe_slds/custody_opened and case.person_identifier_recorded → gtid_recorded (INC); case.custody_closed → custody_closed and case.custody_close_corrected → custody_corrected (OUC); case.custody_retracted → custody_retracted and case.person_identifier_ended → gtid_ended (RMV; ⁂ retraction as removal). case.legal_status_changed binds nothing.

  • Exchange: Family::DoeSlds, six DoeSlds* legs (ex/triggers/legs.rs:57-100, :171); EntityKind::CustodyEpisode (custody_*, keyed episode_id) and PersonIdentifier (gtid_*, keyed identifier_id; admits_event only for kind = gtid) (:145). The revision is 0, except custody_corrected, which keys on the event’s act_id so each correction is its own admission (the CprsInvPrincipalAdded precedent, admission.rs:185-192). subject_person_id comes from the event’s child_id / person_id; the request type is Leg::doe_request_type() (a record job takes its leg from its admission, dispatch.rs:761-781); TriggerSettings.doe_slds + its enabled arm; catch_up_leg(doe_slds, CustodyEpisode) = custody_opened.

  • Pinning. U6’s migration adds exchange_outbound_recipients.subject_identifier_id UUID NULL (NULL for CPRS), an index on (interface, partner_id, person_id, subject_identifier_id) WHERE removed_at IS NULL, and bumps exchange’s schema_compat_floor (Rollout). INC’s admit_new stamps the served GTID’s identifier_id. The gtid_ended RMV stages only the subject’s same-partner recipients with subject_identifier_id = the admission’s entity_id; OUC, the retraction RMV and the F12 re-send read with identifier = the recipient’s subject_identifier_id, on the resolve read, every record-job read and supersession (OutboundReads::stage_principal gains it, dispatch.rs:537-585). So a later GTID never replaces the one DOE listed, and ending an old GTID never touches a recipient listed under a newer one.

  • Ordering across episodes. Every DOE resolve takes, after its stage lock (taken first by every resolve, ex/store/trigger_stages.rs), a per-child transaction lock (a two-key advisory lock with its own class constant, the ex/store/trigger_stages.rs:38-45 precedent) before its ledger reads, and DOE record jobs take the ordering key doe_slds:{person_id} (the child), not the stage (dispatch.rs:815-818 gains a per-family key; CPRS unchanged), so one child’s DOE records send in staging order (the claim guard, send_jobs.rs:267-272). Under the lock, with "older" and "newer" by stage id (v7; only open stages are admitted, so creation order is custody order):

    • an INC resolve waits while the child holds an older same-partner recipient with neither closed_sent_at nor removed_at whose closing admission is not dismissed: a new retryable class predecessor-unsettled (ex/triggers/settlement.rs:86-91) whose last attempt holds the admission with that token rather than retries-exhausted (ex/send_worker.rs:241-252). The transaction that stages a child’s removal (CloseExisting, RemoveAndSend) releases that child’s admissions held predecessor-unsettled, re-evaluated as the operator release does (ex/triggers/acts.rs:121);

    • an INC, a retraction RMV or an F12 re-send for a stage older than the child’s newest same-partner recipient settles superseded-by-reentry, nothing sent (⁂ DOE keeps the older stage’s last data). A gtid_ended RMV is never skipped: it only removes;

    • at assembly, an INC re-stages behind any pending or in-flight DOE record of the child on another stage, through the supersede path (dispatch.rs:707-746), so a superseded OUC re-inserted with a newer id still sends first;

    • together: an earlier episode’s removal is sent before a later episode’s INC, and nothing for an older stage follows it except a gtid_ended RMV, which removes only the GTID it names, whichever key DOE lists by (GTID or stage; cat/:70, :73 leave it unstated).

  • INC (AdmitNew): the stage is the episode, or for an identifier the person’s open episode (D6’s person arm). Leg::admits gains the stage (today (principal, today), legs.rs:298) and admits the child with a live GTID on an open stage only, so admit_new’s closed-stage staging (decision 9, `dispatch.rs:325-371) never fires for DOE (DOE lists children in care, cat/:393): a historical episode never reaches DOE. Whichever fact commits second admits; the recipient UNIQUE absorbs a duplicate.

  • OUC (CloseExisting): stamps closed_sent_at and bumps the stage epoch (#1839). F12 re-send: a new ResolveRule::ResendClose for custody_corrected stages one OUC per same-partner recipient of the stage with closed_sent_at set and removed_at NULL, assembled from the current projection ⁂ (the catalogue is silent on a second OUC; DOE-4.1, cat/:41, asks for updated SHINES data fields). An open episode’s start-date correction reaches DOE in its OUC, whose In-Care date is the corrected custody_from.

  • RMV: a new ResolveRule::RemoveAndSend (+ ReadingRule, legs.rs:103-128): read the subject’s record pinned as above; under the stage lock bump the epoch, stamp removed_at via retire_recipient (now returning the row and, for gtid_ended, filtering on the pin, ex/store/trigger_ledgers.rs:325-345) and stage one record for a recipient it stamped. Stages: the episode (a retraction), or the subject’s pinned custody_episode recipients (an identifier). It reaches a recipient whether or not its OUC was sent (cat/:457 conditions RMV on the GTID’s end only) ⁂.

  • INC guard. INC assembles only from an open episode and a live GTID, else terminal assembly-refused, nothing sent: a superseded job re-stages behind a later OUC or RMV in the FIFO (ADR-075 decision 8; ex/store/send_jobs.rs:242-272), and an INC after its own end would re-list the child. DOE may then get an OUC or RMV for a child whose INC was refused, which only de-lists.

  • Assembly of DoeSldsCustodyEntry (doe/:221-290), validated per request type: case_id, person_id, stage_id, first_name, last_name, date_of_birth and legal_status become Option, and a garde validator requires each, non-empty, for INC and OUC and only gtid and legal_status_start_date for RMV (cat/:486, :492, :498); the mock validates and gains a 10-digit reject sentinel (today REJECT_FOR_TEST_GTID, crates/craig-partner-doe-slds/src/mock.rs:35, which no GTID passes). An RMV is never refused for demographics.

    • submitted_date the record job’s created_at as a business date (BusinessClock::date_of; a retry is byte-identical, DOE-2.1.3); request_type by leg; status NEW (DOE-4.1.2 / 4.1.3); transaction_id the job’s correlation id.

    • gtid the pinned GTID; case_id the stage’s partner_case_id (referral_id ?? id, ADR-075 :165); person_id the child; stage_id the episode; names and DOB from the principal; middle_name absent: CRAIG records none, where cat/:486, :492 list it ⁂.

    • legal_status: INC and RMV the latest served in-custody row’s token (a retracted episode’s snapshot always holds one, D2); OUC the closing row’s token; one outside DoeSldsLegalStatus is assembly-refused.

    • legal_status_start_date: INC that row’s effective_on (DOE-2.1.14, cat/:441); OUC and RMV custody_from (the In-Care date) ⁂.

    • legal_status_end_date: INC and RMV absent; OUC custody_until, the catalogue’s Out-of-Care date (cat/:492) on the wire’s custody-expiration field (cat/:445) ⁂.

  • Acknowledgement. classify_ack accepts a DoeSldsCustodyAck whose transaction_id and gtid equal what was sent (the sent GTID rides SentRecord in memory), else ack-mismatch, and whose status is SNT, else partner-rejected (the mock’s 200 ERR, mock.rs:32-35); errors classify as CPRS’s (legs.rs:482-510). The worker stores an accepted response (ex/send_worker.rs:671-678), so AckOutcome::Accepted carries the body to store: DOE’s minus gtid. No GTID rests in exchange.

D8 — Web (U7; F10)

A legal-status panel on the child-in-case view (the child_facts_panel.html pattern) with open / change / close / history / correct / retract, and a person-identifiers section on the person view (record, end, retract, audited reveal); Fluent keys; Playwright journeys by test id.

F2 — custody model. A (rec): D2, an episode identity row plus a legal-status ledger. Consequence: two tables and a deferred trigger; the DOE stage_id never moves. B: one status ledger, the episode derived as the maximal in-custody run. Consequence: one table, but the stage id drifts unless roots are tracked, non-overlap is not a database fact, and every consumer re-derives the episode. C: the placement removal episode. Consequence: contradicts the separate-fact ruling, needs a cross-service reference, conflates placement-and-care with custody.

F6 — where the GTID lives. G-a (rec): D5, as SHINES does (cat/:401). Consequence: one cases projection serves the bind, the end date RMV needs is a ledger fact, EMPI joins later as a kind. G-b: education_records.gtid in placement, as #1806 is written. Consequence: rows edited in place carry no end date for RMV, and this program gains a placement S2S projection and an exchange placement client.

F7 — how it is validated. Worker-attested now, with a filed issue for the GTIDLookup adapter (rec). Consequence: no external gate; a mistyped GTID that passes the format check reaches DOE until a worker ends it (RMV), and as recipients are insert-once (ex/store/trigger_ledgers.rs:184-206) the corrected GTID reaches DOE only with the child’s next episode (the second-GTID follow-up). Verify-first: a new DOE adapter plus DOE / GTA access. Consequence: the build gains an external gate, and the unit likely splits.

F11 — case closure with custody open. A (rec): D3, closure or transfer refused while an episode is open, by a DB trigger. Consequence: the worker records the not-in-custody status first; as an in-agency move is a reassignment, transferred means the case left the agency and custody ends first (NCO, NTT, NCS). B: custody acts pass on a closed or transferred case. Consequence: the DOE stage outlives the case; a second #1631 exception.

F12 — a corrected close. A (rec): D7’s re-send for the child’s latest stage, ⁂ that DOE takes a later OUC as a replacement. Consequence: a DOE that refuses it answers ERR (partner-rejected); an older episode’s correction stays in CRAIG only. B: no re-send; an operator procedure. Consequence: DOE keeps the wrong dates until a person acts outside CRAIG.

Minor forks. F1 vocabulary in the StateBundle with a per-token class (rec) OR craig-reference as #1804 says (a GA list in the neutral crate). F3 per-transition keys (rec) OR one case.legal_status_changed with a categorical transition. F4 the status named on the order act (rec) OR manual-only in v1. F5 independent of removal episodes plus a filed advisory-check issue (rec) OR enforced coupling. F8 BlindIndex (rec; duplicate check, future DOE inbound match) OR Opaque (no duplicate check). F9 DATE ordered within a day by chain root (rec; court and CLEGSTAT dates; a same-day exit and re-entry is not representable) OR TIMESTAMPTZ. F10 web (rec) OR API only.

Units — each its own MR, one epic

Order: U0 → U1 → U2 → (U3 ∥ U4) → U5 → U6; U7 after U2 and U4; U6 waits on the fix lane (#1815 typed-partner correlation, #1837 act bounds, #1838 contested census). Each MR closes its own unit issue (epic &107: U1 #2341, U2 #2342, U5 #2343, U7 #2344) and Relates to its parent; U3 closes #1804, U4 #1806, U6 #1821. The first code unit sets Status In progress; each MR is green alone with its CHANGELOG entry; each new test carries // @axis:. Whichever of U6 and U7 merges last closes out (Status Done, the archive row, plan-lint --done --allow-open 1073,1813,2345,2346,2347,2348).

U W Content and why it is one MR Pages

U0

1

The epic (&107); re-parent #1804, #1806, #1821; unit issues; follow-ups #2345–#2348; restated ACs on the issues; D1’s classes and the ⁂ readings on #1073. Docs only

this page (Active nav), ADR-081 (Proposed, the custody model)

U1

2

D1: spec, GA data, the drift pin, boot resolution. Data with no consumer is inert, so it ships alone

shared-crates.adoc, CHANGELOG

U2

8

D2 + D3: migration (both tables, the closure trigger, the retired reason), acts with stated intent, history rows, reads, field specs, events with ADR-003 rows and security arms (ADR-003’s same-MR rule)

data-model-cases.adoc, api/craig-cases.adoc, ADR-003, ADR-081 Accepted, CHANGELOG

U3

3

D4: the court-order act, its V3 intent and its sweep, a separate contested surface

data-model-cases.adoc, api/craig-cases.adoc, CHANGELOG (with the V3 retry ops note)

U4

3

D5, parallel to U3; the registry, seeder and lineage move with the column; the demographics guard; its events take ADR-003 rows and security arms here

data-model-cases.adoc, api/craig-cases.adoc, ADR-003, ADR-048 (:294), shared-crates.adoc, CHANGELOG

U5

3

D6 and the exchange arms the new kind forces (inert until U6’s rows)

ADR-075 amendment, shared-crates.adoc, api/craig-cases.adoc, CHANGELOG

U6

8

D7: the pin migration and floor bump, the per-child lock and ordering key, predecessor-unsettled and its release, the superseded-by-reentry skip, matrix, six legs, RemoveAndSend, ResendClose, the guard, the per-type wire validation, the ack store, knob, devstack partner row, capture, contested legs; the knob gates every leg

deployment-guide.adoc (:896-968), devstack.adoc, data-model-exchange.adoc, operations/coverage-matrix.adoc, CHANGELOG

U7

3

D8 and Playwright

guide/caseworker.adoc, CHANGELOG

Test matrix (each row red on main)

Test Axis U Asserts; why red on main

ga_legal_statuses_match_the_doe_wire

happy

U1

24 tokens equal `DoeSldsLegalStatus’s serde tokens; classes as D1’s table. Red: no spec

legal_status_token_parse_is_total (proptest)

evil

U1

any string never panics; accepted ⇔ a bundle token; token → wire → token. Red: no parser

a_malformed_vocabulary_refuses_boot

sad

U1

a duplicate or malformed token is a boot error. Red: no vocabulary

an_empty_vocabulary_refuses_custody_acts

sad

U2

TX stub: 422 legal-status-vocabulary-missing, nothing written. Red: 404

an_in_custody_status_opens_one_episode

happy

U2

201, episode with custody_from, case.custody_opened ids-only (strict decode). Red: 404

a_second_live_episode_for_a_child_is_a_409

evil

U2

overlapping open, same or another case: custody-episode-overlap. Red: no table

concurrent_opens_for_one_child_leave_one_episode

conc

U2

two racing or serialized opens: one 201, one 409; a racing change and close serialize, no 500. Red: no table

custody_rows_follow_the_episode_rules

sad

U2

close; a date correction keeps the id; flip 422; a named closed episode 409; rules (i)–(iii); a one-day episode; a change then a close on one day; an initial NCT and a NAF after NCO as history; a history row while open 409. Red: no acts

a_retired_episode_keeps_every_row_as_its_snapshot

evil

U2

an episode retract, and a last-row retract (rule ii): every live row, the triggering one too, retires episode_retracted. Red: no acts

episode_instants_equal_live_rows_at_commit

evil

U2

a direct instant UPDATE fails at commit. Red: no trigger

a_custody_retry_replays

replay

U2

same client_request_id returns the original; another intent 409 idempotency-conflict. Red: no act

custody_reads_and_writes_are_authorized

evil

U2

a worker outside the case’s unit: 403 on read and write; security records the episode. Red: 404

a_case_with_open_custody_cannot_close

conc

U2

close or transfer 409; racing open and close: one commits; a direct status UPDATE (an old replica’s write) refused by the trigger; closed case: open 409, correct passes. Red: closes

a_custody_order_writes_restates_and_retires_by_rule

sad

U3

per-child rows; a judge-name edit keeps them; restating corrects; delete (i)–(iii); two orders naming the same two children in opposite order do not deadlock. Red: no field

a_changed_custody_order_retry_is_an_intent_conflict

replay

U3

same client_request_id, other children, status or date: 409 idempotency-conflict; the same body replays. Red: custody unhashed

gtid_format_is_total (proptest)

evil

U4

any string never panics; accepted ⇔ ten ASCII digits ⁂; no trimming. Red: no parser

a_gtid_is_stored_encrypted_and_unique_per_person

evil

U4

CGEF + hmac; another’s live GTID 409 naming no one; verify-seed covers it. Red: no table

gtid_acts_are_catalogued_and_reveals_audited

evil

U4

end, retract emit _ended; a reveal stages its release first. Red: no act

a_gtid_needs_demographics_and_valid_dates

sad

U4

no DOB or a blank name 422; a holder’s name blanked 409, also racing the record (one fails); a future start or an end before the start 422; the DOB supplied, the record passes. Red: no act

identifier_authz_inherits_the_person

evil

U4

a caseworker records, ends and retracts but cannot reveal (403); read-only sees the masked list only; a supervisor reveals; a pure service caller 403 on every route. Red: no act

the_custody_projection_serves_exchange_only

evil

U5

other callers 403 first; a release per read; retracted and ended served; CPRS bytes same. Red: no arm

open_custody_stages_need_a_live_gtid

happy

U5

open-stages pages open episodes with a live GTID only. Red: no arm

a_retracted_episode_serves_its_snapshot

evil

U5

an order delete retires an episode’s only row (rule ii): the arm still serves it as retracted with its in-custody token. Red: no arm

doe_slds_settings_load_the_knob

happy

U6

CRAIG_EXCHANGETRIGGERSDOE_SLDS__ENABLED=true → enabled("doe_slds") == Some(true). Red: None

inc_is_sent_once_whichever_fact_lands_second

conc

U6

GTID then custody, custody then GTID, both racing: one INC at the capture. Red: no leg

a_dob_then_a_gtid_sends_one_inc

sad

U6

custody open, GTID refused without a DOB, DOB supplied, GTID recorded: exactly one INC. Red: no leg

no_inc_without_both_facts_consent_or_care

evil

U6

one fact only, a historical episode, a resolve after the close, a non-gtid kind: nothing; knob off: held. Red: no rows

an_inc_is_never_sent_after_its_end

conc

U6

INC staged, then a close, a GTID end or a GTID retraction, and a name change: no INC after the OUC or RMV. Red: no leg

an_earlier_removal_always_precedes_a_later_inc

conc

U6

A closes and B opens, events delivered in either order: OUC(A) sent before INC(B), B’s held resolve released by A’s staging; OUC(A) superseded behind a staged INC(B): INC(B) re-stages behind it. Red: no leg

nothing_for_an_older_stage_follows_a_newer_inc

evil

U6

after B is listed, A’s retraction and A’s close correction settle superseded-by-reentry, nothing sent; X’s end still removes A. Red: no leg

close_sends_ouc_and_reentry_sends_inc

sad

U6

OUC on the episode’s stage; a new episode: INC under a new stage_id. Red: no leg

ending_an_old_gtid_never_removes_a_newer_listing

evil

U6

A listed under X, B under Y, X’s end delayed past B’s INC: the RMV carries X and reaches only A’s recipient; B’s later OUC is sent. Red: no leg

gtid_end_or_retraction_sends_rmv

sad

U6

RMV with the pinned GTID at the capture, removed_at stamped, also when a new GTID follows the end; an order-delete retraction carries the in-custody token; no recipient: nothing. Red: no leg

a_corrected_close_resends_ouc

sad

U6

the latest stage’s exit date corrected twice, then its closing token: three OUCs, each current; an open episode’s start correction rides its OUC. Red: no leg

doe_acks_and_failures_settle_by_class

fault

U6

GTID or transaction_id mismatch ack-mismatch; ERR (the 10-digit sentinel) partner-rejected; 5xx, 4xx by class; no gtid stored. Red: no leg

the_doe_entry_validates_per_type_and_round_trips (proptest)

evil

U6

INC / OUC without a demographic invalid, RMV with only GTID and In-Care date valid; per D7, JSON round-trips; one job, one byte string. Red: no validator

cases-custody.spec.ts

happy

U7

open, close, history, GTID record, reveal and end, by test id. Red: no UI

Rollout and risks

  1. Cases first, additive. U1–U5 add tables, arms and the closure trigger, with no floor bump (ADR-063 D3). Before U6 is activated a cases image rollback stays possible: the trigger still refuses closing a case with open custody (a 500 on the old binary), and custody routes are 404s there.

  2. Activation prerequisites, in order (the CPRS pattern, deployment-guide.adoc:906-961): every cases replica on U5 or later; every exchange replica on U6 with none older remaining (U6’s floor bump stops an older replica from starting, not one already running, :917-920; a pre-U6 worker settles a DOE job naming a leg it lacks as terminal unresolvable-dispatch, ex/triggers/dispatch.rs:777-779, :107-111, :458-462); one active DOE-SLDS partner row with an admitting DSA; then the knob. Knob off: DOE receives nothing and each admission holds as knob-off until released; no partner or DSA: no-partner / dsa-*. An episode opened before admissions were recorded reaches DOE only through a catch-up walk. Before #1813 a production send has no partner credential path.

  3. Downgrade boundaries. Exchange cannot roll back below U6 once its migration runs (the floor, :909-916). Once the bind is active, a cases rollback below U5 answers every custody read with 404, which exchange settles terminal assembly-refused (ex/triggers/cases_reads.rs:295; record jobs are not walked back, ex/send_worker.rs:589-599). The knob off holds later admissions only: it is read at admission and release (ex/triggers/admission.rs:272-276). The brake for staged DOE jobs is to deactivate the DOE partner row or its DSA, after which record dispatch’s rebind settles each partner-changed (dispatch.rs:672-683). No pause exists (#2348). U2–U6 migrations are additive.

  4. Reclassification. A #1073 ruling that moves a code’s class changes new writes only (the class is stamped per row); correcting history is a worker act.

Review log

Round Vendor Resolved model Verdict

1

Anthropic, one fresh contextless reviewer (the page, the rules, the four questions)

Claude Opus 5.5

no-ship: 6 blockers (D1 classes, RMV, wire mapping, order sweep, case lifecycle, U4 catalogue and reveal) fixed; non-blocking items folded; a GTID stored from the DOE ack fixed

2

OpenAI (maintainer-run)

GPT Astra

no-ship: 13 findings (5 P1, 8 P2), all fixed (the pinned GTID, demographics before a GTID, the retraction snapshot, cross-episode order, mixed-binary rollout, corrected closes, history outside custody, identifier dates, stated intent, the order intent hash, identifier authz, per-type validation, same-day order); three research passes, a fold audit (7 / 6 / 0) and a gap hunt (3 P1, 3 P2, 4 P3) followed, each folded

Edit this page · latest