Skip to main content

Module completion_backend

Module completion_backend 

Source
Expand description

The CompletionBackend trait — backend-agnostic completion subscription surface (issue #90).

ff-engine’s DAG promotion listener used to SUBSCRIBE ff:dag:completions directly on a dedicated RESP3 ferriskey::Client — a Valkey-specific wire detail baked into an otherwise backend-agnostic crate. RFC-012 trait-ifies the write surface via [EngineBackend]; this trait closes the symmetric gap on the read-side notification path. A Postgres backend would implement this over LISTEN/NOTIFY; the Valkey backend keeps the pubsub wiring but hides the channel string behind the trait.

§Object safety

CompletionBackend is object-safe: the single method is async fn behind #[async_trait] and takes &self. Consumers can hold Arc<dyn CompletionBackend> alongside Arc<dyn EngineBackend> for heterogeneous-backend deployments. A compile-time assertion ([_assert_dyn_compatible]) guards future method additions against accidental dyn-incompatibility.

§Fanout policy

Each subscribe_completions() call returns an independent CompletionStream. Backends are free to implement fanout however they like — the Valkey backend today opens one SUBSCRIBE per call on a dedicated RESP3 connection. Callers that want to share a single subscription across many consumers should wrap the stream in a broadcast themselves; the trait does not assume shared-subscription semantics.

§Reconnect + transient errors

The stream yields CompletionPayload (not Result<_, _>) indefinitely until the consumer drops it. Backends handle reconnect, resubscribe, and transient-error logging internally; completions produced during a reconnect window may be missed and are picked up by ff-engine’s dependency_reconciler safety net. Issue #90 does NOT promise at-least-once delivery through the stream — that contract stays with the reconciler scanner.

§Scope: no publish_completion

The publisher side of the completion channel is backend-internal. On Valkey, ff_complete_execution / ff_fail_execution / ff_cancel_execution PUBLISH from inside Lua (FCALL-atomic); on Postgres, the stored procedure would NOTIFY. Rust never publishes. There is intentionally no publish_completion method on this trait — if you find yourself wanting one, you are on the wrong side of the atomicity boundary.

Traits§

CompletionBackend
Backend surface for subscribing to completion events.

Type Aliases§

CompletionStream
A backend-agnostic stream of completion events.