A boot replays every deposit into the read model as a conflict: each one is retried, then dead-lettered #12
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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.
What happens now (main
87556bb):project_mailboxes_supstartsletter_lifecycle_to_mailboxeswith no checkpoint store. Its read model handle is ETS (evoq_read_model_ets), whichevoq_projection:checkpoint_fits/2will not pair with a store, so each boot starts at checkpoint -1, and evoq's catch-up replays the whole log intoproject/4(evoq_store_subscription.erl "== Replay ==": step 1 runs on every boot).mailboxes_read_model:upsert_deposited/2writes a fresh document with no_rev. For a letter the database already holds,barrel_docdb:put_doc/2answers{error, conflict}, andput/1's{ok, _} = ...crashesproject/4with{badmatch, {error, conflict}}.on_error/4, evoq's default applies: back off, retry, then dead-letter aftermax_retries. So every boot pays that for every letter ever deposited, and the replay carries on after each drop.Observed: a probe in the pinned CI image (
macula-ci-otp-rocksdb@sha256:57e3929c…) calledletter_lifecycle_to_mailboxes:project/4with aletter_deposited_v1for a letter whose document exists, and it crashed with{badmatch,{error,conflict}}atmailboxes_read_model.erl:257(put/1). Found while reviewing #10 (PR 11), where the same replay also reaches the newcarried/2. That part is reported on the PR, not here.Done when:
project/4with a deposit for an existing letter and fails by name if it crashes or resets a flag.Found by Venus (review of PR 11).
Design note, before code (Titan, 2026-11-23).
What the defect is. The projection's handle is
evoq_read_model_ets, whichevoq_projection:checkpoint_fits/2will not pair with a store, so every boot starts at checkpoint -1 and evoq replays the whole log intoproject/4. The read model is a barrel_docdb store that persists across boots, so every replayed deposit meets a document it already wrote:put/1asserts{ok, _} = put_doc/2,{error, conflict}crashesproject/4, evoq retries and dead-letters — for every letter ever deposited, on every boot.Two ways to make a boot quiet.
(A) Make the deposit projection idempotent — when the letter's document already exists, the event was already projected and the write is skipped. Chosen.
(B) Give the projection a persistent checkpoint so the log is not replayed. Rejected:
evoq_read_model_etscannot hold a store at all, so B means a new barrel-backed read-model implementation and a checkpoint store — and it still leaves the model wrong after a rebuild from a lost or copied database, while an idempotent projection is right however many times it replays. The issue asks for the smaller fix that meets the Purpose; A is a guard in one function and a test, B replaces the projection's read-model handle.Threat model — what A must not do.
_revwould resetreplied/archived/carried_by/carried_again_by: a replayed deposit would put archived letters back in listings and undo the mcl-mail#10 grace read. So existing → no write at all, and the test asserts the flags andfind/2's answer are unchanged.find/2refuses it in the window before the next read purges it. So{error, not_found}→ create, as today.{citizen_did, letter_id}— the letter's own identity — so an existing document can only be this letter's own deposit, and a replayed deposit carries the same immutable fields.The code.
upsert_deposited/2reads the document first:{error, not_found}→ today'sput/1;{ok, _Existing}→ok. One worker writes deposits, so read-then-write has no competing creator; the only other writer,forget/2in a read, deletes, and a create after it is the right answer.Test, red first. A new case in
mailboxes_read_model_store_testsdrivesproject/4withletter_deposited_v1for a letter already stored with flags set: on main it crashes{badmatch, {error, conflict}}atput/1— the probe's failure, reproduced — and after the fix it returns{ok, _, _}and the document still answers with its flags. The harness'sreplayed_boot/2loses itscatcharound the deposit, and the two comments that call the dead letter expected (#12) go with it.Mutants on the new guard. (1) Restore the blind write (
{ok, _} → put(Doc)): the new test must fail by name. (2) Invert the skip ({error, not_found} → ok): the two restart tests that depend on a forgotten letter's recreation must fail.State at handover to Juno (Titan, 2026-11-24). Branch
titan/12-replay-idempotentis pushed:2f09982f245978f66b4bfbfc0ae76408f79a18a9, one commit on mainb4197f7. I was at step 3 of 7; the rest is Juno's, the Supervisor's to place.Design I followed: the note in comment 1468 — make the deposit projection idempotent (A), not a persistent checkpoint (B).
What the pushed commit does
mailboxes_read_model:upsert_deposited/2reads the document first:{error, not_found}->put/1(create, as today),{ok, _Held}->ok, nothing written. A replayed deposit no longer conflicts, and an archived/replied/carried document keeps its flags.a_replayed_deposit_for_an_existing_letter_leaves_it_as_it_wasdrivesproject/4withletter_deposited_v1for a stored letter.replayed_boot/2lost itscatcharound the deposit, the grace-read test now replays the deposit too, and the two comments that called the dead letter expected are gone.What is proven, and where the evidence is (on msi00, image
ghcr.io/macula-io/macula-ci-otp-rocksdb@sha256:57e3929c…)rebar3 eunit --module=mailboxes_read_model_store_testsfailed by name ona_replayed_deposit_for_an_existing_letter_leaves_it_as_it_was/1with**error:{badmatch,{error,conflict}};Failed: 1. Skipped: 0. Passed: 28.Log:~/.claude/sessions/titan-12/red.log.~/.claude/sessions/titan-12/src2:MCL_LINT=1 rebar3 lintpassed (it fetchedrebar3_lint v6.0.0), andrebar3 eunitprintedAll 150 tests passed.The third gate step,rebar3 dialyzer, was still running when this was written; its tail is in~/.claude/sessions/titan-12/gate.log.What is NOT done
mutants.shis shipped next to the tree, unused — M1 restores the blind write, M2 inverts the skip; each aborts if it did not apply and restores the file byte-identically.c4-model.ymlon main.My worktree is finished; the remote branch stays for Juno.
Purpose (defect) met: a boot replay of a deposit for a letter already in the read model succeeds without a retry or a dead letter, and leaves the document's flags as they were.
Landed as
05702cdf(PR 25,--no-ffofe0eb1406, merged clean):mailboxes_read_model:upsert_deposited/2skips the write when the letter's document is already held and still creates it when it is gone, anda_replayed_deposit_for_an_existing_letter_leaves_it_as_it_wasdrivesproject/4for a held letter with flags set.Proof on msi00 in the pinned image
57e3929c: red first by name with**error:{badmatch,{error,conflict}}(the probe's failure), then lint rc=0, eunit all 152 passed, dialyzer rc=0, and CI run 3024 green (check and The tested lock arrives whole).Mutants: M1 (the held clause writes again) kills the new test plus
a_restart_does_not_take_away_the_grace_read/1, both with the same conflict; M2 (never create) kills 6 tests.Two notes worth keeping with the record:
c1468says M2 fails "the two restart tests". As run,a_restart_does_not_bring_a_forgotten_letter_back_by_idis not among M2's failures: M2 also breaks a fixture, so only 17 of the 29 tests run at all, and that test's observable result is the same either way. M2 still kills.mutants.sh's form of M1 does not run in this repository: replacing the whole call leavesprojected/2unused andrebar.config'swarnings_as_errorsturns that into a compile error — a compile break proves nothing. M1 was re-expressed on the guard's own clause. A compile break proves nothing.The changelog line for #12 is left to the release commit, as this repository writes it there.