Skip to main content

Module reducer_helpers

Module reducer_helpers 

Source
Expand description

Phase E.2c.2 reducer-dispatch helpers shared by the service handlers and (via crate::server::service::…) the sagas.

FunctionsΒ§

compensate_via_reducer πŸ”’
Compensation helper: dispatch a command into the reducer and apply its emitted events to mstore best-effort. Used when an earlier sync apply partially wrote SQLite and we need to undo the leaked rows. SQLite errors during compensation are logged but ignored β€” the caller is already returning an error to the client; throwing on the cleanup just hides the original cause. (codex P1 + reagent P2 #616 β€” partial-write cleanup.)
dispatch_to_reducer πŸ”’
Dispatch a command into the srv reducer and return the emitted events. Locks the reducer mutex briefly; the lock is released before any I/O (caller is responsible for publishing the events to the broadcast bus).
mstore_workspace_exists πŸ”’
Existence check used by DeleteWorkspace to decide whether to run the wcore delete path. Propagates StoreError so the caller can surface real I/O / corruption failures instead of misclassifying them as β€œnot found” (codex P2 #615 carryover β€” the prior bool return collapsed Err(_) into false, which led to silent successes when SQLite was unhealthy: reducer would delete its own copy and report success while the disk row was never touched).
publish_events πŸ”’
Publish each event on the srv broadcast bus. Failures (no subscribers) are non-fatal.
queue_layout_actions_via_reducer πŸ”’
SPEC_864 Phase 4 β€” single-writer queue append. Dispatch a LayoutQueueBackendActions and persist the resulting LayoutBackendActionsQueued inside ONE hold of the reducer mutex (same critical-section contract as seed_layout_via_reducer), so a concurrent frontend ACK slice (LayoutSetTree REPLACE) can’t interleave between dispatch and persist. Replaces the five store-direct pendingbackendactions writers (layout_helpers’ insert/split/delete queuers + the two inline app_api sites).
seed_layout_via_reducer πŸ”’
SPEC_864 Phase 3 β€” single-writer layout seeding. Dispatch a LayoutSetTree (tree + focus + leaforder as client slices) and persist it inside ONE hold of the reducer mutex, so persist order equals dispatch order β€” the same contract as UpdateObject’s Phase-2 route in object.rs. Replaces the wcore-direct seeders (write_default_three_pane_layout post-bootstrap caller, setup_torn_off_block_layout): the reducer’s TabRecord.rootnode is authoritative, and the persist subscriber is the sole db_layout writer on this path.