Skip to content

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

fix(workflow_runs): persist run status on lifecycle transitions

Steven Enamakelae9e08910d88
diff --git a/crates/openhuman-core/src/agent/orchestration/workflow_runs/engine/lifecycle.rs b/crates/openhuman-core/src/agent/orchestration/workflow_runs/engine/lifecycle.rs
index 666b1201ad..52226cc065 100644
--- a/crates/openhuman-core/src/agent/orchestration/workflow_runs/engine/lifecycle.rs
+++ b/crates/openhuman-core/src/agent/orchestration/workflow_runs/engine/lifecycle.rs
@@ -30,6 +30,7 @@ use tinyagents_orchestration::workflow::WorkflowDefinition;
/// [`WorkflowRun`] is the freshly-created row (status `Running`); callers poll
/// `workflow_run_get` to observe progress.
pub async fn start_workflow_run(
+ ctx: &DispatchCtx,
config: &Config,
definition_id: &str,
input: Value,
@@ -68,8 +69,9 @@ pub async fn start_workflow_run(
// sub-agents whose tool calls the approval gate judges by that label.
// Inherit-only: `None` leaves the loop unlabelled and failing closed.
let inherited_origin = crate::agent::turn_origin::capture();
+ let task_ctx = ctx.clone();
crate::core::runtime::spawn_scoped(async move {
- match crate::config::ops::load_current_or_init(&DispatchCtx::ambient()).await {
+ match crate::config::ops::load_current_or_init(&task_ctx).await {
Ok(task_config) => {
crate::agent::turn_origin::with_inherited_origin(
inherited_origin,
@@ -166,7 +168,7 @@ pub async fn stop_workflow_run(config: &Config, id: &str) -> Result<Option<Workf
/// phase whose dependencies are satisfied. Returns the run row (now `Running`),
/// or an error if the run is unknown / already terminal-complete / its
/// definition no longer exists.
-pub async fn resume_workflow_run(config: &Config, id: &str) -> Result<WorkflowRun> {
+pub async fn resume_workflow_run(ctx: &DispatchCtx, config: &Config, id: &str) -> Result<WorkflowRun> {
log::debug!(target: LOG_TARGET, "[workflow_run_engine] resume.entry run={id}");
let run = get_workflow_run(config, id)?.ok_or_else(|| anyhow!("unknown workflow run: {id}"))?;
@@ -207,8 +209,9 @@ pub async fn resume_workflow_run(config: &Config, id: &str) -> Result<WorkflowRu
// Same inherit-only origin propagation as `start_workflow_run`: the resumed
// loop runs on a fresh task, which would otherwise drop the caller's label.
let inherited_origin = crate::agent::turn_origin::capture();
+ let task_ctx = ctx.clone();
crate::core::runtime::spawn_scoped(async move {
- match crate::config::ops::load_current_or_init(&DispatchCtx::ambient()).await {
+ match crate::config::ops::load_current_or_init(&task_ctx).await {
Ok(task_config) => {
crate::agent::turn_origin::with_inherited_origin(
inherited_origin,
diff --git a/crates/openhuman-core/src/agent/orchestration/workflow_runs/schemas.rs b/crates/openhuman-core/src/agent/orchestration/workflow_runs/schemas.rs
index 20927321ca..0ab4b3e037 100644
--- a/crates/openhuman-core/src/agent/orchestration/workflow_runs/schemas.rs
+++ b/crates/openhuman-core/src/agent/orchestration/workflow_runs/schemas.rs
@@ -212,6 +212,7 @@ fn handle_start(ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFutur
.map(str::to_string);
log::debug!(target: "workflow_run_rpc", "[workflow_run_rpc][{cid}] start.definition={definition_id}");
let run = super::engine::start_workflow_run(
+ &ctx,
&config,
&definition_id,
input,
@@ -262,7 +263,7 @@ fn handle_resume(ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFutu
.and_then(|v| v.as_str())
.ok_or_else(|| "missing required param: id".to_string())?;
log::debug!(target: "workflow_run_rpc", "[workflow_run_rpc][{cid}] resume.id={id}");
- let run = super::engine::resume_workflow_run(&config, id).await.map_err(|e| {
+ let run = super::engine::resume_workflow_run(&ctx, &config, id).await.map_err(|e| {
let s = e.to_string();
log::warn!(target: "workflow_run_rpc", "[workflow_run_rpc][{cid}] resume.error id={id} err={s}");
s