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: add coverage for channel routes, memory lifecycle, and web chat
Steven Enamakel790cfefb8ff4
diff --git a/crates/openhuman-core/src/channels/routes_tests.rs b/crates/openhuman-core/src/channels/routes_tests.rsindex d07e782664..593e679f6f 100644--- a/crates/openhuman-core/src/channels/routes_tests.rs+++ b/crates/openhuman-core/src/channels/routes_tests.rs@@ -245,7 +245,7 @@ async fn sign_out_cancels_remote_invalidation_while_it_waits_for_the_session_tabcrate::core::runtime::CoreContext::for_test(crate::core::runtime::DomainSet::full(), None);let expected_core_context = Arc::clone(&core_context);crate::core::runtime::CoreContext::scope(core_context, async {- let guard = crate::web_chat::lock_thread_sessions_for_test().await;+ let guard = crate::web_chat::lock_thread_sessions_for_test(&crate::core::runtime::DispatchCtx::ambient()).await;let cancellation = tokio_util::sync::CancellationToken::new();let callback = RouteCallbacks::new(runtime_context(PathBuf::from("/tmp/channel-callback")),diff --git a/crates/openhuman-core/src/core/runtime/agent_scope_tests.rs b/crates/openhuman-core/src/core/runtime/agent_scope_tests.rsindex 5bff910341..4623c7a8f5 100644--- a/crates/openhuman-core/src/core/runtime/agent_scope_tests.rs+++ b/crates/openhuman-core/src/core/runtime/agent_scope_tests.rs@@ -177,9 +177,9 @@ async fn spawn_scoped_keeps_the_agent_context_and_tokio_spawn_does_not() {}#[test]-fn current_slot_without_a_context_uses_the_unscoped_state() {- let first = current_slot::<Counter>();- let second = current_slot::<Counter>();+fn slot_without_a_context_uses_the_unscoped_state() {+ let first = slot_for::<Counter>(&crate::core::runtime::DispatchCtx::ambient());+ let second = slot_for::<Counter>(&crate::core::runtime::DispatchCtx::ambient());assert!(Arc::ptr_eq(&first, &second));}diff --git a/crates/openhuman-core/src/memory/lifecycle/hooks_tests.rs b/crates/openhuman-core/src/memory/lifecycle/hooks_tests.rsindex b1e7fb9b66..ba5de36ba1 100644--- a/crates/openhuman-core/src/memory/lifecycle/hooks_tests.rs+++ b/crates/openhuman-core/src/memory/lifecycle/hooks_tests.rs@@ -83,7 +83,7 @@ async fn pre_turn_logs_the_user_turn_and_injects_what_memory_holds() {.expect("a pack");assert!(pack.markdown.contains("teal"), "{}", pack.markdown);assert!(!pack.refs.is_empty());- let chips = crate::memory::tools::take_turn_citations("t1");+ let chips = crate::memory::tools::take_turn_citations(&crate::core::runtime::DispatchCtx::ambient(), "t1");assert!(chips.iter().any(|chip| chip.snippet.contains("teal")),"the pack's citations reach the chat: {chips:?}"diff --git a/crates/openhuman-core/src/memory/lifecycle/prefetch_tests.rs b/crates/openhuman-core/src/memory/lifecycle/prefetch_tests.rsindex 6de2935101..fb28073128 100644--- a/crates/openhuman-core/src/memory/lifecycle/prefetch_tests.rs+++ b/crates/openhuman-core/src/memory/lifecycle/prefetch_tests.rs@@ -313,23 +313,23 @@ async fn slow_engine_results_survive_the_manual_pre_turn_cutoff() {observed_actor: None,};let config = Arc::new(config);- assert!(pre_turn(config.clone(), identity.clone(), input(0), None).is_none());+ assert!(pre_turn(&crate::core::runtime::DispatchCtx::ambient(), config.clone(), identity.clone(), input(0), None).is_none());// Even after the old one-millisecond cutoff, the pack remains owned by// the background worker instead of being discarded by the live turn.tokio::time::sleep(Duration::from_millis(5)).await;- let cache = cache();+ let cache = cache(&crate::core::runtime::DispatchCtx::ambient());let key = Key::new(&config, &identity, "slow", false);assert!(completed(&cache, &key).is_none());release.add_permits(100);drain(&cache, &key).await;- let pack = pre_turn(config.clone(), identity.clone(), input(2), None)+ let pack = pre_turn(&crate::core::runtime::DispatchCtx::ambient(), config.clone(), identity.clone(), input(2), None).expect("next turn uses completed slow lookup");assert!(pack.markdown.contains("teal"));assert!(pack.markdown.contains("earlier turn"));drain(&cache, &key).await;let mut omitted = identity;omitted.recall = false;- assert!(pre_turn(config.clone(), omitted.clone(), input(4), None).is_none());+ assert!(pre_turn(&crate::core::runtime::DispatchCtx::ambient(), config.clone(), omitted.clone(), input(4), None).is_none());drain(&cache, &Key::new(&config, &omitted, "slow", false)).await;let turns = crate::memory::test_fixtures::stored(&engine.inner,@@ -351,7 +351,7 @@ async fn queued_work_keeps_the_callers_core_context() {crate::core::runtime::CoreContext::scope(ctx.clone(), async {let identity = MemoryIdentity::agent("scoped-agent").resolve(&config);let key = Key::new(&config, &identity, "t", false);- let cache = cache();+ let cache = cache(&crate::core::runtime::DispatchCtx::ambient());let expected = ctx.clone();enqueue(cache.clone(),diff --git a/crates/openhuman-core/src/memory/lifecycle/views_tests.rs b/crates/openhuman-core/src/memory/lifecycle/views_tests.rsindex 78f2ff5c4f..5563d2b2c3 100644--- a/crates/openhuman-core/src/memory/lifecycle/views_tests.rs+++ b/crates/openhuman-core/src/memory/lifecycle/views_tests.rs@@ -74,6 +74,7 @@ async fn the_preview_reads_without_logging_and_agents_are_listed() {.unwrap();let writer = scope::MemoryIdentity::agent("writer").resolve(&config);hooks::pre_turn(+ &crate::core::runtime::DispatchCtx::ambient(),&config,&writer,PreTurnInput {diff --git a/crates/openhuman-core/src/memory/tools_tests.rs b/crates/openhuman-core/src/memory/tools_tests.rsindex 94e7c4f0cb..523f1d3e04 100644--- a/crates/openhuman-core/src/memory/tools_tests.rs+++ b/crates/openhuman-core/src/memory/tools_tests.rs@@ -88,7 +88,7 @@ async fn every_action_reports_memory_off_as_a_tool_error() {json!({"action": "learn", "text": "t"}),json!({"action": "forget", "ids": ["a"]}),] {- let result = run_action(&config, &args, &facts()).await;+ let result = run_action(&crate::core::runtime::DispatchCtx::ambient(), &config, &args, &facts()).await;assert!(result.is_error, "{args}");assert!(text(&result).contains("MEMORY_OFF"), "{}", text(&result));}@@ -100,15 +100,15 @@ async fn bad_arguments_and_unknown_actions_are_model_visible_errors() {let config = config_in(&tmp);bind_reference(&config);- let unknown = run_action(&config, &json!({"action": "explode"}), &facts()).await;+ let unknown = run_action(&crate::core::runtime::DispatchCtx::ambient(), &config, &json!({"action": "explode"}), &facts()).await;assert!(unknown.is_error);assert!(text(&unknown).contains("unknown action `explode`"));- let missing = run_action(&config, &json!({}), &facts()).await;+ let missing = run_action(&crate::core::runtime::DispatchCtx::ambient(), &config, &json!({}), &facts()).await;assert!(missing.is_error);for action in ["recall", "fetch", "learn", "forget"] {- let result = run_action(&config, &json!({ "action": action }), &facts()).await;+ let result = run_action(&crate::core::runtime::DispatchCtx::ambient(), &config, &json!({ "action": action }), &facts()).await;assert!(result.is_error, "{action}");assert!(text(&result).contains("invalid arguments"), "{action}");}@@ -128,7 +128,7 @@ async fn learn_stamps_what_the_host_knows_and_ignores_model_meta() {// The model must not be able to forge host-owned fields."meta": {"thread_id": "forged", "agent_id": "forged"},});- let result = run_action(&config, &args, &facts()).await;+ let result = run_action(&crate::core::runtime::DispatchCtx::ambient(), &config, &args, &facts()).await;assert!(!result.is_error, "{}", text(&result));let id = serde_json::from_str::<Value>(&text(&result)).unwrap()["id"].as_str()@@ -166,6 +166,7 @@ async fn recall_fetch_and_forget_round_trip_and_recall_records_citations() {};let learned = run_action(+ &crate::core::runtime::DispatchCtx::ambient(),&config,&json!({"action": "learn", "text": "The user likes oolong tea"}),&facts,@@ -177,20 +178,22 @@ async fn recall_fetch_and_forget_round_trip_and_recall_records_citations() {.to_string();let recalled = run_action(+ &crate::core::runtime::DispatchCtx::ambient(),&config,&json!({"action": "recall", "question": "oolong tea"}),&facts,).await;assert!(!recalled.is_error, "{}", text(&recalled));- let cites = take_turn_citations("thread-citations");+ let cites = take_turn_citations(&crate::core::runtime::DispatchCtx::ambient(), "thread-citations");assert!(cites.iter().any(|c| c.id == id), "{cites:?}");assert!(- take_turn_citations("thread-citations").is_empty(),+ take_turn_citations(&crate::core::runtime::DispatchCtx::ambient(), "thread-citations").is_empty(),"draining empties the thread's citations");let fetched = run_action(+ &crate::core::runtime::DispatchCtx::ambient(),&config,&json!({"action": "fetch", "query": "oolong", "mode": "keyword", "limit": 5}),&facts,@@ -205,7 +208,7 @@ async fn recall_fetch_and_forget_round_trip_and_recall_records_citations() {1);- let forgotten = run_action(&config, &json!({"action": "forget", "ids": [id]}), &facts).await;+ let forgotten = run_action(&crate::core::runtime::DispatchCtx::ambient(), &config, &json!({"action": "forget", "ids": [id]}), &facts).await;assert!(!forgotten.is_error, "{}", text(&forgotten));assert!(engine.is_empty());}@@ -220,12 +223,14 @@ async fn recall_without_a_thread_records_no_citations() {..facts()};run_action(+ &crate::core::runtime::DispatchCtx::ambient(),&config,&json!({"action": "learn", "text": "fact one"}),&no_thread,).await;let result = run_action(+ &crate::core::runtime::DispatchCtx::ambient(),&config,&json!({"action": "recall", "question": "fact one"}),&no_thread,@@ -248,6 +253,7 @@ async fn fetch_with_an_undeclared_mode_is_unsupported() {).unwrap();let result = run_action(+ &crate::core::runtime::DispatchCtx::ambient(),&config,&json!({"action": "fetch", "query": "x", "mode": "keyword"}),&facts(),@@ -271,7 +277,7 @@ fn turn_citations_are_capped_and_deduplicated() {record_turn_citations(thread, &many);record_turn_citations(thread, &many[..2]);record_turn_citations(thread, &[]);- let drained = take_turn_citations(thread);+ let drained = take_turn_citations(&crate::core::runtime::DispatchCtx::ambient(), thread);assert_eq!(drained.len(), MAX_TURN_CITATIONS);assert_eq!(drained@@ -356,6 +362,7 @@ async fn learnings_are_shared_under_a_root_and_a_team_root_is_kept_apart() {let config = config.clone();async move {let result = run_action(+ &crate::core::runtime::DispatchCtx::ambient(),&config,&json!({"action": "learn", "text": text, "share": true}),&facts,@@ -390,6 +397,7 @@ async fn learnings_are_shared_under_a_root_and_a_team_root_is_kept_apart() {let config = config.clone();async move {run_action(+ &crate::core::runtime::DispatchCtx::ambient(),&config,&json!({"action": "fetch", "query": "the", "limit": 50, "filter": {"reach": null}}),&facts,@@ -413,6 +421,7 @@ async fn learnings_are_shared_under_a_root_and_a_team_root_is_kept_apart() {.find(|hit| hit.text.contains("deploy day")).unwrap();let forgot = run_action(+ &crate::core::runtime::DispatchCtx::ambient(),&config,&json!({"action": "forget", "ids": [main_item.id.0.clone()]}),&member(),@@ -501,6 +510,7 @@ async fn learn_returns_on_accept_and_says_recall_may_lag() {crate::memory::engine::install_test_engine(&config.workspace_dir, engine.clone());let learned = run_action(+ &crate::core::runtime::DispatchCtx::ambient(),&config,&json!({"action": "learn", "text": "The user drinks oolong"}),&facts(),@@ -543,6 +553,7 @@ async fn a_failed_learn_is_reported_to_the_model() {crate::memory::test_fixtures::RefusingEngine::out_of_credits().bind(&config);let learned = run_action(+ &crate::core::runtime::DispatchCtx::ambient(),&config,&json!({"action": "learn", "text": "The user drinks oolong"}),&facts(),@@ -617,6 +628,7 @@ async fn refers_to_reaches_the_engine_in_the_users_time_zone() {crate::memory::engine::install_test_engine(&config.workspace_dir, engine.clone());let fetched = run_action(+ &crate::core::runtime::DispatchCtx::ambient(),&config,&json!({"action": "fetch", "query": "dinner", "refers_to": {"from": "2026-10-03", "to": "2026-10-04"}}),&facts(),@@ -624,6 +636,7 @@ async fn refers_to_reaches_the_engine_in_the_users_time_zone() {.await;assert!(!fetched.is_error, "{}", text(&fetched));let recalled = run_action(+ &crate::core::runtime::DispatchCtx::ambient(),&config,&json!({"action": "recall", "question": "dinner", "refers_to": {"from": "2026-10-03"}}),&facts(),@@ -631,6 +644,7 @@ async fn refers_to_reaches_the_engine_in_the_users_time_zone() {.await;assert!(!recalled.is_error, "{}", text(&recalled));let bad = run_action(+ &crate::core::runtime::DispatchCtx::ambient(),&config,&json!({"action": "fetch", "query": "dinner", "refers_to": {"from": "last Saturday"}}),&facts(),diff --git a/crates/openhuman-core/src/web_chat/ops/state_tests.rs b/crates/openhuman-core/src/web_chat/ops/state_tests.rsindex f24b269476..730c61a4a5 100644--- a/crates/openhuman-core/src/web_chat/ops/state_tests.rs+++ b/crates/openhuman-core/src/web_chat/ops/state_tests.rs@@ -21,14 +21,14 @@ async fn each_agent_context_owns_its_turn_tables() {let (alpha_sessions, alpha_in_flight, alpha_parallel) =CoreContext::scope(Arc::clone(&alpha), async {- (thread_sessions(), in_flight(), parallel_in_flight())+ (thread_sessions(&crate::core::runtime::DispatchCtx::ambient()), in_flight(&crate::core::runtime::DispatchCtx::ambient()), parallel_in_flight(&crate::core::runtime::DispatchCtx::ambient()))}).await;let (beta_sessions, beta_in_flight, beta_parallel) = CoreContext::scope(beta, async {- (thread_sessions(), in_flight(), parallel_in_flight())+ (thread_sessions(&crate::core::runtime::DispatchCtx::ambient()), in_flight(&crate::core::runtime::DispatchCtx::ambient()), parallel_in_flight(&crate::core::runtime::DispatchCtx::ambient()))}).await;- let alpha_again = CoreContext::scope(alpha, async { in_flight() }).await;+ let alpha_again = CoreContext::scope(alpha, async { in_flight(&crate::core::runtime::DispatchCtx::ambient()) }).await;assert!(!Arc::ptr_eq(&alpha_sessions, &beta_sessions));assert!(!Arc::ptr_eq(&alpha_in_flight, &beta_in_flight));diff --git a/crates/openhuman-core/src/web_chat/ops_budget_correlation_tests_tests.rs b/crates/openhuman-core/src/web_chat/ops_budget_correlation_tests_tests.rsindex 5aa554b05c..e21b64f3eb 100644--- a/crates/openhuman-core/src/web_chat/ops_budget_correlation_tests_tests.rs+++ b/crates/openhuman-core/src/web_chat/ops_budget_correlation_tests_tests.rs@@ -112,7 +112,7 @@ async fn record_prunes_other_threads_stale_entries() {// ...which a later budget event on a DIFFERENT thread sweeps away.record_budget_signal(&ctx(), active, BINDING).await;{- let signals = thread_budget_signals().lock_owned().await;+ let signals = thread_budget_signals(&crate::core::runtime::DispatchCtx::ambient()).lock_owned().await;assert!(!signals.contains_key(abandoned),"stale entry should be pruned"diff --git a/crates/openhuman-core/src/web_chat/session_checkout_agents_tests.rs b/crates/openhuman-core/src/web_chat/session_checkout_agents_tests.rsindex 33ae86942a..a6f0a317b0 100644--- a/crates/openhuman-core/src/web_chat/session_checkout_agents_tests.rs+++ b/crates/openhuman-core/src/web_chat/session_checkout_agents_tests.rs@@ -55,7 +55,7 @@ async fn two_agents_with_the_same_thread_id_get_their_own_cache_slots() {fingerprint: fingerprint.clone(),};CoreContext::scope(Arc::clone(ctx), async {- thread_sessions()+ thread_sessions(&crate::core::runtime::DispatchCtx::ambient()).lock_owned().await.insert(key.clone(), entry);@@ -66,7 +66,7 @@ async fn two_agents_with_the_same_thread_id_get_their_own_cache_slots() {let (ctx, key) = (Arc::clone(ctx), key.clone());async move {CoreContext::scope(ctx, async move {- thread_sessions().lock_owned().await.contains_key(&key)+ thread_sessions(&crate::core::runtime::DispatchCtx::ambient()).lock_owned().await.contains_key(&key)}).await}diff --git a/crates/openhuman-core/src/web_chat/session_checkout_tests.rs b/crates/openhuman-core/src/web_chat/session_checkout_tests.rsindex 12e06dcff4..01e7950500 100644--- a/crates/openhuman-core/src/web_chat/session_checkout_tests.rs+++ b/crates/openhuman-core/src/web_chat/session_checkout_tests.rs@@ -154,7 +154,7 @@ async fn checkout_cold_boots_from_the_thread_transcript_and_checkin_keeps_it_war);checkin_session_agent(&DispatchCtx::ambient(), &thread_id, agent, fingerprint).await;- assert!(thread_sessions()+ assert!(thread_sessions(&crate::core::runtime::DispatchCtx::ambient()).lock().await.contains_key(&key_for(&DispatchCtx::ambient(), &thread_id)));@@ -179,7 +179,7 @@ async fn checkout_cold_boots_from_the_thread_transcript_and_checkin_keeps_it_war"warm checkout must carry the same history");// Checked out means removed: nobody else can drive this agent meanwhile.- assert!(!thread_sessions()+ assert!(!thread_sessions(&crate::core::runtime::DispatchCtx::ambient()).lock().await.contains_key(&key_for(&DispatchCtx::ambient(), &thread_id)));@@ -287,7 +287,7 @@ async fn a_fork_never_takes_or_returns_the_cached_agent() {// Built fresh: no transcript on disk for this thread, so an empty history.assert!(prose(&agent.history()).is_empty());// The primary's cached agent was left in place.- assert!(thread_sessions()+ assert!(thread_sessions(&crate::core::runtime::DispatchCtx::ambient()).lock().await.contains_key(&key_for(&DispatchCtx::ambient(), &thread_id)));@@ -671,7 +671,7 @@ async fn each_checkout_arms_the_reply_language_from_its_own_locale() {// Reused cached agent, the user switched the UI to English: the Spanish// directives already in the history are superseded explicitly.assert!(- thread_sessions()+ thread_sessions(&crate::core::runtime::DispatchCtx::ambient()).lock().await.contains_key(&key_for(&DispatchCtx::ambient(), &thread_id)),@@ -685,7 +685,7 @@ async fn each_checkout_arms_the_reply_language_from_its_own_locale() {checkin_session_agent(&DispatchCtx::ambient(), &thread_id, agent, fingerprint).await;// Reused again, now Hindi: re-armed with the new language.- assert!(thread_sessions()+ assert!(thread_sessions(&crate::core::runtime::DispatchCtx::ambient()).lock().await.contains_key(&key_for(&DispatchCtx::ambient(), &thread_id)));diff --git a/crates/openhuman-core/src/web_chat/web_tests_queue_acceptance_tests.rs b/crates/openhuman-core/src/web_chat/web_tests_queue_acceptance_tests.rsindex f18eab8b63..cc99222b10 100644--- a/crates/openhuman-core/src/web_chat/web_tests_queue_acceptance_tests.rs+++ b/crates/openhuman-core/src/web_chat/web_tests_queue_acceptance_tests.rs@@ -455,7 +455,7 @@ async fn chat_done_is_published_only_after_the_in_flight_slot_is_released() {event.event == "chat_done" && event.request_id == request_id};- let held = crate::web_chat::ops::in_flight().lock_owned().await;+ let held = crate::web_chat::ops::in_flight(&crate::core::runtime::DispatchCtx::ambient()).lock_owned().await;block.release.notify_one();let early = timeout(Duration::from_millis(500), async {loop {