Plan: End a case household membership

Status

Done (2026-11-26) — a worker ends a case household membership with the day it ended, through a craig-cases act authorized as the add is and a control on the case page’s Household tab; a closed or transferred case refuses it with the 409 case-closed. case_household carries ended_on, tied to active by a CHECK. A Playwright leg ends a child’s membership and records a late entry for that child, and the four test helpers that ended a membership with SQL call the route. Correcting or undoing an end is not built and not filed.

Closes: #2460, on the last step.
Tree: written against main at 529c6c928.
Rulings (maintainer, 2026-11-24/25): this issue is next; whoever may add a member may end one (Update on the case); a closed or transferred case refuses the act, as it refuses every other new case fact.

Context

A case household row (case_household) has an active flag and no way to clear it. The household route is GET and POST only (services/craig-cases/src/api/mod.rs), no craig-cases code writes active = false, and the table has no column for when a membership ended. Tests reach the ended state only with direct SQL (the files are listed in D4), and Playwright has no database path, so the web cannot reach the state at all.

The state matters: a child-fact ledger admits a late entry for an ended child membership (store::cases::child_membership_exists has no active filter), the case page lists ended rows (include_inactive, #2002), and the Federal facts card shows a "Membership ended" badge for them.

What already exists and is reused unchanged:

  • the add handler’s shape (api/cases/lifecycle.rs::add_household_member): read the case, Action::Update on it, an ADR-062 claim, the closed-case gate inside the claimed transaction, an act event, the cohort bump;

  • store::cases::require_case_open (the typed 409 case-closed);

  • craig_ledger::refusal::require_on_or_before_today (the typed 400 ledger-date-after-today);

  • the partial unique index case_household_one_active_membership (WHERE active), which is why re-adding an ended person already works.

Scope

In:

  1. A column for the end date, and the act that sets it.

  2. The craig-web act on the Household tab.

  3. One Playwright leg: end a child’s membership in the web, then record a late entry for that child.

  4. Every test that writes an inactive row with SQL keeps passing under the new CHECK, in the same MR as the CHECK; the helpers that end a membership then move onto the route.

Out:

  • Correcting or undoing an end. A wrong end is fixed today by re-adding the person (a new row). A correction act for closed cases would follow the ledgers' rule (corrections are admitted on a closed case); nothing asks for it.

  • A reason for the end, and who-ended-it columns on the row. The act event carries the actor.

  • Any ruleset change: the act is authorized as the add is.

Design

D1. The column

One migration, services/craig-cases/migrations/<stamp>_case_household_ended_on.sql:

ALTER TABLE case_household
    ADD COLUMN ended_on DATE,
    ADD CONSTRAINT case_household_ended_iff_inactive
        CHECK (active = (ended_on IS NULL));

ended_on is a business date, not an instant: the worker states the day the person left, which may be before the day it is recorded.

Existing rows. The CHECK holds for every row the product can have written, since nothing sets active = false. A database that does hold an inactive row (set by hand) would fail the ADD CONSTRAINT. The migration therefore counts such rows first and raises naming the count, the form 20261010120000_case_household_one_active_membership uses, and chooses no date for them.

Schema floor. A released binary only ever inserts a row with active defaulted true and no ended_on, which satisfies the CHECK, and it decodes rows with SELECT * into a struct with no ended_on field. Whether sqlx’s FromRow tolerates the extra column for the N−1 binary, and whether the floor lint (cargo xtask validate-migration-constraints) classes a new nullable column plus a new CHECK as binding, are settled by running the lint in step 2, where the migration is written; the migration bumps schema_compat_floor.min_required_version if either says so.

store::models::CaseHousehold gains pub(crate) ended_on: Option<NaiveDate> ("The day the membership ended; absent while it is active"). The household GET then serves it.

D2. The act

POST /v1/cases/cases/{case_id}/household/{member_id}/end, handler api/cases/lifecycle.rs::end_household_member, request type in crates/craig-cases-contracts/src/cases.rs:

/// Request body for `POST /v1/cases/cases/{case_id}/household/{member_id}/end`.
pub struct EndHouseholdMemberRequest {
    /// Client-minted idempotency id, required.
    pub client_request_id: Uuid,
    /// The day the person left the household; on or before today.
    pub ended_on: NaiveDate,
}

A POST with a verb segment, as the screening-run cancel is, because the body carries a fact and an idempotency id.

Order of checks, each with the status it answers:

  1. the case exists, else 404;

  2. Action::Update on the case (case_resource_ref), else 403: the ruled reading;

  3. require_on_or_before_today(body.ended_on, "ended_on", jurisdiction), else 400 ledger-date-after-today;

  4. the ADR-062 claim, new scope HOUSEHOLD_MEMBER_END (ClaimScope("cases.end_household_member"), EntityKind("household_member"), revision 1), path legs case_id and member_id, registered in claimed_requests! and given its row in every_request_scope_hashes_to_its_pinned_value;

  5. inside the claimed transaction, after the claim: require_case_open, else 409 case-closed (the claim rolls back);

  6. the row, read and locked: SELECT * FROM case_household WHERE id = $1 AND case_id = $2 FOR UPDATE. No row answers 404. An inactive row is the typed 409 household-member-ended (new constant HOUSEHOLD_MEMBER_ENDED).

  7. the window, in Rust on one clock: ended_on must be on or after BusinessClock::for_jurisdiction(jurisdiction).date_of(row.added_at), else 400 ledger-window-invalid naming ended_on ("before the day the member was added"). Both bounds of ended_on are then the jurisdiction’s business dates: the day added, and today (check 3). A member added today can be ended today at any hour, which a UTC date in SQL would refuse every evening in a US timezone.

  8. the write: UPDATE case_household SET active = false, ended_on = $2 WHERE id = $1 RETURNING *.

  9. the act event and the cohort bump, as the add stages them: a new publish_household_member_ended beside publish_household_member_added in events.rs ("case.household_member_ended", audit (Update, HouseholdMember, Some(member.id), Sub(user_id)), payload {id, case_id, ended_on, user_id}), then note_case_cohort_change(tx, case_id, CohortChangeKind::Household).

The answer is the updated CaseHousehold row (200). A replay re-reads the row with get_household_member.

Two concurrent ends. require_case_open locks the case row and the read locks the membership row, so the second transaction reads the row after the first commits, finds it inactive and answers 409 household-member-ended.

Re-add. Nothing changes: an ended row is outside the partial unique index.

The handler’s name holds no entry of TRANSITION_VERBS, so the contention ratchet does not require a test by name; the concurrency test is written anyway (see Tests). The evil-corpus ratchet does scan it (a post handler): the handler gets a hostile-input test in an evil.rs file, not a baseline line.

OpenAPI responses(…​) lists 200, 400, 401, 403, 404, 409 and 422.

D3. The web act

services/craig-web/src/routes/cases/household.rs gains end_household_member and EndHouseholdMemberForm { client_request_id: Uuid, ended_on: NaiveDate }, routed at POST /cases/{id}/household/{member_id}/end in main.rs beside the add and under the same gate argument, RoleGate::CaseworkerDefault (every worker session; craig-cases decides), relaying to the craig-cases act and flashing a refusal’s problem detail through rejection_detail, as the add does. It redirects to /cases/{id}. The issue’s "marked `// caseworker+`" is read as that gate: the route table takes the gate as an argument and carries no such comment.

_tab_household.html: each active row gains an "End membership" control (a date input defaulting to today and a submit, CSRF field, a render-minted client_request_id per row), shown under the same condition as the add form (ctx.user.can_write() and an open case). The Active column shows the end date for an ended row. HouseholdMemberView gains ended_on: Option<String>. New Fluent keys household-btn-end, household-form-ended-on, household-col-ended in locales/en/web.ftl.

D4. The tests that write an inactive row

D1’s CHECK refuses active = false without an ended_on, so every test that writes such a row with SQL fails the moment the migration lands. Two kinds, handled in two steps.

In step 2, with the migration: each direct write also sets a date, so the suites stay green. A test-only change of one clause (ended_on = CURRENT_DATE, or the column added to the INSERT), no behaviour change:

File What it writes

services/craig-cases/tests/api/child_facts.rs (end_membership)

UPDATE … SET active = false

services/craig-cases/tests/api/placement_facts.rs

the same UPDATE

services/craig-cases/tests/api/cases_keyed.rs

the same UPDATE, by row id

services/craig-exchange/tests/api/outbound_triggers.rs

the same UPDATE

services/craig-cases/tests/api/person_lock_order_concurrent.rs

an INSERT of an ended row

services/craig-cases/tests/api/afcars_export_seed.rs (member)

an INSERT with active as a parameter

services/craig-cases/tests/invariants/case_household_member_unique.rs (insert_row)

an INSERT with active as a parameter

services/craig-cases/tests/constraints/case_household_one_active_membership_migration.rs

INSERTs of ended rows around the #1831 migration; it replays an older migration on a scratch table, so step 2 first checks whether the new CHECK is present on that table at all, and changes the file only if it is

Step 2 finds the list again with a search for writes to case_household that name active, rather than trusting this table, and runs the craig-cases and craig-exchange suites on a devstack before it lands.

In step 5: the helpers that end a membership move onto the route. That is the four UPDATE rows above. Each calls the route where its test’s service can reach it; a test that needs the row ended without the cohort bump, or that writes the row inside a transaction it holds open (the lock-order test), keeps SQL with that reason written beside it. The INSERT fixtures stay SQL: they build a past state, they do not perform the act.

crates/craig-test-lib/src/clients/cases/service.rs gains end_household_member(case_id: &str, member_id: &str, body: &EndHouseholdMemberRequest) → Result<ApiResponse<HouseholdMember>>. The row type craig-cases serves (store::models::CaseHousehold) is pub(crate), so the test client cannot name it; HouseholdMember is a new Deserialize struct in crates/craig-cases-contracts/src/cases.rs with the served fields (id, case_id, person_id, role: HouseholdRole, primary_caregiver, active, added_at, ended_on). It is the client-side view of that response only; the handler keeps returning the store model, and the existing add_household_member client method is left as it is. A typed return keeps the untyped-test-method budget (B7 counts methods whose return type holds serde_json::Value) from rising.

Steps

Each step is one MR on the train; later steps stack on earlier ones.

  1. Plan page. This file under docs/modules/ROOT/pages/plans/, the nav entry.

  2. Column and act (D1, D2). The migration, the model field, the contract type, the handler, the route, the event, the problem type, the test-lib client method, the API tests, cargo xtask api-docs, docs and the release note, and D4’s first half: every direct SQL write of an inactive row gains its date. A devstack run of the new tests and of the craig-cases and craig-exchange suites on luchs before the MR lands.

  3. Web act (D3). The handler, the template, the keys, the wiremock route tests, the guide page.

  4. Playwright leg. tests/e2e/specs/cases-household-end.spec.ts, caseworker project.

  5. Helpers and close (D4, second half). Move the four ending helpers onto the route, archive the plan.

Risks

Risk Mode Mitigation

The migration meets a database holding a hand-set inactive row and the CHECK cannot be added

fail-closed

the migration counts such rows first and raises naming the count and the remedy (set ended_on on those rows); it never invents a date

A released binary cannot decode a row carrying the new column, or the lint classes the change as binding

fail-closed

step 2 runs cargo xtask validate-migration-constraints; the migration bumps the schema floor when the lint or the N−1 decode requires it, so an old binary refuses to serve rather than failing per request

The end leaves the screening cohort revision unchanged, so a stale screening run still witnesses an IV-E determination

fail-open

the act bumps the cohort in the same transaction, as the add does; test ending_a_member_bumps_the_cohort_revision reads the revision before and after

The act is allowed on a closed case

fail-open

require_case_open inside the claimed transaction; test ending_a_member_of_a_closed_case_is_the_case_closed_409 asserts the 409 and the row unchanged

A caller without Update on the case ends a membership (BOLA)

fail-open

the Update check on the parent case before any write; test a_caller_denied_update_cannot_end_a_member asserts 403 and the row unchanged on the shipped engine

Two workers end the same membership with different dates and both believe they won

silent

the row is read under a lock, so one write wins; the loser gets the typed 409 naming the row as already ended; the concurrency test asserts exactly one 200 and the stored date is the winner’s

A member id of another case is ended through this case’s path

fail-open

the locked read binds case_id, and the write happens only after it; test a_member_of_another_case_is_a_404 asserts the 404 and that row unchanged

A server-side reader that should ignore ended members now sees one

silent

no reader changes; the readers that mean "current household" already filter active (list_household, the cohort, IV-E, matching seeds), and the ones that mean "ever a child of the case" (child_membership_exists, the AFCARS fence) deliberately do not; the late-entry test pins the second kind

The end date is compared with the day added on a different clock than "today", leaving a member added this evening with no acceptable end date

fail-closed

both bounds use the jurisdiction’s business clock, in Rust; unit test the_end_window_is_the_jurisdictions_business_dates covers an instant after local midnight UTC but before it locally, and the API test ends a member on the day it was added

The CHECK lands and a test that writes an inactive row with SQL starts failing, or is missed and fails only in the car

fail-closed

step 2 changes every such write in the same MR, finds them by search and not from D4’s table, and runs both services' suites on a devstack before landing

A moved test helper changes what a test proves (the route bumps the cohort, SQL did not)

silent

each moved helper’s test is re-run on a devstack; a helper whose test depended on the bare flag keeps SQL with its reason written beside it

Tests

All API tests are devstack-gated and carry // @axis:; they go in services/craig-cases/tests/api/household_end.rs unless named otherwise.

  • Contract (wire): ending_a_member_answers_the_ended_row (@axis: happy): 200 with active: false and the date; the default household GET drops the row and include_inactive=true lists it with ended_on. The request scope’s pinned digest row. cargo xtask api-docs --check.

  • Boundary (@axis: boundary): a_member_added_today_can_be_ended_today (API), and the unit test the_end_window_is_the_jurisdictions_business_dates on the window check: for added_at at 02:00 UTC in a jurisdiction five hours behind, the previous local day is admitted and the day before it is refused.

  • Refusals (@axis: sad): an already-ended row is 409 household-member-ended; a date after today is 400 ledger-date-after-today; a date before the member was added is 400 ledger-window-invalid; a closed case is 409 case-closed; another case’s member is 404. Each asserts the row unchanged.

  • Authorization (@axis: evil): a_caller_denied_update_cannot_end_a_member, on the shipped engine.

  • Hostile input: the handler’s entry in services/craig-cases/tests/api/evil_corpus.rs.

  • Replay (@axis: replay): the same client_request_id and body answers the first outcome and stages no second event; the same id with another date is 409 idempotency-conflict.

  • Concurrency (@axis: conc): two_concurrent_ends_have_exactly_one_winner, in services/craig-cases/tests/api/household_end_concurrent.rs.

  • Regression (the case that would have caught the gap): an_ended_child_still_takes_a_late_ledger_entry and an_ended_person_can_be_added_again, both reaching the ended state through the route, not SQL.

  • Events: one case.household_member_ended row naming the actor, and the cohort revision one higher.

  • Migration: a scratch-database test that the migration refuses a database holding an inactive row and applies to a clean one.

  • Web: wiremock route tests in household.rs: the relay’s body (happy) and a refusal’s detail flashed (sad).

  • Browser: the Playwright leg (@axis: happy): end a child’s membership, see the ended badge on the Federal facts card, record a late entry for that child, read it back from the API.

  • Red proof: for the closed-case gate and for the Update check, the line is removed and its test is shown to fail, then restored. No property category applies: nothing here parses.

Every always / never in this plan and the test that pins it: "a closed case refuses the act" → ending_a_member_of_a_closed_case_is_the_case_closed_409; "exactly one of two concurrent ends wins" → two_concurrent_ends_have_exactly_one_winner; "the migration never invents a date" → the migration test; "a replay stages no second event" → the replay test.

Delivery

  • Doc pages: docs/modules/ROOT/pages/data-model-cases.adoc (the case_household row and the act, beside the add); the generated api/craig-cases.adoc; implementation-guide.adoc and ADR-003’s catalog for the new event; guide/caseworker.adoc § Household for the web act.

  • CHANGELOG entry: changelog.d/2460.added.adoc for the act and the web control, with its Ops: clause naming the migration’s refusal on a hand-set inactive row; a second fragment only if the web step lands in a later release.

  • Close: Closes #2460 on the last MR; milestone; a closing note with merge shas, cars, and anything left (the correction act for closed cases, as a possible follow-up, not filed unless asked); the plan archived with its review log.

Review log

Round Vendor Resolved model Verdict

1

Anthropic (Vertex)

vertex-anthropic/claude-fable-5-2

FLAGS on the second question: the end date was compared with the day added on the UTC date while "today" used the business clock; the test client’s return type did not exist; two step numbers; the web route’s gate. Each fixed in the plan.

2

Google (Vertex)

vertex-gemini/gemini-4-carbon

FLAGS on the same clock mismatch, read on the draft before the fix; the maintainer then approved the edited plan for implementation.

Erratum (2026-11-25, before step 1 landed): the commit review of this page found that the plan listed four of the eight test files that write an inactive row with SQL, and deferred all of them to the last step although D1’s CHECK breaks them in step 2. D4, Scope item 4, step 2, step 5 and one Risks row are rewritten; the design of the act is unchanged.

Erratum (2026-11-25, step 2): the migration is additive and takes no schema-floor bump (the floor lint reports none required; a released binary reads the table by column name). The request scope’s entity id is the membership’s own id, so a replay re-reads that row. The test client’s typed return made the add’s client method the only untyped one left for this route; it is unchanged. The #1831 migration test needed its inserts dated, as D4 expected. Also step 2: the route answers the contract type HouseholdMember (the role as its typed token), not the store row D2 names, because the store-model baseline refuses a new handler that serves a store row; the fields on the wire are the same. Test names differ from the ones above: ending_a_member_bumps_the_cohort_revision is ending_a_member_stages_its_event_and_bumps_the_cohort_revision; a_member_of_another_case_is_a_404 is a leg of a_refused_end_leaves_the_membership_as_it_was; the replay test is a_replayed_end_answers_the_first_outcome_once; the already-ended refusal is ending_an_ended_member_is_the_household_member_ended_409.

Erratum (2026-11-26, step 5): the step landed as two MRs, the helpers and then this page’s archive. The three helpers that know the person and not the membership id share craig_test_lib::clients::cases::household::end_active_membership, a function over the cases client rather than a method on it, because that client is at its method cap; the fourth (cases_keyed.rs) calls the client’s end_household_member, which step 2 added as D4 planned. No helper needed the bare flag, so none kept SQL.

Edit this page · latest