Data Model: Data Exchange & ICPC
Overview
The exchange service manages inter-agency data sharing (partners, agreements, transactions) and Interstate Compact on the Placement of Children (ICPC) requests with home studies and attachments.
Partners define external systems to exchange data with. Agreements establish the legal basis. Transactions record individual data exchange operations. ICPC requests follow a handler-enforced status workflow from draft to completion; home studies and attachments are child records that never advance the request.
The fleet-standard platform tables also live in this schema and are documented
centrally: event_outbox / event_inbox / event_inbox_collisions
(ADR-022 and the ADR-062 §A
attempt machine), request_claims
(ADR-062 §B),
schema_compat_floor (ADR-063), and since #3190 the
background-job ledger background_jobs + background_job_attempts
(ADR-068 § Amendment — #1571), on which a collection
run executes as the collection_run kind.
A claim’s actor is the ADR-085 D3 column pair (#2740): request_claims.created_by_sub holds a worker’s UUID
and created_by_sub_service a service’s service:<name> encoding, with a CHECK that exactly one is set.
Recorders name the acting worker (#2321). No craig-exchange recorder (a who-acted column or an event’s actor key)
names the request token’s own sub / preferred_username: under a BFF-lifted token that token is craig-web’s
service principal, so a staff write names claims.acting_worker() or the claim’s effective actor (ADR-028, ADR-062),
the lifted worker, or the token’s own subject when nothing is lifted. That covers icpc_requests.created_by /
created_by_name, exchange_transactions.initiated_by / initiated_by_name on a manual send (and
initiated_by on an operator’s collection run, whose initiated_by_name is collection:<interface>/<leg>; a
run the collection schedule started records initiated_by = system, as a triggered send does, #3190),
icpc_home_studies.assessed_by / assessed_by_name (the worker who submits the home study in CRAIG) and
exchange_trigger_catchup_runs.requested_by, plus the icpc.created, icpc.status_changed and
exchange.send_requested user_id. Each name column is the acting worker’s username. The screening writes
record craig-cases' body.requested_by (a body-named actor from the allowlisted producer), which since #2498 must
name the worker in the verified X-Craig-Actor craig-cases relays, and the run start’s request_claims row records
that worker, never service:craig-cases.
Since #2522 the Claims fields are private and crates/craig-test-lib/tests/acting_identity_census.rs pins it: the
token’s own identity is read only through a bearer() accessor, each such read under services/craig-exchange/src
is pinned with its reason, and a recorded worker is claims.worker_subject(), which reads the
claims.acting_worker() view, never the bare claims (#2740 removed parse_sub / parse_actor_sub).
Tables
| Table | Purpose |
|---|---|
|
#1466 B5 (ADR-065/066 §Amendment #1479) SSA screening run-lifecycle substrate: per-case cohort watermarks backing stale-run invalidation delivery |
|
External agencies/systems configured for data exchange. Soft-deleted rows stay
REGISTRY-VISIBLE (#1580, ruled 2026-08-29): the admin/supervisor default list + GET return
|
|
Legal agreements governing data exchange with a partner. |
|
Individual send/receive operations with payload and status tracking.
A DOE-SLDS trigger send stores the acknowledgement’s |
|
Async partner-send queue behind the 202-Accepted handler (platform-stab-2 §D5; #1185 lease + fencing).
#1835 adds |
|
#1828 (ADR-075): ONE row per outbound-trigger OCCURRENCE, under an identity
that deliberately excludes the partner — |
|
#1828 (ADR-075): the catalogued OUTBOUND table — one row per |
|
#1839 (ADR-075): one counter per |
|
#1835 (ADR-075 decision 15): one row per operator catch-up walk — the
interface and stage kind it covered, who asked for it, what it scanned and
created, and whether it completed. The walk itself is idempotent, so this
exists to answer the operator afterwards rather than to gate a re-run; a
row left |
|
Interstate placement requests with multi-step status workflow. Carries the
|
|
Structured home study evaluations for ICPC requests (one-to-one); carries
the same denorm triple via the |
|
Documents attached to ICPC requests — stored in object storage; carries
the same denorm triple via the |
|
ADR-062 §U upload-attempt tombstones (SU2 #1248): one immutable row per client
upload operation, id = the client-held request id; generation-fenced CAS
state machine + replay decision table live in |
|
SSA SOLQ screening runs (#1462, plan |
|
One row per screened household member: |
|
The typed job queue the |
|
E3 (#1566): the UD4 provenance handoff relation — one insert-only row per
member, written INSIDE the transport prune transaction, snapshotting the
facts only the pruned job/transaction rows held (correlation token,
partner, attempts, final status, categorical |
|
E3 (#1566): craig-exchange’s durable archive ledger (the craig-rules shape
verbatim; ADR-058 D8) — one row per archived-and-pruned provenance batch,
written inside the prune transaction; |
Names kept from the SOLQ interface (#3176)
The SSA screening was built against SSA’s SOLQ interface and now asks Gateway’s income inquiry
(the interface page). The partner that answers it has the kind
gateway_income, provided by the configuration layer’s crate craig-partner-gateway-income. Until #3176 the kind
was ssa_solq; a migration gives a stored partner row the new kind.
Three tokens that are stored in rows keep the old name. Renaming them would rewrite history in two databases and change nothing a deployment does:
| Token | Where it is stored | What it means now |
|---|---|---|
|
|
The transaction of one screening member’s question to the income inquiry. The retention sweep finds screening transactions by it. |
|
|
A benefit fact that an SSA screening’s answer asserted, whichever interface answered it. It is the only source the column admits. |
|
|
The value reserved for an SSN verification that a screening recorded. No current path writes it: a worker’s attestation stores the worker’s own text. |
ER Diagram
exchange_send_jobs
The send worker’s queue: one row per staged partner send or outbound-trigger
job, drained by ExchangeSendWorker (claim → dispatch → fenced finalize).
Statuses: pending / in_flight / sent / failed. Every column is
NOT NULL unless its Notes say when it is NULL.
| Column | Type | Notes |
|---|---|---|
|
UUID |
PK (uuidv7) |
|
UUID |
FK → |
|
UUID |
Target partner |
|
UUID |
UNIQUE: the partner-side idempotency token. A |
|
JSONB |
A |
|
TEXT |
CHECK |
|
UUID |
FK → |
|
UUID |
FK → |
|
TEXT |
The source version a |
|
TEXT |
FIFO key (#1828, ADR-075 decision 9) on |
|
BOOLEAN |
Default |
|
TEXT |
CHECK pending / in_flight / sent / failed |
|
INT |
Incremented on every claim (incl. lease reclaims). A local-read retry (#2244) refunds its claim’s increment, so on a trigger job |
|
TEXT |
Latest adapter/dispatch error. NULL until a retry or a terminal failure writes it; a |
|
UUID |
#2427: the job the release record arm re-staged this failed |
|
TIMESTAMPTZ |
Scheduled ELIGIBILITY (backoff target) — deliberately untouched at claim; never a claim clock — the partner ladder’s target, or for |
|
TIMESTAMPTZ |
#1185: the REAL claim clock. NULL (never claimed / legacy / crash residue) counts as an expired lease |
|
BIGINT |
#1185: fencing token — every claim increments it; every terminal/retry transition carries a |
|
TIMESTAMPTZ |
Stage / terminal stamps. |
Lease semantics (#1185): the claim query itself re-admits in_flight
rows whose claimed_at is NULL or older than the worker’s
CLAIM_LEASE_SECS (90s = 3× the 30s transport cap) — recovery is
continuous on the 1s poll; there is no recovery sweep. A crash after
the partner accepted but before finalize re-sends after lease expiry:
at-least-once by design (ADR-022 #1185 amendment), re-sending the
same token, on the carrier above, for the partner to dedup on.
Retry schedules (#2244). A retryable failure goes back to pending with
next_attempt_at set; the claim is released either way. Partner-facing
failures (transport, timeout, partner-unavailable, and every manual
send’s adapter error but an invalid payload, which settles terminal
payload-invalid on its first attempt: a wire-contract refusal, or since
#2397 a payload that does not decode into the partner’s typed outbound)
take the ladder,
BACKOFF_SCHEDULE_SECS indexed by attempts: 5 s, 30 s, 120 s, 300 s,
900 s, then retries-exhausted. A referral whose receipt could not be
handed to craig-cases (receipt-unapplied, #3193) takes the same ladder:
each retry sends the same record under the same correlation id and hands
the receipt over again; spent, it ends under its own class, not
retries-exhausted. One whose receipt craig-cases refused as a second
reference for the application ends at once under receipt-conflict. A trigger job whose cases read failed
(assembly-unavailable) first takes the local-read schedule: four retries
at 0.5–1 s, 1–2 s, 2–4 s, 4–8 s, the point in each range fixed by the low
ten bits of the job id, each refunding its claim; then the ladder at the
rung its ladder attempts have reached (the first, 5 s, for a job whose
failures were all local).
Claim lanes (#2071): the worker claims in two lanes, one statement each, so a
trigger backlog never queues ahead of a partner send. The send lane takes
kind = 'payload'; the trigger lane takes every other kind (resolve,
record). Each lane has its own dispatch budget per worker,
SEND_CONCURRENCY (8) and TRIGGER_CONCURRENCY (8), so trigger jobs, however
many or however slow, never hold a partner send’s capacity. Every pass
claims the send lane first, then the trigger lane, each up to its free budget.
A pass runs on the 1s poll, or sooner (#2076): when a lane’s last claim took
every free permit of its budget, so more due rows may be waiting, the next
pass starts as soon as one of that lane’s permits frees. A burst therefore
drains at the rate its dispatches finish instead of one budget per second. A
pass in which every lane’s claim came back short, or that failed, waits the
full second, so an idle worker polls no faster than before.
Both statements come from one template: the due-pending and expired-lease
arms, ORDER BY next_attempt_at, FOR UPDATE SKIP LOCKED and the
FIFO guard are identical. The guard still matches an earlier non-terminal job
with the same ordering_key of any kind. payload jobs carry no key, so the
guard never makes one lane wait on the other. The two lanes share the worker’s
DB pool (3 connections). Re-claiming does not raise the pool’s peak demand,
which is still at most SEND_CONCURRENCY + TRIGGER_CONCURRENCY dispatches
plus the loop’s one claim at a time. It only lengthens how long a burst keeps
the pool busy, so 3 stands (#2076).
Auth-class recovery (#2427, TP-2 D3). A record job that failed under an auth class (auth-unsupported,
auth-misconfigured, auth-unavailable, auth-refused) is not lost.
POST /v1/exchange/triggers/admissions/release with record_class locks the
interface’s failed record jobs whose last_error leading token is that class and whose restaged_as is NULL
(FOR UPDATE, blocking; at most 500 per pass, oldest first), re-runs the consent chain for each, and re-stages a
job the chain admits for its own partner as a supersession does: the same ordering_key, admission, recipient,
source_version and record_closure under a new transaction and correlation, with a fresh attempt budget. The
old row stays failed with its class and names the replacement in restaged_as. A re-staged row is never
selected again, so a repeated or concurrent release re-stages nothing. A job the chain refuses is left as it is
and counted refused. Any other class is a 422
release-record-class-unsupported (#2436 owns general record recovery). A refused job stays selectable and
every pass re-reads it, so past 500 refused jobs newer ones are named with ids. The replacement takes a new id,
so it queues behind any job of its key staged since the original failed (the FIFO is by id). Until it is
released, such a job is exempt from the send-job retention sweep.
Key Indexes
-
idx_exchange_partners_type— filter by partner type -
idx_exchange_partners_active— active partner lookup -
uq_exchange_partners_kind_caller— UNIQUE(adapter_kind, caller_partner_id)WHERE the caller is set and the row is active (#3193): the row a partner’s call resolves to -
idx_agreements_partner— agreements by partner -
idx_agreements_status— agreement status filtering -
idx_exchange_partners_created_at/idx_agreements_created_at— #3170(created_at): the partner list’s and the agreement list’s default sort (ORDER BY created_at DESC LIMIT n), read in index order so a page’s cost does not grow with the table -
idx_transactions_partner— transactions by partner -
idx_transactions_status— transaction status filtering -
idx_transactions_initiated_at— time-range queries -
idx_icpc_case— ICPC requests by case -
idx_icpc_child— ICPC requests by child -
idx_icpc_status— ICPC status filtering -
idx_icpc_direction— inbound vs outbound ICPC -
ssa_screening_runs_one_active_idx— UNIQUE (case_id) WHERE pending AND not invalidated: the one-ACTIVE-run-per-case safety net (#1462) -
ssa_screening_runs_case_idx— run history by case (D3 freshness checks) -
ssa_screening_members_person_idx/_ordinal_idx— UNIQUE per run -
ssa_screening_members_transaction_idx— UNIQUE fleet-wide (txn↔member 1:1) -
ssa_screening_jobs_member_idx/_correlation_idx— UNIQUE -
ssa_screening_jobs_drainable_idx/_lease_idx— the B4 worker’s claim
lease-recovery partials (theexchange_send_jobsshape) -
ssa_screening_runs_held_idx— partial on(id) WHERE legal_hold(#1566): the held-runs gauge + hold-shield predicates; held rows are rare by design -
ssa_transport_handoffs_completed_idx— the archive spec’s(ts, id)paging key (#1566; the family’s shared age clock) -
idx_archive_ledger_id_range—(first_record_id, last_record_id): the D17 archive-fetch batch resolution (#1566) -
idx_icpc_home_study_request— home study by ICPC request -
idx_icpc_attachments_request— attachments by ICPC request -
idx_exchange_send_jobs_drainable— partial on(next_attempt_at) WHERE status = 'pending'; the trigger lane’s due-pending arm -
idx_exchange_send_jobs_drainable_payload— partial on(next_attempt_at) WHERE status = 'pending' AND kind = 'payload'(#2071); the send lane’s due-pending arm, so the send-lane claim need not read the trigger backlog -
idx_exchange_send_jobs_lease— partial on(claimed_at) WHERE status = 'in_flight'(#1185); the claim query’s expired-lease arm (replaced the wrong-clockstuck_in_flightindex) -
idx_exchange_send_jobs_correlation— UNIQUE oncorrelation_id -
idx_exchange_send_jobs_ordering_key— partial on(ordering_key, id) WHERE ordering_key IS NOT NULL AND status IN ('pending', 'in_flight')(#1828, ADR-075 decision 9); the claim’s FIFO guard (no earlier non-terminal job with the same key, by id) and the DOE-SLDS older-stage check (older_stage_record_pending, #1821) -
idx_exchange_send_jobs_restaged_as— partial on(restaged_as) WHERE restaged_as IS NOT NULL(#2427); the self-FK lookup each retention delete runs -
idx_exchange_trigger_admissions_subject_held— partial on(interface, subject_person_id) WHERE status = 'held': the child-scoped release a DOE removal runs (#1821) -
idx_exchange_trigger_admissions_held_attempted— partial on(interface, last_attempted_at NULLS FIRST, created_at) WHERE status = 'held'(#2401): the release pass’s order