Saga

Trait Saga 

Source
pub trait Saga: Send {
    // Required methods
    fn start(&mut self, ctx: &SagaCtx) -> SagaAction;
    fn on_event(&mut self, event: &Event, ctx: &SagaCtx) -> SagaAction;
    fn name(&self) -> &'static str;

    // Provided methods
    fn input_snapshot(&self) -> Value { ... }
    fn timeout(&self) -> Duration { ... }
}
Expand description

A multi-step, multi-reducer state machine. Implementations describe one logical operation (tear-off, pool-respawn, etc.).

Lifecycle: coordinator calls start once when the saga is added to in_flight. After that, every event on the bus is passed to on_event. The saga inspects the event, advances its internal state, returns the next action.

Identification: sagas know which events belong to them by inspecting saga_id in lifecycle events or by matching patterns in event payloads (e.g. specific labels). F.5 sagas correlate by event type only (pool_respawn matches any PoolWindowAdded after start). Per-variant saga_id tagging on commands/events is deferred until concurrent same-type sagas are needed.

Required Methods§

Source

fn start(&mut self, ctx: &SagaCtx) -> SagaAction

Source

fn on_event(&mut self, event: &Event, ctx: &SagaCtx) -> SagaAction

Source

fn name(&self) -> &'static str

Provided Methods§

Source

fn input_snapshot(&self) -> Value

LSD-2 — saga’s input arguments serialized for the durable log’s input_json column. The coordinator calls this once at spawn_saga time (before start) and writes the result via LauncherSagaLog::start_saga. Operators see this in --diag sagas output (e.g. {"closed_label":"win-3"}) so they can tell which window’s cleanup a recovered-failed saga belonged to.

Default Value::Null — sagas with no input fields can ignore it. Concrete sagas should override with a serde_json::json! of their constructor args.

Source

fn timeout(&self) -> Duration

CPD-3 — per-saga deadline budget for completing all IssueCmd+wait cycles. Coordinator arms a timer when the saga registers; if the saga is still in_flight when timeout() elapses, it is force-failed (SagaFailed { reason: "saga timeout" }) and removed from the registry.

Default 5s — fits class-C single-step host dispatch (e.g. pool respawn). WindowCleanupCascade overrides to 30s because pane drain on a workspace with many panes can legitimately take that long. Per spec §3.10.

Implementors§