Plan: AFCARS Source History — the Class-3 Columns Read As Of (#2131)

Archive record

Merge requests: !1814 (U0 plan page + the ADR-078 / ADR-079 amendments + the unit and follow-up issues, Relates #2131) + !1815 (U1, Closes #2186) + !1816 (U2, Closes #2187) + !1817 (U3, Closes #2188) + !1818 (U4, Closes #2189); the close-out (U5, Closes #2190 and #2131)

2026-10-05 — approved in plan mode 2026-10-05 (rulings R-H1–R-H9 as recommended) after a contextless round 1 (no-ship, 2 blockers fixed, 17 findings folded), the maintainer’s round 2 (no-ship, 5 findings folded), a three-pass fold check and a closure check. What landed, column by column (P-D1 D3’s class 3): six columns reclassified with no code (D1: cases.admin_unit, placement started_at, placement_type, ffh_type_* and the setting, payments.status); the (b)(18) share as of as_of (U1, D3: PAID_CHILD_IDS_SQL subtracts the adjustments approved after as_of from the stored net, keeping the generated column’s rounding; no schema); write-once end stamps (U2, D4: placements.ended_recorded_at and caregiver_bindings.ended_recorded_at, stamped statement_timestamp() by the end and binding writers and now() by the born-ended insert, under four named CHECKs; the backfill takes activated_at / created_at; an end or cancel recorded after as_of reads open; a required floor bump); prior-value revisions (U3 and U4, D5: placement_fact_revisions, health_record_revisions and contact_revisions, insert-only under refuse_revision_mutation(), written in the UPDATE’s own statement through Postgres 18’s RETURNING old and stamped clock_timestamp() after the row lock; the export reads the earliest revision superseded after as_of, never COALESCE`d; the histories start with their migrations; voluntary floor bumps); the household fence (U4, D2: `case_household.added_at ⇐ as_of; the fixtures backdated and the seed’s added_at its case’s opened_at); persons current-state (D6, ⁂ on #1073: a correction, never a dated change). Reads at one as_of now agree on every former class-3 column but persons (and D3’s unbacked fixture row, which production never writes); a fresh generate still answers edits made after its predecessor’s as_of. One erratum: U2’s migration header says Plaintext but not SCHEME-FROZEN. Follow-up: #2185 (structurally refuse an issued payment’s void and an edit to an approved adjustment’s four D3 columns).

Status

Done (2026-10-05) — !1818

Anchor What binds here

#2131; AFCARS 2020 Program (#949)

every class-3 column gets an outcome: an as-of history the export reads, or a current-state ruling (⁂ on #1073); a replay test per history; the route texts and three data-model pages name exactly what stays current; the work is split into child issues before the first MR

P-D1 (#1965) D3 (:107-156), D7, § Rollout + risks

the three as-of classes; as_of lies at least EXTENDED_REQUEST_CEILING (5 min) in the past, so every transaction stamped at or before it has ended before page 1; class 3 reads current until this issue lands

P-D2 (#2125) D8

a replay (a re-export of stored records) never differs; a fresh generate mints a new as_of (craig-reporting/src/api/afcars.rs:102-105). After this plan, reads at one as_of agree on every former class-3 column but persons (and D3’s unbacked row, which production never writes); a fresh generate still answers edits made after its predecessor’s as_of and at or before its own, as it must

ADR-078 D1; ADR-079 D3 and § Amendment #2052 D1

identity facts are corrected in place (the persons ruling); activated_at is the DB instant of activation; the sixteen arrangement facts are a full-state PUT that stages no event and no audit. Both amended (R-H6)

ADR-041, ADR-051; ADR-063 D3

DOB is ciphertext (no revision column is encrypted); the compatibility floor (R-H9)

Context (census 2026-10-05, on main)

  • The class-3 text lives in the three route docs (craig-placement/src/api/afcars_export.rs:64, craig-cases/src/api/afcars_export.rs:69, craig-financial/src/api/afcars_facts.rs:48) and the data-model pages (data-model-placement.adoc:1138, :1397; data-model-cases.adoc:1317; data-model-financial.adoc:385).

  • Not edited in place. cases.admin_unit is insert-only (craig-cases/src/store/cases.rs:35-44); case_household has one writer, an INSERT with added_at DEFAULT now() (:330). No UPDATE placements site (craig-placement/src/store/placements.rs:374, :410, :464, :493) sets placement_type, ffh_type_* or the setting; started_at rides only the activating request (api/placements.rs:407-425). Every void writer filters status IN ('pending', 'approved') (craig-financial/src/store/ payments.rs:293-300, :338; subsidy/generator.rs:294), so an issued payment can only become cleared.

  • Write-once ends. placements.ended_at comes only from the ending transition (store/placements.rs:376; transitions.rs:115-140) and the born-ended insert (:214-250); caregiver_bindings.ended_on only from end_binding (store/caregivers.rs:442-458; a cancel is ended_on = effective_from). Neither records when the end was written.

  • Multi-edit sets. The sixteen arrangement facts are a full-state PUT (placements.rs:410-426); update_health_record rewrites visit_date / health_assessment behind an IS-DISTINCT gate (store/health.rs:218-244); update_contact rewrites the three visit columns under the version CAS (craig-cases/src/store/contacts.rs:178-188).

  • The export reads. Placement: kind 7’s key SQL (store/afcars_export.rs:95-100), ARRANGEMENTS_SQL (:123-136), CAREGIVER_SLOTS_SQL (store/afcars_export_facts.rs:37-45) and VISITS_SQL (:48). Cases: VISITS_SQL (store/afcars_ledgers.rs:287-292) and the unfenced child_memberships (store/afcars_export.rs:26-42). Financial: PAID_CHILD_IDS_SQL tests ffp_amount > 0 (store/afcars_facts.rs:29-38).

  • net_amount is derivable. The approval transaction recomputes net_amount = gross + Σ approved (api/adjustments_resolution.rs: 300-343); approval is terminal and stamps approved_at (transitions.rs:39-49, store/adjustments.rs:94-99); ffp_amount is generated (migrations/20260703130000_financial_domain_constraints.sql:29-34) from inputs frozen before issue (payments.rs:406-416); idx_payment_adjustments_payment_approved exists (migrations/20260726050000_hot_path_indexes.sql:6-7).

  • No house revision table. The ledgers' refuse_event_row_mutation admits an UPDATE as a RETIRE, which never fits here. The fully append-only shape is refuse_end_reason_rewrite_mutation (craig-placement/migrations/20260926120000_end_reason_narrowing.sql:66-76) plus #2174’s truncate trigger (craig-reporting/migrations/20261004130000_afcars_retained_policy_immutable.sql:21-30). Postgres 18 (devstack/postgres/Dockerfile:1; implementation-guide.adoc:132) has UPDATE … RETURNING old.<col>.

Scope

In: D1–D6; the class-3 text of the three routes, their module docs and the three data-model pages; the ADR-078 and ADR-079 amendments; CHANGELOG entries; the seed and the test fixtures that a new CHECK (U2) or the fence (U4) touches.

Out: a persons history (R-H4); prior values for edits made before a migration (none exist); reporting (no wire shape changes); a structural refusal of issued | cleared → voided and of edits to an approved adjustment’s payment_id, amount, status or approved_at (its admin_unit and assignment stay writable, craig-financial/src/inbox/case_assignment.rs:391-476; U0 files one follow-up issue).

Design

D1 — Reclassified, no code (R-H1)

cases.admin_unit (fixed at insert), placement started_at (fixed at activation, so the class-2 fence covers it), placement_type, ffh_type_* and the setting (foster_family_home, foster_home_id, kinship_household_id, fixed at insert), and payments.status. Status needs care: given issued_at ⇐ as_of, the row was issued at as_of and can now only be issued or cleared, and the predicate counts both. Each service’s MR moves its columns out of the class-3 sentence, with the reason in one clause. After U4 the cases route’s class 3 is persons alone (D6), and the placement and financial routes have none.

D2 — The case_household fence (R-H7)

child_memberships gains an as_of parameter (read_keys passes window.as_of, api/afcars_export_page.rs:81) and AND h.added_at ⇐ $4. It becomes class 2: a membership added after as_of gives that key’s not_found row, so reads at one as_of agree. No schema. The cases-export fixtures are wrong under the fence: they add memberships at now(), after every random_as_of() (tests/api/afcars_export_seed.rs:111-115). Fx::member, and so child_case, writes added_at = now() - interval '2 hours' (:336-353); dev_case_with_child (:80-107) backdates its membership the same way by SQL after the API add; the commit message says why. The seed renders case_household.added_at as its case’s opened_at, not load time (which hides seeded memberships from a generate for 5 min), and the cases hashes in tools/craig-seed/tests/sql_byte_identity.rs are re-blessed.

D3 — The (b)(18) share as of as_of (R-H8)

PAID_CHILD_IDS_SQL replaces p.ffp_amount > 0 with the share as it stood at as_of. It subtracts the approvals recorded after as_of from the stored net and keeps the generated column’s rounding:

CASE WHEN p.ive_eligible THEN round((p.net_amount - COALESCE((SELECT sum(a.amount) FROM payment_adjustments a
  WHERE a.payment_id = p.id AND a.status = 'approved' AND a.approved_at > $3), 0)) * p.ffp_rate, 2) ELSE 0 END > 0

With no approval after as_of, this equals ffp_amount, so older periods do not move. It assumes two things: each approval moved net_amount by its own amount in its own transaction, and an approved row’s payment_id, amount, status and approved_at never change (its admin_unit and assignment do, which D3 never reads). It does not assume adjustments = Σ approved, so a row whose adjustments has no rows behind it (the zero_net fixture) reads right unless it is also adjusted after as_of, when the recompute drops the unbacked part. Production writes no such row (create_payment leaves adjustments at 0). approved_at is the handler’s clock, as issued_at is (P-D1 accepted that stamp). The existing index serves the subquery. No schema.

D4 — Write-once record stamps (R-H5)

  • Columns. placements.ended_recorded_at and caregiver_bindings.ended_recorded_at, both TIMESTAMPTZ, hold the DB instant of the statement that wrote the end. Neither reaches a response body (no wire change).

  • CHECKs, named to sort after the names tests pin on rows that also break a pairing, since Postgres tests CHECKs in name order (caregiver_bindings_interval, tests/api/caregivers.rs:831; placements_ended_has_ended_at, tests/api/placements.rs:914). Pairing, (<end> IS NULL) = (ended_recorded_at IS NULL): placements_ended_recorded_pairing, caregiver_bindings_recorded_pairing; placements_ended_recorded_after_activation (>= activated_at) and caregiver_bindings_recorded_after_creation (>= created_at).

  • Writers. update_placement adds ended_recorded_at = COALESCE(ended_recorded_at, CASE WHEN $3 IS NOT NULL THEN statement_timestamp() END) and end_binding stamps statement_timestamp(): not now() (as store/removal_episodes.rs:722), since an end begun before a racing activation would stamp before activated_at and fail the bound, while its UPDATE runs after the locked read. insert_historical_placement stamps now(), its own activated_at (no race; no torn read inside the insert). A stamp at or before as_of still means a transaction begun by then (P-D1).

  • Backfill (same migration, before the CHECKs). Every placement with ended_at IS NOT NULL (ended, or retracted from ended, api/arrangement_acts/status_acts.rs:299-304) takes activated_at, and every binding with ended_on IS NOT NULL (an end or a cancel) created_at: the proven lower bound, since an end is never recorded before the activation or creation (a later request, or the born-ended insert itself; placements_activated_pairing, 20260925170000_retracted_arrangements.sql:38). A legacy end therefore reads as known from activation, which is today’s answer, so no past period moves. ended_at is not a bound, because nothing refuses a future-dated end. The UPDATE touches only the new column, so the occupancy trigger’s WHEN guard and ck_arrangement_in_episode stay silent.

  • Fixtures. "Head schema" means a database built by the full MIGRATOR (scratch() or the devstack). There a raw test write of an end stamps what the statement gives activated_at (an UPDATE’s COALESCE(activated_at, now()), as constraints/occupancy_recompute_race.rs:139), else the row’s activated_at / created_at, or now() when created_at defaults, as CASE WHEN <end> IS NULL THEN NULL ELSE … END, where <end> is the value the statement writes (its bind, literal or expression), never the column, as update_placement tests $3. Only a leg testing a late stamp differs. So replay legs keep their ends and evil legs their pinned names. A pool from chain_db(v) (constraints/removal_episodes_migration.rs:285) with v at or below this migration’s version keeps its shape (a chain above it stamps as the head does): legacy_arrangement callers (end_reason_narrowing_migration.rs:193), the raw INSERT at removal_episodes_migration.rs:410, and kinship_households_migration.rs’s bindings (:145-160`, ended at :394, on a post-#2056 chain that also uses the head builders). ended_by() (removal_episodes_ddl.rs:319) splits: ended() stamps, legacy_ended() does not. The backfill leg writes its ends unstamped with arrangement() and explicit columns.

  • Read. CASE WHEN ended_recorded_at ⇐ $as_of THEN ended_at END in ARRANGEMENTS_SQL (which gains an as_of bind), and the same for b.ended_on in both of CAREGIVER_SLOTS_SQL’s predicates. An end or cancel recorded after `as_of reads open.

D5 — Prior-value revisions for the multi-edit sets (R-H2, R-H3)

  • Tables. Three tables, each narrow (the export columns only; the parent’s types and nullability, so visit_date, health_assessment and occurred_at are NOT NULL and the rest nullable; no copied domain CHECKs), plaintext-only and insert-only:

    • placement_fact_revisions: placement_id and the sixteen facts;

    • health_record_revisions: health_record_id, visit_date, health_assessment;

    • contact_revisions: contact_id, the superseded version (UNIQUE (contact_id, version)), occurred_at, visited_child_id (REFERENCES persons(id) ON DELETE RESTRICT, as on contacts), location.

  • Columns and keys. Each has id UUID PRIMARY KEY DEFAULT uuidv7(), superseded_at TIMESTAMPTZ NOT NULL (no default), the parent FK ON DELETE RESTRICT and an index on (<parent>_id, superseded_at, id). A row holds the values that stood until superseded_at.

  • The instant is read after the row lock. The writer inserts superseded_at = clock_timestamp(), never now(). now() is the transaction’s start; the placement and health handlers lock inside the transaction (craig-placement/src/api/health.rs:324-334, api/placements.rs:1606-1660) and a contact’s UPDATE takes its own lock, so two edits whose transactions began in the opposite order to their locks would sort backwards. An earlier as_of would then answer the second prior value. The INSERT consumes the UPDATE’s output, so its clock is read after the lock is held: a later edit waited for the earlier one’s commit and always sorts after it. superseded_at ⇐ as_of still means committed before page 1 (P-D1).

  • Guard. One function per service, refuse_revision_mutation(), raises integrity_constraint_violation naming the table and TG_OP, attached BEFORE UPDATE OR DELETE … FOR EACH ROW and BEFORE TRUNCATE … FOR EACH STATEMENT. The guard makes each table SCHEME-FROZEN, so no column may join resolve::ALLOWLIST. Revision columns are not element-map sources (no FieldSpec). No REVOKE: the guard refuses every role; the house revokes only where the serving role never writes (end_reason_narrowing.sql:78-84).

  • Writer: the same statement as the UPDATE. Each store writer (update_arrangement_facts, update_health_record, update_contact) moves its UPDATE into a CTE. The CTE’s RETURNING adds the prior export columns through Postgres 18’s old alias. A second CTE inserts the revision from that output WHERE (old cols) IS DISTINCT FROM (new cols), and the outer SELECT returns the row, which sqlx maps by name. A revision exists exactly when the UPDATE landed and changed an export column: a CAS or IS-DISTINCT miss, a notes-only health edit and a narrative-only contact edit write none; no trigger writes data (the house’s triggers are guards). First use of RETURNING old: read the PG 18 docs first.

  • As-of read, one shape for all three. Never COALESCE a value: a prior NULL (an unanswered fact, a cleared visit) is an answer:

    LEFT JOIN LATERAL (SELECT r.id, r.<cols> FROM <t>_revisions r
      WHERE r.<parent>_id = x.id AND r.superseded_at > $as_of ORDER BY r.superseded_at, r.id LIMIT 1) r ON true
    -- each column: CASE WHEN r.id IS NULL THEN x.<col> ELSE r.<col> END
  • Where it applies.

    • Placement: ARRANGEMENTS_SQL’s facts, kind 7’s key predicate, and `VISITS_SQL, which gains an as_of bind.

    • Cases: VISITS_SQL resolves the as-of trio for each contact of the key’s case, then filters on the as-of visited_child_id and occurred_at < to, so a re-pointed visit answers under its as-of child.

  • No backfill. A row with no revision has stood unchanged since the migration. An edit made before the migration kept no prior value, so each route’s text says its history starts with this release.

D6 — persons stays current-state (R-H4, ⁂ on #1073)

  • Corrections. UPDATE_PERSON_SQL rewrites sex, the encrypted DOB, birth_year, dob_estimated_abandoned and year_of_birth_declared (craig-cases/src/store/persons.rs:212-221). ADR-078 D1 calls such a write "a correction of an identity, never a dated change", so no prior value is worth keeping; parents' birth_year is the same.

  • Cost and effect. Demographics that change are class-1 ledgers already (person_demographic_facts); a history would copy DOB ciphertext into the crypto registry, the scheme rewrite and key rotation (an ADR-041/051 amendment). A replay never differs (P-D2 D8) and a fresh generate reads at a new as_of, so it carries a correction either way. Current-state means only that a correction landing mid-walk answers on the pages read after it: persons is the one table where reads at one as_of can disagree (beside D3’s unbacked row, which production never writes).

Units

Each MR Relates to #2131, #1965 and #949 and closes its own unit issue; U5 closes #2131.

MR Scope W

U0

this page (Active nav); the unit issues under &99 (Plan::AFCARS, a type and a priority label, these weights); the per-column outcomes (R-H1) on #2131; ⁂ R-H4 on #1073; the follow-up issue (Out); the ADR-078 and ADR-079 amendments, Proposed, in the == Amendment (date, #2131) shape (adr-079…:382); the round-2 vendor and model in the review log

1

U1

FINANCIAL: D1 (status), D3; the edited test legs, the financial Window gaining late; route text, module doc, the craig-financial-contracts/src/afcars.rs schema docs, data-model-financial; Changed

2

U2

PLACEMENT STAMPS: D4’s migration (lock, backfill, CHECKs, floor bump LAST), the three writers, the two reads; D4’s head-schema fixtures (not the chain_db files): every end in rg -n -e ended_at -e ended_on services/craig-placement/tests or rg -n -e 'INSERT INTO placements\b' -e 'INSERT INTO caregiver_bindings\b' -e 'ended_at *=' -e 'ended_on *=' services/craig-placement/src (pipe-free, so the table escaping cannot change them); the test module doc tests/api/afcars_export.rs:7 narrowed for the ends; the raw UPDATEs at constraints/occupancy_recompute_race.rs:139, api/caregiver_concurrent.rs:752 and constraints/removal_episodes_ddl.rs:1790 (the End act; wrote_a_row swallows its refusal); the seed (tools/craig-seed: model, datagen, sql_row_impls.rs:867-870; ended placements stamp activated_at; the placement hashes in sql_byte_identity.rs, base and variants, re-blessed with the house comment); route text, module docs, the ends' schema docs in craig-placement-contracts/src/afcars_export.rs, data-model-placement

3

U3

PLACEMENT REVISIONS: D5’s two tables, guard and floor bump; the two writers and the three reads; D1’s placement columns; the route text, module docs (with the test module doc, tests/api/afcars_export.rs:7), the rest of those schema docs, data-model-placement

5

U4

CASES: contact_revisions (D5), the fence with its fixtures and seed (D2), admin_unit (D1) and the persons sentence (D6); route text, module docs, the craig-cases-contracts/src/afcars_export.rs schema docs, data-model-cases

3

U5

CLOSE-OUT: the amendments Accepted; Status Done (YYYY-MM-DD) — !N and the page moved to plans/archive/, its nav entry to Archive; plan-lint --done; the archive row; a #1965 note (reads at one as_of agree on every former class-3 column but persons and D3’s unbacked row; a fresh generate still answers edits made after its predecessor’s as_of)

1

  • Migrations. Each file sorts after its service’s latest (20260930140000 placement, 20260930150000 cases). Its header takes the class (ADDITIVE) and "Plaintext … SCHEME-FROZEN" from placement’s 20260930140000_child_facts.sql:30-50, the floor and rollback sentences from 20260925170000_retracted_arrangements.sql:17-22 (with R-H9’s reason). Then SET LOCAL statement_timeout and lock_timeout; U2 adds LOCK TABLE placements, caregiver_bindings IN ACCESS EXCLUSIVE MODE (explicit hold and lock order, as …_placement_setting_vocabulary.sql:33-36). Last, UPDATE schema_compat_floor SET min_required_version = <own timestamp>;. Erratum (2026-10-05): U2’s migration header says Plaintext but not SCHEME-FROZEN: its stamp columns sit on placements and caregiver_bindings, which carry no row guard (#2187).

  • Order and weight. Weight 15. U0 first; then U1, U2 → U3 (placement’s migration order) and U4 in any order, since no unit reads another’s change. Each MR is green alone with its CHANGELOG entry (Changed: the answers move; Added: the schema, with the deploy note); every new test carries // @axis:.

  • Test placement. Devstack legs live in each service’s tests/api/afcars_*.rs and migration legs in tests/constraints/. The race legs call crate-private writers, so they are scratch-DB #[path] siblings under src/store/: craig-placement’s placements_tests.rs (U2’s end race, U3’s facts race) and health_tests.rs (U3’s health race), and craig-cases' contacts_tests.rs (U4’s). No test fn added to a src/**/*tests.rs file may contain _and: the fn-name-and lint walks those files (xtask/src/cmd/lints.rs:2445-2460). Replay legs follow rows_recorded_retired_or_closed_after_as_of_read_as_at_as_of (craig-placement/tests/api/afcars_export.rs:461): a Window with as_of = now − 1 h, recorded = now − 2 h, late = now − 30 min (afcars_export_seed.rs:19-70); financial’s Window gains late = now − 30 min (U1); cases stamps with Window::after(). An API edit made now is after as_of. Legs seed random far-past windows, leave residue and never delete an edited row (the RESTRICT FK and guard refuse it).

Test matrix (by risk)

Test Axis Unit Asserts

a_recovery_approved_after_as_of_leaves_the_child_counted

replay

U1

an adjustment row approved at late (SQL, net recomputed): the child answers at as_of; at an as_of after late, it is absent

only_an_issued_federally_claimed_per_diem_in_the_window_counts (edited)

sad

U1

its API recovery leg (craig-financial/tests/api/afcars_facts.rs:355-356, approved after as_of) asserted the current read; it moves to the leg above, whose later as_of shows an earlier approval removes the child; the partial leg’s −40 is seeded by SQL before as_of (net recomputed) so it still reads 60; zero_net (unbacked adjustments) stays absent; the commit says why

a_walk_racing_recovery_approvals_answers_the_as_of_cohort

conc

U1

full API recoveries mid-walk: every page equals the baseline

an_end_recorded_after_as_of_reads_open

replay

U2

stamped late: ended_at null at as_of; at as_of = late (the inclusive ⇐) and after it, the end answers

a_binding_ended_or_cancelled_after_as_of_still_fills_its_slot

replay

U2

both stamped at late fill the slots at as_of

the_ending_transition_stamps_its_record_instant

happy

U2

an API placement end, an API binding end and an API cancel each stamp a DB instant between clock_timestamp() reads around the request, at or after activated_at / created_at; a born-ended historical record stamps its activated_at; an open row stays null

an_end_begun_before_its_activation_is_admitted

conc

U2

transaction A begins; B activates the row and commits; A locks it and calls update_placement to end it: admitted, ended_recorded_at >= activated_at

an_end_without_its_stamp_is_refused

evil

U2

the four named CHECKs each refuse a raw write, by name

the_stamp_backfill_takes_the_proven_lower_bound

happy

U2

ended and retracted-from-ended rows take activated_at, ended and cancelled bindings created_at; open rows stay null

arrangement_facts_edited_after_as_of_read_as_at_as_of

replay

U3

a facts PUT through the API after as_of clears an answered fact and answers a NULL one: the row answers the pre-edit facts, NULLs included

two_edits_after_as_of_answer_the_earliest_prior_value

replay

U3

two PUTs: the first revision answers

fact_revisions_sort_by_edit_order_not_transaction_start

conc

U3

placements_tests.rs: A begins and reads now(); B edits a fact X→Y and commits; A takes get_placement_for_update and calls update_arrangement_facts for Y→Z. Revisions sort X, Y; an as_of before both answers X (now() stamps answer Y); at the first revision’s superseded_at, Y (the strict >); after, Z

health_revisions_sort_by_edit_order_not_transaction_start

conc

U3

health_tests.rs: the same race and the same three boundary reads on a health record’s visit_date, through get_health_for_update and update_health_record

a_health_record_edited_after_as_of_keeps_its_visit

replay

U3

visit_date moved past to and the flag cleared after as_of: key and visit answer the as-of values; a record flagged only after as_of is absent

an_unchanged_write_records_no_revision

happy

U3

an identical facts PUT, health’s IS-DISTINCT miss and a notes-only health edit insert nothing

revision_rows_refuse_every_mutation

evil

U3

UPDATE, DELETE and TRUNCATE refused on both tables, owner role included

a_walk_racing_fact_edits_answers_the_as_of_facts

conc

U3

PUTs during a walk: every page answers the pre-edit facts

contacts_edited_after_as_of_read_as_at_as_of

replay

U4

A and B are active child members of one case; after as_of: a visit moved past to, one re-pointed from A to B, and A set on a contact with none. A answers exactly the first two at their as-of values; B answers its person rows and no visit

a_membership_added_after_as_of_answers_not_found

replay

U4

added_at after as_of gives not_found; before gives the rows

a_narrative_only_edit_records_no_revision

happy

U4

version bumps, no revision row, the export unchanged

contact_revision_rows_refuse_every_mutation

evil

U4

UPDATE, DELETE, TRUNCATE and a duplicate (contact_id, version) refused

contact_revisions_sort_by_edit_order

conc

U4

the same opposite-start race on a contact: the revisions sort by version and superseded_at alike; the same three boundary reads answer the original trio, the second trio and the live one

a_walk_racing_contact_edits_answers_the_as_of_visits

conc

U4

contact PUTs during a walk: every page equals the baseline

Verification

  • Per MR: fmt, clippy, the budgets, validate-migration-constraints (U2–U4), api-docs --check (each route text change), coverage-matrix-mapping --check, check-docs, plan-lint; the constraint legs locally; then the battery (bare git push).

  • Close-out: cargo xtask plan-lint --done docs/modules/ROOT/pages/plans/archive/afcars-source-history.adoc --allow-open 949,1073,1965,2131, plus U5’s own unit issue and the follow-up issue U0 files.

Rollout and risks

  • Rollout. U1 has no migration. U2–U4 each bump the floor LAST and replace every replica of that service before traffic (R-H9); rollback is N-1 images and a database restore; the CHANGELOG ops note names each migration as the start of its history.

  • Risks. An as_of before a migration can still read an earlier edit’s value (the route text says so). Legacy ends read as known from activation (D4). An approved adjustment’s four D3 columns and the void writers' status sets rest on the writers (the follow-up issue). A request spanning as_of can read partly applied for at most its own duration (activation is now(), a revision clock_timestamp()); reads at one as_of still agree, since the request ended before page 1 (P-D1).

# Recommendation Alternative

R-H1

Treatments per D1–D6: six reclassified, one fence, one derivation, two stamps, three revision sets, persons current

a revision table for every column D3 lists

R-H2

Arrangement facts keep prior-value revisions

a P-B1-style response ledger (supersedes_id, recorded / retired, one live per placement, a deferred CHECK holding the columns equal to it, ADR-079 D2’s shape; ≈ +5)

R-H3

A CTE in the store writer (RETURNING old), stamped clock_timestamp() after the row lock

an AFTER UPDATE OF trigger (covers raw and N-1 writes; a data-writing trigger in a house of guards)

R-H4

persons current-state, ⁂ on #1073

a persons revision table holding DOB ciphertext (registry, ALLOWLIST; ≈ +5–8)

R-H5

Backfill stamps at the proven lower bound (activated_at, created_at), keeping every past answer

ended_at (not a bound); bindings' exact updated_at (past answers move); NULL read as unknown

R-H6

Amend ADR-079 (facts, health, stamps) and ADR-078 (contacts; D1 reaffirmed for persons)

a new cross-service ADR

R-H7

Fence case_household on added_at

rule it current-state

R-H8

Subtract the approvals after as_of from the stored net

rebuild from gross plus approvals at or before as_of (wrong for a row whose adjustments has no rows behind it)

R-H9

A floor bump on each schema MR: U2’s required (an N-1 end breaks the pairing CHECK); U3’s and U4’s voluntary under ADR-063 D3 and taken (20260930150000_tribe_order_of_preference.sql:19-24), since an N-1 edit leaves no revision. Replacing every replica before traffic closes what the floor cannot

no bump on U3 / U4 (N-1 edits unrevised)

Review log

Round Vendor Resolved model Verdict

1

Anthropic — one fresh contextless reviewer (the page, the rules, the four questions; 56 citations checked)

Claude Opus 5.5

no-ship — 2 blockers fixed (the household fence’s fixtures backdated; the stamp fixture sweep widened and the CHECKs named); 17 of 17 findings folded

2

OpenAI — maintainer-run (2026-10-05)

GPT Astra

no-ship — 5 findings folded: revisions stamped clock_timestamp() after the row lock, with opposite-start race tests; legacy-chain fixtures keep their shape; the guarantee scoped to one as_of; the end replay’s second read at late; the follow-up’s immutability limited to four columns. Fold check (three contextless Anthropic passes, Claude Opus 5.5) and a two-pass closure check: no blockers; every gap fixed

Edit this page · latest