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.

Structs§

ReducerTiming 🔒
Where a reducer dispatch spent its time: waiting for the reducer mutex (another command held it), and running the reducer itself.

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.)
create_block_in_tab 🔒
A new block in tab_id with meta, through the reducer (never the store alone: a block the reducer does not know cannot be torn off or redocked later). caller starts its messages (“pane.open”, “agent.open”), followed by “: CreateBlock”. The block has no place in the layout yet: placing it is the caller’s next step.
create_via_reducer 🔒
Run a command that creates a block and return the new block’s id: the reducer’s refusal is the error, the events are written to the store (a write that fails is logged and the open goes on, as every caller did) and published. Each caller keeps its own words: a refusal reads “refused: <the reducer’s message>”, a reducer that answered without a block “missing emitted no BlockCreated”, and a failed write is logged as “apply mstore apply failed”.
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).
dispatch_to_reducer_timed 🔒
dispatch_to_reducer that also says how long it waited for the reducer mutex and how long the reducer took. Used where a slow call has to be told apart as queue wait, reducer or persist (#47767).
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 queue writes land in dispatch order. 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 as client slices) and persist it inside ONE hold of the reducer mutex, so persist order equals dispatch order — the same contract as apply_layout_intent (layout_intents.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.