A3 package 4: each mesh fact goes out once per cluster (mcl_om_singleton) #5
Loading…
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 (feature): in a clustered mcl-martha, each whiteboard mesh fact goes out once per cluster, not once per node. Read models stay per node, and the standalone release behaves exactly as it does today.
Raf, 2026-12-02: "Run the whole path (Recommended)"
Raf, 2026-12-02: "Three for failover (Recommended)"
Refs martha-ai/mcl-martha#1, macula-services/mcl-whiteboard#3, macula-services/mcl-om#8
Consolidation analysis §A1 (side effects run once per node), A3 package 4.
The side effect
GuideBoardLifecycle.Supervisorstarts three evoq event handlers that republish domain events as mesh facts through:mcl_om_pubsub.publish/3:BoardLifecycleV1ToMesh(board initiated/hosted/archived/unarchived/renamed),ShapeLifecycle.ShapeLifecycleV1ToMesh(shape initiated/amended/removed),LeaveBoard.PeerDepartedV1ToMesh(peer departed). The analysis names only the first, but the other two have the same shape.evoq delivers events only to handlers on the local node (
evoq_event_router.erl:181). On a cluster whose store replicates, every node receives every event, so every node would publish each fact once.What changes
mcl_om_singleton:child_spec/2(hex mcl_om 1.9.0, pinned~> 1.9), named after its module. Exactly one node of a connected cluster runs it. When that node goes away, a standby on another node starts it.ProjectWhiteboardBoards.*) and every mesh subscriber are unchanged. They stay per node.A double run, and a gap
globalsees only connected nodes, so each connected partition runs its own copy, and each publishes the facts of events that its node receives. When the partitions meet again,mcl_om_singleton:resolve/3keeps one copy. No harm: every receiver is idempotent. Board facts are upserts keyed byboard_id, wherenilmeans no update.shape_initiated_v1is deduplicated byStore.new_shape?/1.shape_amended_v1sets the same points again.shape_removed_v1andpeer_departed_v1remove something that is already gone. On a cluster-mode store, the minority side of a split cannot append (Ra quorum), so in practice it has nothing new to publish.replay_policy: :skip, and a fresh handler gets only new events). This is the same loss as a dark mesh today. Peers catch up through the board list and snapshot queries on their next page load. No guard is added.mode: :single, so each clustered node holds its own events and the one holder publishes only its own node's events. A board on a standby node is not announced live: peers see it only on their next query. This holds only for a cluster that A3 package 2 has not yet made replicated, and no such release ships. Package 2 closes it.Done when
*ToMeshhandlers start throughmcl_om_singleton:child_spec/2, and the mcl_om pin in the umbrella apps is~> 1.9(hex 1.9.0, not a git ref).GuideBoardLifecycle.Supervisor, exactly one node has a handler registered for each published event type. After that node stops, the other node has it.mix format --check-formatted,mix compile --warnings-as-errors,mix credo,mix testandmix dialyzerare green on OTP 28 / Elixir 1.18.4, in the forgegatesjob.Not in scope: store mode from config (A3 package 2, which waits for the reckon-db minor), and anything else on whiteboard (paused except for path work).
Held until A3 package 2. Not pushed.
Mars (2026-12-02), after Jupiter's finding on scribe: the wrap is right only once whiteboard's store replicates. The code confirms this:
MclWhiteboard.Service.event_store/0still opensmode: :single(apps/mcl_whiteboard/lib/mcl_whiteboard/service.ex:124), so each node has its own store. The*ToMeshhandlers project only their own node's store. Today each node publishing its own events is correct and is not a double. Under a singleton held on node A, events written on node B would never be published. The third bullet of "A double run, and a gap" above names this. It is a reason to hold the wrap, not an interim cost. This wrap lands with whiteboard's A3 package 2 (store mode from config), in the same range.The built work is kept on the local branch
venus/a3-mesh-singletonat71c944f(worktreemcl-whiteboard-a3-mesh-singleton), on base509c6c5. It contains:mcl_om_singleton, with the pin at~> 1.9;test/one_node_publishes_test.exs: a standalone case, and two peer nodes with exactly one handler per event type plus the takeover;Local results on OTP 28.4.3 / Elixir 1.18.4: format, compile
--warnings-as-errors, credo, the wholemix test(126 tests, 0 failures) and dialyzer are all green.Correction to "During a handover" above: a takeover makes a burst, not a gap. I read this in evoq 1.32
evoq_store_subscription.erl(module doc "Registrants", andpending/3+backfill/5). A handler that registers after the store subscription has started is backfilled fromfrom(0) up to the subscription's current position, and only then becomes active. Belowmax(SeenUpTo, Reach[identity]), events are marked replay.SeenUpTois that node's checkpoint at boot.Reachis 0 on a node that has never run this handler. So when the standby takes over:replay_policy: :skipdrops them;The burst is harmless: every receiver is idempotent (see above). A gap remains only in one narrow case: the holder dies while the standby's own node is itself down. Events the standby consumed before its own last restart that the holder had not yet published are then replay and are skipped. A node that took over before and later takes over again has its
Reachset, so it republishes only what has arrived since it last held the handler.Done on main
9c6fe7c(PR #7, landed together with #6). Main runs 6914 (c4) and 6915 (gates) are green. Each Done-when item:*ToMeshhandlers start throughmcl_om_singleton:child_spec/2in cluster mode (71c944f). #6 then made that depend on the store mode: in single mode each node's store holds only its own events, so each node runs plain handlers. mcl_om pin~> 1.9(hex 1.9.0) in the umbrella apps.one_node_publishes_test.exs, cluster mode: one handler per type across two connected peers, and it moves when its node stops.9c6fe7c, main 6915.