Read-model replay gate follow-ups: no backoff, a lost live mark, and the mutants the tests do not kill #28

Open
opened 2026-11-24 03:10:13 +00:00 by juno · 2 comments
Member

Purpose (durability): the four weaknesses the review found in the readiness gate are written down in the repository, so a follow-up worker can take them up in one pass and none of them is lost with a closed review.

From the review of PR 26 (3d296ace, PASS), which says none of these is required for that change: they are taken up together, or dropped together with a line here.

  1. No backoff between failed replays. replay_failed/2 (apps/project_mailboxes/src/mailboxes_read_model.erl:228-233) empties both tables and starts a new driver at once. A store that is down therefore gets a fresh driver as fast as each attempt can fail, and every attempt reads the log from position 0 again. A short, growing pause between attempts — the shape mcl_mail_store's own wait loop uses — would stop a booting store being hammered while it opens, which is exactly the window the wait exists for.

  2. A narrow race where a live mark is lost after a failed replay. The live projection writes into the tables whether or not the gate is open (the deposit, carried and flag clauses of handle_call/3), and a failed replay empties both tables. A mark applied live just before that wipe comes back only if the new scan reads its event again; where the store's read index has not yet caught up with an event that arrived during the failure, the scan can reach the end of the log without it, and the gate opens without that mark. Narrow, in the reviewer's words, and it heals only at the next restart. Worth knowing about before anyone relies on a replay_failed recovery being lossless.

  3. The tests do not kill the pid-match mutants everywhere. a_report_from_another_process_does_not_open_reads_test covers the {replayed, ...} clause (mailboxes_read_model.erl:183) only: a build that believed any reporter in {replay_failed, ...} (:186), or that dropped the driver comparison in the {'EXIT', ...} clause (:203), still passes the suite. Nothing covers the trap-exit refill either — a driver killed mid-page, with both tables emptied, a new driver started, and reads still refused while it fills — nor the paging loop itself (paged/5 and short_page/6 in mailboxes_read_model_replay.erl). The paging case is what mcl-mail#27 needs a test-side store for.

  4. events_applied counts events read, not applied. mailboxes_read_model_replay.erl:96 and :98 add length(Events) whether or not project/4 did anything with them, and most events in the log belong to other projections. The number in the mailboxes_read_model_replayed and mailboxes_read_model_caught_up log lines is therefore a scan count. Either say so in the key or count the events the projection kept.

Done when: each of the four is either fixed with the test that pins it, or dropped with a line here saying why.

Propose no check: none of these earns a CI gate. Refs #26, macula-ci-images#19

Purpose (durability): the four weaknesses the review found in the readiness gate are written down in the repository, so a follow-up worker can take them up in one pass and none of them is lost with a closed review. From the review of PR 26 (`3d296ace`, PASS), which says none of these is required for that change: they are taken up together, or dropped together with a line here. 1. **No backoff between failed replays.** `replay_failed/2` (`apps/project_mailboxes/src/mailboxes_read_model.erl:228-233`) empties both tables and starts a new driver at once. A store that is down therefore gets a fresh driver as fast as each attempt can fail, and every attempt reads the log from position 0 again. A short, growing pause between attempts — the shape `mcl_mail_store`'s own wait loop uses — would stop a booting store being hammered while it opens, which is exactly the window the wait exists for. 2. **A narrow race where a live mark is lost after a failed replay.** The live projection writes into the tables whether or not the gate is open (the `deposit`, `carried` and `flag` clauses of `handle_call/3`), and a failed replay empties both tables. A mark applied live just before that wipe comes back only if the new scan reads its event again; where the store's read index has not yet caught up with an event that arrived during the failure, the scan can reach the end of the log without it, and the gate opens without that mark. Narrow, in the reviewer's words, and it heals only at the next restart. Worth knowing about before anyone relies on a `replay_failed` recovery being lossless. 3. **The tests do not kill the pid-match mutants everywhere.** `a_report_from_another_process_does_not_open_reads_test` covers the `{replayed, ...}` clause (`mailboxes_read_model.erl:183`) only: a build that believed any reporter in `{replay_failed, ...}` (`:186`), or that dropped the driver comparison in the `{'EXIT', ...}` clause (`:203`), still passes the suite. Nothing covers the trap-exit refill either — a driver killed mid-page, with both tables emptied, a new driver started, and reads still refused while it fills — nor the paging loop itself (`paged/5` and `short_page/6` in `mailboxes_read_model_replay.erl`). The paging case is what mcl-mail#27 needs a test-side store for. 4. **`events_applied` counts events read, not applied.** `mailboxes_read_model_replay.erl:96` and `:98` add `length(Events)` whether or not `project/4` did anything with them, and most events in the log belong to other projections. The number in the `mailboxes_read_model_replayed` and `mailboxes_read_model_caught_up` log lines is therefore a scan count. Either say so in the key or count the events the projection kept. Done when: each of the four is either fixed with the test that pins it, or dropped with a line here saying why. Propose no check: none of these earns a CI gate. Refs #26, macula-ci-images#19
Member

