Skip to content

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

chore: files changed crates/openhuman-core/src/flows/ops/resume.rs,crates/openhuman-core/src/flows/o

Steven Enamakel374eeece0093
diff --git a/crates/openhuman-core/src/flows/ops/resume.rs b/crates/openhuman-core/src/flows/ops/resume.rs
index 592d456ccf..754ac5528f 100644
--- a/crates/openhuman-core/src/flows/ops/resume.rs
+++ b/crates/openhuman-core/src/flows/ops/resume.rs
@@ -25,6 +25,26 @@ pub async fn flows_resume(
approvals: Vec<String>,
rejections: Vec<String>,
) -> Result<Outcome<Value>, String> {
+ flows_resume_with_refusal_hook(ctx, config, flow_id, thread_id, approvals, rejections, || {})
+ .await
+}
+
+/// Runs the resume lifecycle with an invocation-scoped hook immediately
+/// before either parked-run refusal attempts its compare-and-swap. Production
+/// callers use the no-op hook; tests use it to place a competing resume
+/// between the snapshot read and the guarded settlement without timing races.
+pub(super) async fn flows_resume_with_refusal_hook<F>(
+ ctx: &crate::core::runtime::DispatchCtx,
+ config: &Config,
+ flow_id: &str,
+ thread_id: &str,
+ approvals: Vec<String>,
+ rejections: Vec<String>,
+ mut before_refusal_settle: F,
+) -> Result<Outcome<Value>, String>
+where
+ F: FnMut(),
+{
let flow = store::get_flow(config, flow_id)
.map_err(|e| e.to_string())?
.ok_or_else(|| format!("flow '{flow_id}' not found"))?;
@@ -123,6 +143,7 @@ pub async fn flows_resume(
//
// A is refused either way: its own view of the graph is stale,
// so it must never proceed regardless of who owns the row.
+ before_refusal_settle();
let settled_by_us = super::run_management::settle_parked_run(
config,
thread_id,
@@ -165,6 +186,7 @@ pub async fn flows_resume(
// A pending checkpoint may have been created before this compatibility
// gate shipped, so resume is an independent authoritative boundary.
if let Err(error) = ensure_config_aware_engine_compatible(config, &flow.graph) {
+ before_refusal_settle();
let settled_by_us =
super::run_management::settle_parked_run(config, thread_id, flow_id, "failed", &error)
.await;
diff --git a/crates/openhuman-core/src/flows/ops/run_management.rs b/crates/openhuman-core/src/flows/ops/run_management.rs
index 5176f48e14..62156d97f6 100644
--- a/crates/openhuman-core/src/flows/ops/run_management.rs
+++ b/crates/openhuman-core/src/flows/ops/run_management.rs
@@ -25,6 +25,22 @@ pub async fn flows_cancel_run(config: &Config, run_id: &str) -> Result<Outcome<V
let run = store::get_flow_run(config, run_id)
.map_err(|e| e.to_string())?
.ok_or_else(|| format!("flow run '{run_id}' not found"))?;
+ flows_cancel_run_with_snapshot(config, run_id, run, || {}).await
+}
+
+/// Runs cancellation from the persisted-row snapshot. The invocation-scoped
+/// hook lets tests place a resume claim after cancellation observes no registry
+/// entry and before the parked-only compare-and-swap, without sleeps or shared
+/// global state.
+pub(super) async fn flows_cancel_run_with_snapshot<F>(
+ config: &Config,
+ run_id: &str,
+ run: FlowRun,
+ mut before_parked_settle: F,
+) -> Result<Outcome<Value>, String>
+where
+ F: FnMut(),
+{
if rm::is_terminal_run_status(&run.status) {
return Err(rm::already_terminal_error(run_id, &run.status));
@@ -67,6 +83,7 @@ pub async fn flows_cancel_run(config: &Config, run_id: &str) -> Result<Outcome<V
// A resume may claim this parked row after the initial read and after
// `cancel` found no registry entry; the parked-only CAS then loses
// cleanly instead of tearing down the starting resume.
+ before_parked_settle();
settle_parked_run(config, run_id, &run.flow_id, "cancelled", "run cancelled").await
} else {
// A stale `running` row cannot be newly claimed by ResumeRun, so the