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::Updateon 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 409case-closed); -
craig_ledger::refusal::require_on_or_before_today(the typed 400ledger-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:
-
A column for the end date, and the act that sets it.
-
The craig-web act on the Household tab.
-
One Playwright leg: end a child’s membership in the web, then record a late entry for that child.
-
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:
-
the case exists, else 404;
-
Action::Updateon the case (case_resource_ref), else 403: the ruled reading; -
require_on_or_before_today(body.ended_on, "ended_on", jurisdiction), else 400ledger-date-after-today; -
the ADR-062 claim, new scope
HOUSEHOLD_MEMBER_END(ClaimScope("cases.end_household_member"),EntityKind("household_member"), revision 1), path legscase_idandmember_id, registered inclaimed_requests!and given its row inevery_request_scope_hashes_to_its_pinned_value; -
inside the claimed transaction, after the claim:
require_case_open, else 409case-closed(the claim rolls back); -
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 409household-member-ended(new constantHOUSEHOLD_MEMBER_ENDED). -
the window, in Rust on one clock:
ended_onmust be on or afterBusinessClock::for_jurisdiction(jurisdiction).date_of(row.added_at), else 400ledger-window-invalidnamingended_on("before the day the member was added"). Both bounds ofended_onare 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. -
the write:
UPDATE case_household SET active = false, ended_on = $2 WHERE id = $1 RETURNING *. -
the act event and the cohort bump, as the add stages them: a new
publish_household_member_endedbesidepublish_household_member_addedinevents.rs("case.household_member_ended", audit(Update, HouseholdMember, Some(member.id), Sub(user_id)), payload{id, case_id, ended_on, user_id}), thennote_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 |
|---|---|
|
|
|
the same UPDATE |
|
the same UPDATE, by row id |
|
the same UPDATE |
|
an INSERT of an ended row |
|
an INSERT with |
|
an INSERT with |
|
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.
-
Plan page. This file under
docs/modules/ROOT/pages/plans/, the nav entry. -
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. -
Web act (D3). The handler, the template, the keys, the wiremock route tests, the guide page.
-
Playwright leg.
tests/e2e/specs/cases-household-end.spec.ts, caseworker project. -
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 |
A released binary cannot decode a row carrying the new column, or the lint classes the change as binding |
fail-closed |
step 2 runs |
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
|
The act is allowed on a closed case |
fail-open |
|
A caller without Update on the case ends a membership (BOLA) |
fail-open |
the Update check on the parent case
before any write; test |
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 |
A server-side reader that should ignore ended members now sees one |
silent |
no reader changes; the readers that
mean "current household" already filter |
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 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 withactive: falseand the date; the default household GET drops the row andinclude_inactive=truelists it withended_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 testthe_end_window_is_the_jurisdictions_business_dateson the window check: foradded_atat 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 409household-member-ended; a date after today is 400ledger-date-after-today; a date before the member was added is 400ledger-window-invalid; a closed case is 409case-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 sameclient_request_idand body answers the first outcome and stages no second event; the same id with another date is 409idempotency-conflict. -
Concurrency (
@axis: conc):two_concurrent_ends_have_exactly_one_winner, inservices/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_entryandan_ended_person_can_be_added_again, both reaching the ended state through the route, not SQL. -
Events: one
case.household_member_endedrow 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(thecase_householdrow and the act, beside the add); the generatedapi/craig-cases.adoc;implementation-guide.adocand ADR-003’s catalog for the new event;guide/caseworker.adoc§ Household for the web act. -
CHANGELOG entry:
changelog.d/2460.added.adocfor 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 #2460on 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) |
|
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) |
|
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.