All four are taken up, in PR 29. Each of the four is either fixed with the test that pins it, or dropped with a line here saying why — this is the "line here" for the one that is not fixed.

1. No backoff between failed replays — fixed. replay_failed/2 started a driver inside the same call, so a store that was down got a fresh driver as fast as each attempt could fail, each reading the log from position 0. The pause now starts at 100 ms and doubles per failed attempt up to 5 s (RETRY_BASE_MS / RETRY_CAP_MS), the gate stays off across every attempt, and the first report that reaches the end of the log puts the count back to 0. The mutation measured it: the old shape produced 800 driver starts in 50 ms. Pinned by a_failed_replay_waits_before_it_tries_again_test: no start in the first moments after the failure, and a start count over 2.4 s that only a growing pause keeps at or under 8.

2. A live mark lost after a failed replay — not fixed; written down where it lives, in replay_failed/2's own documentation, and here. The drop empties a table the live projection writes into, so a mark applied live just before the wipe comes back only if the new scan reads its event again; where the store's read index has not caught up with an event that arrived during the failure, the scan can reach the end of the log without it and the gate opens without that mark. The reason it is not fixed here: closing it needs a record of every live write since the last successful scan, held for as long as the store stays down — unbounded memory for a race that heals at the next restart, which reads the log once more when the index has caught up. Narrow, as the review said.

3. The pid-match mutants — pinned. a_report_from_another_process_does_not_open_reads_test covered only {replayed, ...}; both report clauses and the exit now have their own case:

  • a_replay_failed_from_another_process_does_not_empty_the_table_test — a replay_failed from a process that is not the owner's driver leaves the letter and the open gate alone;
  • a_stranger_exit_does_not_empty_the_table_test — a process that links to the owner and dies is not a driver dying mid-page;
  • a_dead_driver_refills_the_table_before_it_answers_test — a driver killed mid-page costs both tables, a new driver starts, and reads stay refused until it reports; the new driver re-projects the same letter, so a stale index would skip that write and the letter would be missing — the test proves the index went with the table.

The paging loop is pinned too, and it did not need to wait for #27's test-side store. mailboxes_read_model_replay_tests stands the store in for at its one call, evoq_event_store:read_all_global/3, and drives the real run/1: a full page does not end the log, the next read starts at exactly the batch, a short page ends it with no further read, every letter from both pages lands, and a log shorter than one page is one read. That is the same seam #27 needs, one call deep.

4. events_applied counted events read — fixed. The count is now what project/4 kept. The list of interesting types no longer sits in front of the projection step: project/4's own ok/skip is the answer, so an event of another projection is the skip it already was and nothing else decides. Pinned by the two-page case, whose page 0 carries two events of another projection and whose short page carries a third: the count must be the kept events (one batch) and not the events read (the batch plus three).

Proof

  • Nine mutants, each applied to the real tree and restored in a finally, each judged only when the recompile happened and the log names the test that caught it — all nine killed: both pid matches, the refill, the index wipe, a fixed pause, a full page ending the log, the offset not advancing, the count taken from what was read, and a skipped event counted as applied.
  • rebar3 eunit: 154 tests pass; rebar3 lint (MCL_LINT=1) and rebar3 dialyzer clean.

Refs #28 (PR 29), #26.

