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
fix(threads): thread dispatch context through store and ops calls
Steven Enamakel591a506fcf2d
diff --git a/crates/openhuman-core/src/agent/attachments/mod_access_tests.rs b/crates/openhuman-core/src/agent/attachments/mod_access_tests.rsindex 21ef4eea0e..5f7a19a90c 100644--- a/crates/openhuman-core/src/agent/attachments/mod_access_tests.rs+++ b/crates/openhuman-core/src/agent/attachments/mod_access_tests.rs@@ -118,6 +118,7 @@ async fn delegation_rejects_malformed_explicit_paths_and_external_reads_before_casync fn thread_in(config: &Config, id: &str, working_dir: Option<&Path>) {crate::threads::store::blocking::ensure_thread(+ crate::core::runtime::DispatchCtx::ambient(),config.workspace_dir.clone(),crate::threads::store::CreateConversationThread {id: id.into(),diff --git a/crates/openhuman-core/src/agent/orchestration/tools/spawn_async_subagent_tests.rs b/crates/openhuman-core/src/agent/orchestration/tools/spawn_async_subagent_tests.rsindex 91c84c80e1..77f815a2c3 100644--- a/crates/openhuman-core/src/agent/orchestration/tools/spawn_async_subagent_tests.rs+++ b/crates/openhuman-core/src/agent/orchestration/tools/spawn_async_subagent_tests.rs@@ -396,6 +396,7 @@ fn attach_workflow_proposal_persists_thread_message_and_extends_summary() {use crate::threads::store::CreateConversationThread;let temp = tempfile::tempdir().expect("tempdir");conversations::ensure_thread(+ crate::core::runtime::DispatchCtx::ambient(),temp.path().to_path_buf(),CreateConversationThread {id: "thread-parent".into(),@@ -430,7 +431,7 @@ fn attach_workflow_proposal_persists_thread_message_and_extends_summary() {// Proposal is durably persisted in the parent thread with rehydratable// metadata (this is what survives reload / a dropped socket event).let messages =- conversations::get_messages(temp.path().to_path_buf(), "thread-parent").expect("messages");+ conversations::get_messages(crate::core::runtime::DispatchCtx::ambient(), temp.path().to_path_buf(), "thread-parent").expect("messages");let proposal_msg = messages.iter().find(|m| m.id == "workflow-proposal:sub-task-1")diff --git a/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_tests.rs b/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_tests.rsindex c440b28499..02c5f2a452 100644--- a/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_tests.rs+++ b/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_tests.rs@@ -105,7 +105,7 @@ fn persist_worker_thread_creates_thread_with_tasks_label_and_messages() {assert!(thread_id.starts_with("worker-"));- let threads = conversations::list_threads(temp.path().to_path_buf()).expect("list threads");+ let threads = conversations::list_threads(crate::core::runtime::DispatchCtx::ambient(), temp.path().to_path_buf()).expect("list threads");let worker = threads.iter().find(|t| t.id == thread_id)@@ -114,7 +114,7 @@ fn persist_worker_thread_creates_thread_with_tasks_label_and_messages() {assert!(worker.title.starts_with("draft a long research plan"));let messages =- conversations::get_messages(temp.path().to_path_buf(), &thread_id).expect("messages");+ conversations::get_messages(crate::core::runtime::DispatchCtx::ambient(), temp.path().to_path_buf(), &thread_id).expect("messages");assert_eq!(messages.len(), 2);assert_eq!(messages[0].sender, "user");assert_eq!(messages[0].content, "draft a long research plan");diff --git a/crates/openhuman-core/src/agent/orchestration/tools/spawn_worker_thread_tests.rs b/crates/openhuman-core/src/agent/orchestration/tools/spawn_worker_thread_tests.rsindex 28ba341e9c..adca9fd175 100644--- a/crates/openhuman-core/src/agent/orchestration/tools/spawn_worker_thread_tests.rs+++ b/crates/openhuman-core/src/agent/orchestration/tools/spawn_worker_thread_tests.rs@@ -45,6 +45,7 @@ async fn rejects_if_already_worker_thread() {let temp = TempDir::new().unwrap();let thread_id = "worker-123";conversations::ensure_thread(+ crate::core::runtime::DispatchCtx::ambient(),temp.path().to_path_buf(),CreateConversationThread {id: thread_id.to_string(),@@ -71,6 +72,7 @@ async fn rejects_if_has_parent_thread_id() {let temp = TempDir::new().unwrap();let thread_id = "sub-123";conversations::ensure_thread(+ crate::core::runtime::DispatchCtx::ambient(),temp.path().to_path_buf(),CreateConversationThread {id: thread_id.to_string(),diff --git a/crates/openhuman-core/src/agent/orchestration/tools/tools_e2e_tests.rs b/crates/openhuman-core/src/agent/orchestration/tools/tools_e2e_tests.rsindex 52da93d325..66286a5a08 100644--- a/crates/openhuman-core/src/agent/orchestration/tools/tools_e2e_tests.rs+++ b/crates/openhuman-core/src/agent/orchestration/tools/tools_e2e_tests.rs@@ -466,14 +466,14 @@ async fn spawn_worker_thread_tool_persists_worker_thread_e2e() {assert!(provider.saw(WORKER_THREAD_CANARY));let threads =- conversations::list_threads(workspace.path().to_path_buf()).expect("worker threads");+ conversations::list_threads(crate::core::runtime::DispatchCtx::ambient(), workspace.path().to_path_buf()).expect("worker threads");let worker = threads.iter().find(|thread| thread.labels.contains(&"tasks".to_string())).expect("worker thread was persisted");assert_eq!(worker.title, "Long delegated task");- let messages = conversations::get_messages(workspace.path().to_path_buf(), &worker.id)+ let messages = conversations::get_messages(crate::core::runtime::DispatchCtx::ambient(), workspace.path().to_path_buf(), &worker.id).expect("worker messages");assert_eq!(messages.len(), 2);assert_eq!(messages[0].sender, "user");diff --git a/crates/openhuman-core/src/agent/orchestration/tools/worker_thread_tests.rs b/crates/openhuman-core/src/agent/orchestration/tools/worker_thread_tests.rsindex bde56d0757..96ce771888 100644--- a/crates/openhuman-core/src/agent/orchestration/tools/worker_thread_tests.rs+++ b/crates/openhuman-core/src/agent/orchestration/tools/worker_thread_tests.rs@@ -16,7 +16,7 @@ fn creates_child_thread_linked_to_parent_and_seeds_prompt() {// The new thread is labelled `tasks` and linked to the parent so it// stays grouped with delegated task work in the chat sidebar.- let threads = conversations::list_threads(dir.clone()).unwrap();+ let threads = conversations::list_threads(crate::core::runtime::DispatchCtx::ambient(), dir.clone()).unwrap();let thread = threads.iter().find(|t| t.id == id)@@ -26,7 +26,7 @@ fn creates_child_thread_linked_to_parent_and_seeds_prompt() {// It opens with the delegation prompt as the user message, so the// drawer can render the parent↔subagent chat from memory on reopen.- let messages = conversations::get_messages(dir.clone(), &id).unwrap();+ let messages = conversations::get_messages(crate::core::runtime::DispatchCtx::ambient(), dir.clone(), &id).unwrap();assert_eq!(messages.len(), 1);assert_eq!(messages[0].sender, "user");assert_eq!(messages[0].content, "Find Q3");@@ -49,7 +49,7 @@ fn appends_follow_up_prompt_to_existing_worker_thread() {append_worker_user_message(dir.clone(), &id, "researcher", "sub-2", "Follow-up prompt").unwrap();- let messages = conversations::get_messages(dir.clone(), &id).unwrap();+ let messages = conversations::get_messages(crate::core::runtime::DispatchCtx::ambient(), dir.clone(), &id).unwrap();assert_eq!(messages.len(), 2);assert_eq!(messages[1].sender, "user");assert_eq!(messages[1].content, "Follow-up prompt");diff --git a/crates/openhuman-core/src/agent/subagent_host/ops/graph_policy_tests.rs b/crates/openhuman-core/src/agent/subagent_host/ops/graph_policy_tests.rsindex b9a8bf96c5..bee646ebc9 100644--- a/crates/openhuman-core/src/agent/subagent_host/ops/graph_policy_tests.rs+++ b/crates/openhuman-core/src/agent/subagent_host/ops/graph_policy_tests.rs@@ -213,6 +213,7 @@ fn mirrored_tool_results_are_hidden_from_the_worker_thread_chat() {let now = chrono::Utc::now().to_rfc3339();for id in ["worker-typed", "worker-recovered"] {store::ensure_thread(+ crate::core::runtime::DispatchCtx::ambient(),dir.clone(),CreateConversationThread {id: id.to_string(),@@ -273,7 +274,7 @@ fn mirrored_tool_results_are_hidden_from_the_worker_thread_chat() {// failure names every path that is still painting a tool result as chat.let mut painted_as_user_chat: Vec<String> = Vec::new();for thread_id in ["worker-typed", "worker-recovered"] {- let rows = store::get_messages(dir.clone(), thread_id).unwrap();+ let rows = store::get_messages(crate::core::runtime::DispatchCtx::ambient(), dir.clone(), thread_id).unwrap();assert!(rows.iter().any(|r| r.content == RAW),"{thread_id}: the mirror wrote no tool-result row to assert on"diff --git a/crates/openhuman-core/src/channels/host/adapters.rs b/crates/openhuman-core/src/channels/host/adapters.rsindex 085b7dd328..04d54acfad 100644--- a/crates/openhuman-core/src/channels/host/adapters.rs+++ b/crates/openhuman-core/src/channels/host/adapters.rs@@ -208,7 +208,7 @@ impl ConversationStore for ConversationHistoryStore {session_key: &str,limit: usize,) -> anyhow::Result<Vec<ConversationMessage>> {- let messages = crate::threads::store::get_messages(self.workspace_dir.clone(), session_key)+ let messages = crate::threads::store::get_messages(crate::core::runtime::DispatchCtx::ambient(), self.workspace_dir.clone(), session_key).map_err(|e| anyhow::anyhow!(e))?;let start = messages.len().saturating_sub(limit);Ok(messages[start..]@@ -225,6 +225,7 @@ impl ConversationStore for ConversationHistoryStore {let now = chrono::Utc::now().to_rfc3339();// `append_message` requires the thread to exist; create-or-noop first.crate::threads::store::ensure_thread(+ crate::core::runtime::DispatchCtx::ambient(),self.workspace_dir.clone(),crate::threads::store::CreateConversationThread {id: session_key.to_string(),@@ -245,7 +246,7 @@ impl ConversationStore for ConversationHistoryStore {sender: message.role,created_at: now,};- crate::threads::store::append_message(self.workspace_dir.clone(), session_key, stored)+ crate::threads::store::append_message(crate::core::runtime::DispatchCtx::ambient(), self.workspace_dir.clone(), session_key, stored).map_err(|e| anyhow::anyhow!(e))?;Ok(())}diff --git a/crates/openhuman-core/src/channels/providers/relay/ops_tests.rs b/crates/openhuman-core/src/channels/providers/relay/ops_tests.rsindex 4dba42edfd..62f7d757ef 100644--- a/crates/openhuman-core/src/channels/providers/relay/ops_tests.rs+++ b/crates/openhuman-core/src/channels/providers/relay/ops_tests.rs@@ -127,10 +127,10 @@ async fn a_relayed_turn_runs_as_an_external_channel_and_keeps_its_thread() {let p = params(id, text);let thread = p.thread_id();assert_eq!(- store::record_inbound(&workspace, &p, &thread).await,+ store::record_inbound(crate::core::runtime::DispatchCtx::ambient(), &workspace, &p, &thread).await,Ok(Recorded::New));- let replies = run_relay_turn(config.clone(), p, thread, format!("req-{id}")).await;+ let replies = run_relay_turn(crate::core::runtime::DispatchCtx::ambient(), config.clone(), p, thread, format!("req-{id}")).await;assert_eq!(replies.len(), 1, "{replies:?}");}@@ -173,7 +173,7 @@ async fn a_relayed_turn_runs_as_an_external_channel_and_keeps_its_thread() {);let thread = params("m1", "x").thread_id();- let messages = crate::threads::store::get_messages(workspace.clone(), &thread).unwrap();+ let messages = crate::threads::store::get_messages(crate::core::runtime::DispatchCtx::ambient(), workspace.clone(), &thread).unwrap();let ids: Vec<&str> = messages.iter().map(|m| m.id.as_str()).collect();assert_eq!(ids,@@ -212,7 +212,7 @@ async fn invalid_or_repeated_messages_start_no_turn() {let p = params("m1", "hello");let thread = p.thread_id();- store::record_inbound(&workspace, &p, &thread)+ store::record_inbound(crate::core::runtime::DispatchCtx::ambient(), &workspace, &p, &thread).await.unwrap();let outcome = channel_relay_inbound(&crate::core::runtime::DispatchCtx::ambient(), p)diff --git a/crates/openhuman-core/src/channels/providers/relay/store_tests.rs b/crates/openhuman-core/src/channels/providers/relay/store_tests.rsindex be55b3aa54..933bd20f3a 100644--- a/crates/openhuman-core/src/channels/providers/relay/store_tests.rs+++ b/crates/openhuman-core/src/channels/providers/relay/store_tests.rs@@ -18,20 +18,20 @@ async fn an_inbound_message_is_recorded_once() {let p = params("m1", "hello");let thread = p.thread_id();assert_eq!(- record_inbound(tmp.path(), &p, &thread).await,+ record_inbound(crate::core::runtime::DispatchCtx::ambient(), tmp.path(), &p, &thread).await,Ok(Recorded::New));assert_eq!(- record_inbound(tmp.path(), &p, &thread).await,+ record_inbound(crate::core::runtime::DispatchCtx::ambient(), tmp.path(), &p, &thread).await,Ok(Recorded::Duplicate),"a gateway retry is not recorded twice");- let threads = crate::threads::store::list_threads(tmp.path().to_path_buf()).unwrap();+ let threads = crate::threads::store::list_threads(crate::core::runtime::DispatchCtx::ambient(), tmp.path().to_path_buf()).unwrap();assert_eq!(threads.len(), 1);assert_eq!(threads[0].id, thread);assert_eq!(threads[0].title, "telegram · 42 · -100");- let messages = crate::threads::store::get_messages(tmp.path().to_path_buf(), &thread).unwrap();+ let messages = crate::threads::store::get_messages(crate::core::runtime::DispatchCtx::ambient(), tmp.path().to_path_buf(), &thread).unwrap();assert_eq!(messages.len(), 1);assert_eq!(messages[0].id, "user:m1");assert_eq!(messages[0].sender, "user");@@ -43,17 +43,17 @@ async fn replies_are_recorded_and_seed_the_next_turn() {let tmp = tempfile::tempdir().unwrap();let first = params("m1", "hello");let thread = first.thread_id();- record_inbound(tmp.path(), &first, &thread).await.unwrap();- record_reply(tmp.path(), &first, &thread, &[])+ record_inbound(crate::core::runtime::DispatchCtx::ambient(), tmp.path(), &first, &thread).await.unwrap();+ record_reply(crate::core::runtime::DispatchCtx::ambient(), tmp.path(), &first, &thread, &[]).await.expect("nothing sent, nothing recorded");- record_reply(tmp.path(), &first, &thread, &["hi".into(), "there".into()])+ record_reply(crate::core::runtime::DispatchCtx::ambient(), tmp.path(), &first, &thread, &["hi".into(), "there".into()]).await.unwrap();let second = params("m2", "again");- record_inbound(tmp.path(), &second, &thread).await.unwrap();+ record_inbound(crate::core::runtime::DispatchCtx::ambient(), tmp.path(), &second, &thread).await.unwrap();- let prior = prior_turns(tmp.path(), &thread, "m2", 10).await.unwrap();+ let prior = prior_turns(crate::core::runtime::DispatchCtx::ambient(), tmp.path(), &thread, "m2", 10).await.unwrap();let rows: Vec<(String, String)> = prior.iter().map(|m| (m.role.clone(), m.content.clone()))@@ -66,7 +66,7 @@ async fn replies_are_recorded_and_seed_the_next_turn() {],"earlier turns only, not the message being answered");- let limited = prior_turns(tmp.path(), &thread, "m2", 1).await.unwrap();+ let limited = prior_turns(crate::core::runtime::DispatchCtx::ambient(), tmp.path(), &thread, "m2", 1).await.unwrap();assert_eq!(limited.len(), 1);assert_eq!(limited[0].content, "hi\n\nthere", "the most recent rows");}@@ -81,7 +81,7 @@ async fn concurrent_retries_of_one_message_record_it_once() {let dir = tmp.path().to_path_buf();let (p, thread) = (p.clone(), thread.clone());tasks.push(tokio::spawn(async move {- record_inbound(&dir, &p, &thread).await+ record_inbound(crate::core::runtime::DispatchCtx::ambient(), &dir, &p, &thread).await}));}let mut new = 0;@@ -91,6 +91,6 @@ async fn concurrent_retries_of_one_message_record_it_once() {}}assert_eq!(new, 1, "exactly one concurrent retry is the new message");- let messages = crate::threads::store::get_messages(tmp.path().to_path_buf(), &thread).unwrap();+ let messages = crate::threads::store::get_messages(crate::core::runtime::DispatchCtx::ambient(), tmp.path().to_path_buf(), &thread).unwrap();assert_eq!(messages.len(), 1);}diff --git a/crates/openhuman-core/src/cron/scheduler/origin_delivery_tests.rs b/crates/openhuman-core/src/cron/scheduler/origin_delivery_tests.rsindex eafc253ee3..b27502892c 100644--- a/crates/openhuman-core/src/cron/scheduler/origin_delivery_tests.rs+++ b/crates/openhuman-core/src/cron/scheduler/origin_delivery_tests.rs@@ -60,6 +60,7 @@ fn web(thread: &str) -> JobOrigin {fn seed_thread(config: &Config, id: &str) {conversations::ensure_thread(+ crate::core::runtime::DispatchCtx::ambient(),config.workspace_dir.clone(),CreateConversationThread {id: id.into(),@@ -94,7 +95,7 @@ async fn no_reply_is_suppressed_without_writing_anything() {.unwrap();assert_eq!(status, DeliveryStatus::Suppressed);assert!(- conversations::get_messages(cfg.workspace_dir.clone(), "t-1")+ conversations::get_messages(crate::core::runtime::DispatchCtx::ambient(), cfg.workspace_dir.clone(), "t-1").unwrap().is_empty());@@ -113,7 +114,7 @@ async fn web_delivery_stores_one_row_under_the_run_reply_id_and_is_idempotent().unwrap();assert_eq!(status, DeliveryStatus::Delivered);}- let messages = conversations::get_messages(cfg.workspace_dir.clone(), "t-1").unwrap();+ let messages = conversations::get_messages(crate::core::runtime::DispatchCtx::ambient(), cfg.workspace_dir.clone(), "t-1").unwrap();assert_eq!(messages.len(), 1, "same run collapses onto one row");assert_eq!(messages[0].id,@@ -126,7 +127,7 @@ async fn web_delivery_stores_one_row_under_the_run_reply_id_and_is_idempotent().await.unwrap();assert_eq!(- conversations::get_messages(cfg.workspace_dir.clone(), "t-1")+ conversations::get_messages(crate::core::runtime::DispatchCtx::ambient(), cfg.workspace_dir.clone(), "t-1").unwrap().len(),2diff --git a/crates/openhuman-core/src/memory/backfill_tests.rs b/crates/openhuman-core/src/memory/backfill_tests.rsindex 564d075897..fc198ad8b0 100644--- a/crates/openhuman-core/src/memory/backfill_tests.rs+++ b/crates/openhuman-core/src/memory/backfill_tests.rs@@ -21,6 +21,7 @@ fn message(id: &str, sender: &str, content: &str, at: &str) -> ConversationMessaasync fn seed_thread(workspace: &Path, thread_id: &str, messages: &[(&str, &str)]) {threads::ensure_thread(+ crate::core::runtime::DispatchCtx::ambient(),workspace.to_path_buf(),CreateConversationThread {id: thread_id.to_string(),@@ -36,6 +37,7 @@ async fn seed_thread(workspace: &Path, thread_id: &str, messages: &[(&str, &str).unwrap();for (index, (sender, content)) in messages.iter().enumerate() {threads::append_message(+ crate::core::runtime::DispatchCtx::ambient(),workspace.to_path_buf(),thread_id.to_string(),message(diff --git a/crates/openhuman-core/src/threads/ops/crud_message_append_tests.rs b/crates/openhuman-core/src/threads/ops/crud_message_append_tests.rsindex fac7e54950..1d0dd29590 100644--- a/crates/openhuman-core/src/threads/ops/crud_message_append_tests.rs+++ b/crates/openhuman-core/src/threads/ops/crud_message_append_tests.rs@@ -7,6 +7,7 @@ async fn setup() -> (tempfile::TempDir, crate::config::Config) {config.workspace_dir = temp.path().join("internal");config.action_dir = temp.path().join("acting");conversations::blocking::ensure_thread(+ crate::core::runtime::DispatchCtx::ambient(),config.workspace_dir.clone(),conversations::CreateConversationThread {id: "uploads".into(),@@ -28,7 +29,7 @@ async fn append_with_test_config(config: &crate::config::Config,origin: Option<&crate::agent::turn_origin::AgentTurnOrigin>,) -> Result<Outcome<ApiEnvelope<ConversationMessageRecord>>, ThreadsError> {- message_append_with_config(request, config, origin, &config.workspace_dir).await+ message_append_with_config(crate::core::runtime::DispatchCtx::ambient(), request, config, origin, &config.workspace_dir).await}fn request(id: &str, content: &str, sender: &str) -> AppendConversationMessageRequest {@@ -101,7 +102,7 @@ async fn user_append_stages_original_strips_upload_bytes_and_reuses_returned_con.unwrap();assert_eq!(staged, first.content);let persisted =- conversations::blocking::get_messages(config.workspace_dir.clone(), "uploads".into())+ conversations::blocking::get_messages(crate::core::runtime::DispatchCtx::ambient(), config.workspace_dir.clone(), "uploads".into()).await.unwrap();assert_eq!(persisted.len(), 2);@@ -139,7 +140,7 @@ async fn rejected_upload_never_appends_a_message() {.is_err());assert!(- conversations::blocking::get_messages(config.workspace_dir.clone(), "uploads".into())+ conversations::blocking::get_messages(crate::core::runtime::DispatchCtx::ambient(), config.workspace_dir.clone(), "uploads".into()).await.unwrap().is_empty()@@ -172,7 +173,7 @@ async fn external_origin_cannot_reuse_an_existing_attachment_marker() {.is_err());assert!(- conversations::blocking::get_messages(config.workspace_dir, "uploads".into())+ conversations::blocking::get_messages(crate::core::runtime::DispatchCtx::ambient(), config.workspace_dir, "uploads".into()).await.unwrap().is_empty()@@ -212,6 +213,7 @@ async fn append_uses_host_persistence_workspace_separate_from_rpc_config() {let (temp, config) = setup().await;let persistence_dir = temp.path().join("host-thread-store");conversations::blocking::ensure_thread(+ crate::core::runtime::DispatchCtx::ambient(),persistence_dir.clone(),conversations::CreateConversationThread {id: "uploads".into(),@@ -227,6 +229,7 @@ async fn append_uses_host_persistence_workspace_separate_from_rpc_config() {.unwrap();message_append_with_config(+ crate::core::runtime::DispatchCtx::ambient(),request("host-store", "saved in host workspace", "assistant"),&config,None,@@ -235,12 +238,12 @@ async fn append_uses_host_persistence_workspace_separate_from_rpc_config() {.await.unwrap();- let persisted = conversations::blocking::get_messages(persistence_dir, "uploads".into())+ let persisted = conversations::blocking::get_messages(crate::core::runtime::DispatchCtx::ambient(), persistence_dir, "uploads".into()).await.unwrap();assert_eq!(persisted.len(), 1);assert!(- conversations::blocking::get_messages(config.workspace_dir, "uploads".into())+ conversations::blocking::get_messages(crate::core::runtime::DispatchCtx::ambient(), config.workspace_dir, "uploads".into()).await.unwrap().is_empty()@@ -259,7 +262,7 @@ async fn poster_only_user_metadata_is_rejected_before_persistence() {.await.is_err());assert!(- conversations::blocking::get_messages(config.workspace_dir.clone(), "uploads".into())+ conversations::blocking::get_messages(crate::core::runtime::DispatchCtx::ambient(), config.workspace_dir.clone(), "uploads".into()).await.unwrap().is_empty()@@ -273,6 +276,7 @@ async fn raw_append_stages_in_the_bound_thread_folder() {std::fs::create_dir_all(&folder).unwrap();let folder = folder.canonicalize().unwrap();conversations::blocking::ensure_thread(+ crate::core::runtime::DispatchCtx::ambient(),config.workspace_dir.clone(),conversations::CreateConversationThread {id: "bound".into(),diff --git a/crates/openhuman-core/src/threads/ops/edit_turn_state_tests.rs b/crates/openhuman-core/src/threads/ops/edit_turn_state_tests.rsindex 6eafeec902..4094ab5827 100644--- a/crates/openhuman-core/src/threads/ops/edit_turn_state_tests.rs+++ b/crates/openhuman-core/src/threads/ops/edit_turn_state_tests.rs@@ -96,6 +96,7 @@ fn message(id: &str, content: &str, sender: &str) -> ConversationMessage {/// its deterministic reply.async fn seed_message_log(dir: &std::path::Path, thread_id: &str) {conversations::blocking::ensure_thread(+ crate::core::runtime::DispatchCtx::ambient(),dir.to_path_buf(),crate::threads::store::CreateConversationThread {id: thread_id.to_string(),@@ -111,6 +112,7 @@ async fn seed_message_log(dir: &std::path::Path, thread_id: &str) {.expect("ensure_thread");conversations::blocking::append_message(+ crate::core::runtime::DispatchCtx::ambient(),dir.to_path_buf(),thread_id.to_string(),message("user-1", "first question", "user"),@@ -118,6 +120,7 @@ async fn seed_message_log(dir: &std::path::Path, thread_id: &str) {.await.expect("append user-1");conversations::blocking::append_message(+ crate::core::runtime::DispatchCtx::ambient(),dir.to_path_buf(),thread_id.to_string(),message(&run_reply_message_id("turn-1"), "first answer", "assistant"),@@ -125,6 +128,7 @@ async fn seed_message_log(dir: &std::path::Path, thread_id: &str) {.await.expect("append reply for turn-1");conversations::blocking::append_message(+ crate::core::runtime::DispatchCtx::ambient(),dir.to_path_buf(),thread_id.to_string(),message("user-2", "second question", "user"),@@ -132,6 +136,7 @@ async fn seed_message_log(dir: &std::path::Path, thread_id: &str) {.await.expect("append user-2");conversations::blocking::append_message(+ crate::core::runtime::DispatchCtx::ambient(),dir.to_path_buf(),thread_id.to_string(),message(@@ -150,7 +155,7 @@ async fn next_reply_request_id_after_finds_the_correlated_turn() {let thread_id = "thread-reply-lookup";seed_message_log(dir.path(), thread_id).await;- let found = next_reply_request_id_after(dir.path(), thread_id, "user-1")+ let found = next_reply_request_id_after(crate::core::runtime::DispatchCtx::ambient(), dir.path(), thread_id, "user-1").await.expect("lookup");assert_eq!(found, Some("turn-1".to_string()));@@ -163,7 +168,7 @@ async fn next_reply_request_id_after_none_when_message_is_the_log_tail() {seed_message_log(dir.path(), thread_id).await;let last_reply_id = run_reply_message_id("turn-2");- let found = next_reply_request_id_after(dir.path(), thread_id, &last_reply_id)+ let found = next_reply_request_id_after(crate::core::runtime::DispatchCtx::ambient(), dir.path(), thread_id, &last_reply_id).await.expect("lookup");assert_eq!(@@ -178,7 +183,7 @@ async fn next_reply_request_id_after_none_when_message_id_unknown() {let thread_id = "thread-reply-lookup-unknown";seed_message_log(dir.path(), thread_id).await;- let found = next_reply_request_id_after(dir.path(), thread_id, "does-not-exist")+ let found = next_reply_request_id_after(crate::core::runtime::DispatchCtx::ambient(), dir.path(), thread_id, "does-not-exist").await.expect("lookup");assert_eq!(found, None);diff --git a/crates/openhuman-core/src/threads/ops/search_tests.rs b/crates/openhuman-core/src/threads/ops/search_tests.rsindex d3faa34361..f83435b2be 100644--- a/crates/openhuman-core/src/threads/ops/search_tests.rs+++ b/crates/openhuman-core/src/threads/ops/search_tests.rs@@ -47,7 +47,7 @@ fn request_limit_is_optional() {#[tokio::test]async fn blank_query_answers_no_hits() {- let out = thread_search(ThreadSearchRequest {+ let out = thread_search(crate::core::runtime::DispatchCtx::ambient(), ThreadSearchRequest {query: " ".into(),limit: None,})diff --git a/crates/openhuman-core/src/threads/ops_conversion_tests.rs b/crates/openhuman-core/src/threads/ops_conversion_tests.rsindex 4f8af4126f..9b5dd3f124 100644--- a/crates/openhuman-core/src/threads/ops_conversion_tests.rs+++ b/crates/openhuman-core/src/threads/ops_conversion_tests.rs@@ -219,7 +219,7 @@ async fn generate_title_returns_typed_not_found_for_stale_thread() {let _workspace_guard = EnvVarGuard::set("OPENHUMAN_WORKSPACE", workspace.path());let thread_id = "thread-missing";- let err = thread_generate_title(GenerateConversationThreadTitleRequest {+ let err = thread_generate_title(crate::core::runtime::DispatchCtx::ambient(), GenerateConversationThreadTitleRequest {thread_id: thread_id.to_string(),assistant_message: None,})@@ -247,6 +247,7 @@ async fn generate_title_leaves_custom_title_unchanged() {.expect("load config").workspace_dir;conversations_store::append_message(+ crate::core::runtime::DispatchCtx::ambient(),dir,thread_id,ConversationMessage {@@ -260,7 +261,7 @@ async fn generate_title_leaves_custom_title_unchanged() {).unwrap();- let outcome = thread_generate_title(GenerateConversationThreadTitleRequest {+ let outcome = thread_generate_title(crate::core::runtime::DispatchCtx::ambient(), GenerateConversationThreadTitleRequest {thread_id: thread_id.to_string(),assistant_message: None,})@@ -282,7 +283,7 @@ async fn generate_title_returns_existing_title_when_no_user_message_exists() {let thread_id = "thread-no-user";create_thread_with_title(&workspace, thread_id, "Chat Jan 1 1:00 AM").await;- let outcome = thread_generate_title(GenerateConversationThreadTitleRequest {+ let outcome = thread_generate_title(crate::core::runtime::DispatchCtx::ambient(), GenerateConversationThreadTitleRequest {thread_id: thread_id.to_string(),assistant_message: Some("assistant reply".into()),})@@ -308,6 +309,7 @@ async fn generate_title_falls_back_to_first_user_message_when_assistant_missing(.workspace_dir;let user_message = "Please summarize the latest five email threads for me.";conversations_store::append_message(+ crate::core::runtime::DispatchCtx::ambient(),dir,thread_id,ConversationMessage {@@ -321,7 +323,7 @@ async fn generate_title_falls_back_to_first_user_message_when_assistant_missing().unwrap();- let outcome = thread_generate_title(GenerateConversationThreadTitleRequest {+ let outcome = thread_generate_title(crate::core::runtime::DispatchCtx::ambient(), GenerateConversationThreadTitleRequest {thread_id: thread_id.to_string(),assistant_message: None,})@@ -435,7 +437,7 @@ async fn threads_purge_removes_every_turn_state_snapshot() {).await;- threads_purge(EmptyRequest {})+ threads_purge(crate::core::runtime::DispatchCtx::ambient(), EmptyRequest {}).await.expect("purge threads should also clear snapshots");@@ -472,7 +474,7 @@ async fn thread_update_title_rejects_empty_and_whitespace_only_titles() {let _workspace_guard = EnvVarGuard::set("OPENHUMAN_WORKSPACE", workspace.path());for title in ["", " "] {- let err = thread_update_title(crate::threads::UpdateConversationThreadTitleRequest {+ let err = thread_update_title(crate::core::runtime::DispatchCtx::ambient(), crate::threads::UpdateConversationThreadTitleRequest {thread_id: "t-1".to_string(),title: title.to_string(),})diff --git a/crates/openhuman-core/src/threads/ops_tests.rs b/crates/openhuman-core/src/threads/ops_tests.rsindex 4febc8417c..e52d9c6194 100644--- a/crates/openhuman-core/src/threads/ops_tests.rs+++ b/crates/openhuman-core/src/threads/ops_tests.rs@@ -48,6 +48,7 @@ async fn create_thread_with_title(_workspace: &tempfile::TempDir, thread_id: &st.expect("load config").workspace_dir;conversations_store::ensure_thread(+ crate::core::runtime::DispatchCtx::ambient(),dir,CreateConversationThread {id: thread_id.to_string(),diff --git a/crates/openhuman-core/src/threads/ops_title_and_cancellation_tests.rs b/crates/openhuman-core/src/threads/ops_title_and_cancellation_tests.rsindex c84da7a0ce..c2b175b8fc 100644--- a/crates/openhuman-core/src/threads/ops_title_and_cancellation_tests.rs+++ b/crates/openhuman-core/src/threads/ops_title_and_cancellation_tests.rs@@ -9,7 +9,7 @@ async fn thread_update_title_persists_new_title() {let thread_id = "t-title";create_thread_with_title(&workspace, thread_id, "Original title").await;- let outcome = thread_update_title(crate::threads::UpdateConversationThreadTitleRequest {+ let outcome = thread_update_title(crate::core::runtime::DispatchCtx::ambient(), crate::threads::UpdateConversationThreadTitleRequest {thread_id: thread_id.to_string(),title: " Invoice follow-up ".to_string(),})@@ -30,7 +30,7 @@ async fn thread_update_title_returns_error_for_missing_thread() {let workspace = tempfile::tempdir().expect("workspace");let _workspace_guard = EnvVarGuard::set("OPENHUMAN_WORKSPACE", workspace.path());- let err = thread_update_title(crate::threads::UpdateConversationThreadTitleRequest {+ let err = thread_update_title(crate::core::runtime::DispatchCtx::ambient(), crate::threads::UpdateConversationThreadTitleRequest {thread_id: "nonexistent-thread".to_string(),title: "New title".to_string(),})diff --git a/crates/openhuman-core/src/threads/store/blocking_tests.rs b/crates/openhuman-core/src/threads/store/blocking_tests.rsindex f11c3eb3c9..7cbe2355cb 100644--- a/crates/openhuman-core/src/threads/store/blocking_tests.rs+++ b/crates/openhuman-core/src/threads/store/blocking_tests.rs@@ -40,22 +40,22 @@ async fn create_append_read_round_trips_through_the_blocking_pool() {let tmp = TempDir::new().unwrap();let dir = tmp.path().to_path_buf();- let thread = ensure_thread(dir.clone(), create("thread-a"))+ let thread = ensure_thread(crate::core::runtime::DispatchCtx::ambient(), dir.clone(), create("thread-a")).await.expect("ensure_thread");assert_eq!(thread.id, "thread-a");- append_message(dir.clone(), "thread-a".to_string(), message("m1", "hello"))+ append_message(crate::core::runtime::DispatchCtx::ambient(), dir.clone(), "thread-a".to_string(), message("m1", "hello")).await.expect("append_message");- let messages = get_messages(dir.clone(), "thread-a".to_string())+ let messages = get_messages(crate::core::runtime::DispatchCtx::ambient(), dir.clone(), "thread-a".to_string()).await.expect("get_messages");assert_eq!(messages.len(), 1);assert_eq!(messages[0].content, "hello");- let threads = list_threads(dir.clone()).await.expect("list_threads");+ let threads = list_threads(crate::core::runtime::DispatchCtx::ambient(), dir.clone()).await.expect("list_threads");assert_eq!(threads.len(), 1);assert_eq!(threads[0].message_count, 1);}@@ -68,7 +68,7 @@ async fn store_errors_surface_unchanged() {// Appending to a thread that was never created is the store's own error,// not a join failure — the wrapper must pass it through verbatim so the// RPC layer's thread-scoped error mapping still recognises it.- let error = append_message(dir, "missing".to_string(), message("m1", "hello"))+ let error = append_message(crate::core::runtime::DispatchCtx::ambient(), dir, "missing".to_string(), message("m1", "hello")).await.expect_err("append to a missing thread must fail");assert!(@@ -167,10 +167,11 @@ async fn concurrent_operations_complete_without_stalling_the_single_async_workerfor idx in 0..8 {let dir = dir.clone();handles.push(tokio::spawn(async move {- let thread = ensure_thread(dir.clone(), create(&format!("thread-{idx}")))+ let thread = ensure_thread(crate::core::runtime::DispatchCtx::ambient(), dir.clone(), create(&format!("thread-{idx}"))).await.expect("ensure_thread");append_message(+ crate::core::runtime::DispatchCtx::ambient(),dir,thread.id.clone(),message(&format!("m{idx}"), "concurrent"),@@ -211,7 +212,7 @@ async fn concurrent_operations_complete_without_stalling_the_single_async_worker"every concurrent create must land its own thread");- let threads = list_threads(dir).await.expect("list_threads");+ let threads = list_threads(crate::core::runtime::DispatchCtx::ambient(), dir).await.expect("list_threads");assert_eq!(threads.len(), 8);assert!(threads.iter().all(|thread| thread.message_count == 1));}@@ -220,11 +221,12 @@ async fn concurrent_operations_complete_without_stalling_the_single_async_workerasync fn title_labels_delete_and_purge_round_trip() {let tmp = TempDir::new().unwrap();let dir = tmp.path().to_path_buf();- ensure_thread(dir.clone(), create("thread-a"))+ ensure_thread(crate::core::runtime::DispatchCtx::ambient(), dir.clone(), create("thread-a")).await.expect("ensure_thread");let retitled = update_thread_title(+ crate::core::runtime::DispatchCtx::ambient(),dir.clone(),"thread-a".to_string(),"Renamed".to_string(),@@ -235,6 +237,7 @@ async fn title_labels_delete_and_purge_round_trip() {assert_eq!(retitled.title, "Renamed");let relabelled = update_thread_labels(+ crate::core::runtime::DispatchCtx::ambient(),dir.clone(),"thread-a".to_string(),vec!["general".to_string()],@@ -247,6 +250,7 @@ async fn title_labels_delete_and_purge_round_trip() {assert!(delete_thread(+ crate::core::runtime::DispatchCtx::ambient(),dir.clone(),"thread-a".to_string(),"2026-07-30T00:03:00Z".to_string()@@ -255,23 +259,24 @@ async fn title_labels_delete_and_purge_round_trip() {.expect("delete_thread"),"deleting a live thread reports true");- assert!(list_threads(dir.clone()).await.unwrap().is_empty());+ assert!(list_threads(crate::core::runtime::DispatchCtx::ambient(), dir.clone()).await.unwrap().is_empty());- ensure_thread(dir.clone(), create("thread-b"))+ ensure_thread(crate::core::runtime::DispatchCtx::ambient(), dir.clone(), create("thread-b")).await.expect("ensure_thread");- purge_threads(dir.clone()).await.expect("purge_threads");- assert!(list_threads(dir).await.unwrap().is_empty());+ purge_threads(crate::core::runtime::DispatchCtx::ambient(), dir.clone()).await.expect("purge_threads");+ assert!(list_threads(crate::core::runtime::DispatchCtx::ambient(), dir).await.unwrap().is_empty());}#[tokio::test]async fn update_message_patches_metadata_and_search_finds_content() {let tmp = TempDir::new().unwrap();let dir = tmp.path().to_path_buf();- ensure_thread(dir.clone(), create("thread-a"))+ ensure_thread(crate::core::runtime::DispatchCtx::ambient(), dir.clone(), create("thread-a")).await.expect("ensure_thread");append_message(+ crate::core::runtime::DispatchCtx::ambient(),dir.clone(),"thread-a".to_string(),message("m1", "quarterly roadmap review"),@@ -280,6 +285,7 @@ async fn update_message_patches_metadata_and_search_finds_content() {.expect("append_message");let patched = update_message(+ crate::core::runtime::DispatchCtx::ambient(),dir.clone(),"thread-a".to_string(),"m1".to_string(),@@ -291,7 +297,7 @@ async fn update_message_patches_metadata_and_search_finds_content() {.expect("update_message");assert_eq!(patched.extra_metadata, json!({"pinned": true}));- let hits = search_cross_thread_messages(dir, "roadmap".to_string(), 10, None)+ let hits = search_cross_thread_messages(crate::core::runtime::DispatchCtx::ambient(), dir, "roadmap".to_string(), 10, None).await.expect("search_cross_thread_messages");assert!(diff --git a/crates/openhuman-core/src/threads/store/bus_tests.rs b/crates/openhuman-core/src/threads/store/bus_tests.rsindex f63dfcc269..fb8708529d 100644--- a/crates/openhuman-core/src/threads/store/bus_tests.rs+++ b/crates/openhuman-core/src/threads/store/bus_tests.rs@@ -62,11 +62,11 @@ async fn persists_inbound_and_processed_turns_into_workspace_thread() {}).await;- let threads = crate::threads::store::list_threads(temp.path().to_path_buf()).expect("threads");+ let threads = crate::threads::store::list_threads(crate::core::runtime::DispatchCtx::ambient(), temp.path().to_path_buf()).expect("threads");assert_eq!(threads.len(), 1);assert_eq!(threads[0].id, "channel:slack_alice_general_thread:thread-1");- let messages = crate::threads::store::get_messages(temp.path().to_path_buf(), &threads[0].id)+ let messages = crate::threads::store::get_messages(crate::core::runtime::DispatchCtx::ambient(), temp.path().to_path_buf(), &threads[0].id).expect("messages");assert_eq!(messages.len(), 2);assert_eq!(messages[0].id, "user:m1");@@ -113,7 +113,7 @@ async fn telegram_thread_ts_does_not_split_persisted_thread() {}).await;- let threads = crate::threads::store::list_threads(temp.path().to_path_buf()).expect("threads");+ let threads = crate::threads::store::list_threads(crate::core::runtime::DispatchCtx::ambient(), temp.path().to_path_buf()).expect("threads");assert_eq!(threads.len(), 1);assert_eq!(threads[0].id, "channel:telegram_alice_chat-1");}@@ -138,6 +138,7 @@ async fn duplicate_events_do_not_append_duplicate_messages() {subscriber.handle(&event).await;let messages = crate::threads::store::get_messages(+ crate::core::runtime::DispatchCtx::ambient(),temp.path().to_path_buf(),"channel:discord_alice_room-1",)@@ -195,7 +196,7 @@ async fn received_matching_workspace_is_persisted() {.await;let messages =- crate::threads::store::get_messages(temp.path().to_path_buf(), "channel:slack_bob_dev")+ crate::threads::store::get_messages(crate::core::runtime::DispatchCtx::ambient(), temp.path().to_path_buf(), "channel:slack_bob_dev").expect("messages");assert_eq!(messages.len(), 1);assert_eq!(messages[0].id, "user:m1");@@ -223,7 +224,7 @@ async fn received_stale_workspace_is_dropped() {.await;// No thread should have been created in temp (the subscriber's workspace).- let threads = crate::threads::store::list_threads(temp.path().to_path_buf()).expect("threads");+ let threads = crate::threads::store::list_threads(crate::core::runtime::DispatchCtx::ambient(), temp.path().to_path_buf()).expect("threads");assert!(threads.is_empty(),"stale-workspace event must not create a thread"@@ -269,6 +270,7 @@ async fn processed_matching_workspace_is_appended() {.await;let messages = crate::threads::store::get_messages(+ crate::core::runtime::DispatchCtx::ambient(),temp.path().to_path_buf(),"channel:slack_alice_general",)@@ -319,6 +321,7 @@ async fn processed_stale_workspace_is_dropped() {.await;let messages = crate::threads::store::get_messages(+ crate::core::runtime::DispatchCtx::ambient(),temp.path().to_path_buf(),"channel:slack_alice_general",)@@ -391,6 +394,7 @@ async fn workspace_switch_mid_conversation() {.await;let messages = crate::threads::store::get_messages(+ crate::core::runtime::DispatchCtx::ambient(),workspace_a.path().to_path_buf(),"channel:telegram_alice_chat-1",)@@ -430,7 +434,7 @@ async fn multiple_stale_workspaces_all_dropped() {.await;}- let threads = crate::threads::store::list_threads(temp.path().to_path_buf()).expect("threads");+ let threads = crate::threads::store::list_threads(crate::core::runtime::DispatchCtx::ambient(), temp.path().to_path_buf()).expect("threads");assert!(threads.is_empty(),"no events from wrong workspaces should create a thread"@@ -474,6 +478,7 @@ async fn correct_workspace_after_stale_events() {.await;let messages = crate::threads::store::get_messages(+ crate::core::runtime::DispatchCtx::ambient(),temp.path().to_path_buf(),"channel:slack_alice_general",)@@ -524,7 +529,7 @@ async fn claimed_channel_turns_are_left_to_their_caller() {subscriber.handle(&event).await;}- let threads = crate::threads::store::list_threads(temp.path().to_path_buf()).expect("threads");+ let threads = crate::threads::store::list_threads(crate::core::runtime::DispatchCtx::ambient(), temp.path().to_path_buf()).expect("threads");assert!(threads.is_empty(),"a claimed turn is not mirrored: {threads:?}"diff --git a/crates/openhuman-core/src/threads/store/legacy_import_tests.rs b/crates/openhuman-core/src/threads/store/legacy_import_tests.rsindex 6a580ade1f..e9fe56fd8e 100644--- a/crates/openhuman-core/src/threads/store/legacy_import_tests.rs+++ b/crates/openhuman-core/src/threads/store/legacy_import_tests.rs@@ -66,7 +66,7 @@ fn legacy_jsonl_conversations_are_imported_and_the_files_stay_byte_identical() {write_legacy(&root, &log_refs, &[("t1", &[m1.as_str(), m2.as_str()])]);let before = snapshot(&root);- let store = ConversationStore::new(dir.path().to_path_buf());+ let store = ConversationStore::new(crate::core::runtime::DispatchCtx::ambient(), dir.path().to_path_buf());let threads = store.list_threads().unwrap();assert_eq!(threads.len(), 1, "the deleted thread is not imported");assert_eq!(threads[0].id, "t1");@@ -86,7 +86,7 @@ fn legacy_import_runs_once_even_when_the_files_change_afterwards() {let m1 = message("m1", "hello", "2026-01-01T00:00:01Z");write_legacy(&root, &[&upsert("t1", "First")], &[("t1", &[m1.as_str()])]);- let store = ConversationStore::new(dir.path().to_path_buf());+ let store = ConversationStore::new(crate::core::runtime::DispatchCtx::ambient(), dir.path().to_path_buf());assert_eq!(store.list_threads().unwrap().len(), 1);// A new process on the same workspace: the marker, not the process cache,@@ -97,7 +97,7 @@ fn legacy_import_runs_once_even_when_the_files_change_afterwards() {&[&upsert("t1", "First"), &upsert("t9", "Late")],&[("t1", &[m1.as_str()])],);- let after = ConversationStore::new(dir.path().to_path_buf());+ let after = ConversationStore::new(crate::core::runtime::DispatchCtx::ambient(), dir.path().to_path_buf());let threads = after.list_threads().unwrap();assert_eq!(threads.len(), 1);assert_eq!(after.get_messages("t1").unwrap().len(), 1);@@ -106,7 +106,7 @@ fn legacy_import_runs_once_even_when_the_files_change_afterwards() {#[test]fn a_workspace_without_legacy_files_starts_empty() {let dir = tempfile::tempdir().unwrap();- let store = ConversationStore::new(dir.path().to_path_buf());+ let store = ConversationStore::new(crate::core::runtime::DispatchCtx::ambient(), dir.path().to_path_buf());assert!(store.list_threads().unwrap().is_empty());assert!(store.get_messages("nope").unwrap().is_empty());assert!(!backend::legacy_root(dir.path()).exists());@@ -115,7 +115,7 @@ fn a_workspace_without_legacy_files_starts_empty() {#[test]fn threads_round_trip_through_the_backend_store() {let dir = tempfile::tempdir().unwrap();- let store = ConversationStore::new(dir.path().to_path_buf());+ let store = ConversationStore::new(crate::core::runtime::DispatchCtx::ambient(), dir.path().to_path_buf());store.ensure_thread(CreateConversationThread {id: "t".into(),@@ -169,7 +169,7 @@ fn an_unreadable_legacy_log_is_an_error_not_an_empty_store() {std::fs::set_permissions(&root, std::fs::Permissions::from_mode(0o000)).unwrap();// Root bypasses permission bits; only assert when the stat truly fails.let blocked = std::fs::metadata(root.join("threads.jsonl")).is_err();- let result = ConversationStore::new(dir.path().to_path_buf()).list_threads();+ let result = ConversationStore::new(crate::core::runtime::DispatchCtx::ambient(), dir.path().to_path_buf()).list_threads();std::fs::set_permissions(&root, std::fs::Permissions::from_mode(0o755)).unwrap();if blocked {assert!(diff --git a/crates/openhuman-core/src/threads/welcome_migration_tests.rs b/crates/openhuman-core/src/threads/welcome_migration_tests.rsindex e505932b99..c64f411bef 100644--- a/crates/openhuman-core/src/threads/welcome_migration_tests.rs+++ b/crates/openhuman-core/src/threads/welcome_migration_tests.rs@@ -28,6 +28,7 @@ fn migration_updates_thread_labels_and_transcripts() {let workspace = tmp.path();ensure_thread(+ crate::core::runtime::DispatchCtx::ambient(),workspace.to_path_buf(),make_thread("welcome-thread",@@ -49,7 +50,7 @@ fn migration_updates_thread_labels_and_transcripts() {assert_eq!(result.transcript_files_renamed, 1);assert_eq!(result.markdown_files_renamed, 1);- let threads = list_threads(workspace.to_path_buf()).unwrap();+ let threads = list_threads(crate::core::runtime::DispatchCtx::ambient(), workspace.to_path_buf()).unwrap();let thread = threads.iter().find(|thread| thread.id == "welcome-thread")diff --git a/crates/openhuman-core/src/voice/live/persist.rs b/crates/openhuman-core/src/voice/live/persist.rsindex 1ac1011354..c5780c9b7c 100644--- a/crates/openhuman-core/src/voice/live/persist.rs+++ b/crates/openhuman-core/src/voice/live/persist.rs@@ -75,6 +75,7 @@ impl TranscriptPersister {};let id = message.id.clone();match crate::threads::store::blocking::append_message(+ crate::core::runtime::DispatchCtx::ambient(),self.workspace_dir.clone(),self.thread_id.clone(),message,diff --git a/crates/openhuman-core/src/voice/live/persist_tests.rs b/crates/openhuman-core/src/voice/live/persist_tests.rsindex 06a0cac7c5..96409d2306 100644--- a/crates/openhuman-core/src/voice/live/persist_tests.rs+++ b/crates/openhuman-core/src/voice/live/persist_tests.rs@@ -26,6 +26,7 @@ fn builds_deterministic_messages_and_skips_blank_text() {async fn saves_into_the_thread_store() {let dir = tempfile::tempdir().unwrap();crate::threads::store::blocking::ensure_thread(+ crate::core::runtime::DispatchCtx::ambient(),dir.path().to_path_buf(),crate::threads::store::CreateConversationThread {id: "t1".into(),@@ -44,7 +45,7 @@ async fn saves_into_the_thread_store() {p.save(TranscriptRole::Agent, "hi there").await;p.save(TranscriptRole::Agent, "").await;let messages =- crate::threads::store::blocking::get_messages(dir.path().to_path_buf(), "t1".into())+ crate::threads::store::blocking::get_messages(crate::core::runtime::DispatchCtx::ambient(), dir.path().to_path_buf(), "t1".into()).await.unwrap();let texts: Vec<_> = messagesdiff --git a/crates/openhuman-core/src/voice/live/session.rs b/crates/openhuman-core/src/voice/live/session.rsindex c34887b448..05bbe60dd3 100644--- a/crates/openhuman-core/src/voice/live/session.rs+++ b/crates/openhuman-core/src/voice/live/session.rs@@ -101,6 +101,7 @@ async fn ensure_thread(.filter(|t| !t.trim().is_empty()).unwrap_or_else(|| format!("voice-{}", uuid::Uuid::new_v4()));crate::threads::store::blocking::ensure_thread(+ crate::core::runtime::DispatchCtx::ambient(),config.workspace_dir.clone(),CreateConversationThread {id: id.clone(),@@ -139,6 +140,7 @@ pub(crate) async fn start(let harness = assemble_live_tool_harness(host.live_tool_surface());let recent = crate::threads::store::blocking::get_messages(+ crate::core::runtime::DispatchCtx::ambient(),config.workspace_dir.clone(),thread_id.clone(),)diff --git a/crates/openhuman-core/src/web_chat/presentation_tests.rs b/crates/openhuman-core/src/web_chat/presentation_tests.rsindex 4e25164218..90ad14bd2a 100644--- a/crates/openhuman-core/src/web_chat/presentation_tests.rs+++ b/crates/openhuman-core/src/web_chat/presentation_tests.rs@@ -134,6 +134,7 @@ async fn delivery_stores_the_reply_before_announcing_it() {let ws = std::env::temp_dir().join(format!("deliver-persist-{}", uuid::Uuid::new_v4()));std::fs::create_dir_all(&ws).unwrap();conversations::ensure_thread(+ crate::core::runtime::DispatchCtx::ambient(),ws.clone(),CreateConversationThread {id: "t-deliver".to_string(),@@ -170,7 +171,7 @@ async fn delivery_stores_the_reply_before_announcing_it() {// a row present here proves the write happened no later than the announce.// A client that never receives that event, or fails to append it, no longer// decides whether the reply exists.- let messages = conversations::get_messages(ws.clone(), "t-deliver").expect("messages");+ let messages = conversations::get_messages(crate::core::runtime::DispatchCtx::ambient(), ws.clone(), "t-deliver").expect("messages");assert_eq!(messages.len(), 1, "delivery must leave exactly one row");assert_eq!(messages[0].id, "agent:req-deliver");assert_eq!(messages[0].content, "Here is the summary you asked for.");@@ -206,7 +207,7 @@ async fn delivery_still_announces_when_the_reply_cannot_be_stored() {// `get_messages` answers `Ok(vec![])` for a thread it has never seen — only// `append_message` refuses one — so absence is what proves the write was// rejected and swallowed rather than silently creating a thread.- let messages = crate::threads::store::get_messages(ws.clone(), "absent-thread")+ let messages = crate::threads::store::get_messages(crate::core::runtime::DispatchCtx::ambient(), ws.clone(), "absent-thread").expect("reading an unknown thread is not an error");assert!(messages.is_empty(),diff --git a/crates/openhuman-core/src/web_chat/reply_persistence_tests.rs b/crates/openhuman-core/src/web_chat/reply_persistence_tests.rsindex c6b8d707de..a259efae9f 100644--- a/crates/openhuman-core/src/web_chat/reply_persistence_tests.rs+++ b/crates/openhuman-core/src/web_chat/reply_persistence_tests.rs@@ -12,6 +12,7 @@ fn temp_ws() -> PathBuf {fn seed_thread(ws: &Path, thread_id: &str) {conversations::ensure_thread(+ crate::core::runtime::DispatchCtx::ambient(),ws.to_path_buf(),CreateConversationThread {id: thread_id.to_string(),@@ -31,11 +32,11 @@ fn persists_the_reply_under_the_id_the_client_will_reuse() {let ws = temp_ws();seed_thread(&ws, "t-1");- let stored = persist_delivered_reply(&ws, "t-1", "req-1", "Done, the draft is updated.", &[])+ let stored = persist_delivered_reply(crate::core::runtime::DispatchCtx::ambient(), &ws, "t-1", "req-1", "Done, the draft is updated.", &[]).expect("append succeeds");assert!(stored, "a non-empty reply must report that it was stored");- let messages = conversations::get_messages(ws.clone(), "t-1").expect("messages");+ let messages = conversations::get_messages(crate::core::runtime::DispatchCtx::ambient(), ws.clone(), "t-1").expect("messages");assert_eq!(messages.len(), 1);// The id is what makes the client's own append collapse onto this row// instead of adding a duplicate bubble (#5933 / #6034).@@ -51,14 +52,14 @@ fn a_second_write_of_the_same_turn_does_not_add_a_row() {let ws = temp_ws();seed_thread(&ws, "t-2");- persist_delivered_reply(&ws, "t-2", "req-2", "First", &[]).expect("first append");+ persist_delivered_reply(crate::core::runtime::DispatchCtx::ambient(), &ws, "t-2", "req-2", "First", &[]).expect("first append");// The client persists the same reply from the `chat_done` it received. The// store's idempotency for deterministic ids is what keeps the thread at one// row; assert the second write here so a change to the id shape (which// would silently opt out of that lookup) fails loudly.- persist_delivered_reply(&ws, "t-2", "req-2", "First", &[]).expect("second append");+ persist_delivered_reply(crate::core::runtime::DispatchCtx::ambient(), &ws, "t-2", "req-2", "First", &[]).expect("second append");- let messages = conversations::get_messages(ws.clone(), "t-2").expect("messages");+ let messages = conversations::get_messages(crate::core::runtime::DispatchCtx::ambient(), ws.clone(), "t-2").expect("messages");assert_eq!(messages.len(), 1, "one turn must never leave two rows");}@@ -67,9 +68,9 @@ fn an_empty_reply_is_not_stored() {let ws = temp_ws();seed_thread(&ws, "t-3");- let stored = persist_delivered_reply(&ws, "t-3", "req-3", " \n ", &[]).expect("no error");+ let stored = persist_delivered_reply(crate::core::runtime::DispatchCtx::ambient(), &ws, "t-3", "req-3", " \n ", &[]).expect("no error");assert!(!stored, "an empty reply reports that nothing was stored");- assert!(conversations::get_messages(ws.clone(), "t-3")+ assert!(conversations::get_messages(crate::core::runtime::DispatchCtx::ambient(), ws.clone(), "t-3").expect("messages").is_empty());}@@ -79,9 +80,9 @@ fn content_is_trimmed_the_way_the_autonomous_path_trims_it() {let ws = temp_ws();seed_thread(&ws, "t-4");- persist_delivered_reply(&ws, "t-4", "req-4", " padded reply\n", &[]).expect("append");+ persist_delivered_reply(crate::core::runtime::DispatchCtx::ambient(), &ws, "t-4", "req-4", " padded reply\n", &[]).expect("append");- let messages = conversations::get_messages(ws.clone(), "t-4").expect("messages");+ let messages = conversations::get_messages(crate::core::runtime::DispatchCtx::ambient(), ws.clone(), "t-4").expect("messages");assert_eq!(messages[0].content, "padded reply");}@@ -89,7 +90,7 @@ fn content_is_trimmed_the_way_the_autonomous_path_trims_it() {fn a_missing_thread_is_reported_rather_than_silently_dropped() {let ws = temp_ws();- let err = persist_delivered_reply(&ws, "nope", "req-5", "text", &[])+ let err = persist_delivered_reply(crate::core::runtime::DispatchCtx::ambient(), &ws, "nope", "req-5", "text", &[]).expect_err("a missing thread must not look like a successful store");assert!(err.contains("nope"), "error names the thread: {err}");}@@ -107,13 +108,13 @@ fn citations_ride_on_the_authoritative_row() {timestamp: "2026-09-04T00:00:00Z".to_string(),snippet: "The draft lives in Notion.".to_string(),};- persist_delivered_reply(&ws, "t-6", "req-6", "Updated the draft.", &[citation])+ persist_delivered_reply(crate::core::runtime::DispatchCtx::ambient(), &ws, "t-6", "req-6", "Updated the draft.", &[citation]).expect("append");// The client's append is deduped onto this row, so whatever is missing here// is missing from the rendered message — citation chips included. Losing// them was a real regression caught in review of #6034.- let messages = conversations::get_messages(ws.clone(), "t-6").expect("messages");+ let messages = conversations::get_messages(crate::core::runtime::DispatchCtx::ambient(), ws.clone(), "t-6").expect("messages");let cites = messages[0].extra_metadata["citations"].as_array().expect("citations are stored as an array");@@ -126,9 +127,9 @@ fn a_reply_without_citations_stores_no_citations_key() {let ws = temp_ws();seed_thread(&ws, "t-7");- persist_delivered_reply(&ws, "t-7", "req-7", "No sources for this one.", &[]).expect("append");+ persist_delivered_reply(crate::core::runtime::DispatchCtx::ambient(), &ws, "t-7", "req-7", "No sources for this one.", &[]).expect("append");- let messages = conversations::get_messages(ws.clone(), "t-7").expect("messages");+ let messages = conversations::get_messages(crate::core::runtime::DispatchCtx::ambient(), ws.clone(), "t-7").expect("messages");assert!(messages[0].extra_metadata.get("citations").is_none(),"an empty citation list must not add an empty array the client never wrote"