The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
test(workflow_runs): cover losing resume cas preserving installed generation
Steven Enamakele6f2eca0b97f
diff --git a/crates/openhuman-core/src/agent/orchestration/workflow_runs/engine/lifecycle_tests.rs b/crates/openhuman-core/src/agent/orchestration/workflow_runs/engine/lifecycle_tests.rsindex 36c4714b8e..8e74e0ea75 100644--- a/crates/openhuman-core/src/agent/orchestration/workflow_runs/engine/lifecycle_tests.rs+++ b/crates/openhuman-core/src/agent/orchestration/workflow_runs/engine/lifecycle_tests.rs@@ -137,3 +137,87 @@ async fn stale_workflow_generation_cannot_fail_its_replacement() {assert_eq!(stopped.status, WorkflowRunStatus::Interrupted);assert!(current.cancellation_token().is_cancelled());}++#[tokio::test]+async fn losing_resume_cas_keeps_the_installed_workflow_generation() {+ let workspace = tempfile::tempdir().expect("workspace");+ let config = Config {+ workspace_dir: workspace.path().to_path_buf(),+ ..Config::default()+ };+ let run_id = format!("resume-cas-race-{}", uuid::Uuid::new_v4());+ let interrupted = crate::storage::sessions::with_ledger(&config.workspace_dir, |ledger| {+ let row = WorkflowRunUpsert {+ id: run_id.clone(),+ definition_id: "parallel_research_cross_check".into(),+ parent_thread_id: None,+ input: json!({"question":"q"}),+ phase_states: json!({"research":{"status":"pending","outputs":[]}}),+ child_run_ids: Vec::new(),+ status: WorkflowRunStatus::Interrupted,+ summary: None,+ started_at: None,+ completed_at: None,+ };+ async move { ledger.upsert_workflow_run(row).await }+ })+ .expect("seed interrupted run");++ let supervisor = workflow_supervisor().clone();+ let old = supervisor.start_scoped_with_handle(+ run_id.clone(),+ |token| async move { token.cancelled().await },+ |future| future,+ |future| future,+ |_handle, future| {+ tokio::spawn(future);+ },+ );+ let make_commit = || {+ let config = config.clone();+ let interrupted = interrupted.clone();+ move || {+ compare_and_swap_workflow_run_lifecycle(+ &config,+ WorkflowRunUpsert {+ id: interrupted.id.clone(),+ definition_id: interrupted.definition_id.clone(),+ parent_thread_id: interrupted.parent_thread_id.clone(),+ input: interrupted.input.clone(),+ phase_states: interrupted.phase_states.clone(),+ child_run_ids: interrupted.child_run_ids.clone(),+ status: WorkflowRunStatus::Running,+ summary: interrupted.summary.clone(),+ started_at: Some(interrupted.started_at),+ completed_at: None,+ },+ interrupted.revision,+ )?+ .ok_or_else(|| anyhow!("workflow run changed before resume"))+ }+ };+ let resume = |commit| {+ supervisor.resume_scoped_with_commit(+ run_id.clone(),+ commit,+ |token| async move { token.cancelled().await },+ |future| future,+ |future| future,+ |_handle, future| {+ tokio::spawn(future);+ },+ )+ };++ let (winner, resumed) = resume(make_commit()).expect("one resume commits");+ assert!(old.cancellation_token().is_cancelled());+ assert!(supervisor.is_current(&winner));+ assert_eq!(resumed.status, WorkflowRunStatus::Running);++ assert!(resume(make_commit()).is_err(), "stale resume CAS must lose");+ assert!(supervisor.is_current(&winner));+ assert!(+ !winner.cancellation_token().is_cancelled(),+ "a losing resume must not cancel the committed generation"+ );+}