Skip to content

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

fix(flows): keep run session alive when start reports an existing run

Steven Enamakelb8c818fae533
diff --git a/crates/openhuman-core/src/flows/runs_adapter.rs b/crates/openhuman-core/src/flows/runs_adapter.rs
index 59163b4204..04c2ca7a3c 100644
--- a/crates/openhuman-core/src/flows/runs_adapter.rs
+++ b/crates/openhuman-core/src/flows/runs_adapter.rs
@@ -134,14 +134,13 @@ pub(crate) async fn start_run(
0,
);
let receiver = session.subscribe();
- session::insert(Arc::clone(&session))?;
+ let graph = serde_json::to_value(&flow.graph)
+ .map_err(|error| format!("encode workflow graph: {error}"))?;
let proxy = match module::runs_proxy(config).await {
Ok(proxy) => proxy,
- Err(error) => {
- session::remove(&session);
- return Err(error);
- }
+ Err(error) => return Err(error),
};
+ session::insert(Arc::clone(&session))?;
let request = StartRun {
run_id: run_id.to_owned(),
context: runs::RunContext {
@@ -154,8 +153,7 @@ pub(crate) async fn start_run(
},
caps_host: bindings.caps_host(),
storage: bindings.storage(),
- graph: serde_json::to_value(&flow.graph)
- .map_err(|error| format!("encode workflow graph: {error}"))?,
+ graph,
trigger_kind: bus_trigger(trigger),
trigger_data: input,
inputs,
@@ -167,7 +165,10 @@ pub(crate) async fn start_run(
{
Ok(started) => started,
Err(error) => {
- session::remove(&session);
+ match run_exists(config, bindings.storage(), run_id).await {
+ Ok(true) | Err(_) => session.start_polling(proxy),
+ Ok(false) => session::remove(&session),
+ }
return Err(error.wire_message());
}
};
@@ -512,3 +513,22 @@ fn bus_trigger(trigger: FlowRunTrigger) -> runs::FlowRunTrigger {
FlowRunTrigger::Resume => runs::FlowRunTrigger::Resume,
}
}
+
+async fn run_exists(
+ config: &Config,
+ storage: tinyflows_bus::catalog::CatalogStorage,
+ run_id: &str,
+) -> Result<bool, String> {
+ let proxy = module::catalog_proxy(config).await?;
+ let run: Option<tinyflows_bus::catalog::FlowRun> = proxy
+ .call(
+ tinyflows_bus::catalog::members::GET_RUN,
+ (tinyflows_bus::catalog::RunIdRequest {
+ storage,
+ id: run_id.to_owned(),
+ },),
+ )
+ .await
+ .map_err(|error| error.wire_message())?;
+ Ok(run.is_some())
+}