Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

refactor(flows): drop host run observer in favour of module events

Steven Enamakeld0bbb9cb0faf
diff --git a/crates/openhuman-core/src/core/events.rs b/crates/openhuman-core/src/core/events.rs
index 0678a77e36..a8231d313b 100644
--- a/crates/openhuman-core/src/core/events.rs
+++ b/crates/openhuman-core/src/core/events.rs
@@ -405,15 +405,11 @@ pub enum DomainEvent {
#[serde(default, skip_serializing_if = "Option::is_none")]
tenant: Option<crate::core::runtime::Tenant>,
},
- /// Live per-step progress of an in-flight `flows_run` / `flows_resume`
- /// (issue G2, live run observation). Published from
- /// `flows::observability::FlowRunObserver::on_step_finish` as each
- /// non-trigger node settles, so the Workflows UI can show a run advancing
- /// node-by-node instead of only polling the settled `flow_runs` row. The
- /// durable `flow_runs` row (updated incrementally by the same observer and
- /// finalized at settle) remains the source of truth — this event is a
- /// best-effort progress feed (broadcast bridges drop on lag), which is why
- /// the frontend keeps its 2s poller as a fallback.
+ /// Live per-step progress of an in-flight `flows_run` / `flows_resume`.
+ /// The OpenHuman Runs adapter projects TinyFlows' ordered `step_started`
+ /// and `step` events so the Workflows UI can show a run advancing
+ /// node-by-node instead of only polling the module-owned run row. This is
+ /// a best-effort feed; the frontend keeps its 2s poller as a fallback.
FlowRunProgress {
/// The run's stable identifier (== the tinyflows checkpointer thread id).
run_id: String,
@@ -423,14 +419,11 @@ pub enum DomainEvent {
status: String,
},
- /// A `flows_run` (or `flows_resume`) invocation just persisted its
- /// `flow_runs` row, before execution begins (issue B35, runs-rail live
- /// refresh). Published from `flows::ops::flows_run` right after
- /// `start_flow_run_row` returns, so the UI can show "Running" immediately
- /// instead of waiting for the blocking RPC to resolve or the first
- /// `FlowRunProgress` step. Covers every run source (Rpc/Schedule/AppEvent/
- /// Resume, incl. copilot live-run) since they all funnel through
- /// `start_flow_run_row`.
+ /// A `flows_run` (or `flows_resume`) invocation has started in the
+ /// TinyFlows Runs module, before execution begins. The OpenHuman Runs
+ /// adapter projects the module's `started` event so the UI can show
+ /// "Running" immediately instead of waiting for the blocking RPC or first
+ /// step event. Covers RPC, schedule, app-event, resume, and detached runs.
FlowRunStarted {
/// The affected flow's id.
flow_id: String,
@@ -438,11 +431,10 @@ pub enum DomainEvent {
run_id: String,
},
- /// The terminal companion to [`FlowRunStarted`] (issue B35 follow-up, runs
- /// rail live finish). Published from `flows::ops::finish_flow_run_row`
- /// right after `store::finish_flow_run` persists the terminal
- /// `flow_runs` row, so the UI can flip a run to Completed/Failed live
- /// instead of relying on a poll to notice the settled row.
+ /// The terminal companion to [`FlowRunStarted`]. The OpenHuman Runs
+ /// adapter publishes it once when PollRun returns the module's terminal
+ /// `finished` event, so the UI can update without waiting for its next
+ /// history poll.
FlowRunFinished {
/// The affected flow's id.
flow_id: String,
diff --git a/crates/openhuman-core/src/flows/tinyflows/observability.rs b/crates/openhuman-core/src/flows/tinyflows/observability.rs
deleted file mode 100644
index 496687157f..0000000000
--- a/crates/openhuman-core/src/flows/tinyflows/observability.rs
+++ /dev/null
@@ -1,188 +0,0 @@
-//! Host [`tinyflows::observability::RunObserver`] impls for the `flows::`
-//! domain.
-//!
-//! `tinyflows` emits structured run/step records; the host decides what to do
-//! with them. The observer that lives here:
-//!
-//! - [`FlowRunObserver`] — used by the durable run path (issue
-//! G2, live run observation). It publishes a [`DomainEvent::FlowRunProgress`]
-//! twice per non-trigger node — `running` when the node activates, then its
-//! terminal `success`/`error` when it finishes — so the frontend socket
-//! bridge can stream the run advancing node-by-node. On finish it also
-//! persists a [`FlowRunStep`] incrementally into the run's `flow_runs` row
-//! via `flows::store::upsert_flow_run_step`. All effects are best-effort: a
-//! step that fails to persist is logged, never fatal to the run.
-//!
-//! The `running` half matters for more than symmetry: the canvas's
-//! `.flow-node-running` pulse is bound to that status, so while only
-//! `on_step_finish` was implemented the pulse was unreachable and the live
-//! overlay rendered as a completion trail — each node gaining a static ring
-//! only after it had already finished.
-//!
-//! The durable + journaled run path used by `flows_run`/`flows_resume` now
-//! accepts an observer (tinyflows 0.3.1's
-//! `run_with_checkpointer_journaled_observed` /
-//! `resume_with_checkpointer_journaled_observed`), so [`FlowRunObserver`] sees
-//! steps live instead of the run being reconstructed only after it settles.
-
-use std::sync::Arc;
-
-use tinyflows::observability::{ExecutionStep, Run, RunObserver};
-use tinyflows::observe::step_status_str;
-
-use crate::config::Config;
-use crate::core::bus::BUS;
-use crate::core::events::DomainEvent;
-use {crate::flows::upsert_flow_run_step, tinyflows_catalog::FlowRunStep};
-
-/// The durable-run observer (issue G2): persists each finished step
-/// incrementally and streams a progress event to the frontend.
-///
-/// Held by the engine as `Arc<dyn RunObserver>` and cloned into node handlers
-/// that run across threads, so it must be cheap and non-blocking-ish — it does
-/// one small SQLite read-modify-write per step (WAL + `busy_timeout` absorb the
-/// concurrent settle write) and one fire-and-forget broadcast publish. Never
-/// logs step output/PII: only ids, status, and timing are logged/emitted.
-pub struct FlowRunObserver {
- config: Arc<Config>,
- flow_id: String,
- /// The run's checkpointer thread id, which doubles as the `flow_runs` row
- /// id and the `run_id` on the emitted progress event.
- run_id: String,
-}
-
-impl FlowRunObserver {
- /// Builds an observer bound to one `flows_run` / `flows_resume` invocation.
- pub fn new(config: Arc<Config>, flow_id: impl Into<String>, run_id: impl Into<String>) -> Self {
- Self {
- config,
- flow_id: flow_id.into(),
- run_id: run_id.into(),
- }
- }
-}
-
-impl RunObserver for FlowRunObserver {
- fn on_run_start(&self, run_id: &str) {
- tracing::debug!(
- target: "flows",
- flow_id = %self.flow_id,
- run_id = %self.run_id,
- engine_run_id = %run_id,
- "[flows] observer: run start"
- );
- }
-
- /// Announces a node as `running` the moment it activates, so the canvas can
- /// show what is executing *now* rather than only what has already finished.
- ///
- /// Without this the overlay could never do that: `on_step_finish` is the
- /// only event that ever fired, so the socket only ever carried `success` /
- /// `failed`, and a node stayed unstyled until it was already done. The
- /// canvas's `.flow-node-running` pulse (`flow-node-run-pulse`, written for
- /// exactly this) was therefore unreachable, and the "live run overlay" read
- /// as a completion trail — nodes acquiring a static ring after the fact.
- ///
- /// Publish-only, deliberately: the durable `flow_runs` row stays
- /// finish-driven. A started-but-unfinished node has no output, duration, or
- /// terminal status to record, and writing a placeholder row would put a
- /// `running` step into run history that the post-hoc reconstruction at
- /// settle would then have to reconcile away. The socket event is ephemeral
- /// UI state; the row remains the source of truth.
- fn on_step_start(&self, node_id: &str) {
- tracing::debug!(
- target: "flows",
- flow_id = %self.flow_id,
- run_id = %self.run_id,
- node = %node_id,
- "[flows] observer: step started — publishing FlowRunProgress(running)"
- );
- BUS.publish(DomainEvent::FlowRunProgress {
- run_id: self.run_id.clone(),
- node_id: node_id.to_string(),
- status: "running".to_string(),
- });
- }
-
- fn on_step_finish(&self, step: &ExecutionStep) {
- let status = step_status_str(&step.status);
- tracing::debug!(
- target: "flows",
- flow_id = %self.flow_id,
- run_id = %self.run_id,
- node = %step.node_id,
- status,
- duration_ms = step.duration_ms,
- "[flows] observer: step finished — persisting incrementally"
- );
-
- // Persist the live step. `duration_ms` is `u128` on the engine side;
- // clamp into `u64` (a node executor taking > 584 million years is not a
- // real concern, but never panic on cast).
- if !step.diagnostics.is_empty() {
- tracing::warn!(
- target: "flows",
- flow_id = %self.flow_id,
- run_id = %self.run_id,
- node = %step.node_id,
- diagnostics = ?step.diagnostics,
- "[flows] observer: step reported null-resolved expression(s) — persisting for the run view"
- );
- }
- let flow_step = FlowRunStep {
- node_id: step.node_id.clone(),
- output: step.output.clone(),
- port: None,
- status: Some(status.to_string()),
- duration_ms: Some(u64::try_from(step.duration_ms).unwrap_or(u64::MAX)),
- diagnostics: step
- .diagnostics
- .iter()
- .map(|d| serde_json::to_value(d).unwrap_or(serde_json::Value::Null))
- .collect(),
- };
- if let Err(e) = upsert_flow_run_step(&self.config, &self.run_id, &flow_step) {
- tracing::warn!(
- target: "flows",
- flow_id = %self.flow_id,
- run_id = %self.run_id,
- node = %step.node_id,
- error = %e,
- "[flows] observer: failed to persist incremental step (run continues; post-hoc reconstruction will fill it in at settle)"
- );
- }
-
- // Best-effort progress feed to the frontend socket bridge. The durable
- // `flow_runs` row remains the source of truth; this event may be
- // dropped under broadcast lag, so the UI keeps its 2s poller fallback.
- tracing::debug!(
- target: "flows",
- flow_id = %self.flow_id,
- run_id = %self.run_id,
- node = %step.node_id,
- status,
- "[flows] observer: publishing FlowRunProgress"
- );
- BUS.publish(DomainEvent::FlowRunProgress {
- run_id: self.run_id.clone(),
- node_id: step.node_id.clone(),
- status: status.to_string(),
- });
- }
-
- fn on_run_finish(&self, run: &Run) {
- tracing::debug!(
- target: "flows",
- flow_id = %self.flow_id,
- run_id = %self.run_id,
- engine_run_id = %run.id,
- steps = run.steps.len(),
- status = ?run.status,
- "[flows] observer: run finished"
- );
- }
-}
-
-#[cfg(test)]
-#[path = "observability_tests.rs"]
-mod tests;
diff --git a/crates/openhuman-core/src/flows/tinyflows/observability_tests.rs b/crates/openhuman-core/src/flows/tinyflows/observability_tests.rs
deleted file mode 100644
index b2263a8b1c..0000000000
--- a/crates/openhuman-core/src/flows/tinyflows/observability_tests.rs
+++ /dev/null
@@ -1,52 +0,0 @@
-use super::*;
-
-/// The canvas's `.flow-node-running` pulse is bound to a `running` status
-/// that only `on_step_start` can produce. Before it was implemented the
-/// socket carried nothing but `success`/`failed`, so the pulse was
-/// unreachable and the "live" overlay was really a completion trail.
-/// Assert the trait method is actually overridden — a default no-op here
-/// silently returns the UI to that state with every other test still green.
-#[test]
-fn on_step_start_is_implemented_so_the_running_status_can_reach_the_canvas() {
- use std::sync::atomic::{AtomicBool, Ordering};
- use std::sync::Arc;
-
- // A probe observer whose `on_step_start` records that the *trait's*
- // dispatch reached an override rather than the blanket default.
- struct Probe {
- started: Arc<AtomicBool>,
- }
- impl RunObserver for Probe {
- fn on_step_start(&self, _node_id: &str) {
- self.started.store(true, Ordering::SeqCst);
- }
- }
- let started = Arc::new(AtomicBool::new(false));
- let probe: Box<dyn RunObserver> = Box::new(Probe {
- started: started.clone(),
- });
- probe.on_step_start("n1");
- assert!(
- started.load(Ordering::SeqCst),
- "the engine dispatches on_step_start through the trait object — if this ever \
- stops holding, FlowRunObserver's override cannot fire either"
- );
-
- // And the real observer must override it, not inherit the no-op.
- let src = include_str!("observability.rs");
- assert!(
- src.contains("fn on_step_start(&self, node_id: &str)"),
- "FlowRunObserver must implement on_step_start — without it no `running` \
- status is ever published and the canvas pulse is dead code"
- );
- assert!(
- src.contains("status: \"running\".to_string()"),
- "on_step_start must publish FlowRunProgress with status=running"
- );
-}
-
-// The end-to-end proof that `FlowRunObserver::on_step_finish` persists each
-// step into the `flow_runs` row lives in `flows::ops_tests`
-// (`observer_persists_each_step_incrementally` and the run-driven
-// `flows_run_persists_live_steps_with_status_and_timing`), where the flows
-// `store` internals are in scope for seeding/asserting rows.