Skip to content

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

refactor(session_host): split runtime session into focused modules

Steven Enamakel1cc016eceb33
diff --git a/crates/openhuman-core/src/agent/session_host/prelude_integrations.rs b/crates/openhuman-core/src/agent/session_host/prelude_integrations.rs
index f1a70a0876..977eff98e2 100644
--- a/crates/openhuman-core/src/agent/session_host/prelude_integrations.rs
+++ b/crates/openhuman-core/src/agent/session_host/prelude_integrations.rs
@@ -362,7 +362,7 @@ impl OpenHumanTurnPrelude {
}
let config = match self.runtime_config.clone() {
Some(config) => Some(config),
- None => crate::config::ops::load_current_or_init(&DispatchCtx::ambient())
+ None => crate::config::ops::load_current_or_init(&self.dispatch_ctx())
.await
.ok()
.map(Arc::new),
@@ -400,7 +400,7 @@ impl OpenHumanTurnPrelude {
let skills_changed = self.drain_host_events();
let config = match self.runtime_config.clone() {
Some(config) => Some(config),
- None => crate::config::ops::load_current_or_init(&DispatchCtx::ambient())
+ None => crate::config::ops::load_current_or_init(&self.dispatch_ctx())
.await
.ok()
.map(Arc::new),
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session.rs b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
index f98a81a27f..9a3b8d68c9 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_session.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
@@ -183,6 +183,15 @@ struct OpenHumanTurnPreludeMutable {
}
impl OpenHumanTurnPrelude {
+ /// The context this session's turns run under, from the host environment
+ /// bound at the start of the turn.
+ fn dispatch_ctx(&self) -> crate::core::runtime::DispatchCtx {
+ match &self.host_env.core {
+ Some(core) => crate::core::runtime::DispatchCtx::new(Arc::clone(core)),
+ None => crate::core::runtime::DispatchCtx::ambient(),
+ }
+ }
+
#[allow(clippy::type_complexity)]
fn current_tool_source(
&self,
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session/memory_ingest.rs b/crates/openhuman-core/src/agent/session_host/runtime_session/memory_ingest.rs
index d5b3e8520c..6b1801640b 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_session/memory_ingest.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session/memory_ingest.rs
@@ -78,7 +78,7 @@ impl OpenHumanTurnPrelude {
return Some(config.clone());
}
crate::config::rpc::load_config_for_workspace_with_timeout(
- &DispatchCtx::ambient(),
+ &self.dispatch_ctx(),
&self.workspace_dir,
)
.await
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session_turn.rs b/crates/openhuman-core/src/agent/session_host/runtime_session_turn.rs
index c732cad534..0382f1c785 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_session_turn.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session_turn.rs
@@ -27,13 +27,14 @@ impl OpenHumanSessionHost {
origin: Option<&crate::agent::turn_origin::AgentTurnOrigin>,
approval: crate::security::approval::ApprovalTurnContext,
) -> Result<String> {
- self.ensure_runtime_session()?;
- let staged = super::attachment_input::stage_turn(self, user_message, origin).await?;
- // The turn's context is bound once, here: the one ambient read at the
- // turn boundary for a host that did not hand a context over.
+ // The turn's context is bound once, here, before the runtime session
+ // snapshots the host environment: the one ambient read at the turn
+ // boundary, for a host that did not hand a context over.
if self.host_env.core.is_none() {
self.host_env.core = crate::core::runtime::DispatchCtx::ambient().into_core();
}
+ self.ensure_runtime_session()?;
+ let staged = super::attachment_input::stage_turn(self, user_message, origin).await?;
let mut context = OpenHumanRunContext::new().with_host_env(&self.host_env);
context.untrusted_input_turn = self.untrusted_input;
context.origin = origin.cloned();