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 across restarts

Steven Enamakel7484652f72c4
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 07ba1a959b..5df931b859 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_session.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
@@ -1414,18 +1414,8 @@ impl OpenHumanSessionHost {
}
self.session_history_locator_memo
.get_or_init(|| {
- // 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 = if tenant.profile.is_some() {
- crate::core::runtime::session_key(&tenant)
- } else {
- tenant
- .agent
- .unwrap_or_else(|| self.agent_definition_id.clone())
- };
+ let session_agent_id =
+ crate::agent::session_store::current_agent_key_or(&self.agent_definition_id);
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 c74100ce73..6095eafe79 100644
--- a/crates/openhuman-core/src/agent/session_store/mod.rs
+++ b/crates/openhuman-core/src/agent/session_store/mod.rs
@@ -189,6 +189,19 @@ pub fn current() -> Option<AgentStores> {
Some(provider.for_agent(&crate::core::runtime::session_key(&tenant)))
}
+/// The agent id a session host resolves transcripts under for the current
+/// tenant: the [`session_key`](crate::core::runtime::session_key) when it
+/// serves a SaaS profile, else the context's agent, else `fallback` (the
+/// session's own definition id), as before profiles existed.
+#[must_use]
+pub fn current_agent_key_or(fallback: &str) -> String {
+ let tenant = crate::core::runtime::tenant::current_tenant_or_isolated("session_locator");
+ if tenant.profile.is_some() {
+ return crate::core::runtime::session_key(&tenant);
+ }
+ tenant.agent.unwrap_or_else(|| fallback.to_string())
+}
+
/// The workspace the current [`CoreContext`](crate::core::runtime::CoreContext)
/// is bound to, for a file-backed store that must follow it (the desktop
/// rebinds it when a different user signs in). Before the core has booted —
diff --git a/scripts/ci/check-openhuman-rust-layout.mjs b/scripts/ci/check-openhuman-rust-layout.mjs
index e75700a10a..c7c6444e65 100644
--- a/scripts/ci/check-openhuman-rust-layout.mjs
+++ b/scripts/ci/check-openhuman-rust-layout.mjs
@@ -38,7 +38,7 @@ const LEGACY_LIMIT_ENTRIES = [
// under the general 750 limit, so it needs no exception at all.
// The session-todo integration added transcript metadata construction to
// this already-exempt composition seam. Keep its allowance exact.
- ["crates/openhuman-core/src/agent/session_host/runtime_session.rs", 1466],
+ ["crates/openhuman-core/src/agent/session_host/runtime_session.rs", 1465],
// Session-host factory still assembles the product's deliberately coupled
// provider, security, memory, tool and prompt policy. Generic session
// state moved to tinyagents-runtime; this remaining composition is split in