Skip to content

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

fix(agent): deliver background results to the originating session

Steven Enamakel7639c6a9e091
diff --git a/crates/openhuman-core/src/agent/orchestration/background_delivery.rs b/crates/openhuman-core/src/agent/orchestration/background_delivery.rs
index 8010936524..41c7c9e26a 100644
--- a/crates/openhuman-core/src/agent/orchestration/background_delivery.rs
+++ b/crates/openhuman-core/src/agent/orchestration/background_delivery.rs
@@ -401,8 +401,8 @@ async fn try_deliver(busy_ctx: DispatchCtx, thread_id: String, fence: DrainFence
};
let router = background_completions::router_for_workspace(&workspace_dir);
let turn_workspace = workspace_dir.clone();
- // A drain is event-driven and carries no context of its own.
- let ctx = DispatchCtx::host_default();
+ // The turn runs under the context the drain was scheduled for.
+ let ctx = busy_ctx.clone();
let give_up_ctx = busy_ctx.clone();
let retry_after = try_deliver_with(
&busy_ctx,
diff --git a/crates/openhuman-core/src/core/runtime/dispatch_ctx.rs b/crates/openhuman-core/src/core/runtime/dispatch_ctx.rs
index 2c2054518a..ed9e63afb4 100644
--- a/crates/openhuman-core/src/core/runtime/dispatch_ctx.rs
+++ b/crates/openhuman-core/src/core/runtime/dispatch_ctx.rs
@@ -65,14 +65,16 @@ impl DispatchCtx {
Self { core }
}
- /// The context for work that arrives with none of its own: a bus event, a
- /// module host callback, a shutdown hook. Outside SaaS that is the process
- /// default, the one context a single-user host has. In SaaS it is the
- /// task's own tenant scope only, so work that lost its tenant fails closed
- /// instead of acting as the operator.
+ /// The context for work that arrives with none of its own and no tenant on
+ /// the wire: a socket-driven bus event, a module host callback, a shutdown
+ /// hook. Outside SaaS that is the process default, the one context a
+ /// single-user host has. In SaaS it is unbound, so work that lost its
+ /// tenant fails closed instead of acting as the operator. It never reads
+ /// the calling task's scope; an event that names its tenant uses
+ /// [`for_event`](Self::for_event), a caller holding a context passes it.
pub fn host_default() -> Self {
if super::is_saas() {
- Self::ambient()
+ Self::unbound()
} else {
Self::process_default()
}
diff --git a/crates/openhuman-core/src/core/runtime/saas.rs b/crates/openhuman-core/src/core/runtime/saas.rs
index 6dbe680626..467f42ee43 100644
--- a/crates/openhuman-core/src/core/runtime/saas.rs
+++ b/crates/openhuman-core/src/core/runtime/saas.rs
@@ -416,7 +416,7 @@ pub async fn build_with_profile_capabilities(
capabilities: Option<Arc<crate::profiles::capabilities::ProfileCapabilities>>,
) -> anyhow::Result<CoreRuntime> {
crate::profiles::provider_settings::ProfileProviderSettings::from_saas(&config)?;
- if CoreContext::current().is_some() {
+ if CoreContext::default_context().is_some() {
anyhow::bail!(
"[saas] a core is already running in this process; a SaaS core must be the only one"
);