Plan: A placement’s end settles its per-diem to the days in care

Status

Done (2026-11-30) — a placement’s end settles its undisbursed per-diems to the days in care instead of voiding them: a row wholly in care is kept, a row that runs past the last paid day is shortened in place, and a row with no day in care is voided. The last paid day is the day before the end, or the end day where the jurisdiction’s perdiem_pays_end_day setting says so. The termination tombstone keeps the end instant, so an activation consumed after the end bills the same days, and either order of the two events leaves the same row.

Closes: #3189. Epic: &124. Relates to: #776 (the void this narrows), #1193 (the tombstone), #1179 (the lifetime key), #2030 and ADR-079 (later periods are paid outside CRAIG), #3199 (issued and cleared rows, out of scope). Tree: written against main at 6374ceff9; #3190’s two open merge requests land first.
Maintainer (2026-11-29, issue note 4350914123): shorten in place; the exit day is not paid by default, as a jurisdiction setting; a shortened approved row returns to pending; issued and cleared rows are #3199; an end with no end date still voids; the shortening acts on the ended placement’s own row only.
Maintainer (2026-11-30): an activation that arrives after the end bills the days in care too.

Context

placement.activated writes a placement’s one per-diem row: its start date through the end of that billing period (services/craig-financial/src/inbox/placement_billing.rs). placement.ended voids every undisbursed row of the placement, whatever days it covers (inbox/placement_termination.rs, store::payments::void_undisbursed_payments_for_placement), and reads no end date. A child placed on the 25th who goes home on the 27th therefore leaves no live payment: the caregiver is owed the days in care and the ledger holds nothing for them. A voided row cannot be replaced, because payments_one_perdiem_per_placement_period is a lifetime key with no status filter (docs/modules/ROOT/pages/data-model-financial.adoc).

The same loss happens by another road. When placement.ended is consumed before placement.activated, the termination tombstone refuses the late activation and no row is ever written. Under the old rule nothing was owed then; under the new one the days in care are.

Scope

In scope: the jurisdiction setting (D1); the last paid day and the settling rule (D2); the end handler (D3); the event (D4); the tombstone’s end date and the late activation (D5).

