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
refactor(flows): simplify flow stream finalization and tests
Steven Enamakel9745e7afb9d5
diff --git a/crates/openhuman-core/src/flows/ops/streaming.rs b/crates/openhuman-core/src/flows/ops/streaming.rsindex eb06c5a5a1..eb50a67cb7 100644--- a/crates/openhuman-core/src/flows/ops/streaming.rs+++ b/crates/openhuman-core/src/flows/ops/streaming.rs@@ -98,7 +98,7 @@ pub(super) async fn finalize_flow_stream(target: &FlowStreamTarget,result: &Result<String, String>,prompt: &str,- _config: &Config,+ config: &Config,) {match result {Ok(text) => {@@ -146,24 +146,25 @@ pub(super) async fn finalize_flow_stream(// left non-terminal makes `threads_turn_state_get` report the turn as still// running, so re-entering the thread paints a permanent "Thinking..."// indicator under a reply that already landed.- if let Ok(config) = ctx.load_config().await {- let lifecycle = if result.is_ok() {- tinyagents_session::turn_state::TurnLifecycle::Completed- } else {- tinyagents_session::turn_state::TurnLifecycle::Interrupted- };- let now = chrono::Utc::now().to_rfc3339();- if let Err(err) = crate::storage::sessions::turn_states_for(&config.workspace_dir)- .settle_turn(&target.thread_id, &target.request_id, lifecycle, &now)- {- tracing::warn!(- target: "flows",- thread_id = %target.thread_id,- request_id = %target.request_id,- error = %err,- "[flows] failed to settle turn snapshot"- );- }+ let lifecycle = if result.is_ok() {+ tinyagents_session::turn_state::TurnLifecycle::Completed+ } else {+ tinyagents_session::turn_state::TurnLifecycle::Interrupted+ };+ let now = chrono::Utc::now().to_rfc3339();+ if let Err(err) = crate::storage::sessions::turn_states_for(&config.workspace_dir).settle_turn(+ &target.thread_id,+ &target.request_id,+ lifecycle,+ &now,+ ) {+ tracing::warn!(+ target: "flows",+ thread_id = %target.thread_id,+ request_id = %target.request_id,+ error = %err,+ "[flows] failed to settle turn snapshot"+ );}tracing::info!(target: "flows",diff --git a/crates/openhuman-core/src/flows/ops_resume_decision_tests.rs b/crates/openhuman-core/src/flows/ops_resume_decision_tests.rsindex 63d853991b..c1d404942e 100644--- a/crates/openhuman-core/src/flows/ops_resume_decision_tests.rs+++ b/crates/openhuman-core/src/flows/ops_resume_decision_tests.rs@@ -92,22 +92,9 @@ async fn flows_resume_with_mismatched_approvals_is_rejected() {async fn flows_resume_with_the_correct_gate_completes_and_runs_downstream() {let tmp = TempDir::new().unwrap();let config = test_config(&tmp);- let created = flows_create(&config, "gated".to_string(), approval_gated_graph(), false).await;- if std::env::var_os("OPENHUMAN_TINYFLOWS_RUN_DIAGNOSTICS").is_some() {- if let Err(error) = &created {- let tenant_scoped = crate::core::runtime::DispatchCtx::ambient()- .tenant()- .map(|tenant| tenant.is_scoped())- .unwrap_or(false);- let module_state = crate::modules::ops::state_of("tinyflows");- eprintln!(- "flows_create after resume fixtures failed: {error}; workspace={}; tenant_scoped={tenant_scoped}; TinyFlows state={module_state:?}; artifact={:?}",- config.workspace_dir.display(),- crate::modules::local_artifact("tinyflows")- );- }- }- let created = created.unwrap();+ let created = flows_create(&config, "gated".to_string(), approval_gated_graph(), false)+ .await+ .unwrap();let run = flows_run(&crate::core::runtime::DispatchCtx::ambient(),@@ -312,41 +299,6 @@ async fn flows_resume_of_a_non_paused_run_errors_clearly() {.await.expect_err("resuming an already-completed run must be a clear error, not a silent no-op");let expected = "is not waiting for approval";- if std::env::var_os("OPENHUMAN_TINYFLOWS_RUN_DIAGNOSTICS").is_some() || !err.contains(expected)- {- let dispatch = crate::core::runtime::DispatchCtx::ambient();- let tenant_scoped = dispatch- .tenant()- .map(|tenant| tenant.is_scoped())- .unwrap_or(false);- let module_state = crate::modules::ops::state_of("tinyflows");- let module_version = crate::modules::registry::find("tinyflows")- .map(|record| record.version)- .unwrap_or("missing");- let loaded_module = crate::modules::runtime::runtime()- .await- .ok()- .and_then(|runtime| {- runtime- .host()- .list()- .into_iter()- .find(|module| module.name == "tinyflows-module")- });- eprintln!(- "ResumeRun nonparked-status diagnostic: error={err}; workspace={}; tenant_scoped={tenant_scoped}; TinyFlows state={module_state:?}; registry_version={module_version}; loaded_version={}; loaded_file={}; artifact={:?}",- config.workspace_dir.display(),- loaded_module- .as_ref()- .map(|module| module.version.as_str())- .unwrap_or("missing"),- loaded_module- .as_ref()- .map(|module| module.file.as_str())- .unwrap_or("missing"),- crate::modules::local_artifact("tinyflows")- );- }assert!(err.contains(expected),"expected a clear non-paused-run error, got: {err}"diff --git a/crates/openhuman-core/src/flows/ops_run_rows_and_notifications_tests.rs b/crates/openhuman-core/src/flows/ops_run_rows_and_notifications_tests.rsindex de572a6d52..6763f7d824 100644--- a/crates/openhuman-core/src/flows/ops_run_rows_and_notifications_tests.rs+++ b/crates/openhuman-core/src/flows/ops_run_rows_and_notifications_tests.rs@@ -18,7 +18,18 @@ async fn flows_resume_with_no_recorded_run_for_thread_id_errors_clearly() {).await.expect_err("must error when no run is recorded for this thread_id");- assert!(err.contains("flow run does not exist in this owner scope"));+ assert!(+ err.contains("thread-that-was-never-started") && err.contains("not found"),+ "unexpected missing-run error: {err}"+ );+ assert!(+ flows_list_runs(&config, &created.value.id, 20)+ .await+ .unwrap()+ .value+ .is_empty(),+ "rejecting an unknown thread must not admit a run"+ );}// ── run history (flows_list_runs / flows_get_run) ────────────────────────@@ -621,9 +632,14 @@ async fn flows_cancel_run_cancels_a_parked_pending_approval_run() {.await.expect_err("a cancelled run must not be resumable");assert!(- err.contains("flow run is not parked for approval (status: cancelled)"),- "{err}"+ err.contains(&format!(+ "flow run '{thread_id}' is not waiting for approval"+ )),+ "unexpected cancelled-run resume error: {err}");+ let unchanged = flows_get_run(&config, &thread_id).await.unwrap().value;+ assert_eq!(unchanged.status, "cancelled");+ assert!(unchanged.pending_approvals.is_empty());}#[tokio::test]diff --git a/crates/openhuman-core/src/flows/ops_validate_warnings_and_connections_tests.rs b/crates/openhuman-core/src/flows/ops_validate_warnings_and_connections_tests.rsindex aa250f5b1a..f4b00c7ec5 100644--- a/crates/openhuman-core/src/flows/ops_validate_warnings_and_connections_tests.rs+++ b/crates/openhuman-core/src/flows/ops_validate_warnings_and_connections_tests.rs@@ -139,15 +139,6 @@ async fn flows_validate_reports_error_for_graph_without_trigger() {graph,).await;- if std::env::var_os("OPENHUMAN_TINYFLOWS_RUN_DIAGNOSTICS").is_some() {- eprintln!(- "flows_validate structural diagnostic: valid={} errors={:?} warnings={:?} error_details={:?}",- outcome.value.valid,- outcome.value.errors,- outcome.value.warnings,- outcome.value.error_details- );- }assert!(!outcome.value.valid);assert_eq!(outcome.value.errors.len(), 1);assert!(outcome.value.errors[0].contains("trigger"));