Skip to content

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

feat(session): persist runtime session state to the session store

Steven Enamakel5eb01de4e922
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 ced685c839..4b9c36e09e 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_session.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
@@ -1414,9 +1414,16 @@ impl OpenHumanSessionHost {
}
self.session_history_locator_memo
.get_or_init(|| {
- let session_agent_id = crate::core::runtime::CoreContext::current()
- .and_then(|context| context.session_agent().map(str::to_owned))
- .unwrap_or_else(|| self.agent_definition_id.clone());
+ // A profile's conversations key on the tenant; elsewhere the
+ // context's agent, else this session's definition, as before.
+ let tenant = crate::core::runtime::tenant::current_tenant_or_isolated(
+ "session_locator",
+ );
+ let session_agent_id = match (&tenant.profile, tenant.agent) {
+ (Some(_), _) => crate::core::runtime::session_key(&tenant),
+ (None, Some(agent)) => agent,
+ (None, None) => self.agent_definition_id.clone(),
+ };
transcripts_or_files(&session_agent_id, &self.workspace_dir)
})
.clone()
diff --git a/crates/openhuman-core/src/agent/session_store/mod.rs b/crates/openhuman-core/src/agent/session_store/mod.rs
index fddcdafd95..c74100ce73 100644
--- a/crates/openhuman-core/src/agent/session_store/mod.rs
+++ b/crates/openhuman-core/src/agent/session_store/mod.rs
@@ -163,23 +163,30 @@ pub fn transcript_root(workspace_dir: &std::path::Path) -> std::path::PathBuf {
}
}
-/// The stores of the agent the current [`CoreContext`] works for — the one
-/// it was derived for ([`CoreContext::session_agent`]), else
-/// [`DEFAULT_AGENT`] — or `None` when the core keeps the on-disk layout.
+/// The stores of the tenant the current [`CoreContext`] works for, keyed by
+/// [`session_key`](crate::core::runtime::session_key): the agent it was
+/// derived for ([`CoreContext::session_agent`]), else [`DEFAULT_AGENT`],
+/// prefixed by its SaaS profile when it serves one — or `None` when the core
+/// keeps the on-disk layout.
///
/// For code that has a workspace path but no agent id of its own (goals,
/// todos, the turn journal): under an embedded agent's context it lands in
-/// that agent's stores.
+/// that agent's stores. A SaaS task with no scope gets none rather than the
+/// shared default bucket.
///
/// [`CoreContext`]: crate::core::runtime::CoreContext
/// [`CoreContext::session_agent`]: crate::core::runtime::CoreContext::session_agent
#[must_use]
pub fn current() -> Option<AgentStores> {
let provider = installed()?;
- let agent = crate::core::runtime::CoreContext::current()
- .and_then(|context| context.session_agent().map(str::to_owned))
- .unwrap_or_else(|| DEFAULT_AGENT.to_string());
- Some(provider.for_agent(&agent))
+ let tenant = match crate::core::runtime::current_tenant() {
+ Ok(tenant) => tenant,
+ Err(no_tenant) => {
+ log::warn!("[session_store] current: {no_tenant}");
+ return None;
+ }
+ };
+ Some(provider.for_agent(&crate::core::runtime::session_key(&tenant)))
}
/// The workspace the current [`CoreContext`](crate::core::runtime::CoreContext)