Out of scope: issued and cleared rows (#3199); any payment for a later billing period (#2030); recomputing rows an end voided before this release (pre-1.0: no backfill); a rule of one payee per child per day (respite and concurrent per diem pay two homes for one night); placement.retracted, which keeps voiding every undisbursed row.

Design

D1. The setting: is the end day paid

One key in a jurisdiction’s bundle/settings.toml: perdiem_pays_end_day, a boolean, absent meaning false.

  • crates/craig-state-bundle/src/bundle.rs: StateBundle::perdiem_pays_end_day(&self) → bool, default false.

  • crates/craig-config-bundle/src/schema.rs (SettingsFile, #[serde(default)]) and src/bundle.rs (Declarations, the trait impl).

  • craig-financial reads it once at boot: boot_subsidy_reference (services/craig-financial/src/subsidy/bundle.rs) copies it into SubsidyJurisdictionReference, which the inbox already holds as InboxMoney.reference, beside the rate-class policy billing reads from it.

No layer sets it in this plan: Georgia and Texas both run on the default. SettingsFile refuses an unknown key, so a configuration repository can write the key only once it pins a CRAIG version that carries it (Delivery).

D2. The last paid day, and what becomes of a row

Two pure functions in services/craig-financial/src/calc.rs.

last_paid_day(ended_on, pays_end_day): the end date itself when the setting is true, else the day before. The end date is PlacementEndedPayload.ended_at on the jurisdiction’s calendar (BusinessClock::for_jurisdiction(..).date_of(..)), as activation dates the start (perdiem_start_date).

settle_perdiem(row, last_paid_day) answers one of three things for an undisbursed row:

Where the last paid day falls The row

On or after the row’s period_end

Kept: every day of it was in care. Nothing is written.

From period_start to the day before period_end

Shortened: period_end is the last paid day, and day_count, gross_amount and net_amount are recomputed by inclusive_day_count, period_gross and net_amount (the functions the row was priced with).

Before period_start

Voided: no day of it was in care. Placed and ended on one day, with the end day unpaid, is this case.

A shortened row whose approved adjustments would take its net below zero is voided instead: payments_net_non_negative would refuse the row, and a refused row would send the event to the dead-letter queue.

D3. The end handler

handle_placement_ended (inbox/placement_termination.rs) keeps its order: the lifecycle lock, the tombstone, the child pay-exclusion locks. Then:

  • An end with a date. It reads the placement’s undisbursed per-diems FOR UPDATE, ordered by id (store::payments), settles each (D2), voids the voided set in one statement and shortens each shortened row. The row locks make a racing approval wait and then act on the settled row.

  • An end with no date (an envelope older than #1123), and a retraction: the set-based void of today, unchanged.

A shortened row is written pending with approved_by, approved_by_name and approved_at cleared, whatever it was: an approval was for the larger amount. This is the one writer of approved to pending. can_payment_transition (src/transitions.rs), which the approve, issue and clear routes use, still refuses that edge. The database guard trg_payments_disbursed_moves_forward binds only issued and cleared rows, which this handler never selects.

What it stages, in the same transaction: one financial.payments_voided (cause placement_ended) for the voided set, as today; one financial.payment_period_shortened per shortened row (D4); and the per-diem-change enqueue (enqueue_perdiem_change_for_child) for each voided row’s span and each shortened row’s former span, since the freed days re-open the subsidy question exactly as a void does. A redelivered end finds every row kept or already voided, writes nothing and stages nothing.

D4. The event

financial.payment_period_shortened, built in services/craig-financial/src/payment_events.rs beside payments_voided_envelope. Payload: \{ payment_id, placement_id, child_id, case_id, period_start, period_end, previous_period_end, day_count, previous_day_count, returned_to_pending, cause }, cause = placement_ended. Ids, dates and counts; no money, as the void events carry none. Audit header: the system’s update of the payment. The publisher gets a row in SYSTEM_OR_RECORDLESS and the ceiling rises by one (services/craig-security/src/audit_header_census_tests.rs). craig-reporting routes it past its payment-shape validator, as it does every financial type not listed in payment_shaped_financial_event.

D5. The tombstone keeps the end date, and a late activation bills the days in care

  • Migration services/craig-financial/migrations/20261201120000_termination_ended_at.sql: placement_terminations.ended_at TIMESTAMPTZ, nullable. Additive, no floor bump: a row an older binary writes has none, and reads as an end with no date.

  • store::placement_terminations::record_placement_terminated stores the end’s ended_at; a retraction stores none. A new read returns the tombstone (ended_at, retracted_at) in place of placement_is_terminated.

  • Activation (bill_placement_activation, persist_placement_payment). A tombstone that is retracted, has no ended_at, or whose last paid day is before the start bills nothing, as today. Otherwise the row is the start through the earlier of the period’s end and the last paid day. That cap is decided under the lifecycle lock, from the tombstone read there, so an end that commits between the early probe and the lock is seen; the rate lookup stays before the lock. The amounts are computed after the cap, so the replay compare in log_perdiem_absorbed still compares like with like.

Either order of the two events then leaves the same live row.

Steps

One merge request each, in this order.

  1. The plan page.

  2. The end settles the row (D1 to D4), with the two journeys and the scenario inventory.

  3. The late activation (D5). Its merge request closes #3189.

Erratum (2026-11-30): the scenario’s id (core.placement.end-voids-perdiem), its spec file and the oracle key placement_end_voids_live_perdiem keep their names. The coverage ledger is forward-only: an id leaves only through a human-authored tombstone and an oracle set never shrinks. Their titles and relations say what an end now does, and core.permanency.report-to-reunification gains that key instead of a new one.
Erratum (2026-11-30): the invariant subsidy_err_ended_placement_anchor read "every per-diem voided" as "the placement ended", a signal this plan removes. By the maintainer’s ruling (2026-11-30) it reads the termination tombstone instead, with the same reach: an active ERR whose anchor has a tombstone, a per-diem row, and none issued or cleared. an_ended_err_anchor_is_surfaced_while_no_perdiem_was_disbursed pins it.
Erratum (2026-11-30): subsidy exclusivity judges whole months, so a month in which the per-diem keeps a paid day has no subsidy row. Before, an end voided an undisbursed per-diem and re-opened that month; now the month stays closed, as it already did when the per-diem was disbursed before the end. Exclusivity itself is unchanged (maintainer informed, 2026-11-30).

Risks

  • A live row covers a day after the end, or loses a day in care — silent (wrong money). Mitigation: one pure rule (D2): settled_days_never_pass_the_last_paid_day, an_end_shortens_the_straddling_perdiem_to_the_last_paid_day, a_perdiem_wholly_in_care_survives_the_end_untouched.

  • An approval survives a changed amount — silent. Mitigation: D3’s reset: an_approved_perdiem_shortened_returns_to_pending_without_its_approval.

  • An approval races the end and lands on the old period — silent. Mitigation: D3’s row locks: an_approval_racing_the_end_leaves_no_approved_row_past_the_end.

  • The end is dated on the UTC calendar — silent (off by a day near midnight). Mitigation: the jurisdiction’s clock: the_end_is_dated_on_the_jurisdictions_calendar.

  • Another placement’s row of the same child is cut — silent. Mitigation: every statement is keyed by the ended placement: ending_one_placement_leaves_the_childs_other_placement_alone.

  • A shortened net below zero aborts the handler — fail-closed (the event dead-letters and nothing settles). Mitigation: void instead: a_clawback_larger_than_the_shortened_gross_voids_the_row.

  • A redelivered end acts twice — fail-closed: the second pass selects nothing to change: a_replayed_end_changes_nothing_and_stages_nothing.

  • The end outruns its activation and nothing is paid — silent. Mitigation: D5: an_end_consumed_before_its_activation_still_bills_the_days_in_care, an_end_racing_its_activation_settles_to_the_same_row.

  • An older craig-financial replica consumes the end during a roll — silent (it voids, as before, and writes a tombstone with no date). Mitigation: the changelog’s Ops note says to replace every replica before relying on the fix; nothing is corrupted.

  • A configuration layer writes the key before it pins a CRAIG that reads it — fail-closed (the layer is refused at boot). Mitigation: the delivery step tells both configuration agents when.

  • Issued and cleared rows still pay to the period’s end — silent, and not this plan’s: #3199. an_issued_perdiem_is_left_as_it_is pins that this plan does not touch them.

  • Rows an end voided before this release stay voided — silent. Pre-1.0: no backfill; the changelog says so.

  • The new row locks deadlock with another payment writer — fail-closed (the attempt aborts and is retried). Mitigation: the lock order of today (lifecycle, child, then rows by id).

Tests

  • Property (calc.rs): settled_days_never_pass_the_last_paid_day (proptest over a row’s start, length, rate and adjustments and a last paid day: no panic; a kept row ends on or before it; a shortened row starts on or before it, ends on it, is shorter than before, and its gross and net are the priced amounts; anything else is voided); the_last_paid_day_is_the_end_day_or_the_day_before.

  • Unit: a_row_is_kept_shortened_or_voided_by_where_the_last_paid_day_falls (the four boundary days); a_clawback_larger_than_the_shortened_gross_voids_the_row; the_end_is_dated_on_the_jurisdictions_calendar (a zone west of UTC); the_end_day_setting_defaults_to_unpaid_and_reads_true and a wrong-typed value refused (crates/craig-config-bundle/src/tests/); the existing payment_state_machine_matrix_is_exhaustive (services/craig-financial/tests/transitions_matrix.rs) stays at seven valid edges.

  • Contract (wire): the_shortened_event_carries_ids_dates_and_counts_and_no_money (the payload’s exact keys and its audit header); payment_shape_gate_polarity in services/craig-reporting/src/main.rs gains the new type among those routed past; the audit census row.

  • Scratch database (new services/craig-financial/src/inbox/placement_settlement_tests.rs, the handlers called on the test’s own transaction): an_end_shortens_the_straddling_perdiem_to_the_last_paid_day; the_end_day_is_paid_where_the_jurisdiction_says_so; a_perdiem_wholly_in_care_survives_the_end_untouched; a_perdiem_wholly_after_the_end_is_voided (and placed and ended on one day); an_approved_perdiem_shortened_returns_to_pending_without_its_approval; an_issued_perdiem_is_left_as_it_is; a_replayed_end_changes_nothing_and_stages_nothing; an_end_with_no_date_voids_every_undisbursed_perdiem; a_retraction_voids_a_perdiem_whatever_days_it_covers; ending_one_placement_leaves_the_childs_other_placement_alone. Step 3 adds an_end_consumed_before_its_activation_still_bills_the_days_in_care, a_late_activation_bills_nothing_for_a_dateless_end_a_retraction_or_no_paid_day and a_replayed_end_after_a_late_activation_changes_nothing.

  • Concurrency: an_approval_racing_the_end_leaves_no_approved_row_past_the_end (step 2); an_end_racing_its_activation_settles_to_the_same_row (step 3: the two handlers run together, repeatedly, and every run ends with the same one live row).

  • Devstack (services/craig-financial/tests/api/placement_ended_void.rs): an_end_with_its_date_shortens_the_perdiem_through_the_live_consumer; a_shortened_perdiem_enqueues_the_perdiem_change. Regression: that file’s three existing tests and ended_then_activated_creates_no_payment (tests/api/placement_activated_billing.rs) publish an end with no date and keep their names and assertions: they pin that such an end still voids and bills nothing.

  • Journeys: tests/e2e/specs/journey-placement-end-voids-perdiem.spec.ts is renamed journey-placement-end-settles-perdiem.spec.ts: placed yesterday and ended today, the row stays pending for one day, yesterday. tests/e2e/specs/journey-lifecycle-reunification.spec.ts: the row stays live through the earlier of its period’s end and the day before the child went home. The retract test in tests/e2e/specs/placement.spec.ts is unchanged.

  • Scenario inventory (compliance/scenario-inventory/placement.toml, permanency.toml, the lock re-blessed with cargo xtask scenarios audit --bless): scenario core.placement.end-voids-perdiem becomes core.placement.end-settles-perdiem, and its oracle placement_end_voids_live_perdiem becomes placement_end_settles_perdiem (the placement’s live per-diem covers its days in care in the period and no later day) in both scenarios that carry it; the binding’s file and describe follow the renamed spec. core.permanency.report-to-reunification gains that oracle beside no_perdiem_period_after_placement_end, its slice says the payment is shortened, and the reunification journey asserts it. Step 3 rewrites the relation of out_of_order_end_leaves_tombstone: the tombstone stays, and the late activation bills the days in care, or nothing for an end with no date. The scenario id’s two uses as sample data in crates/craig-test-lib (src/journey_sweep.rs, tests/journey_sweep_scoped.rs) follow the rename; plans/policy-journey.adoc is history and keeps the old name.

Delivery

  • Canonical page: docs/modules/ROOT/pages/data-model-financial.adoc (what an end does to a per-diem row; the tombstone’s ended_at).

  • Other docs, with the step that changes the surface: state-machines.adoc (its payment section gains the approved to pending edge the end handler takes, in the text and in the diagram); implementation-guide.adoc and adrs/adr-003-rabbitmq-topology.adoc (the event); multi-jurisdiction-extensibility.adoc (the setting).

  • CHANGELOG entry: changelog.d/3189.settle-at-end.fixed.adoc (step 2; Ops: replace every craig-financial replica; rows already voided are not recomputed; the setting and its default) and changelog.d/3189.late-activation.fixed.adoc (step 3; Ops: the additive migration).

  • Plan page: committed under docs/modules/ROOT/pages/plans/ with step 1, In progress at step 2, Done and archived at step 3 (this page, docs/modules/ROOT/pages/plans/archive/perdiem-settles-at-placement-end.adoc).

  • Configuration repositories: once step 2 is on main, a message to the Georgia and Texas configuration agents naming the key, its default and the ruling. Texas may write perdiem_pays_end_day = false with its citation (40 TAC §700.329(b)) once its layer pins that CRAIG version; Georgia stays on the default, its discharge-day question recorded as unsourced.

  • Close: step 3’s merge request closes #3189, with the merge SHA noted on it and on &124.

Review log

Round Vendor Resolved model Verdict

1

Anthropic

vertex-anthropic/claude-fable-5-2

CLEAN. One note taken: the scenario binding’s file follows the spec’s rename (now stated in Tests).

2

Google

vertex-gemini/gemini-4-carbon

CLEAN.

3

Human

the maintainer

Approved (2026-11-30).

Edit this page · latest