Skip to content

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

test: replace CoreContext::scope with DispatchCtx::new in tenant tests

Steven Enamakelc4019c4d333a
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 e6e6d902e9..13c6988f5c 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
@@ -49,10 +49,12 @@ async fn one_profiles_stop_and_delete_never_reach_anothers_thread() {
let bob = profile("u-bob", ws_b.path());
// Alice presses Stop on her `t1`.
- CoreContext::scope(Arc::clone(&alice), async {
- discard_pending_for_thread(&DispatchCtx::ambient(), "t1");
- })
- .await;
+ {
+ let scope_ctx = 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;
@@ -62,23 +64,27 @@ async fn one_profiles_stop_and_delete_never_reach_anothers_thread() {
assert!(pending(ws_a.path()).is_empty());
// Bob deletes his `t1`; Alice re-engages hers and keeps working.
- CoreContext::scope(Arc::clone(&bob), async {
- discard_for_thread(&DispatchCtx::ambient(), ws_b.path(), "t1");
- })
- .await;
- CoreContext::scope(Arc::clone(&alice), async {
- resume_stopped_thread(&DispatchCtx::ambient(), "t1");
+ {
+ let scope_ctx = DispatchCtx::new(Arc::clone(&bob));
+
+ discard_for_thread(&scope_ctx, ws_b.path(), "t1");
+
+};
+ {
+ let scope_ctx = DispatchCtx::new(Arc::clone(&alice));
+
+ resume_stopped_thread(&scope_ctx, "t1");
assert!(
!mark_stopped_task_if_thread_stopped(
- &DispatchCtx::ambient(),
+ &scope_ctx,
ws_a.path(),
"t1",
"alice-2"
),
"bob's delete does not abort alice's child"
);
- })
- .await;
+
+};
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/running_subagents_tenant_tests.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents_tenant_tests.rs
index d61a7a81a2..cb29a515ed 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
@@ -227,10 +227,12 @@ async fn saas_dispatch_exposes_only_the_callers_detached_worker_controls() {
);
})
.await;
- CoreContext::scope(pair.alice.clone(), async {
- assert!(resume_ref_for_task(&DispatchCtx::ambient(), &pair.a.task, PARENT).is_ok());
- })
- .await;
+ {
+ let scope_ctx = 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());
}
@@ -359,18 +361,20 @@ async fn same_parent_resolution_and_wait_refuse_foreign_workers() {
return;
}
let pair = Pair::new();
- CoreContext::scope(pair.bob.clone(), async {
+ {
+ let scope_ctx = DispatchCtx::new(pair.bob.clone());
+
assert!(matches!(
- task_id_for_session(&DispatchCtx::ambient(), &pair.a.session, PARENT),
+ task_id_for_session(&scope_ctx, &pair.a.session, PARENT),
Err(WaitError::NotOwned)
));
assert!(matches!(
- resume_ref_for_task(&DispatchCtx::ambient(), &pair.a.task, PARENT),
+ resume_ref_for_task(&scope_ctx, &pair.a.task, PARENT),
Err(WaitError::NotOwned)
));
assert!(matches!(
wait(
- &DispatchCtx::ambient(),
+ &scope_ctx,
&pair.a.task,
PARENT,
Duration::ZERO
@@ -379,11 +383,11 @@ async fn same_parent_resolution_and_wait_refuse_foreign_workers() {
Err(WaitError::NotOwned)
));
assert_eq!(
- task_id_for_session(&DispatchCtx::ambient(), &pair.b.session, PARENT).unwrap(),
+ task_id_for_session(&scope_ctx, &pair.b.session, PARENT).unwrap(),
pair.b.task
);
- })
- .await;
+
+};
}
#[tokio::test]
@@ -395,10 +399,12 @@ async fn same_parent_agent_steering_refuses_foreign_worker() {
return;
}
let pair = Pair::new();
- CoreContext::scope(pair.bob.clone(), async {
+ {
+ let scope_ctx = DispatchCtx::new(pair.bob.clone());
+
assert_eq!(
steer(
- &DispatchCtx::ambient(),
+ &scope_ctx,
&pair.a.task,
PARENT,
"foreign".into(),
@@ -409,7 +415,7 @@ async fn same_parent_agent_steering_refuses_foreign_worker() {
);
assert_eq!(pair.a.queue.status().await.steers, 0);
steer(
- &DispatchCtx::ambient(),
+ &scope_ctx,
&pair.b.task,
PARENT,
"own".into(),
@@ -418,8 +424,8 @@ async fn same_parent_agent_steering_refuses_foreign_worker() {
.await
.unwrap();
assert_eq!(pair.b.queue.status().await.steers, 1);
- })
- .await;
+
+};
}
#[tokio::test]
@@ -452,25 +458,29 @@ async fn public_cancellation_refuses_another_profiles_task() {
return;
}
let pair = Pair::new();
- CoreContext::scope(pair.bob.clone(), async {
+ {
+ let scope_ctx = DispatchCtx::new(pair.bob.clone());
+
assert_eq!(
field(&control("cancel", &pair.a.task).await, "cancelled"),
Some(false)
);
- assert!(resume_ref_for_task(&DispatchCtx::ambient(), &pair.b.task, PARENT).is_ok());
+ assert!(resume_ref_for_task(&scope_ctx, &pair.b.task, PARENT).is_ok());
assert_eq!(
field(&control("cancel", &pair.b.task).await, "cancelled"),
Some(true)
);
- })
- .await;
- CoreContext::scope(pair.alice.clone(), async {
+
+};
+ {
+ let scope_ctx = DispatchCtx::new(pair.alice.clone());
+
assert!(
- resume_ref_for_task(&DispatchCtx::ambient(), &pair.a.task, PARENT).is_ok(),
+ resume_ref_for_task(&scope_ctx, &pair.a.task, PARENT).is_ok(),
"foreign cancel leaves original worker live"
);
- })
- .await;
+
+};
}
#[tokio::test]
@@ -512,10 +522,12 @@ async fn missing_saas_scope_cannot_observe_or_control_workers() {
assert!(resume_ref_for_task(&DispatchCtx::ambient(), &pair.a.task, PARENT).is_ok())
});
// A scoped kernel context without an admitted profile is not authority.
- CoreContext::scope(CoreContext::for_test(DomainSet::full(), None), async {
- assert!(snapshot_for_parent(&DispatchCtx::ambient(), PARENT).is_empty());
+ {
+ let scope_ctx = DispatchCtx::new(CoreContext::for_test(DomainSet::full(), None));
+
+ assert!(snapshot_for_parent(&scope_ctx, PARENT).is_empty());
assert!(matches!(
- resume_ref_for_task(&DispatchCtx::ambient(), &pair.a.task, PARENT),
+ resume_ref_for_task(&scope_ctx, &pair.a.task, PARENT),
Err(WaitError::NotOwned)
));
assert_eq!(
@@ -526,8 +538,8 @@ async fn missing_saas_scope_cannot_observe_or_control_workers() {
field(&control("cancel", &pair.a.task).await, "cancelled"),
Some(false)
);
- })
- .await;
+
+};
}
#[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 418dde4438..8da8359aa5 100644
--- a/crates/openhuman-core/src/agent/subagent_host/lifecycle_tests.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/lifecycle_tests.rs
@@ -331,18 +331,24 @@ async fn each_agent_dedupes_its_own_in_flight_sub_agents() {
let alpha = test_agent_context(&root, "alpha");
let beta = test_agent_context(&root, "beta");
- let alpha_map = CoreContext::scope(Arc::clone(&alpha), async {
- host_in_flight(&crate::core::runtime::DispatchCtx::ambient())
- })
- .await;
- let beta_map = CoreContext::scope(beta, async {
- host_in_flight(&crate::core::runtime::DispatchCtx::ambient())
- })
- .await;
- let alpha_again = CoreContext::scope(alpha, async {
- host_in_flight(&crate::core::runtime::DispatchCtx::ambient())
- })
- .await;
+ let alpha_map = {
+ let scope_ctx = DispatchCtx::new(Arc::clone(&alpha));
+
+ host_in_flight(&crate::core::runtime::scope_ctx.clone())
+
+};
+ let beta_map = {
+ let scope_ctx = DispatchCtx::new(beta);
+
+ host_in_flight(&crate::core::runtime::scope_ctx.clone())
+
+};
+ let alpha_again = {
+ let scope_ctx = DispatchCtx::new(alpha);
+
+ host_in_flight(&crate::core::runtime::scope_ctx.clone())
+
+};
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 2b25b310fe..43ad86a861 100644
--- a/crates/openhuman-core/src/agent/tinyagents/journal_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/journal_tests.rs
@@ -8,27 +8,33 @@ async fn request_journal_runs_stay_with_the_agent_that_registered_them() {
let alpha = test_agent_context(&root, "alpha");
let beta = test_agent_context(&root, "beta");
- CoreContext::scope(std::sync::Arc::clone(&alpha), async {
+ {
+ let scope_ctx = DispatchCtx::new(std::sync::Arc::clone(&alpha));
+
register_request_journal_run(
- &crate::core::runtime::DispatchCtx::ambient(),
+ &crate::core::runtime::scope_ctx.clone(),
"req-shared",
"run-alpha",
);
- })
- .await;
+
+};
assert_eq!(
- CoreContext::scope(beta, async {
- take_request_journal_run(&crate::core::runtime::DispatchCtx::ambient(), "req-shared")
- })
- .await,
+ {
+ let scope_ctx = DispatchCtx::new(beta);
+
+ take_request_journal_run(&crate::core::runtime::scope_ctx.clone(), "req-shared")
+
+},
None
);
assert_eq!(
- CoreContext::scope(alpha, async {
- take_request_journal_run(&crate::core::runtime::DispatchCtx::ambient(), "req-shared")
- })
- .await,
+ {
+ let scope_ctx = DispatchCtx::new(alpha);
+
+ take_request_journal_run(&crate::core::runtime::scope_ctx.clone(), "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 c1770181a6..9dfa1c24f1 100644
--- a/crates/openhuman-core/src/agent/tinyagents/reasoning_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/reasoning_tests.rs
@@ -291,27 +291,33 @@ async fn reasoning_effort_stays_with_the_agent_that_chose_it() {
let beta = test_agent_context(&root, "beta");
let thread = "effort-shared-thread";
- CoreContext::scope(std::sync::Arc::clone(&alpha), async {
+ {
+ let scope_ctx = DispatchCtx::new(std::sync::Arc::clone(&alpha));
+
set_thread_effort(
- &crate::core::runtime::DispatchCtx::ambient(),
+ &crate::core::runtime::scope_ctx.clone(),
thread,
Some(ReasoningEffort::High),
);
- })
- .await;
+
+};
assert_eq!(
- CoreContext::scope(alpha, async {
- thread_effort(&crate::core::runtime::DispatchCtx::ambient(), thread)
- })
- .await,
+ {
+ let scope_ctx = DispatchCtx::new(alpha);
+
+ thread_effort(&crate::core::runtime::scope_ctx.clone(), thread)
+
+},
Some(ReasoningEffort::High)
);
assert_eq!(
- CoreContext::scope(beta, async {
- thread_effort(&crate::core::runtime::DispatchCtx::ambient(), thread)
- })
- .await,
+ {
+ let scope_ctx = DispatchCtx::new(beta);
+
+ thread_effort(&crate::core::runtime::scope_ctx.clone(), 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 3e8e5f7866..f257db632c 100644
--- a/crates/openhuman-core/src/agent/tinyagents/run_mode_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/run_mode_tests.rs
@@ -62,27 +62,33 @@ async fn plan_mode_stays_with_the_agent_that_set_it() {
let beta = test_agent_context(&root, "beta");
let thread = "plan-mode-shared-thread";
- CoreContext::scope(std::sync::Arc::clone(&alpha), async {
+ {
+ let scope_ctx = DispatchCtx::new(std::sync::Arc::clone(&alpha));
+
set_mode(
- &crate::core::runtime::DispatchCtx::ambient(),
+ &crate::core::runtime::scope_ctx.clone(),
thread,
RunMode::Plan,
);
- })
- .await;
+
+};
assert_eq!(
- CoreContext::scope(alpha, async {
- get_mode(&crate::core::runtime::DispatchCtx::ambient(), thread)
- })
- .await,
+ {
+ let scope_ctx = DispatchCtx::new(alpha);
+
+ get_mode(&crate::core::runtime::scope_ctx.clone(), thread)
+
+},
RunMode::Plan
);
assert_eq!(
- CoreContext::scope(beta, async {
- get_mode(&crate::core::runtime::DispatchCtx::ambient(), thread)
- })
- .await,
+ {
+ let scope_ctx = DispatchCtx::new(beta);
+
+ get_mode(&crate::core::runtime::scope_ctx.clone(), 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 8dede88376..57e0a1302e 100644
--- a/crates/openhuman-core/src/agent/tinyagents/turn_models_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/turn_models_tests.rs
@@ -27,8 +27,10 @@ async fn role_pins_apply_when_the_primary_uses_config_routing() {
ContextOverlay::new(config.clone(), DomainSet::full(), Default::default())
.host_overrides(Arc::new(overrides)),
);
- CoreContext::scope(context, async {
- let models = TurnModelSource::new_crate_native(&crate::core::runtime::DispatchCtx::ambient(), "chat", Arc::new(config))
+ {
+ let scope_ctx = DispatchCtx::new(context);
+
+ let models = TurnModelSource::new_crate_native(&crate::core::runtime::scope_ctx.clone(), "chat", Arc::new(config))
.build("hint:chat", 0.0, None, None)
.expect("config-routed models");
let coding = models
@@ -38,8 +40,8 @@ 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");
- })
- .await;
+
+};
}
/// 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 feecd730e1..6e73e805e5 100644
--- a/crates/openhuman-core/src/agent/tools/run_workflow_tests.rs
+++ b/crates/openhuman-core/src/agent/tools/run_workflow_tests.rs
@@ -189,21 +189,27 @@ async fn each_agent_owns_its_workflow_await_guard() {
let beta = test_agent_context(&root, "beta");
let key = "agent-guard-shared-key".to_string();
- let held = CoreContext::scope(std::sync::Arc::clone(&alpha), async {
- super::guard::acquire_await(&crate::core::runtime::DispatchCtx::ambient(), key.clone())
+ let held = {
+ let scope_ctx = DispatchCtx::new(std::sync::Arc::clone(&alpha));
+
+ super::guard::acquire_await(&crate::core::runtime::scope_ctx.clone(), key.clone())
.expect("alpha acquires")
- })
- .await;
+
+};
- let beta_result = CoreContext::scope(beta, async {
- super::guard::acquire_await(&crate::core::runtime::DispatchCtx::ambient(), key.clone())
- })
- .await;
+ let beta_result = {
+ let scope_ctx = DispatchCtx::new(beta);
+
+ super::guard::acquire_await(&crate::core::runtime::scope_ctx.clone(), key.clone())
+
+};
assert!(beta_result.is_ok(), "beta is not blocked by alpha's await");
- let alpha_again = CoreContext::scope(alpha, async {
- super::guard::acquire_await(&crate::core::runtime::DispatchCtx::ambient(), key.clone())
- })
- .await;
+ let alpha_again = {
+ let scope_ctx = DispatchCtx::new(alpha);
+
+ super::guard::acquire_await(&crate::core::runtime::scope_ctx.clone(), 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 b97c68a7c3..70b1e04558 100644
--- a/crates/openhuman-core/src/channels/providers/relay/ops_tests.rs
+++ b/crates/openhuman-core/src/channels/providers/relay/ops_tests.rs
@@ -226,10 +226,12 @@ async fn invalid_or_repeated_messages_start_no_turn() {
ContextOverlay::new(config, DomainSet::full(), Default::default()),
);
- CoreContext::scope(ctx, async {
+ {
+ let scope_ctx = DispatchCtx::new(ctx);
+
let mut bad = params("m1", "hello");
bad.chat_id = "a/b".into();
- let err = channel_relay_inbound(&crate::core::runtime::DispatchCtx::ambient(), bad)
+ let err = channel_relay_inbound(&crate::core::runtime::scope_ctx.clone(), bad)
.await
.expect_err("invalid");
assert!(err.contains("chat_id"), "{err}");
@@ -237,20 +239,20 @@ async fn invalid_or_repeated_messages_start_no_turn() {
let p = params("m1", "hello");
let thread = p.thread_id();
store::record_inbound(
- &crate::core::runtime::DispatchCtx::ambient(),
+ &crate::core::runtime::scope_ctx.clone(),
&workspace,
&p,
&thread,
)
.await
.unwrap();
- let outcome = channel_relay_inbound(&crate::core::runtime::DispatchCtx::ambient(), p)
+ let outcome = channel_relay_inbound(&crate::core::runtime::scope_ctx.clone(), 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}");
- })
- .await;
+
+};
}
diff --git a/crates/openhuman-core/src/channels/routes_tests.rs b/crates/openhuman-core/src/channels/routes_tests.rs
index ca25fd4b39..be9b6f9a96 100644
--- a/crates/openhuman-core/src/channels/routes_tests.rs
+++ b/crates/openhuman-core/src/channels/routes_tests.rs
@@ -244,9 +244,11 @@ 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::CoreContext::scope(core_context, async {
+ crate::core::runtime::{
+ let scope_ctx = DispatchCtx::new(core_context);
+
let guard = crate::web_chat::lock_thread_sessions_for_test(
- &crate::core::runtime::DispatchCtx::ambient(),
+ &crate::core::runtime::scope_ctx.clone(),
)
.await;
let cancellation = tokio_util::sync::CancellationToken::new();
@@ -283,8 +285,8 @@ async fn sign_out_cancels_remote_invalidation_while_it_waits_for_the_session_tab
);
drop(guard);
- })
- .await;
+
+};
}
#[cfg(feature = "modules")]
diff --git a/crates/openhuman-core/src/core/invoke_tests.rs b/crates/openhuman-core/src/core/invoke_tests.rs
index 8e3a09ac10..e163aa487f 100644
--- a/crates/openhuman-core/src/core/invoke_tests.rs
+++ b/crates/openhuman-core/src/core/invoke_tests.rs
@@ -68,16 +68,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 = CoreContext::scope(
- ctx,
- invoke_method(
- DispatchCtx::ambient(),
+ let err = {
+ let scope_ctx = 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 25744fe531..1866cdb555 100644
--- a/crates/openhuman-core/src/cron/completion_owner_tests.rs
+++ b/crates/openhuman-core/src/cron/completion_owner_tests.rs
@@ -11,13 +11,15 @@ async fn a_job_completed_as_an_agent_is_noted_once() {
)
.session_agent("completion-owner-agent"),
);
- CoreContext::scope(agent, async {
+ {
+ let scope_ctx = DispatchCtx::new(agent);
+
note(
- &crate::core::runtime::DispatchCtx::ambient(),
+ &crate::core::runtime::scope_ctx.clone(),
"completion-owner-job",
)
- })
- .await;
+
+};
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 e7480e70db..35f5cb0678 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,13 +543,15 @@ async fn a_noted_cron_completion_names_its_agent() {
)
.session_agent("notif-owner-agent"),
);
- crate::core::runtime::CoreContext::scope(context, async {
+ crate::core::runtime::{
+ let scope_ctx = DispatchCtx::new(context);
+
crate::cron::completion_owner::note(
- &crate::core::runtime::DispatchCtx::ambient(),
+ &crate::core::runtime::scope_ctx.clone(),
"notif-owner-job",
);
- })
- .await;
+
+};
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 d3127bfc54..d530d3847e 100644
--- a/crates/openhuman-core/src/memory/lifecycle/prefetch_tests.rs
+++ b/crates/openhuman-core/src/memory/lifecycle/prefetch_tests.rs
@@ -368,10 +368,12 @@ async fn queued_work_keeps_the_callers_core_context() {
crate::core::runtime::DomainSet::full(),
Some(config.workspace_dir.clone()),
);
- crate::core::runtime::CoreContext::scope(ctx.clone(), async {
+ crate::core::runtime::{
+ let scope_ctx = 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::DispatchCtx::ambient());
+ let cache = cache(&crate::core::runtime::scope_ctx.clone());
let expected = ctx.clone();
enqueue(
cache.clone(),
@@ -386,8 +388,8 @@ async fn queued_work_keeps_the_callers_core_context() {
);
drain(&cache, &key).await;
assert_eq!(completed(&cache, &key).unwrap().markdown, "scoped");
- })
- .await;
+
+};
}
#[test]
diff --git a/crates/openhuman-core/src/memory/tools_agent_tests.rs b/crates/openhuman-core/src/memory/tools_agent_tests.rs
index 8deeefa640..2b96801866 100644
--- a/crates/openhuman-core/src/memory/tools_agent_tests.rs
+++ b/crates/openhuman-core/src/memory/tools_agent_tests.rs
@@ -33,31 +33,39 @@ async fn turn_citations_stay_with_the_agent_that_recorded_them() {
let beta = agent(&root, "beta");
let thread = "shared-thread";
- CoreContext::scope(Arc::clone(&alpha), async {
+ {
+ let scope_ctx = DispatchCtx::new(Arc::clone(&alpha));
+
record_pack_citations(
- &crate::core::runtime::DispatchCtx::ambient(),
+ &crate::core::runtime::scope_ctx.clone(),
thread,
vec![citation("alpha-cite")],
);
- })
- .await;
- CoreContext::scope(Arc::clone(&beta), async {
+
+};
+ {
+ let scope_ctx = DispatchCtx::new(Arc::clone(&beta));
+
record_pack_citations(
- &crate::core::runtime::DispatchCtx::ambient(),
+ &crate::core::runtime::scope_ctx.clone(),
thread,
vec![citation("beta-cite")],
);
- })
- .await;
+
+};
+
+ let from_beta = {
+ let scope_ctx = DispatchCtx::new(beta);
+
+ take_turn_citations(&crate::core::runtime::scope_ctx.clone(), thread)
+
+};
+ let from_alpha = {
+ let scope_ctx = DispatchCtx::new(alpha);
- let from_beta = CoreContext::scope(beta, async {
- take_turn_citations(&crate::core::runtime::DispatchCtx::ambient(), thread)
- })
- .await;
- let from_alpha = CoreContext::scope(alpha, async {
- take_turn_citations(&crate::core::runtime::DispatchCtx::ambient(), thread)
- })
- .await;
+ take_turn_citations(&crate::core::runtime::scope_ctx.clone(), 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 1d359bbeca..317fc31490 100644
--- a/crates/openhuman-core/src/platform/cost/scope_tests.rs
+++ b/crates/openhuman-core/src/platform/cost/scope_tests.rs
@@ -63,15 +63,15 @@ 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::CoreContext::scope(
- ctx,
- crate::agent::turn_origin::with_origin(origin, async {
+ let (parent, child) = crate::core::runtime::{
+ let scope_ctx = DispatchCtx::new(ctx);
+ crate::agent::turn_origin::with_origin(origin, async {
async {
(
- UsageScope::in_ctx(&DispatchCtx::ambient(), Some("openhuman"), None)
+ UsageScope::in_ctx(&scope_ctx, Some("openhuman"), None)
.with_definition(Some("orchestrator")),
UsageScope::in_ctx(
- &DispatchCtx::ambient(),
+ &scope_ctx,
Some("openhuman"),
Some(("researcher", "task-1")),
)
@@ -79,9 +79,8 @@ 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 9b2e3834d1..0c29b2ea71 100644
--- a/crates/openhuman-core/src/sandbox/ops_tests.rs
+++ b/crates/openhuman-core/src/sandbox/ops_tests.rs
@@ -382,10 +382,12 @@ 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::CoreContext::scope(ctx, async {
- assert!(!sandbox_component_off(&DispatchCtx::ambient()));
- })
- .await;
+ crate::core::runtime::context::{
+ let scope_ctx = 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 f704e9f0b7..309dc2c1c0 100644
--- a/crates/openhuman-core/src/web_chat/ops/state_tests.rs
+++ b/crates/openhuman-core/src/web_chat/ops/state_tests.rs
@@ -20,26 +20,32 @@ async fn each_agent_context_owns_its_turn_tables() {
let beta = agent(&root, "beta");
let (alpha_sessions, alpha_in_flight, alpha_parallel) =
- CoreContext::scope(Arc::clone(&alpha), async {
+ {
+ let scope_ctx = DispatchCtx::new(Arc::clone(&alpha));
+
(
- thread_sessions(&crate::core::runtime::DispatchCtx::ambient()),
- in_flight(&crate::core::runtime::DispatchCtx::ambient()),
- parallel_in_flight(&crate::core::runtime::DispatchCtx::ambient()),
+ 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()),
)
- })
- .await;
- let (beta_sessions, beta_in_flight, beta_parallel) = CoreContext::scope(beta, async {
+
+};
+ let (beta_sessions, beta_in_flight, beta_parallel) = {
+ let scope_ctx = DispatchCtx::new(beta);
+
(
- thread_sessions(&crate::core::runtime::DispatchCtx::ambient()),
- in_flight(&crate::core::runtime::DispatchCtx::ambient()),
- parallel_in_flight(&crate::core::runtime::DispatchCtx::ambient()),
+ 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()),
)
- })
- .await;
- let alpha_again = CoreContext::scope(alpha, async {
- in_flight(&crate::core::runtime::DispatchCtx::ambient())
- })
- .await;
+
+};
+ let alpha_again = {
+ let scope_ctx = DispatchCtx::new(alpha);
+
+ in_flight(&crate::core::runtime::scope_ctx.clone())
+
+};
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 0c36684799..1b66124ff6 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
@@ -54,24 +54,28 @@ async fn two_agents_with_the_same_thread_id_get_their_own_cache_slots() {
agent: host_seeded_with(&config, "x"),
fingerprint: fingerprint.clone(),
};
- CoreContext::scope(Arc::clone(ctx), async {
- thread_sessions(&crate::core::runtime::DispatchCtx::ambient())
+ {
+ let scope_ctx = DispatchCtx::new(Arc::clone(ctx));
+
+ thread_sessions(&crate::core::runtime::scope_ctx.clone())
.lock_owned()
.await
.insert(key.clone(), entry);
- })
- .await;
+
+};
}
let cached = |ctx: &Arc<CoreContext>, key: &String| {
let (ctx, key) = (Arc::clone(ctx), key.clone());
async move {
- CoreContext::scope(ctx, async move {
- thread_sessions(&crate::core::runtime::DispatchCtx::ambient())
+ {
+ let scope_ctx = DispatchCtx::new(ctx);
+
+ thread_sessions(&crate::core::runtime::scope_ctx.clone())
.lock_owned()
.await
.contains_key(&key)
- })
- .await
+
+}
}
};
// Under one agent's scope only that agent's slot goes.