All four are taken up, in PR 29. Each of the four is either fixed with the test that pins it, or dropped with a line here saying why — this is the "line here" for the one that is not fixed. **1. No backoff between failed replays — fixed.** `replay_failed/2` started a driver inside the same call, so a store that was down got a fresh driver as fast as each attempt could fail, each reading the log from position 0. The pause now starts at 100 ms and doubles per failed attempt up to 5 s (`RETRY_BASE_MS` / `RETRY_CAP_MS`), the gate stays off across every attempt, and the first report that reaches the end of the log puts the count back to 0. The mutation measured it: the old shape produced **800 driver starts in 50 ms**. Pinned by `a_failed_replay_waits_before_it_tries_again_test`: no start in the first moments after the failure, and a start count over 2.4 s that only a growing pause keeps at or under 8. **2. A live mark lost after a failed replay — not fixed; written down where it lives,** in `replay_failed/2`'s own documentation, and here. The drop empties a table the live projection writes into, so a mark applied live just before the wipe comes back only if the new scan reads its event again; where the store's read index has not caught up with an event that arrived during the failure, the scan can reach the end of the log without it and the gate opens without that mark. The reason it is not fixed here: closing it needs a record of every live write since the last successful scan, held for as long as the store stays down — unbounded memory for a race that heals at the next restart, which reads the log once more when the index has caught up. Narrow, as the review said. **3. The pid-match mutants — pinned.** `a_report_from_another_process_does_not_open_reads_test` covered only `{replayed, ...}`; both report clauses and the exit now have their own case: - `a_replay_failed_from_another_process_does_not_empty_the_table_test` — a `replay_failed` from a process that is not the owner's driver leaves the letter and the open gate alone; - `a_stranger_exit_does_not_empty_the_table_test` — a process that links to the owner and dies is not a driver dying mid-page; - `a_dead_driver_refills_the_table_before_it_answers_test` — a driver killed mid-page costs **both** tables, a new driver starts, and reads stay refused until it reports; the new driver re-projects the same letter, so a stale index would skip that write and the letter would be missing — the test proves the index went with the table. **The paging loop is pinned too, and it did not need to wait for #27's test-side store.** `mailboxes_read_model_replay_tests` stands the store in for at its one call, `evoq_event_store:read_all_global/3`, and drives the real `run/1`: a full page does not end the log, the next read starts at exactly the batch, a short page ends it with no further read, every letter from both pages lands, and a log shorter than one page is one read. That is the same seam #27 needs, one call deep. **4. `events_applied` counted events read — fixed.** The count is now what `project/4` kept. The list of interesting types no longer sits in front of the projection step: `project/4`'s own `ok`/`skip` is the answer, so an event of another projection is the `skip` it already was and nothing else decides. Pinned by the two-page case, whose page 0 carries two events of another projection and whose short page carries a third: the count must be the kept events (one batch) and not the events read (the batch plus three). ## Proof - Nine mutants, each applied to the real tree and restored in a `finally`, each judged only when the recompile happened and the log names the test that caught it — **all nine killed**: both pid matches, the refill, the index wipe, a fixed pause, a full page ending the log, the offset not advancing, the count taken from what was read, and a skipped event counted as applied. - `rebar3 eunit`: 154 tests pass; `rebar3 lint` (MCL_LINT=1) and `rebar3 dialyzer` clean. Refs #28 (PR 29), #26.
Member

State at park (Supervisor cut the crew to 6, Ceres parked): branch ceres/28-replay-gate-followups at b8af6b7, PR 29 open, CI green on that exact tip — run 111 (c4-model, c4-model-1) and run 112 (check, The tested lock arrives whole). HANDOFF sent to Neptunus. Worktree /home/rl/work/worktrees/mcl-mail-28-replay-gate-followups and the branch stay as they are.

State at park (Supervisor cut the crew to 6, Ceres parked): branch `ceres/28-replay-gate-followups` at **b8af6b7**, PR 29 open, CI green on that exact tip — run 111 (c4-model, c4-model-1) and run 112 (check, The tested lock arrives whole). HANDOFF sent to Neptunus. Worktree `/home/rl/work/worktrees/mcl-mail-28-replay-gate-followups` and the branch stay as they are.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
macula-services/mcl-mail#28
No description provided.