Skip to content

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

fix(agent): use dispatch context tenant for background completion router scope

Steven Enamakel3f0499f76174
diff --git a/crates/openhuman-core/src/agent/orchestration/background_completions.rs b/crates/openhuman-core/src/agent/orchestration/background_completions.rs
index f19a0fd850..3d6f2e3b2d 100644
--- a/crates/openhuman-core/src/agent/orchestration/background_completions.rs
+++ b/crates/openhuman-core/src/agent/orchestration/background_completions.rs
@@ -83,7 +83,7 @@ pub(super) struct RouterScope {
pub(super) fn router_scope_for(ctx: &DispatchCtx, workspace_dir: &Path) -> RouterScope {
let profile = crate::core::runtime::tenant::isolated_unless_tenant(
- DispatchCtx::ambient().tenant(),
+ ctx.tenant(),
"background_completions",
)
.profile_only();
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 eaf114947a..8d0313dffa 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
@@ -206,4 +206,23 @@ async fn explicit_profiles_share_a_workspace_without_sharing_completion_routers(
assert_eq!(alice_tasks, ["alice-task"]);
assert_eq!(bob_tasks, ["bob-task"]);
+
+ router_pool()
+ .clear()
+ .expect("simulate reopening each profile's storage-backed router");
+ let alice_recovered = recover_pending_threads(&alice, ws.path());
+ let bob_recovered = recover_pending_threads(&bob, ws.path());
+ assert_eq!(alice_recovered, ["same-thread"]);
+ assert_eq!(bob_recovered, ["same-thread"]);
+
+ let alice_after_reopen: Vec<_> = pending_for_ctx(&alice, ws.path(), "same-thread")
+ .into_iter()
+ .map(|record| record.task_id)
+ .collect();
+ let bob_after_reopen: Vec<_> = pending_for_ctx(&bob, ws.path(), "same-thread")
+ .into_iter()
+ .map(|record| record.task_id)
+ .collect();
+ assert_eq!(alice_after_reopen, ["alice-task"]);
+ assert_eq!(bob_after_reopen, ["bob-task"]);
}