Skip to content

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

refactor(flows): simplify trigger extraction logic

Steven Enamakelb17b5e107cba
diff --git a/crates/openhuman-core/src/flows/bus.rs b/crates/openhuman-core/src/flows/bus.rs
index b46a340612..1350be39fd 100644
--- a/crates/openhuman-core/src/flows/bus.rs
+++ b/crates/openhuman-core/src/flows/bus.rs
@@ -17,7 +17,7 @@ mod trigger;
pub use run_digest::FlowRunDigestSubscriber;
pub use trigger::FlowTriggerSubscriber;
-pub(crate) use trigger::{describe_trigger, extract_trigger_config, extract_trigger_kind};
+pub(crate) use trigger::describe_trigger;
// Private helpers and shared imports the colocated tests reach through
// `use super::*`.
diff --git a/crates/openhuman-core/src/flows/bus/trigger.rs b/crates/openhuman-core/src/flows/bus/trigger.rs
index cd1f6273ec..1831288768 100644
--- a/crates/openhuman-core/src/flows/bus/trigger.rs
+++ b/crates/openhuman-core/src/flows/bus/trigger.rs
@@ -16,7 +16,6 @@ use std::pin::Pin;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::{Arc, Mutex, RwLock};
use tinybus::EventHandler;
-use tinyflows::model::TriggerKind;
use tinyflows_catalog::Flow;
use tokio::sync::{mpsc, Mutex as AsyncMutex};
@@ -38,17 +37,6 @@ where
.map_err(|error| error.to_string())
}
-// Temporary reproduction of the pre-cleanup helper for the red regression
-// run: it compares the full trigger config, including pinned inputs.
-pub(crate) fn extract_trigger_kind(flow: &Flow) -> Option<TriggerKind> {
- let trigger = flow.graph.trigger()?;
- serde_json::from_value(trigger.config.get("trigger_kind")?.clone()).ok()
-}
-
-pub(crate) fn extract_trigger_config(flow: &Flow) -> Option<&Value> {
- Some(&flow.graph.trigger()?.config)
-}
-
/// Ask TinyFlows for normalized trigger metadata used by host bindings.
pub(crate) fn describe_trigger(
config: &Config,
diff --git a/crates/openhuman-core/src/flows/ops/updates.rs b/crates/openhuman-core/src/flows/ops/updates.rs
index c628b13d77..90ffd66efb 100644
--- a/crates/openhuman-core/src/flows/ops/updates.rs
+++ b/crates/openhuman-core/src/flows/ops/updates.rs
@@ -228,10 +228,25 @@ async fn flows_update_inner(
}
if graph_changed && updated.enabled {
- let trigger_unchanged = bus::extract_trigger_kind(&existing)
- == bus::extract_trigger_kind(&updated)
- && bus::extract_trigger_config(&existing) == bus::extract_trigger_config(&updated);
- if !trigger_unchanged {
+ let rebind = match (
+ bus::describe_trigger(config, &existing),
+ bus::describe_trigger(config, &updated),
+ ) {
+ (Ok(previous), Ok(current)) => previous != current,
+ (previous, current) => {
+ if let Err(error) = previous {
+ tracing::warn!(target: "flows", flow_id = %id, %error, "[flows] could not describe previous trigger during update");
+ }
+ if let Err(error) = current {
+ tracing::warn!(target: "flows", flow_id = %id, %error, "[flows] could not describe updated trigger during update");
+ }
+ // Trigger details are best-effort. Refresh when either
+ // description fails, so an old schedule is not kept live
+ // after a malformed schedule edit.
+ true
+ }
+ };
+ if rebind {
tracing::debug!(target: "flows", flow_id = %id, "[flows] flows_update: trigger changed on an enabled flow — rebinding automatic-dispatch trigger");
unbind_trigger(config, &existing);
bind_trigger(config, &updated);