Expand description
Phase E.2c.2 reducer-dispatch helpers shared by the service handlers and
(via crate::server::service::…) the sagas.
Structs§
- Reducer
Timing 🔒 - 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_idwithmeta, through the reducer (never the store alone: a block the reducer does not know cannot be torn off or redocked later).callerstarts 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 “missingemitted no BlockCreated”, and a failed write is logged as “applymstore 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_reducerthat 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
DeleteWorkspaceto decide whether to run the wcore delete path. PropagatesStoreErrorso the caller can surface real I/O / corruption failures instead of misclassifying them as “not found” (codex P2 #615 carryover — the priorboolreturn collapsedErr(_)intofalse, 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
LayoutQueueBackendActionsand persist the resultingLayoutBackendActionsQueuedinside ONE hold of the reducer mutex (same critical-section contract asseed_layout_via_reducer), so queue writes land in dispatch order. Replaces the five store-directpendingbackendactionswriters (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 asapply_layout_intent(layout_intents.rs). Replaces the wcore-direct seeders (write_default_three_pane_layoutpost-bootstrap caller,setup_torn_off_block_layout): the reducer’sTabRecord.rootnodeis authoritative, and the persist subscriber is the soledb_layoutwriter on this path.