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
chore(orchestration): reformat background delivery tests and helpers
Steven Enamakel9ef1ec44a95e
diff --git a/crates/openhuman-core/src/agent/orchestration/background_completions_tests.rs b/crates/openhuman-core/src/agent/orchestration/background_completions_tests.rsindex 074d2999c8..022b364298 100644--- a/crates/openhuman-core/src/agent/orchestration/background_completions_tests.rs+++ b/crates/openhuman-core/src/agent/orchestration/background_completions_tests.rs@@ -16,7 +16,8 @@ fn workspace() -> TestWorkspace {}fn record(ws: &Path, session: &str, task: &str, summary: &str, thread: Option<&str>) {- futures::executor::block_on(record_completion(&crate::core::runtime::DispatchCtx::ambient(),+ futures::executor::block_on(record_completion(+ &crate::core::runtime::DispatchCtx::ambient(),ws,session,task,@@ -76,7 +77,10 @@ fn headless_completion_is_dropped() {.claim_pending("", usize::MAX).unwrap().is_empty());- assert!(recover_pending_threads(&crate::core::runtime::DispatchCtx::ambient(), ws.path()).is_empty());+ assert!(+ recover_pending_threads(&crate::core::runtime::DispatchCtx::ambient(), ws.path())+ .is_empty()+ );}#[test]@@ -90,8 +94,14 @@ fn the_session_is_mapped_to_its_thread_for_the_idle_gate() {);// A web-channel session id carries its thread in the JSON body.let web = r#"{"client_id":"c","thread_id":"thread-json"}"#;- assert_eq!(thread_for_session(&crate::core::runtime::DispatchCtx::ambient(), web).as_deref(), Some("thread-json"));- assert_eq!(thread_for_session(&crate::core::runtime::DispatchCtx::ambient(), "cron:job-1"), None);+ assert_eq!(+ thread_for_session(&crate::core::runtime::DispatchCtx::ambient(), web).as_deref(),+ Some("thread-json")+ );+ assert_eq!(+ thread_for_session(&crate::core::runtime::DispatchCtx::ambient(), "cron:job-1"),+ None+ );}#[test]@@ -103,7 +113,14 @@ fn discard_for_thread_removes_matching_and_drops_stragglers() {record(w, "sess-d1", "sub-b", "y", Some("thread-KEEP"));record(w, "sess-d2", "sub-c", "z", Some("thread-DEL"));- assert_eq!(discard_for_thread(&crate::core::runtime::DispatchCtx::ambient(), w, "thread-DEL"), 2);+ assert_eq!(+ discard_for_thread(+ &crate::core::runtime::DispatchCtx::ambient(),+ w,+ "thread-DEL"+ ),+ 2+ );assert!(pending_ids(w, "thread-DEL").is_empty());assert_eq!(pending_ids(w, "thread-KEEP"), ["sub-b"]);}@@ -115,7 +132,11 @@ fn record_after_discard_is_dropped_by_the_cancelled_parent() {let w = ws.path();// The thread is deleted before this process ever saw a child of it: the// delete still writes the cancelled-parent marker in the caller's workspace.- discard_for_thread(&crate::core::runtime::DispatchCtx::ambient(), w, "thread-race");+ discard_for_thread(+ &crate::core::runtime::DispatchCtx::ambient(),+ w,+ "thread-race",+ );// A straggler that records after the sweep (the cooperative-abort race) is// dropped rather than queued.record(w, "sess-race", "sub-late", "stale", Some("thread-race"));@@ -130,17 +151,23 @@ fn a_child_registering_after_its_thread_was_deleted_is_aborted_and_stays_droppedlet _guard = test_guard();let ws = workspace();let w = ws.path();- assert!(!mark_stopped_task_if_thread_stopped(&crate::core::runtime::DispatchCtx::ambient(),+ assert!(!mark_stopped_task_if_thread_stopped(+ &crate::core::runtime::DispatchCtx::ambient(),w,"thread-del-reg","sub-a"));- discard_for_thread(&crate::core::runtime::DispatchCtx::ambient(), w, "thread-del-reg");+ discard_for_thread(+ &crate::core::runtime::DispatchCtx::ambient(),+ w,+ "thread-del-reg",+ );// A child spawned before the delete registers after it: it must be aborted,// and registering must not lift the delete (unlike a stopped thread, a// deleted one never reopens).- assert!(mark_stopped_task_if_thread_stopped(&crate::core::runtime::DispatchCtx::ambient(),+ assert!(mark_stopped_task_if_thread_stopped(+ &crate::core::runtime::DispatchCtx::ambient(),w,"thread-del-reg","sub-b"@@ -162,7 +189,10 @@ fn clear_all_withdraws_every_pending_completion() {assert_eq!(removed, 2);assert!(pending_ids(w, "t1").is_empty());assert!(pending_ids(w, "t2").is_empty());- assert_eq!(clear_all(&crate::core::runtime::DispatchCtx::ambient(), w), 0);+ assert_eq!(+ clear_all(&crate::core::runtime::DispatchCtx::ambient(), w),+ 0+ );}#[test]@@ -173,7 +203,10 @@ fn clear_all_is_scoped_to_its_workspace() {record(purged.path(), "sess-p", "sub-1", "a", Some("t-purged"));record(other.path(), "sess-o", "sub-2", "b", Some("t-other"));- assert_eq!(clear_all(&crate::core::runtime::DispatchCtx::ambient(), purged.path()), 1);+ assert_eq!(+ clear_all(&crate::core::runtime::DispatchCtx::ambient(), purged.path()),+ 1+ );assert!(pending_ids(purged.path(), "t-purged").is_empty());assert_eq!(@@ -254,6 +287,7 @@ fn record_failure_queues_a_framed_failure_for_delivery() {let ws = workspace();let w = ws.path();futures::executor::block_on(record_failure(+ &crate::core::runtime::DispatchCtx::ambient(),w,"sess-fail","sub-bad",@@ -273,7 +307,8 @@ fn record_awaiting_input_queues_a_framed_needs_input_for_delivery() {let _guard = test_guard();let ws = workspace();let w = ws.path();- futures::executor::block_on(record_awaiting_input(&crate::core::runtime::DispatchCtx::ambient(),+ futures::executor::block_on(record_awaiting_input(+ &crate::core::runtime::DispatchCtx::ambient(),w,"sess-ask","sub-ask",@@ -296,7 +331,8 @@ fn the_outcome_survives_a_claim() {let _guard = test_guard();let ws = workspace();let w = ws.path();- futures::executor::block_on(record_outcome(&crate::core::runtime::DispatchCtx::ambient(),+ futures::executor::block_on(record_outcome(+ &crate::core::runtime::DispatchCtx::ambient(),w,"sess-out","sub-1",@@ -335,7 +371,13 @@ fn discard_pending_for_thread_blocks_late_results_until_the_next_turn() {);// Stop drops the undelivered result so it can't start a delivery turn...- assert_eq!(discard_pending_for_thread(&crate::core::runtime::DispatchCtx::ambient(), "thread-stop-live"), 1);+ assert_eq!(+ discard_pending_for_thread(+ &crate::core::runtime::DispatchCtx::ambient(),+ "thread-stop-live"+ ),+ 1+ );assert!(pending_ids(w, "thread-stop-live").is_empty());assert_eq!(pending_ids(w, "thread-stop-other"), ["sub-stop-keep"]);@@ -352,7 +394,11 @@ fn discard_pending_for_thread_blocks_late_results_until_the_next_turn() {// Completing Stop keeps the thread gate until a new user turn begins, so a// child that registers after the cancellation sweep is still rejected.- finish_stop_for_thread(&crate::core::runtime::DispatchCtx::ambient(), "thread-stop-live", &["sub-stop-later".into()]);+ finish_stop_for_thread(+ &crate::core::runtime::DispatchCtx::ambient(),+ "thread-stop-live",+ &["sub-stop-later".into()],+ );record(w,"sess-stop",@@ -364,13 +410,17 @@ fn discard_pending_for_thread_blocks_late_results_until_the_next_turn() {// A child that was spawned before Stop but registers after the registry// sweep gets its own tombstone before the thread can be reopened.- assert!(mark_stopped_task_if_thread_stopped(&crate::core::runtime::DispatchCtx::ambient(),+ assert!(mark_stopped_task_if_thread_stopped(+ &crate::core::runtime::DispatchCtx::ambient(),w,"thread-stop-live","sub-stop-registered-late"));- resume_stopped_thread(&crate::core::runtime::DispatchCtx::ambient(), "thread-stop-live");+ resume_stopped_thread(+ &crate::core::runtime::DispatchCtx::ambient(),+ "thread-stop-live",+ );record(w,"sess-stop",@@ -398,12 +448,19 @@ fn a_stop_before_a_restart_is_lifted_by_the_first_new_spawn() {let ws = workspace();let w = ws.path();record(w, "sess-rs", "sub-1", "x", Some("thread-restart-stop"));- assert_eq!(discard_pending_for_thread(&crate::core::runtime::DispatchCtx::ambient(), "thread-restart-stop"), 1);+ assert_eq!(+ discard_pending_for_thread(+ &crate::core::runtime::DispatchCtx::ambient(),+ "thread-restart-stop"+ ),+ 1+ );// A restart: the in-memory gate is gone, the durable cancelled-parent// marker is not.forget_workspace_for_test(w);- assert!(!mark_stopped_task_if_thread_stopped(&crate::core::runtime::DispatchCtx::ambient(),+ assert!(!mark_stopped_task_if_thread_stopped(+ &crate::core::runtime::DispatchCtx::ambient(),w,"thread-restart-stop","sub-new"@@ -460,7 +517,9 @@ fn undelivered_completions_are_found_again_after_a_restart() {pending_for(w, "thread-boot")[0].result.text,"unseen result");- assert!(router_for_thread(&crate::core::runtime::DispatchCtx::ambient(), "thread-boot").is_some());+ assert!(+ router_for_thread(&crate::core::runtime::DispatchCtx::ambient(), "thread-boot").is_some()+ );}#[test]@@ -469,13 +528,21 @@ fn a_delete_survives_a_restart_and_is_not_lifted_by_a_new_spawn() {let ws = workspace();let w = ws.path();record(w, "sess-dr", "sub-1", "x", Some("thread-del-restart"));- assert_eq!(discard_for_thread(&crate::core::runtime::DispatchCtx::ambient(), w, "thread-del-restart"), 1);+ assert_eq!(+ discard_for_thread(+ &crate::core::runtime::DispatchCtx::ambient(),+ w,+ "thread-del-restart"+ ),+ 1+ );// A restart: memory is gone, the durable markers are not. A late child for// the deleted thread must be aborted rather than treated as a user returning// to a stopped thread, and its result must stay dropped.forget_workspace_for_test(w);- assert!(mark_stopped_task_if_thread_stopped(&crate::core::runtime::DispatchCtx::ambient(),+ assert!(mark_stopped_task_if_thread_stopped(+ &crate::core::runtime::DispatchCtx::ambient(),w,"thread-del-restart","sub-late"@@ -522,7 +589,10 @@ fn clear_all_also_withdraws_a_completion_a_delivery_has_leased() {1);- assert_eq!(clear_all(&crate::core::runtime::DispatchCtx::ambient(), w), 1);+ assert_eq!(+ clear_all(&crate::core::runtime::DispatchCtx::ambient(), w),+ 1+ );assert!(pending_ids(w, "thread-leased").is_empty());assert_eq!(@@ -536,12 +606,27 @@ fn clear_all_also_withdraws_a_completion_a_delivery_has_leased() {fn the_session_cache_evicts_its_oldest_mapping_only() {let _guard = test_guard();for i in 0..(SESSION_THREADS_CAP + 5) {- note_session_thread(&crate::core::runtime::DispatchCtx::ambient(), &format!("evict-sess-{i}"), &format!("evict-thread-{i}"));+ note_session_thread(+ &crate::core::runtime::DispatchCtx::ambient(),+ &format!("evict-sess-{i}"),+ &format!("evict-thread-{i}"),+ );}- assert_eq!(thread_for_session(&crate::core::runtime::DispatchCtx::ambient(), "evict-sess-0"), None, "oldest evicted");+ assert_eq!(+ thread_for_session(+ &crate::core::runtime::DispatchCtx::ambient(),+ "evict-sess-0"+ ),+ None,+ "oldest evicted"+ );for survivor in [5, SESSION_THREADS_CAP / 2, SESSION_THREADS_CAP + 4] {assert_eq!(- thread_for_session(&crate::core::runtime::DispatchCtx::ambient(), &format!("evict-sess-{survivor}")).as_deref(),+ thread_for_session(+ &crate::core::runtime::DispatchCtx::ambient(),+ &format!("evict-sess-{survivor}")+ )+ .as_deref(),Some(format!("evict-thread-{survivor}").as_str()),"a surviving session still resolves to its own thread");@@ -554,14 +639,19 @@ fn a_delete_marker_outlives_compaction() {let ws = workspace();let w = ws.path();record(w, "sess-cm", "sub-1", "x", Some("thread-compact"));- discard_for_thread(&crate::core::runtime::DispatchCtx::ambient(), w, "thread-compact");+ discard_for_thread(+ &crate::core::runtime::DispatchCtx::ambient(),+ w,+ "thread-compact",+ );// Settled records expire; the deletion must not.router_for_workspace(w).compact(std::time::Duration::ZERO).unwrap();forget_workspace_for_test(w);- assert!(mark_stopped_task_if_thread_stopped(&crate::core::runtime::DispatchCtx::ambient(),+ assert!(mark_stopped_task_if_thread_stopped(+ &crate::core::runtime::DispatchCtx::ambient(),w,"thread-compact","sub-late"@@ -573,7 +663,14 @@ fn deleting_a_thread_that_never_used_background_work_writes_nothing() {let _guard = test_guard();let ws = workspace();let w = ws.path();- assert_eq!(discard_for_thread(&crate::core::runtime::DispatchCtx::ambient(), w, "thread-plain"), 0);+ assert_eq!(+ discard_for_thread(+ &crate::core::runtime::DispatchCtx::ambient(),+ w,+ "thread-plain"+ ),+ 0+ );assert!(entry_for(w).store.list(None).is_empty(),"no marker is persisted for an ordinary thread"@@ -589,7 +686,11 @@ fn a_late_record_for_a_deleted_thread_is_dropped_by_the_durable_marker_alone() {let ws = workspace();let w = ws.path();record(w, "sess-dm", "sub-1", "x", Some("thread-dm"));- discard_for_thread(&crate::core::runtime::DispatchCtx::ambient(), w, "thread-dm");+ discard_for_thread(+ &crate::core::runtime::DispatchCtx::ambient(),+ w,+ "thread-dm",+ );// A restart empties the in-memory gates; the marker on disk still decides.forget_workspace_for_test(w);record(w, "sess-dm", "sub-late", "stale", Some("thread-dm"));@@ -601,7 +702,8 @@ async fn release_all_closes_every_router_and_the_log_stays_replayable() {let _guard = crate::config::TEST_ENV_LOCK.lock().await;let ws = workspace();let w = ws.path();- record_completion(&crate::core::runtime::DispatchCtx::ambient(),+ record_completion(+ &crate::core::runtime::DispatchCtx::ambient(),w,"sess-rel","sub-1",@@ -622,7 +724,10 @@ async fn release_all_closes_every_router_and_the_log_stays_replayable() {);// The next boot finds the undelivered completion from the log alone.- assert_eq!(recover_pending_threads(&crate::core::runtime::DispatchCtx::ambient(), w), ["thread-rel"]);+ assert_eq!(+ recover_pending_threads(&crate::core::runtime::DispatchCtx::ambient(), w),+ ["thread-rel"]+ );}#[tokio::test(start_paused = true)]@@ -662,16 +767,40 @@ async fn release_all_keeps_the_stop_and_delete_gates() {let _guard = crate::config::TEST_ENV_LOCK.lock().await;let ws = workspace();let w = ws.path();- discard_pending_for_thread(&crate::core::runtime::DispatchCtx::ambient(), "thread-keep-stop");+ discard_pending_for_thread(+ &crate::core::runtime::DispatchCtx::ambient(),+ "thread-keep-stop",+ );state().deleted_threads.insert("thread-keep-del".into());release_all().await;// A detached child finishing after the release is still refused.- record_completion(&crate::core::runtime::DispatchCtx::ambient(), w, "s", "sub-1", "r", "x", Some("thread-keep-stop".into())).await;- record_completion(&crate::core::runtime::DispatchCtx::ambient(), w, "s", "sub-2", "r", "x", Some("thread-keep-del".into())).await;+ record_completion(+ &crate::core::runtime::DispatchCtx::ambient(),+ w,+ "s",+ "sub-1",+ "r",+ "x",+ Some("thread-keep-stop".into()),+ )+ .await;+ record_completion(+ &crate::core::runtime::DispatchCtx::ambient(),+ w,+ "s",+ "sub-2",+ "r",+ "x",+ Some("thread-keep-del".into()),+ )+ .await;assert!(pending_ids(w, "thread-keep-stop").is_empty());assert!(pending_ids(w, "thread-keep-del").is_empty());- resume_stopped_thread(&crate::core::runtime::DispatchCtx::ambient(), "thread-keep-stop");+ resume_stopped_thread(+ &crate::core::runtime::DispatchCtx::ambient(),+ "thread-keep-stop",+ );state().deleted_threads.remove("thread-keep-del");}@@ -708,7 +837,8 @@ async fn a_store_that_keeps_failing_degrades_to_memory_instead_of_losing_the_reslet w = ws.path();install_store_for_test(w, Arc::new(FullDisk(InMemoryCompletionStore::new())));- record_completion(&crate::core::runtime::DispatchCtx::ambient(),+ record_completion(+ &crate::core::runtime::DispatchCtx::ambient(),w,"sess-fd","sub-1",diff --git a/crates/openhuman-core/src/agent/orchestration/background_delivery.rs b/crates/openhuman-core/src/agent/orchestration/background_delivery.rsindex 28bc75a43a..8495a7cf24 100644--- a/crates/openhuman-core/src/agent/orchestration/background_delivery.rs+++ b/crates/openhuman-core/src/agent/orchestration/background_delivery.rs@@ -295,11 +295,18 @@ fn scheduled_for_test() -> &'static Mutex<Vec<(String, Duration)>> {/// after [`RECOVERY_DELAY`], through the normal idle-gated path, fenced by the/// calling profile's lease when there is one. Returns the number of threads/// scheduled.-pub(crate) fn recover_on_boot(ctx: &crate::core::runtime::DispatchCtx, workspace_dir: &Path) -> usize {+pub(crate) fn recover_on_boot(+ ctx: &crate::core::runtime::DispatchCtx,+ workspace_dir: &Path,+) -> usize {recover_fenced(ctx, workspace_dir, DrainFence::current())}-fn recover_fenced(ctx: &crate::core::runtime::DispatchCtx, workspace_dir: &Path, fence: DrainFence) -> usize {+fn recover_fenced(+ ctx: &crate::core::runtime::DispatchCtx,+ workspace_dir: &Path,+ fence: DrainFence,+) -> usize {// Scheduling needs a runtime; check before claiming so a later call retries.if tokio::runtime::Handle::try_current().is_err() {log::warn!(@@ -380,7 +387,8 @@ async fn try_deliver();return;}- let Some(workspace_dir) = background_completions::workspace_for_thread(&busy_ctx, &thread_id) else {+ let Some(workspace_dir) = background_completions::workspace_for_thread(&busy_ctx, &thread_id)+ else {log::debug!("[background_delivery] no workspace for thread_id={thread_id}");return;};@@ -421,13 +429,13 @@ async fn try_deliver(/// outside this module.#[cfg(test)]pub(super) async fn try_deliver_for_test(- ctx: &crate::core::runtime::DispatchCtx,+ ctx: crate::core::runtime::DispatchCtx,thread_id: String,router: Arc<CompletionRouter>,turns: Arc<std::sync::atomic::AtomicU32>,) -> Option<Duration> {try_deliver_with(- ctx,+ &ctx,thread_id,router,move |_, _| {@@ -617,7 +625,11 @@ struct DeliverySlot {impl DeliverySlot {/// `None` when a delivery is already in flight for the thread.- fn claim(ctx: &crate::core::runtime::DispatchCtx, thread_id: &str, router: Arc<CompletionRouter>) -> Option<Self> {+ fn claim(+ ctx: &crate::core::runtime::DispatchCtx,+ thread_id: &str,+ router: Arc<CompletionRouter>,+ ) -> Option<Self> {let key = tenant::profile_key_in(&super::busy_guard::caller(ctx), thread_id);let mut d = delivering().lock().expect("delivering poisoned");if !d.insert(key.clone()) {diff --git a/crates/openhuman-core/src/agent/orchestration/background_delivery_recovery_tests.rs b/crates/openhuman-core/src/agent/orchestration/background_delivery_recovery_tests.rsindex b5614e37ee..69ff8ba1ff 100644--- a/crates/openhuman-core/src/agent/orchestration/background_delivery_recovery_tests.rs+++ b/crates/openhuman-core/src/agent/orchestration/background_delivery_recovery_tests.rs@@ -8,7 +8,8 @@ async fn a_mixed_batch_that_partly_gives_up_still_retries_the_rest() {record(w, "bd-mixed", "sub-old", "old", "thread-mixed").await;let router = router_for_workspace(w);for _ in 0..(DEFAULT_MAX_ATTEMPTS - 1) {- try_deliver_with(&crate::core::runtime::DispatchCtx::ambient(),+ try_deliver_with(+ &crate::core::runtime::DispatchCtx::ambient(),"thread-mixed".into(),router.clone(),|_t, _n| async move { Err::<String, String>("checkout failed".to_string()) },@@ -21,7 +22,8 @@ async fn a_mixed_batch_that_partly_gives_up_still_retries_the_rest() {let gave_up = Arc::new(Mutex::new(String::new()));let sink = Arc::clone(&gave_up);- let retry = try_deliver_with(&crate::core::runtime::DispatchCtx::ambient(),+ let retry = try_deliver_with(+ &crate::core::runtime::DispatchCtx::ambient(),"thread-mixed".into(),router,|_t, _n| async move { Err::<String, String>("checkout failed".to_string()) },diff --git a/crates/openhuman-core/src/agent/orchestration/background_delivery_slots_tests.rs b/crates/openhuman-core/src/agent/orchestration/background_delivery_slots_tests.rsindex 5c2f6b72e8..13a1a583a5 100644--- a/crates/openhuman-core/src/agent/orchestration/background_delivery_slots_tests.rs+++ b/crates/openhuman-core/src/agent/orchestration/background_delivery_slots_tests.rs@@ -49,7 +49,8 @@ async fn pair() -> Pair {for (ctx, ws, task) in [(&alice, &ws_a, "task-alice"), (&bob, &ws_b, "task-bob")] {CoreContext::scope(Arc::clone(ctx),- record_completion(&crate::core::runtime::DispatchCtx::ambient(),+ record_completion(+ &crate::core::runtime::DispatchCtx::ambient(),ws.path(),&session,task,@@ -78,22 +79,48 @@ fn in_scope<R>(ctx: &Arc<CoreContext>, f: impl FnOnce() -> R) -> R {async fn one_profiles_busy_turn_does_not_block_anothers_thread() {let _guard = crate::config::TEST_ENV_LOCK.lock().await;let p = pair().await;- let turn = in_scope(&p.alice, || TurnBusy::start(&crate::core::runtime::DispatchCtx::ambient(), &p.session));+ let turn = in_scope(&p.alice, || {+ TurnBusy::start(&crate::core::runtime::DispatchCtx::ambient(), &p.session)+ });- assert!(in_scope(&p.alice, || is_busy(&crate::core::runtime::DispatchCtx::ambient(), &p.thread)));- assert!(!in_scope(&p.bob, || is_busy(&crate::core::runtime::DispatchCtx::ambient(), &p.thread)));+ assert!(in_scope(&p.alice, || is_busy(+ &crate::core::runtime::DispatchCtx::ambient(),+ &p.thread+ )));+ assert!(!in_scope(&p.bob, || is_busy(+ &crate::core::runtime::DispatchCtx::ambient(),+ &p.thread+ )));let router_b = router_for_workspace(p.ws_b.path());- let batch = in_scope(&p.bob, || claim_ready(&crate::core::runtime::DispatchCtx::ambient(), &router_b, &p.thread))- .expect("bob's thread is idle while alice's turn runs");+ let batch = in_scope(&p.bob, || {+ claim_ready(+ &crate::core::runtime::DispatchCtx::ambient(),+ &router_b,+ &p.thread,+ )+ })+ .expect("bob's thread is idle while alice's turn runs");assert_eq!(batch[0].task_id, "task-bob");router_b.release(&["task-bob".to_string()]);// Bob's Stop clears only Bob's turns; Alice stays busy.- assert_eq!(in_scope(&p.bob, || clear_busy_for_thread(&crate::core::runtime::DispatchCtx::ambient(), &p.thread)), 0);- assert!(in_scope(&p.alice, || is_busy(&crate::core::runtime::DispatchCtx::ambient(), &p.thread)));+ assert_eq!(+ in_scope(&p.bob, || clear_busy_for_thread(+ &crate::core::runtime::DispatchCtx::ambient(),+ &p.thread+ )),+ 0+ );+ assert!(in_scope(&p.alice, || is_busy(+ &crate::core::runtime::DispatchCtx::ambient(),+ &p.thread+ )));drop(turn);- assert!(!in_scope(&p.alice, || is_busy(&crate::core::runtime::DispatchCtx::ambient(), &p.thread)));+ assert!(!in_scope(&p.alice, || is_busy(+ &crate::core::runtime::DispatchCtx::ambient(),+ &p.thread+ )));}#[tokio::test]@@ -106,18 +133,29 @@ async fn a_delivery_in_flight_for_one_profile_does_not_take_anothers_slot() {);let held = in_scope(&p.alice, || {- DeliverySlot::claim(&crate::core::runtime::DispatchCtx::ambient(), &p.thread, router_a.clone())+ DeliverySlot::claim(+ &crate::core::runtime::DispatchCtx::ambient(),+ &p.thread,+ router_a.clone(),+ )}).expect("alice claims her slot");assert!(- in_scope(&p.alice, || DeliverySlot::claim(&crate::core::runtime::DispatchCtx::ambient(),+ in_scope(&p.alice, || DeliverySlot::claim(+ &crate::core::runtime::DispatchCtx::ambient(),&p.thread,router_a.clone())).is_none(),"one delivery per thread within a profile");- let bob_slot = in_scope(&p.bob, || DeliverySlot::claim(&crate::core::runtime::DispatchCtx::ambient(), &p.thread, router_b.clone()));+ let bob_slot = in_scope(&p.bob, || {+ DeliverySlot::claim(+ &crate::core::runtime::DispatchCtx::ambient(),+ &p.thread,+ router_b.clone(),+ )+ });assert!(bob_slot.is_some(),"alice's delivery does not hold bob's slot"@@ -146,9 +184,13 @@ async fn a_delivery_in_flight_for_one_profile_does_not_take_anothers_slot() {async move {let retry = CoreContext::scope(bob,- try_deliver_with(&crate::core::runtime::DispatchCtx::ambient(), thread, router_bob, bob_log, |_t, _n| async {- unreachable!("bob's delivery succeeds")- }),+ try_deliver_with(+ &crate::core::runtime::DispatchCtx::ambient(),+ thread,+ router_bob,+ bob_log,+ |_t, _n| async { unreachable!("bob's delivery succeeds") },+ ),).await;assert_eq!(retry, None);@@ -157,9 +199,13 @@ async fn a_delivery_in_flight_for_one_profile_does_not_take_anothers_slot() {};let retry = CoreContext::scope(Arc::clone(&p.alice),- try_deliver_with(&crate::core::runtime::DispatchCtx::ambient(), p.thread.clone(), router_a, alice_deliver, |_t, _n| async {- unreachable!("alice's delivery succeeds")- }),+ try_deliver_with(+ &crate::core::runtime::DispatchCtx::ambient(),+ p.thread.clone(),+ router_a,+ alice_deliver,+ |_t, _n| async { unreachable!("alice's delivery succeeds") },+ ),).await;assert_eq!(retry, None);@@ -182,18 +228,34 @@ async fn desktop_keys_are_the_bare_ids() {let thread = unique("t-desk");let session = unique("desk-session");in_scope(&desktop, || {- background_completions::note_session_thread(&crate::core::runtime::DispatchCtx::ambient(), &session, &thread)+ background_completions::note_session_thread(+ &crate::core::runtime::DispatchCtx::ambient(),+ &session,+ &thread,+ )});- let turn = in_scope(&desktop, || TurnBusy::start(&crate::core::runtime::DispatchCtx::ambient(), &session));+ let turn = in_scope(&desktop, || {+ TurnBusy::start(&crate::core::runtime::DispatchCtx::ambient(), &session)+ });assert_eq!(turn.key, session);assert!(busy().lock().unwrap().contains_key(&session));- assert!(in_scope(&desktop, || is_busy(&crate::core::runtime::DispatchCtx::ambient(), &thread)));+ assert!(in_scope(&desktop, || is_busy(+ &crate::core::runtime::DispatchCtx::ambient(),+ &thread+ )));drop(turn);assert!(!busy().lock().unwrap().contains_key(&session));let router = router_for_workspace(ws.path());- let slot = in_scope(&desktop, || DeliverySlot::claim(&crate::core::runtime::DispatchCtx::ambient(), &thread, router)).expect("free");+ let slot = in_scope(&desktop, || {+ DeliverySlot::claim(+ &crate::core::runtime::DispatchCtx::ambient(),+ &thread,+ router,+ )+ })+ .expect("free");assert_eq!(slot.key, thread);assert!(delivering().lock().unwrap().contains(&thread));drop(slot);@@ -207,13 +269,23 @@ async fn an_older_guard_dropping_keeps_a_replacement_turn_busy() {let thread = unique("t-interrupt");let session = web_session(&thread);- let old = in_scope(&desktop, || TurnBusy::start(&crate::core::runtime::DispatchCtx::ambient(), &session));- let new = in_scope(&desktop, || TurnBusy::start(&crate::core::runtime::DispatchCtx::ambient(), &session));+ let old = in_scope(&desktop, || {+ TurnBusy::start(&crate::core::runtime::DispatchCtx::ambient(), &session)+ });+ let new = in_scope(&desktop, || {+ TurnBusy::start(&crate::core::runtime::DispatchCtx::ambient(), &session)+ });drop(old);assert!(- in_scope(&desktop, || is_busy(&crate::core::runtime::DispatchCtx::ambient(), &thread)),+ in_scope(&desktop, || is_busy(+ &crate::core::runtime::DispatchCtx::ambient(),+ &thread+ )),"replacement still running");drop(new);- assert!(!in_scope(&desktop, || is_busy(&crate::core::runtime::DispatchCtx::ambient(), &thread)));+ assert!(!in_scope(&desktop, || is_busy(+ &crate::core::runtime::DispatchCtx::ambient(),+ &thread+ )));}diff --git a/crates/openhuman-core/src/agent/orchestration/background_delivery_tests.rs b/crates/openhuman-core/src/agent/orchestration/background_delivery_tests.rsindex d2764396f0..a51b8c213d 100644--- a/crates/openhuman-core/src/agent/orchestration/background_delivery_tests.rs+++ b/crates/openhuman-core/src/agent/orchestration/background_delivery_tests.rs@@ -16,7 +16,16 @@ fn workspace() -> TestWorkspace {}async fn record(ws: &Path, session: &str, task: &str, summary: &str, thread: &str) {let thread = Some(thread.to_owned());- record_completion(&crate::core::runtime::DispatchCtx::ambient(), ws, session, task, "researcher", summary, thread).await;+ record_completion(+ &crate::core::runtime::DispatchCtx::ambient(),+ ws,+ session,+ task,+ "researcher",+ summary,+ thread,+ )+ .await;}fn pending_ids(ws: &Path, thread: &str) -> Vec<String> {pending_for(ws, thread)@@ -47,14 +56,24 @@ async fn claim_takes_the_ready_batch_when_idle() {record(w, "bd-ready", "sub-2", "beta", "thread-ready").await;let router = router_for_workspace(w);- let batch = claim_ready(&crate::core::runtime::DispatchCtx::ambient(), &router, "thread-ready").expect("claims a batch");+ let batch = claim_ready(+ &crate::core::runtime::DispatchCtx::ambient(),+ &router,+ "thread-ready",+ )+ .expect("claims a batch");assert_eq!(batch.len(), 2);let notice = router.formatter().format_batch(&batch);assert!(notice.contains("sub-1") && notice.contains("sub-2"));// The records stay pending (leased) until the turn lands.assert_eq!(pending_ids(w, "thread-ready").len(), 2);assert!(- claim_ready(&crate::core::runtime::DispatchCtx::ambient(), &router, "thread-ready").is_none(),+ claim_ready(+ &crate::core::runtime::DispatchCtx::ambient(),+ &router,+ "thread-ready"+ )+ .is_none(),"a held lease is not claimed twice");}@@ -68,10 +87,20 @@ async fn claim_skips_a_busy_thread_and_leaves_the_queue_intact() {let router = router_for_workspace(w);mark_busy("bd-busy");- assert!(claim_ready(&crate::core::runtime::DispatchCtx::ambient(), &router, "thread-busy").is_none());+ assert!(claim_ready(+ &crate::core::runtime::DispatchCtx::ambient(),+ &router,+ "thread-busy"+ )+ .is_none());clear_busy("bd-busy");assert!(- claim_ready(&crate::core::runtime::DispatchCtx::ambient(), &router, "thread-busy").is_some(),+ claim_ready(+ &crate::core::runtime::DispatchCtx::ambient(),+ &router,+ "thread-busy"+ )+ .is_some(),"a deferral leaves the record claimable");assert_eq!(@@ -86,7 +115,12 @@ async fn claim_is_none_when_nothing_is_pending() {let _g = test_guard().await;let ws = workspace();let router = router_for_workspace(ws.path());- assert!(claim_ready(&crate::core::runtime::DispatchCtx::ambient(), &router, "bd-empty-unique").is_none());+ assert!(claim_ready(+ &crate::core::runtime::DispatchCtx::ambient(),+ &router,+ "bd-empty-unique"+ )+ .is_none());}#[tokio::test]@@ -99,7 +133,8 @@ async fn a_delivered_batch_is_settled_and_not_redelivered() {let turns = Arc::new(AtomicU32::new(0));let seen = Arc::clone(&turns);- try_deliver_with(&crate::core::runtime::DispatchCtx::ambient(),+ try_deliver_with(+ &crate::core::runtime::DispatchCtx::ambient(),"thread-ok".into(),router.clone(),move |thread, notice| {@@ -133,7 +168,8 @@ async fn persistence_failure_releases_batch_without_terminal_announcement() {let announced = Arc::new(AtomicBool::new(false));let announced_for_delivery = Arc::clone(&announced);- try_deliver_with(&crate::core::runtime::DispatchCtx::ambient(),+ try_deliver_with(+ &crate::core::runtime::DispatchCtx::ambient(),"thread-persist".into(),router.clone(),move |_thread_id, _notice| {@@ -174,9 +210,15 @@ async fn a_turn_is_busy_until_its_guard_drops() {let sid = r#"{"client_id":"c","thread_id":"bd-turn-thread"}"#.to_string();let turn = TurnBusy::start(&crate::core::runtime::DispatchCtx::ambient(), &sid);- assert!(is_busy(&crate::core::runtime::DispatchCtx::ambient(), "bd-turn-thread"));+ assert!(is_busy(+ &crate::core::runtime::DispatchCtx::ambient(),+ "bd-turn-thread"+ ));drop(turn);- assert!(!is_busy(&crate::core::runtime::DispatchCtx::ambient(), "bd-turn-thread"));+ assert!(!is_busy(+ &crate::core::runtime::DispatchCtx::ambient(),+ "bd-turn-thread"+ ));// The bus events no longer mark busy: the subscriber runs off-task and// cannot tell which profile a session belongs to.@@ -186,7 +228,10 @@ async fn a_turn_is_busy_until_its_guard_drops() {channel: "test".into(),}).await;- assert!(!is_busy(&crate::core::runtime::DispatchCtx::ambient(), "bd-turn-thread"));+ assert!(!is_busy(+ &crate::core::runtime::DispatchCtx::ambient(),+ "bd-turn-thread"+ ));}/// Drive the real delivery loop with a turn executor that always fails, the@@ -206,7 +251,8 @@ async fn drain_until_empty_or(}let turns_for_delivery = Arc::clone(&turns);let sink = Arc::clone(&undelivered);- try_deliver_with(&crate::core::runtime::DispatchCtx::ambient(),+ try_deliver_with(+ &crate::core::runtime::DispatchCtx::ambient(),thread.to_string(),router.clone(),move |_thread_id, _notice| {@@ -307,7 +353,8 @@ async fn transient_failure_under_the_ceiling_keeps_the_result() {record(w, "bd-transient", "sub-1", "alpha", "thread-transient").await;let router = router_for_workspace(w);- try_deliver_with(&crate::core::runtime::DispatchCtx::ambient(),+ try_deliver_with(+ &crate::core::runtime::DispatchCtx::ambient(),"thread-transient".into(),router.clone(),|_t, _n| async move { Err::<String, String>("blip".to_string()) },@@ -341,7 +388,8 @@ async fn busy_deferral_does_not_consume_the_failure_budget() {for _ in 0..(DEFAULT_MAX_ATTEMPTS * 2) {mark_busy("bd-busy-defer");- try_deliver_with(&crate::core::runtime::DispatchCtx::ambient(),+ try_deliver_with(+ &crate::core::runtime::DispatchCtx::ambient(),"thread-busy-defer".into(),router.clone(),|_t, _n| async move { unreachable!("must not run a delivery turn while busy") },@@ -415,13 +463,21 @@ async fn a_pending_completion_survives_a_restart_and_is_delivered() {drop(router);forget_workspace_for_test(w);- let threads = background_completions::recover_pending_threads(&crate::core::runtime::DispatchCtx::ambient(), w);+ let threads = background_completions::recover_pending_threads(+ &crate::core::runtime::DispatchCtx::ambient(),+ w,+ );assert_eq!(threads, ["thread-restart"]);- let router = background_completions::router_for_thread(&crate::core::runtime::DispatchCtx::ambient(), "thread-restart").expect("recovered");+ let router = background_completions::router_for_thread(+ &crate::core::runtime::DispatchCtx::ambient(),+ "thread-restart",+ )+ .expect("recovered");let delivered = Arc::new(Mutex::new(Vec::<String>::new()));let sink = Arc::clone(&delivered);- try_deliver_with(&crate::core::runtime::DispatchCtx::ambient(),+ try_deliver_with(+ &crate::core::runtime::DispatchCtx::ambient(),"thread-restart".into(),router,move |thread, notice| {@@ -447,7 +503,11 @@ async fn a_pending_completion_survives_a_restart_and_is_delivered() {);forget_workspace_for_test(w);- assert!(background_completions::recover_pending_threads(&crate::core::runtime::DispatchCtx::ambient(), w).is_empty());+ assert!(background_completions::recover_pending_threads(+ &crate::core::runtime::DispatchCtx::ambient(),+ w+ )+ .is_empty());}#[tokio::test]@@ -525,7 +585,8 @@ async fn a_delivered_batch_restores_the_full_failure_budget() {router_for_workspace(w)};for _ in 0..(DEFAULT_MAX_ATTEMPTS - 1) {- try_deliver_with(&crate::core::runtime::DispatchCtx::ambient(),+ try_deliver_with(+ &crate::core::runtime::DispatchCtx::ambient(),"thread-budget".into(),router.clone(),|_t, _n| async move { Err::<String, String>("blip".to_string()) },@@ -533,7 +594,8 @@ async fn a_delivered_batch_restores_the_full_failure_budget() {).await;}- try_deliver_with(&crate::core::runtime::DispatchCtx::ambient(),+ try_deliver_with(+ &crate::core::runtime::DispatchCtx::ambient(),"thread-budget".into(),router.clone(),|_t, _n| async move { Ok::<String, String>("delivered".to_string()) },@@ -567,7 +629,8 @@ async fn a_dropped_delivery_releases_its_slot_and_lease() {let in_flight = tokio::spawn({let router = router.clone();async move {- try_deliver_with(&crate::core::runtime::DispatchCtx::ambient(),+ try_deliver_with(+ &crate::core::runtime::DispatchCtx::ambient(),"thread-drop".into(),router,move |_t, _n| {@@ -587,7 +650,8 @@ async fn a_dropped_delivery_releases_its_slot_and_lease() {let delivered = Arc::new(Mutex::new(false));let flag = Arc::clone(&delivered);- try_deliver_with(&crate::core::runtime::DispatchCtx::ambient(),+ try_deliver_with(+ &crate::core::runtime::DispatchCtx::ambient(),"thread-drop".into(),router,move |_t, _n| {@@ -617,7 +681,8 @@ async fn a_failed_turn_under_the_ceiling_asks_for_a_backoff_retry() {record(w, "bd-retry", "sub-1", "alpha", "thread-retry").await;let router = router_for_workspace(w);- let retry = try_deliver_with(&crate::core::runtime::DispatchCtx::ambient(),+ let retry = try_deliver_with(+ &crate::core::runtime::DispatchCtx::ambient(),"thread-retry".into(),router.clone(),|_t, _n| async move { Err::<String, String>("session checkout failed".to_string()) },@@ -626,7 +691,8 @@ async fn a_failed_turn_under_the_ceiling_asks_for_a_backoff_retry() {.await;assert_eq!(retry, Some(retry_backoff(1)));- let delivered = try_deliver_with(&crate::core::runtime::DispatchCtx::ambient(),+ let delivered = try_deliver_with(+ &crate::core::runtime::DispatchCtx::ambient(),"thread-retry".into(),router,|_t, _n| async move { Ok::<String, String>("presented".to_string()) },@@ -658,7 +724,10 @@ async fn boot_recovery_schedules_a_delivery_for_every_thread_with_undelivered_reforget_workspace_for_test(w);scheduled_for_test().lock().expect("scheduled").clear();- assert_eq!(recover_on_boot(&crate::core::runtime::DispatchCtx::ambient(), w), 1);+ assert_eq!(+ recover_on_boot(&crate::core::runtime::DispatchCtx::ambient(), w),+ 1+ );assert!(scheduled_for_test().lock().expect("scheduled")@@ -677,10 +746,21 @@ async fn recover_on_open_rescans_a_workspace_already_recovered() {let w = ws.path();record(w, "bd-open", "sub-1", "left pending", "thread-open-resc").await;forget_workspace_for_test(w);- assert_eq!(recover_on_boot(&crate::core::runtime::DispatchCtx::ambient(), w), 1);- assert_eq!(recover_on_boot(&crate::core::runtime::DispatchCtx::ambient(), w), 0, "boot recovery claims once");assert_eq!(- recover_on_open(&crate::core::runtime::DispatchCtx::ambient(), w, DrainFence::none()),+ recover_on_boot(&crate::core::runtime::DispatchCtx::ambient(), w),+ 1+ );+ assert_eq!(+ recover_on_boot(&crate::core::runtime::DispatchCtx::ambient(), w),+ 0,+ "boot recovery claims once"+ );+ assert_eq!(+ recover_on_open(+ &crate::core::runtime::DispatchCtx::ambient(),+ w,+ DrainFence::none()+ ),1,"a re-open scans again");@@ -694,12 +774,30 @@ async fn a_cancelled_turn_does_not_leave_the_thread_busy() {let other = r#"{"client_id":"c","thread_id":"bd-other-thread"}"#;mark_busy(session);mark_busy(other);- assert!(is_busy(&crate::core::runtime::DispatchCtx::ambient(), "bd-stale-thread"));+ assert!(is_busy(+ &crate::core::runtime::DispatchCtx::ambient(),+ "bd-stale-thread"+ ));- assert_eq!(clear_busy_for_thread(&crate::core::runtime::DispatchCtx::ambient(), "bd-stale-thread"), 1);+ assert_eq!(+ clear_busy_for_thread(+ &crate::core::runtime::DispatchCtx::ambient(),+ "bd-stale-thread"+ ),+ 1+ );- assert!(!is_busy(&crate::core::runtime::DispatchCtx::ambient(), "bd-stale-thread"));- assert!(is_busy(&crate::core::runtime::DispatchCtx::ambient(), "bd-other-thread"), "other threads are untouched");+ assert!(!is_busy(+ &crate::core::runtime::DispatchCtx::ambient(),+ "bd-stale-thread"+ ));+ assert!(+ is_busy(+ &crate::core::runtime::DispatchCtx::ambient(),+ "bd-other-thread"+ ),+ "other threads are untouched"+ );clear_busy(other);}diff --git a/crates/openhuman-core/src/agent/orchestration/delivery_drain_tests.rs b/crates/openhuman-core/src/agent/orchestration/delivery_drain_tests.rsindex e385371da5..481766e01b 100644--- a/crates/openhuman-core/src/agent/orchestration/delivery_drain_tests.rs+++ b/crates/openhuman-core/src/agent/orchestration/delivery_drain_tests.rs@@ -38,9 +38,17 @@ async fn drain() -> (DrainOutcome, bool) {let ran = Arc::new(AtomicBool::new(false));let flag = Arc::clone(&ran);- let outcome = run_drain(&crate::core::runtime::DispatchCtx::ambient(), thread, delay, wait_idle, fence, SHORT, || async move {- flag.store(true, Ordering::SeqCst);- })+ let outcome = run_drain(+ &crate::core::runtime::DispatchCtx::ambient(),+ thread,+ delay,+ wait_idle,+ fence,+ SHORT,+ || async move {+ flag.store(true, Ordering::SeqCst);+ },+ ).await;(outcome, ran.load(Ordering::SeqCst))}@@ -113,7 +121,10 @@ async fn an_expired_grant_fences_the_drain_without_a_latch() {async fn losing_the_lease_while_waiting_for_an_idle_thread_drops_the_drain() {let _g = crate::config::TEST_ENV_LOCK.lock().await;let (_leases, fence) = live_fence();- let turn = TurnBusy::start_on_thread(&crate::core::runtime::DispatchCtx::ambient(), "dd-busy-fenced");+ let turn = TurnBusy::start_on_thread(+ &crate::core::runtime::DispatchCtx::ambient(),+ "dd-busy-fenced",+ );let latch = Arc::clone(&fence);tokio::spawn(async move {tokio::time::sleep(SHORT * 3).await;@@ -130,7 +141,10 @@ async fn a_recovered_drain_waits_for_a_relayed_turn_on_its_thread() {let _g = crate::config::TEST_ENV_LOCK.lock().await;let thread = "dd-relayed-thread";let turn = TurnBusy::start_on_thread(&crate::core::runtime::DispatchCtx::ambient(), thread);- assert!(is_busy(&crate::core::runtime::DispatchCtx::ambient(), thread), "a relayed turn marks its thread busy");+ assert!(+ is_busy(&crate::core::runtime::DispatchCtx::ambient(), thread),+ "a relayed turn marks its thread busy"+ );let release = tokio::spawn(async move {tokio::time::sleep(SHORT * 3).await;drop(turn);@@ -139,7 +153,10 @@ async fn a_recovered_drain_waits_for_a_relayed_turn_on_its_thread() {release.await.unwrap();assert_eq!(outcome, DrainOutcome::Ran);assert!(ran);- assert!(!is_busy(&crate::core::runtime::DispatchCtx::ambient(), thread));+ assert!(!is_busy(+ &crate::core::runtime::DispatchCtx::ambient(),+ thread+ ));}#[tokio::test]@@ -148,7 +165,8 @@ async fn a_delivery_waits_while_a_relayed_turn_runs_on_its_thread() {let ws = TestWorkspace::new();let w = ws.path();let thread = "dd-relay-deliver";- record_completion(&crate::core::runtime::DispatchCtx::ambient(),+ record_completion(+ &crate::core::runtime::DispatchCtx::ambient(),w,"dd-relay-session","sub-relay",@@ -160,7 +178,8 @@ async fn a_delivery_waits_while_a_relayed_turn_runs_on_its_thread() {let router = router_for_workspace(w);let turns = Arc::new(AtomicU32::new(0));let attempt = |turns: Arc<AtomicU32>| {- super::super::background_delivery::try_deliver_for_test(&crate::core::runtime::DispatchCtx::ambient(),+ super::super::background_delivery::try_deliver_for_test(+ crate::core::runtime::DispatchCtx::ambient(),thread.to_string(),Arc::clone(&router),turns,diff --git a/crates/openhuman-core/src/agent/session_store/mod_tests.rs b/crates/openhuman-core/src/agent/session_store/mod_tests.rsindex 6a916b8125..97da9c0292 100644--- a/crates/openhuman-core/src/agent/session_store/mod_tests.rs+++ b/crates/openhuman-core/src/agent/session_store/mod_tests.rs@@ -29,7 +29,8 @@ async fn a_scoped_provider_serves_only_its_own_task() {async fn work_outside_an_agent_context_uses_the_default_agent() {let provider: Arc<dyn SessionStoreProvider> = Arc::new(InMemorySessionStores::new());let key = scope(provider.clone(), async {- current().map(|stores| stores.transcripts.destination_key())+ current(&crate::core::runtime::DispatchCtx::ambient())+ .map(|stores| stores.transcripts.destination_key())}).await;// No agent context in a unit test: the shared default bucket.@@ -42,7 +43,7 @@ async fn work_outside_an_agent_context_uses_the_default_agent() {.destination_key()));- assert!(current().is_none() || is_installed());+ assert!(current(&crate::core::runtime::DispatchCtx::ambient()).is_none() || is_installed());}#[tokio::test]@@ -68,7 +69,8 @@ async fn transcripts_come_from_the_store_only_when_one_is_in_effect() {async fn without_a_store_transcripts_are_workspace_files() {let dir = std::path::Path::new("/nonexistent-openhuman-workspace");assert_eq!(- transcripts_or_files(&crate::core::runtime::DispatchCtx::ambient(), "u1", dir).destination_key(),+ transcripts_or_files(&crate::core::runtime::DispatchCtx::ambient(), "u1", dir)+ .destination_key(),// tinyagents keys the file destination on the resolved `session_raw`// directory under the workspace (tinyagents#06ad95ea).Some(dir.join("session_raw").to_string_lossy().into_owned())@@ -76,7 +78,8 @@ async fn without_a_store_transcripts_are_workspace_files() {let provider: Arc<dyn SessionStoreProvider> = Arc::new(InMemorySessionStores::new());let expected = provider.for_agent("u1").transcripts.destination_key();let found = scope(provider, async {- transcripts_or_files(&crate::core::runtime::DispatchCtx::ambient(), "u1", dir).destination_key()+ transcripts_or_files(&crate::core::runtime::DispatchCtx::ambient(), "u1", dir)+ .destination_key()}).await;assert_eq!(found, expected);@@ -126,10 +129,25 @@ async fn under<T>(ctx: Arc<crate::core::runtime::CoreContext>, f: impl FnOnce()#[tokio::test]async fn desktop_session_keys_and_transcript_roots_are_unchanged() {let ws = std::path::Path::new("/ws");- assert_eq!(current_agent_key_or(&crate::core::runtime::DispatchCtx::ambient(), "orchestrator"), "orchestrator");- assert_eq!(transcript_root(&crate::core::runtime::DispatchCtx::ambient(), ws), ws.to_path_buf());+ assert_eq!(+ current_agent_key_or(+ &crate::core::runtime::DispatchCtx::ambient(),+ "orchestrator"+ ),+ "orchestrator"+ );+ assert_eq!(+ transcript_root(&crate::core::runtime::DispatchCtx::ambient(), ws),+ ws.to_path_buf()+ );let (key, root) = under(derived(None, Some("alpha")), || {- (current_agent_key_or(&crate::core::runtime::DispatchCtx::ambient(), "orchestrator"), transcript_root(&crate::core::runtime::DispatchCtx::ambient(), ws))+ (+ current_agent_key_or(+ &crate::core::runtime::DispatchCtx::ambient(),+ "orchestrator",+ ),+ transcript_root(&crate::core::runtime::DispatchCtx::ambient(), ws),+ )}).await;assert_eq!(key, "alpha");@@ -140,11 +158,20 @@ async fn desktop_session_keys_and_transcript_roots_are_unchanged() {async fn two_profiles_default_agents_keep_separate_session_keys_and_stores() {let ws = std::path::Path::new("/ws-profile");let (alice_key, alice_root) = under(derived(Some("alice"), None), || {- (current_agent_key_or(&crate::core::runtime::DispatchCtx::ambient(), "orchestrator"), transcript_root(&crate::core::runtime::DispatchCtx::ambient(), ws))+ (+ current_agent_key_or(+ &crate::core::runtime::DispatchCtx::ambient(),+ "orchestrator",+ ),+ transcript_root(&crate::core::runtime::DispatchCtx::ambient(), ws),+ )}).await;let bob_key = under(derived(Some("bob"), None), || {- current_agent_key_or(&crate::core::runtime::DispatchCtx::ambient(), "orchestrator")+ current_agent_key_or(+ &crate::core::runtime::DispatchCtx::ambient(),+ "orchestrator",+ )}).await;assert_eq!(alice_key, "alice~default");@@ -157,7 +184,10 @@ async fn two_profiles_default_agents_keep_separate_session_keys_and_stores() {let provider = provider.clone();crate::core::runtime::CoreContext::scope(derived_with_store(Some(profile), None, provider),- async { current().map(|stores| stores.transcripts.destination_key()) },+ async {+ current(&crate::core::runtime::DispatchCtx::ambient())+ .map(|stores| stores.transcripts.destination_key())+ },)};let (alice, bob) = (stores_of("alice").await, stores_of("bob").await);diff --git a/crates/openhuman-core/src/cron/completion_owner_tests.rs b/crates/openhuman-core/src/cron/completion_owner_tests.rsindex bc7d01b38a..11fa9ca7eb 100644--- a/crates/openhuman-core/src/cron/completion_owner_tests.rs+++ b/crates/openhuman-core/src/cron/completion_owner_tests.rs@@ -11,7 +11,13 @@ async fn a_job_completed_as_an_agent_is_noted_once() {).session_agent("completion-owner-agent"),);- CoreContext::scope(agent, async { note("completion-owner-job") }).await;+ CoreContext::scope(agent, async {+ note(+ &crate::core::runtime::DispatchCtx::ambient(),+ "completion-owner-job",+ )+ })+ .await;assert_eq!(take("completion-owner-job").as_deref(),Some("completion-owner-agent")@@ -21,6 +27,9 @@ async fn a_job_completed_as_an_agent_is_noted_once() {#[test]fn a_job_completed_without_an_agent_is_not_noted() {- note("completion-owner-local");+ note(+ &crate::core::runtime::DispatchCtx::ambient(),+ "completion-owner-local",+ );assert_eq!(take("completion-owner-local"), None);}