emit_saga_started

Function emit_saga_started 

Source
pub async fn emit_saga_started(
    state: &AppState,
    saga_id: u64,
    name: &'static str,
    input: Value,
) -> Result<(), String>
Expand description

Emit Event::SagaStarted for a freshly-allocated saga_id. Sagas call this immediately after alloc_saga_id so subscribers see the start record before any per-step events.

Also writes a running row to the durable saga log (PR 1 of SPEC_SAGA_DURABILITY_2026-05-01.md), recording input as the saga’s arguments serialized to JSON. PR 2’s compensate_unresolved

  • --diag sagas rely on this for crash-recovery provenance, so callers should pass a structured representation of their inputs (typically serde_json::json!({...})). (reagent P1 PR #631 — Value::Null placeholder erased provenance.)

Fail-fast on log error. (codex P1 PR #631 round 2.) If start_saga fails — most likely a UNIQUE constraint violation from a saga_id collision — the saga MUST NOT proceed. Otherwise later terminate() calls would UPDATE saga SET ... WHERE saga_id=? against a different run’s row, mixing lifecycle data across sagas and silently corrupting the durability log. Returning Err here propagates up to the caller, which records the failure via emit_terminal (with a fresh saga_id allocated by the caller’s alloc_saga_id retry path, if any).