Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

test: scope dispatch contexts explicitly in tenant isolation tests

Steven Enamakel595059575ad3
diff --git a/crates/openhuman-core/src/agent/orchestration/background_completions_tenant_tests.rs b/crates/openhuman-core/src/agent/orchestration/background_completions_tenant_tests.rs
index 13c6988f5c..f263e8cfc4 100644
--- a/crates/openhuman-core/src/agent/orchestration/background_completions_tenant_tests.rs
+++ b/crates/openhuman-core/src/agent/orchestration/background_completions_tenant_tests.rs
@@ -22,14 +22,17 @@ fn profile(name: &str, workspace: &std::path::Path) -> Arc<CoreContext> {
}
async fn record(ctx: &Arc<CoreContext>, ws: &std::path::Path, task: &str) {
- record_completion(
- &DispatchCtx::new(Arc::clone(ctx)),
- ws,
- "sess-1",
- task,
- "researcher",
- "done",
- Some("t1".into()),
+ CoreContext::scope(
+ Arc::clone(ctx),
+ record_completion(
+ &DispatchCtx::new(Arc::clone(ctx)),
+ ws,
+ "sess-1",
+ task,
+ "researcher",
+ "done",
+ Some("t1".into()),
+ ),
)
.await;
}
@@ -50,11 +53,10 @@ async fn one_profiles_stop_and_delete_never_reach_anothers_thread() {
// Alice presses Stop on her `t1`.
{
- let scope_ctx = DispatchCtx::new(Arc::clone(&alice));
+ let scope_ctx = crate::core::runtime::DispatchCtx::new(Arc::clone(&alice));
discard_pending_for_thread(&scope_ctx, "t1");
-
-};
+ };
// Bob's `t1` is untouched: his results still queue.
record(&bob, ws_b.path(), "bob-1").await;
@@ -65,26 +67,19 @@ async fn one_profiles_stop_and_delete_never_reach_anothers_thread() {
// Bob deletes his `t1`; Alice re-engages hers and keeps working.
{
- let scope_ctx = DispatchCtx::new(Arc::clone(&bob));
+ let scope_ctx = crate::core::runtime::DispatchCtx::new(Arc::clone(&bob));
discard_for_thread(&scope_ctx, ws_b.path(), "t1");
-
-};
+ };
{
- let scope_ctx = DispatchCtx::new(Arc::clone(&alice));
+ let scope_ctx = crate::core::runtime::DispatchCtx::new(Arc::clone(&alice));
resume_stopped_thread(&scope_ctx, "t1");
assert!(
- !mark_stopped_task_if_thread_stopped(
- &scope_ctx,
- ws_a.path(),
- "t1",
- "alice-2"
- ),
+ !mark_stopped_task_if_thread_stopped(&scope_ctx, ws_a.path(), "t1", "alice-2"),
"bob's delete does not abort alice's child"
);
-
-};
+ };
record(&alice, ws_a.path(), "alice-2").await;
assert_eq!(pending(ws_a.path()), ["alice-2"]);
record(&bob, ws_b.path(), "bob-2").await;
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.rs
index 4df3daa352..e09bc83f43 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
@@ -48,16 +48,19 @@ async fn pair() -> Pair {
let thread = unique("t");
let session = web_session(&thread);
for (ctx, ws, task) in [(&alice, &ws_a, "task-alice"), (&bob, &ws_b, "task-bob")] {
- record_completion(
- &DispatchCtx::new(Arc::clone(ctx)),
- ws.path(),
- &session,
- task,
- "researcher",
- "done",
- Some(thread.clone()),
- )
- .await;
+ {
+ let scope_ctx = crate::core::runtime::DispatchCtx::new(Arc::clone(ctx));
+ record_completion(
+ &scope_ctx,
+ ws.path(),
+ &session,
+ task,
+ "researcher",
+ "done",
+ Some(thread.clone()),
+ )
+ .await
+ };
}
Pair {
alice,
@@ -168,26 +171,28 @@ async fn a_delivery_in_flight_for_one_profile_does_not_take_anothers_slot() {
let (thread, router_bob, bob_log) = (thread.clone(), router_bob.clone(), bob_log.clone());
let alice_log = log("alice");
async move {
- let retry = try_deliver_with(
- &DispatchCtx::new(bob),
- thread,
- router_bob,
- bob_log,
- |_t, _n| async { unreachable!("bob's delivery succeeds") },
- )
- .await;
+ let retry = {
+ let scope_ctx = crate::core::runtime::DispatchCtx::new(bob);
+ try_deliver_with(&scope_ctx, thread, router_bob, bob_log, |_t, _n| async {
+ unreachable!("bob's delivery succeeds")
+ })
+ .await
+ };
assert_eq!(retry, None);
alice_log(thread_a, notice).await
}
};
- let retry = try_deliver_with(
- &DispatchCtx::new(Arc::clone(&p.alice)),
- p.thread.clone(),
- router_a,
- alice_deliver,
- |_t, _n| async { unreachable!("alice's delivery succeeds") },
- )
- .await;
+ let retry = {
+ let scope_ctx = crate::core::runtime::DispatchCtx::new(Arc::clone(&p.alice));
+ try_deliver_with(
+ &scope_ctx,
+ p.thread.clone(),
+ router_a,
+ alice_deliver,
+ |_t, _n| async { unreachable!("alice's delivery succeeds") },
+ )
+ .await
+ };
assert_eq!(retry, None);
let delivered = delivered.lock().unwrap().clone();
diff --git a/crates/openhuman-core/src/agent/orchestration/background_delivery_tenant_tests.rs b/crates/openhuman-core/src/agent/orchestration/background_delivery_tenant_tests.rs
index c72e47df3c..aeb30e745b 100644
--- a/crates/openhuman-core/src/agent/orchestration/background_delivery_tenant_tests.rs
+++ b/crates/openhuman-core/src/agent/orchestration/background_delivery_tenant_tests.rs
@@ -69,14 +69,17 @@ async fn an_off_task_completion_drains_only_its_owners_thread() {
let (task_a, task_b) = (unique("sub-a"), unique("sub-b"));
for (ctx, ws, task) in [(&alice, &ws_a, &task_a), (&bob, &ws_b, &task_b)] {
- record_completion(
- &DispatchCtx::new(Arc::clone(ctx)),
- ws.path(),
- &session,
- task.as_str(),
- "r",
- "done",
- Some(thread.into()),
+ CoreContext::scope(
+ Arc::clone(ctx),
+ record_completion(
+ &DispatchCtx::new(Arc::clone(ctx)),
+ ws.path(),
+ &session,
+ task.as_str(),
+ "r",
+ "done",
+ Some(thread.into()),
+ ),
)
.await;
}
diff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents_tenant_tests.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents_tenant_tests.rs
index cb29a515ed..49f28fb01b 100644
--- a/crates/openhuman-core/src/agent/orchestration/running_subagents_tenant_tests.rs
+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents_tenant_tests.rs
@@ -228,11 +228,10 @@ async fn saas_dispatch_exposes_only_the_callers_detached_worker_controls() {
})
.await;
{
- let scope_ctx = DispatchCtx::new(pair.alice.clone());
+ let scope_ctx = crate::core::runtime::DispatchCtx::new(pair.alice.clone());
assert!(resume_ref_for_task(&scope_ctx, &pair.a.task, PARENT).is_ok());
-
-};
+ };
for function in ["steer", "cancel"] {
assert!(dispatched_control(function, &pair.a.task).await.is_err());
}
@@ -362,7 +361,7 @@ async fn same_parent_resolution_and_wait_refuse_foreign_workers() {
}
let pair = Pair::new();
{
- let scope_ctx = DispatchCtx::new(pair.bob.clone());
+ let scope_ctx = crate::core::runtime::DispatchCtx::new(pair.bob.clone());
assert!(matches!(
task_id_for_session(&scope_ctx, &pair.a.session, PARENT),
@@ -373,21 +372,14 @@ async fn same_parent_resolution_and_wait_refuse_foreign_workers() {
Err(WaitError::NotOwned)
));
assert!(matches!(
- wait(
- &scope_ctx,
- &pair.a.task,
- PARENT,
- Duration::ZERO
- )
- .await,
+ wait(&scope_ctx, &pair.a.task, PARENT, Duration::ZERO).await,
Err(WaitError::NotOwned)
));
assert_eq!(
task_id_for_session(&scope_ctx, &pair.b.session, PARENT).unwrap(),
pair.b.task
);
-
-};
+ };
}
#[tokio::test]
@@ -400,7 +392,7 @@ async fn same_parent_agent_steering_refuses_foreign_worker() {
}
let pair = Pair::new();
{
- let scope_ctx = DispatchCtx::new(pair.bob.clone());
+ let scope_ctx = crate::core::runtime::DispatchCtx::new(pair.bob.clone());
assert_eq!(
steer(
@@ -424,8 +416,7 @@ async fn same_parent_agent_steering_refuses_foreign_worker() {
.await
.unwrap();
assert_eq!(pair.b.queue.status().await.steers, 1);
-
-};
+ };
}
#[tokio::test]
@@ -459,7 +450,7 @@ async fn public_cancellation_refuses_another_profiles_task() {
}
let pair = Pair::new();
{
- let scope_ctx = DispatchCtx::new(pair.bob.clone());
+ let scope_ctx = crate::core::runtime::DispatchCtx::new(pair.bob.clone());
assert_eq!(
field(&control("cancel", &pair.a.task).await, "cancelled"),
@@ -470,17 +461,15 @@ async fn public_cancellation_refuses_another_profiles_task() {
field(&control("cancel", &pair.b.task).await, "cancelled"),
Some(true)
);
-
-};
+ };
{
- let scope_ctx = DispatchCtx::new(pair.alice.clone());
+ let scope_ctx = crate::core::runtime::DispatchCtx::new(pair.alice.clone());
assert!(
resume_ref_for_task(&scope_ctx, &pair.a.task, PARENT).is_ok(),
"foreign cancel leaves original worker live"
);
-
-};
+ };
}
#[tokio::test]
@@ -523,7 +512,8 @@ async fn missing_saas_scope_cannot_observe_or_control_workers() {
});
// A scoped kernel context without an admitted profile is not authority.
{
- let scope_ctx = DispatchCtx::new(CoreContext::for_test(DomainSet::full(), None));
+ let scope_ctx =
+ crate::core::runtime::DispatchCtx::new(CoreContext::for_test(DomainSet::full(), None));
assert!(snapshot_for_parent(&scope_ctx, PARENT).is_empty());
assert!(matches!(
@@ -538,8 +528,7 @@ async fn missing_saas_scope_cannot_observe_or_control_workers() {
field(&control("cancel", &pair.a.task).await, "cancelled"),
Some(false)
);
-
-};
+ };
}
#[tokio::test]
diff --git a/crates/openhuman-core/src/agent/subagent_host/lifecycle_tests.rs b/crates/openhuman-core/src/agent/subagent_host/lifecycle_tests.rs
index 8da8359aa5..e4f900d978 100644
--- a/crates/openhuman-core/src/agent/subagent_host/lifecycle_tests.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/lifecycle_tests.rs
@@ -332,23 +332,20 @@ async fn each_agent_dedupes_its_own_in_flight_sub_agents() {
let beta = test_agent_context(&root, "beta");
let alpha_map = {
- let scope_ctx = DispatchCtx::new(Arc::clone(&alpha));
+ let scope_ctx = crate::core::runtime::DispatchCtx::new(Arc::clone(&alpha));
- host_in_flight(&crate::core::runtime::scope_ctx.clone())
-
-};
+ host_in_flight(&scope_ctx)
+ };
let beta_map = {
- let scope_ctx = DispatchCtx::new(beta);
+ let scope_ctx = crate::core::runtime::DispatchCtx::new(beta);
- host_in_flight(&crate::core::runtime::scope_ctx.clone())
-
-};
+ host_in_flight(&scope_ctx)
+ };
let alpha_again = {
- let scope_ctx = DispatchCtx::new(alpha);
+ let scope_ctx = crate::core::runtime::DispatchCtx::new(alpha);
- host_in_flight(&crate::core::runtime::scope_ctx.clone())
-
-};
+ host_in_flight(&scope_ctx)
+ };
assert!(!Arc::ptr_eq(&alpha_map, &beta_map));
assert!(Arc::ptr_eq(&alpha_map, &alpha_again));
diff --git a/crates/openhuman-core/src/agent/tinyagents/journal_tests.rs b/crates/openhuman-core/src/agent/tinyagents/journal_tests.rs
index 43ad86a861..67247ddfad 100644
--- a/crates/openhuman-core/src/agent/tinyagents/journal_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/journal_tests.rs
@@ -9,32 +9,25 @@ async fn request_journal_runs_stay_with_the_agent_that_registered_them() {
let beta = test_agent_context(&root, "beta");
{
- let scope_ctx = DispatchCtx::new(std::sync::Arc::clone(&alpha));
+ let scope_ctx = crate::core::runtime::DispatchCtx::new(std::sync::Arc::clone(&alpha));
- register_request_journal_run(
- &crate::core::runtime::scope_ctx.clone(),
- "req-shared",
- "run-alpha",
- );
-
-};
+ register_request_journal_run(&scope_ctx, "req-shared", "run-alpha");
+ };
assert_eq!(
{
- let scope_ctx = DispatchCtx::new(beta);
+ let scope_ctx = crate::core::runtime::DispatchCtx::new(beta);
- take_request_journal_run(&crate::core::runtime::scope_ctx.clone(), "req-shared")
-
-},
+ take_request_journal_run(&scope_ctx, "req-shared")
+ },
None
);
assert_eq!(
{
- let scope_ctx = DispatchCtx::new(alpha);
+ let scope_ctx = crate::core::runtime::DispatchCtx::new(alpha);
- take_request_journal_run(&crate::core::runtime::scope_ctx.clone(), "req-shared")
-
-},
+ take_request_journal_run(&scope_ctx, "req-shared")
+ },
Some("run-alpha".to_string())
);
}
diff --git a/crates/openhuman-core/src/agent/tinyagents/reasoning_tests.rs b/crates/openhuman-core/src/agent/tinyagents/reasoning_tests.rs
index 9dfa1c24f1..7efffd319b 100644
--- a/crates/openhuman-core/src/agent/tinyagents/reasoning_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/reasoning_tests.rs
@@ -292,32 +292,25 @@ async fn reasoning_effort_stays_with_the_agent_that_chose_it() {
let thread = "effort-shared-thread";
{
- let scope_ctx = DispatchCtx::new(std::sync::Arc::clone(&alpha));
+ let scope_ctx = crate::core::runtime::DispatchCtx::new(std::sync::Arc::clone(&alpha));
- set_thread_effort(
- &crate::core::runtime::scope_ctx.clone(),
- thread,
- Some(ReasoningEffort::High),
- );
-
-};
+ set_thread_effort(&scope_ctx, thread, Some(ReasoningEffort::High));
+ };
assert_eq!(
{
- let scope_ctx = DispatchCtx::new(alpha);
+ let scope_ctx = crate::core::runtime::DispatchCtx::new(alpha);
- thread_effort(&crate::core::runtime::scope_ctx.clone(), thread)
-
-},
+ thread_effort(&scope_ctx, thread)
+ },
Some(ReasoningEffort::High)
);
assert_eq!(
{
- let scope_ctx = DispatchCtx::new(beta);
+ let scope_ctx = crate::core::runtime::DispatchCtx::new(beta);
- thread_effort(&crate::core::runtime::scope_ctx.clone(), thread)
-
-},
+ thread_effort(&scope_ctx, thread)
+ },
None
);
}
diff --git a/crates/openhuman-core/src/agent/tinyagents/run_mode_tests.rs b/crates/openhuman-core/src/agent/tinyagents/run_mode_tests.rs
index f257db632c..d0586b0d24 100644
--- a/crates/openhuman-core/src/agent/tinyagents/run_mode_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/run_mode_tests.rs
@@ -63,32 +63,25 @@ async fn plan_mode_stays_with_the_agent_that_set_it() {
let thread = "plan-mode-shared-thread";
{
- let scope_ctx = DispatchCtx::new(std::sync::Arc::clone(&alpha));
+ let scope_ctx = crate::core::runtime::DispatchCtx::new(std::sync::Arc::clone(&alpha));
- set_mode(
- &crate::core::runtime::scope_ctx.clone(),
- thread,
- RunMode::Plan,
- );
-
-};
+ set_mode(&scope_ctx, thread, RunMode::Plan);
+ };
assert_eq!(
{
- let scope_ctx = DispatchCtx::new(alpha);
+ let scope_ctx = crate::core::runtime::DispatchCtx::new(alpha);
- get_mode(&crate::core::runtime::scope_ctx.clone(), thread)
-
-},
+ get_mode(&scope_ctx, thread)
+ },
RunMode::Plan
);
assert_eq!(
{
- let scope_ctx = DispatchCtx::new(beta);
+ let scope_ctx = crate::core::runtime::DispatchCtx::new(beta);
- get_mode(&crate::core::runtime::scope_ctx.clone(), thread)
-
-},
+ get_mode(&scope_ctx, thread)
+ },
RunMode::Build
);
}
diff --git a/crates/openhuman-core/src/agent/tinyagents/turn_models_tests.rs b/crates/openhuman-core/src/agent/tinyagents/turn_models_tests.rs
index 57e0a1302e..14a7b0addb 100644
--- a/crates/openhuman-core/src/agent/tinyagents/turn_models_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/turn_models_tests.rs
@@ -28,9 +28,9 @@ async fn role_pins_apply_when_the_primary_uses_config_routing() {
.host_overrides(Arc::new(overrides)),
);
{
- let scope_ctx = DispatchCtx::new(context);
+ let scope_ctx = crate::core::runtime::DispatchCtx::new(context);
- let models = TurnModelSource::new_crate_native(&crate::core::runtime::scope_ctx.clone(), "chat", Arc::new(config))
+ let models = TurnModelSource::new_crate_native(&scope_ctx, "chat", Arc::new(config))
.build("hint:chat", 0.0, None, None)
.expect("config-routed models");
let coding = models
@@ -40,8 +40,7 @@ async fn role_pins_apply_when_the_primary_uses_config_routing() {
.expect("pinned role route");
assert_eq!(name_of(&coding.1).await, "pinned coding");
assert_eq!(name_of(&models.summarizer).await, "pinned summary");
-
-};
+ };
}
/// A stub that answers with its own name so a test can tell which model the
diff --git a/crates/openhuman-core/src/agent/tools/run_workflow_tests.rs b/crates/openhuman-core/src/agent/tools/run_workflow_tests.rs
index 6e73e805e5..86f4899d05 100644
--- a/crates/openhuman-core/src/agent/tools/run_workflow_tests.rs
+++ b/crates/openhuman-core/src/agent/tools/run_workflow_tests.rs
@@ -190,26 +190,22 @@ async fn each_agent_owns_its_workflow_await_guard() {
let key = "agent-guard-shared-key".to_string();
let held = {
- let scope_ctx = DispatchCtx::new(std::sync::Arc::clone(&alpha));
+ let scope_ctx = crate::core::runtime::DispatchCtx::new(std::sync::Arc::clone(&alpha));
- super::guard::acquire_await(&crate::core::runtime::scope_ctx.clone(), key.clone())
- .expect("alpha acquires")
-
-};
+ super::guard::acquire_await(&scope_ctx, key.clone()).expect("alpha acquires")
+ };
let beta_result = {
- let scope_ctx = DispatchCtx::new(beta);
+ let scope_ctx = crate::core::runtime::DispatchCtx::new(beta);
- super::guard::acquire_await(&crate::core::runtime::scope_ctx.clone(), key.clone())
-
-};
+ super::guard::acquire_await(&scope_ctx, key.clone())
+ };
assert!(beta_result.is_ok(), "beta is not blocked by alpha's await");
let alpha_again = {
- let scope_ctx = DispatchCtx::new(alpha);
+ let scope_ctx = crate::core::runtime::DispatchCtx::new(alpha);
- super::guard::acquire_await(&crate::core::runtime::scope_ctx.clone(), key.clone())
-
-};
+ super::guard::acquire_await(&scope_ctx, key.clone())
+ };
assert!(alpha_again.is_err(), "alpha still holds its own key");
drop(held);
}
diff --git a/crates/openhuman-core/src/channels/providers/relay/ops_tests.rs b/crates/openhuman-core/src/channels/providers/relay/ops_tests.rs
index 70b1e04558..2412af1b08 100644
--- a/crates/openhuman-core/src/channels/providers/relay/ops_tests.rs
+++ b/crates/openhuman-core/src/channels/providers/relay/ops_tests.rs
@@ -227,32 +227,26 @@ async fn invalid_or_repeated_messages_start_no_turn() {
);
{
- let scope_ctx = DispatchCtx::new(ctx);
+ let scope_ctx = crate::core::runtime::DispatchCtx::new(ctx);
let mut bad = params("m1", "hello");
bad.chat_id = "a/b".into();
- let err = channel_relay_inbound(&crate::core::runtime::scope_ctx.clone(), bad)
+ let err = channel_relay_inbound(&scope_ctx, bad)
.await
.expect_err("invalid");
assert!(err.contains("chat_id"), "{err}");
let p = params("m1", "hello");
let thread = p.thread_id();
- store::record_inbound(
- &crate::core::runtime::scope_ctx.clone(),
- &workspace,
- &p,
- &thread,
- )
- .await
- .unwrap();
- let outcome = channel_relay_inbound(&crate::core::runtime::scope_ctx.clone(), p)
+ store::record_inbound(&scope_ctx, &workspace, &p, &thread)
+ .await
+ .unwrap();
+ let outcome = channel_relay_inbound(&scope_ctx, p)
.await
.expect("duplicate is not an error");
let value = outcome.into_cli_compatible_json().unwrap();
let text = value.to_string();
assert!(text.contains("\"duplicate\":true"), "{text}");
assert!(text.contains(&thread), "{text}");
-
-};
+ };
}
diff --git a/crates/openhuman-core/src/channels/routes_tests.rs b/crates/openhuman-core/src/channels/routes_tests.rs
index be9b6f9a96..6dcff26406 100644
--- a/crates/openhuman-core/src/channels/routes_tests.rs
+++ b/crates/openhuman-core/src/channels/routes_tests.rs
@@ -244,13 +244,10 @@ async fn sign_out_cancels_remote_invalidation_while_it_waits_for_the_session_tab
let core_context =
crate::core::runtime::CoreContext::for_test(crate::core::runtime::DomainSet::full(), None);
let expected_core_context = Arc::clone(&core_context);
- crate::core::runtime::{
- let scope_ctx = DispatchCtx::new(core_context);
+ {
+ let scope_ctx = crate::core::runtime::DispatchCtx::new(core_context);
- let guard = crate::web_chat::lock_thread_sessions_for_test(
- &crate::core::runtime::scope_ctx.clone(),
- )
- .await;
+ let guard = crate::web_chat::lock_thread_sessions_for_test(&scope_ctx).await;
let cancellation = tokio_util::sync::CancellationToken::new();
let callback = RouteCallbacks::new(
runtime_context(PathBuf::from("/tmp/channel-callback")),
@@ -285,8 +282,7 @@ async fn sign_out_cancels_remote_invalidation_while_it_waits_for_the_session_tab
);
drop(guard);
-
-};
+ };
}
#[cfg(feature = "modules")]
diff --git a/crates/openhuman-core/src/core/invoke_tests.rs b/crates/openhuman-core/src/core/invoke_tests.rs
index e163aa487f..ff4c3d4a27 100644
--- a/crates/openhuman-core/src/core/invoke_tests.rs
+++ b/crates/openhuman-core/src/core/invoke_tests.rs
@@ -69,14 +69,15 @@ async fn gated_method_is_unknown_at_transport_even_with_malformed_params() {
for params in [json!({}), json!({ "obviously_not_a_real_param_xyz": true })] {
let ctx = CoreContext::for_test(DomainSet::harness(), None);
let err = {
- let scope_ctx = DispatchCtx::new(ctx);
- invoke_method(
+ let scope_ctx = crate::core::runtime::DispatchCtx::new(ctx);
+ invoke_method(
scope_ctx.clone(),
default_state(),
&gated_method,
params.clone(),
- ).await
-}
+ )
+ .await
+ }
.expect_err("gated flows method must error under harness()");
assert!(
err.contains("unknown method"),
diff --git a/crates/openhuman-core/src/cron/completion_owner_tests.rs b/crates/openhuman-core/src/cron/completion_owner_tests.rs
index 1866cdb555..a7e21334ef 100644
--- a/crates/openhuman-core/src/cron/completion_owner_tests.rs
+++ b/crates/openhuman-core/src/cron/completion_owner_tests.rs
@@ -12,14 +12,10 @@ async fn a_job_completed_as_an_agent_is_noted_once() {
.session_agent("completion-owner-agent"),
);
{
- let scope_ctx = DispatchCtx::new(agent);
+ let scope_ctx = crate::core::runtime::DispatchCtx::new(agent);
- note(
- &crate::core::runtime::scope_ctx.clone(),
- "completion-owner-job",
- )
-
-};
+ note(&scope_ctx, "completion-owner-job")
+ };
assert_eq!(
take("completion-owner-job").as_deref(),
Some("completion-owner-agent")
diff --git a/crates/openhuman-core/src/desktop/notifications/bus_tests_2_tests.rs b/crates/openhuman-core/src/desktop/notifications/bus_tests_2_tests.rs
index 35f5cb0678..79d2e2bd22 100644
--- a/crates/openhuman-core/src/desktop/notifications/bus_tests_2_tests.rs
+++ b/crates/openhuman-core/src/desktop/notifications/bus_tests_2_tests.rs
@@ -543,15 +543,11 @@ async fn a_noted_cron_completion_names_its_agent() {
)
.session_agent("notif-owner-agent"),
);
- crate::core::runtime::{
- let scope_ctx = DispatchCtx::new(context);
+ {
+ let scope_ctx = crate::core::runtime::DispatchCtx::new(context);
- crate::cron::completion_owner::note(
- &crate::core::runtime::scope_ctx.clone(),
- "notif-owner-job",
- );
-
-};
+ crate::cron::completion_owner::note(&scope_ctx, "notif-owner-job");
+ };
let event = DomainEvent::CronJobCompleted {
job_id: "notif-owner-job".into(),
success: true,
diff --git a/crates/openhuman-core/src/memory/lifecycle/prefetch_tests.rs b/crates/openhuman-core/src/memory/lifecycle/prefetch_tests.rs
index d530d3847e..ce04a36f59 100644
--- a/crates/openhuman-core/src/memory/lifecycle/prefetch_tests.rs
+++ b/crates/openhuman-core/src/memory/lifecycle/prefetch_tests.rs
@@ -368,12 +368,12 @@ async fn queued_work_keeps_the_callers_core_context() {
crate::core::runtime::DomainSet::full(),
Some(config.workspace_dir.clone()),
);
- crate::core::runtime::{
- let scope_ctx = DispatchCtx::new(ctx.clone());
+ {
+ let scope_ctx = crate::core::runtime::DispatchCtx::new(ctx.clone());
let identity = MemoryIdentity::agent("scoped-agent").resolve(&config);
let key = Key::new(&config, &identity, "t", false);
- let cache = cache(&crate::core::runtime::scope_ctx.clone());
+ let cache = cache(&scope_ctx);
let expected = ctx.clone();
enqueue(
cache.clone(),
@@ -388,8 +388,7 @@ async fn queued_work_keeps_the_callers_core_context() {
);
drain(&cache, &key).await;
assert_eq!(completed(&cache, &key).unwrap().markdown, "scoped");
-
-};
+ };
}
#[test]
diff --git a/crates/openhuman-core/src/memory/tools_agent_tests.rs b/crates/openhuman-core/src/memory/tools_agent_tests.rs
index 2b96801866..4ab166bd5f 100644
--- a/crates/openhuman-core/src/memory/tools_agent_tests.rs
+++ b/crates/openhuman-core/src/memory/tools_agent_tests.rs
@@ -34,38 +34,26 @@ async fn turn_citations_stay_with_the_agent_that_recorded_them() {
let thread = "shared-thread";
{
- let scope_ctx = DispatchCtx::new(Arc::clone(&alpha));
+ let scope_ctx = crate::core::runtime::DispatchCtx::new(Arc::clone(&alpha));
- record_pack_citations(
- &crate::core::runtime::scope_ctx.clone(),
- thread,
- vec![citation("alpha-cite")],
- );
-
-};
+ record_pack_citations(&scope_ctx, thread, vec![citation("alpha-cite")]);
+ };
{
- let scope_ctx = DispatchCtx::new(Arc::clone(&beta));
+ let scope_ctx = crate::core::runtime::DispatchCtx::new(Arc::clone(&beta));
- record_pack_citations(
- &crate::core::runtime::scope_ctx.clone(),
- thread,
- vec![citation("beta-cite")],
- );
-
-};
+ record_pack_citations(&scope_ctx, thread, vec![citation("beta-cite")]);
+ };
let from_beta = {
- let scope_ctx = DispatchCtx::new(beta);
+ let scope_ctx = crate::core::runtime::DispatchCtx::new(beta);
- take_turn_citations(&crate::core::runtime::scope_ctx.clone(), thread)
-
-};
+ take_turn_citations(&scope_ctx, thread)
+ };
let from_alpha = {
- let scope_ctx = DispatchCtx::new(alpha);
+ let scope_ctx = crate::core::runtime::DispatchCtx::new(alpha);
- take_turn_citations(&crate::core::runtime::scope_ctx.clone(), thread)
-
-};
+ take_turn_citations(&scope_ctx, thread)
+ };
assert_eq!(
from_alpha.iter().map(|c| c.id.as_str()).collect::<Vec<_>>(),
diff --git a/crates/openhuman-core/src/platform/cost/scope_tests.rs b/crates/openhuman-core/src/platform/cost/scope_tests.rs
index 317fc31490..3ad1352e07 100644
--- a/crates/openhuman-core/src/platform/cost/scope_tests.rs
+++ b/crates/openhuman-core/src/platform/cost/scope_tests.rs
@@ -63,9 +63,9 @@ async fn ambient_scope_reads_the_turn_and_prefers_the_subagent() {
// binds when there is a context to bind it on.
let ctx =
crate::core::runtime::CoreContext::for_test(crate::core::runtime::DomainSet::full(), None);
- let (parent, child) = crate::core::runtime::{
- let scope_ctx = DispatchCtx::new(ctx);
- crate::agent::turn_origin::with_origin(origin, async {
+ let (parent, child) = {
+ let scope_ctx = crate::core::runtime::DispatchCtx::new(ctx);
+ crate::agent::turn_origin::with_origin(origin, async {
async {
(
UsageScope::in_ctx(&scope_ctx, Some("openhuman"), None)
@@ -79,8 +79,9 @@ async fn ambient_scope_reads_the_turn_and_prefers_the_subagent() {
)
}
.await
- }).await
-};
+ })
+ .await
+ };
assert_eq!(parent.thread_id.as_deref(), Some("thread-9"));
assert_eq!(parent.origin.as_deref(), Some("web_chat"));
assert_eq!(parent.agent_id.as_deref(), Some("orchestrator"));
diff --git a/crates/openhuman-core/src/sandbox/ops_tests.rs b/crates/openhuman-core/src/sandbox/ops_tests.rs
index 0c29b2ea71..0824bceeb7 100644
--- a/crates/openhuman-core/src/sandbox/ops_tests.rs
+++ b/crates/openhuman-core/src/sandbox/ops_tests.rs
@@ -382,12 +382,11 @@ async fn sandbox_component_is_on_without_a_context_or_when_enabled() {
let ctx = crate::core::runtime::context::CoreContext::for_test_with_components(
crate::core::runtime::ComponentSet::all(),
);
- crate::core::runtime::context::{
- let scope_ctx = DispatchCtx::new(ctx);
+ {
+ let scope_ctx = crate::core::runtime::DispatchCtx::new(ctx);
assert!(!sandbox_component_off(&scope_ctx));
-
-};
+ };
}
#[test]
diff --git a/crates/openhuman-core/src/web_chat/ops/state_tests.rs b/crates/openhuman-core/src/web_chat/ops/state_tests.rs
index 309dc2c1c0..004601c4a9 100644
--- a/crates/openhuman-core/src/web_chat/ops/state_tests.rs
+++ b/crates/openhuman-core/src/web_chat/ops/state_tests.rs
@@ -19,33 +19,29 @@ async fn each_agent_context_owns_its_turn_tables() {
let alpha = agent(&root, "alpha");
let beta = agent(&root, "beta");
- let (alpha_sessions, alpha_in_flight, alpha_parallel) =
- {
- let scope_ctx = DispatchCtx::new(Arc::clone(&alpha));
+ let (alpha_sessions, alpha_in_flight, alpha_parallel) = {
+ let scope_ctx = crate::core::runtime::DispatchCtx::new(Arc::clone(&alpha));
- (
- thread_sessions(&crate::core::runtime::scope_ctx.clone()),
- in_flight(&crate::core::runtime::scope_ctx.clone()),
- parallel_in_flight(&crate::core::runtime::scope_ctx.clone()),
- )
-
-};
+ (
+ thread_sessions(&scope_ctx),
+ in_flight(&scope_ctx),
+ parallel_in_flight(&scope_ctx),
+ )
+ };
let (beta_sessions, beta_in_flight, beta_parallel) = {
- let scope_ctx = DispatchCtx::new(beta);
+ let scope_ctx = crate::core::runtime::DispatchCtx::new(beta);
(
- thread_sessions(&crate::core::runtime::scope_ctx.clone()),
- in_flight(&crate::core::runtime::scope_ctx.clone()),
- parallel_in_flight(&crate::core::runtime::scope_ctx.clone()),
+ thread_sessions(&scope_ctx),
+ in_flight(&scope_ctx),
+ parallel_in_flight(&scope_ctx),
)
-
-};
+ };
let alpha_again = {
- let scope_ctx = DispatchCtx::new(alpha);
+ let scope_ctx = crate::core::runtime::DispatchCtx::new(alpha);
- in_flight(&crate::core::runtime::scope_ctx.clone())
-
-};
+ in_flight(&scope_ctx)
+ };
assert!(!Arc::ptr_eq(&alpha_sessions, &beta_sessions));
assert!(!Arc::ptr_eq(&alpha_in_flight, &beta_in_flight));
diff --git a/crates/openhuman-core/src/web_chat/session_checkout_agents_tests.rs b/crates/openhuman-core/src/web_chat/session_checkout_agents_tests.rs
index 1b66124ff6..1c7c59e5f7 100644
--- a/crates/openhuman-core/src/web_chat/session_checkout_agents_tests.rs
+++ b/crates/openhuman-core/src/web_chat/session_checkout_agents_tests.rs
@@ -55,27 +55,25 @@ async fn two_agents_with_the_same_thread_id_get_their_own_cache_slots() {
fingerprint: fingerprint.clone(),
};
{
- let scope_ctx = DispatchCtx::new(Arc::clone(ctx));
+ let scope_ctx = crate::core::runtime::DispatchCtx::new(Arc::clone(ctx));
- thread_sessions(&crate::core::runtime::scope_ctx.clone())
+ thread_sessions(&scope_ctx)
.lock_owned()
.await
.insert(key.clone(), entry);
-
-};
+ };
}
let cached = |ctx: &Arc<CoreContext>, key: &String| {
let (ctx, key) = (Arc::clone(ctx), key.clone());
async move {
{
- let scope_ctx = DispatchCtx::new(ctx);
+ let scope_ctx = crate::core::runtime::DispatchCtx::new(ctx);
- thread_sessions(&crate::core::runtime::scope_ctx.clone())
+ thread_sessions(&scope_ctx)
.lock_owned()
.await
.contains_key(&key)
-
-}
+ }
}
};
// Under one agent's scope only that agent's slot goes.