mcl-mail#12: a replayed deposit for a letter already held writes nothing #25

Manually merged
terra merged 2 commits from juno/12-replay-idempotent into main 2026-11-24 00:25:36 +00:00
Member

Refs macula-services/mcl-mail#12.

Purpose (defect): a boot of mcl-mail replays the log into the read model without an error for each letter it already holds, so a restart neither retries nor dead-letters every deposit.

This carries Titan's commit 2f09982f (the fix and its red-first test, from the design note in #12 comment 1468) and finishes the package; the branch is merged up to current main 60ad880, so the diff against main is those two files only.

  • mailboxes_read_model:upsert_deposited/2 reads the document first: {error, not_found} -> put/1 (create, as before — a letter carried twice and forgotten is recreated so its replayed read facts can land), {ok, _Held} -> ok (the deposit was already projected; nothing is written, so no _rev conflict and no flag reset).
  • projected/2 sits beside the module's own advanced/2 (carries) and set_flag/2: same read-then-write shape, same two shapes from get_doc.
  • New test a_replayed_deposit_for_an_existing_letter_leaves_it_as_it_was drives project/4 with letter_deposited_v1 for a stored letter whose archived and replied flags are set, and asserts find/2 still answers with them. replayed_boot/2 lost its catch around the deposit so a crash shows as a failure, not a swallow.

Proven on msi00 in the pinned image macula-ci-otp-rocksdb@sha256:57e3929c… (the same digest lint.yml runs):

  • Red first, on the fix reverted at the guard: a_replayed_deposit_for_an_existing_letter_leaves_it_as_it_was/1 fails with **error:{badmatch,{error,conflict}} — the probe's failure in #12.
  • Fixed tree: MCL_LINT=1 rebar3 lint rc=0, rebar3 eunit all 152 tests passed, rebar3 dialyzer rc=0.
  • Mutant M1 (the held clause writes again, projected({ok, _Held}, Doc) -> put(Doc)): 2 failures, the new test by name plus a_restart_does_not_take_away_the_grace_read/1, both {badmatch,{error,conflict}}. Titan's mutants.sh form of M1 (replace the whole call with put(Doc)) does not run: it leaves projected/2 unused and warnings_as_errors turns that into a compile error, so the mutant was re-expressed on the guard's own clause.
  • Mutant M2 (never create: {error, not_found} -> ok): 6 failures, a_replayed_deposit_for_an_existing_letter_leaves_it_as_it_was/1 among them.
  • The source is restored byte-identically after each mutant (cmp).

Not in this PR: the changelog line for #12, which this repository writes at its release commit.

Refs macula-services/mcl-mail#12. Purpose (defect): a boot of mcl-mail replays the log into the read model without an error for each letter it already holds, so a restart neither retries nor dead-letters every deposit. This carries Titan's commit `2f09982f` (the fix and its red-first test, from the design note in #12 comment 1468) and finishes the package; the branch is merged up to current main `60ad880`, so the diff against main is those two files only. - `mailboxes_read_model:upsert_deposited/2` reads the document first: `{error, not_found}` -> `put/1` (create, as before — a letter carried twice and forgotten is recreated so its replayed read facts can land), `{ok, _Held}` -> `ok` (the deposit was already projected; nothing is written, so no `_rev` conflict and no flag reset). - `projected/2` sits beside the module's own `advanced/2` (carries) and `set_flag/2`: same read-then-write shape, same two shapes from `get_doc`. - New test `a_replayed_deposit_for_an_existing_letter_leaves_it_as_it_was` drives `project/4` with `letter_deposited_v1` for a stored letter whose `archived` and `replied` flags are set, and asserts `find/2` still answers with them. `replayed_boot/2` lost its `catch` around the deposit so a crash shows as a failure, not a swallow. Proven on msi00 in the pinned image `macula-ci-otp-rocksdb@sha256:57e3929c…` (the same digest `lint.yml` runs): - Red first, on the fix reverted at the guard: `a_replayed_deposit_for_an_existing_letter_leaves_it_as_it_was/1` fails with `**error:{badmatch,{error,conflict}}` — the probe's failure in #12. - Fixed tree: `MCL_LINT=1 rebar3 lint` rc=0, `rebar3 eunit` **all 152 tests passed**, `rebar3 dialyzer` rc=0. - Mutant M1 (the held clause writes again, `projected({ok, _Held}, Doc) -> put(Doc)`): **2 failures**, the new test by name plus `a_restart_does_not_take_away_the_grace_read/1`, both `{badmatch,{error,conflict}}`. Titan's `mutants.sh` form of M1 (replace the whole call with `put(Doc)`) does not run: it leaves `projected/2` unused and `warnings_as_errors` turns that into a compile error, so the mutant was re-expressed on the guard's own clause. - Mutant M2 (never create: `{error, not_found}` -> `ok`): **6 failures**, `a_replayed_deposit_for_an_existing_letter_leaves_it_as_it_was/1` among them. - The source is restored byte-identically after each mutant (`cmp`). Not in this PR: the changelog line for #12, which this repository writes at its release commit.
Merge main 60ad880 into juno/12-replay-idempotent (mcl-mail#12)
All checks were successful
c4 model / c4-model-1 (pull_request) Successful in 3s
c4 model / c4-model (pull_request) Successful in 0s
lint-and-test / check (pull_request) Successful in 4m1s
lint-and-test / The tested lock arrives whole (pull_request) Successful in 2s
e0eb1406bf
terra manually merged commit 05702cdf2d into main 2026-11-24 00:25:36 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
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!25
No description provided.