Expand description
Post-completion dependency-resolution cascade (Wave 5a).
When an execution reaches a terminal outcome the Wave 4b writer
(attempt::complete / attempt::fail) / Wave 4c (cancel_flow)
emits an ff_completion_event row. The engine’s dispatch loop
polls the outbox by event_id and, for each event, calls
dispatch_completion. This module is the Postgres twin of the
Valkey ff_resolve_dependency FCALL cascade in
ff-engine::partition_router::dispatch_dependency_resolution.
§Per-hop-tx (K-2 adjudication)
The round-2 RFC debate locked the cascade to per-hop transactions
— NOT one mega-transaction spanning transitive descendants. A
fanout of N downstream edges that each fan out to M further
edges would otherwise hold ff_edge_group row locks across the
entire subgraph for the full cascade duration, which is
user-visible on large flows.
The layout here:
- Outer function
dispatch_completionruns a short claim-tx that atomically flipsff_completion_event.dispatched_at_msfrom NULL tonow_ms()viaUPDATE ... RETURNING— a concurrent dispatcher (retry, reconciler) observes the already-claimed row and short-circuits withDispatchOutcome::NoOp. - For each downstream edge, [
advance_edge_group] runs its own read-committed tx withSELECT ... FOR UPDATEon theff_edge_grouprow. Counter bump + policy eval + downstream state flip + sibling-cancel bookkeeping all commit together at hop boundary, then release the row lock. - If a hop’s tx exhausts its serialization retries we return
[
EngineError::Contention(RetryExhausted)]; the Wave 6 reconciler picks up the uncleareddispatched_at_msvia the partial index added in migration 0003.
Failures mid-cascade leave the outbox row marked dispatched (short-circuited) but partial downstream state; the reconciler catches orphaned work on its next scan.
Enums§
- Dispatch
Outcome - Outcome of a single dispatch invocation. Surfaces enough to let callers (the dispatcher loop, tests) distinguish claim-races from real work.
Functions§
- dispatch_
completion - Public entry point — poll one outbox event and cascade.