The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
feat(session): add live session import and reaper
Steven Enamakel6e7a315285cf
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session.rs b/crates/openhuman-core/src/agent/session_host/runtime_session.rsindex 565fdf502d..7e2aa5914c 100644--- a/crates/openhuman-core/src/agent/session_host/runtime_session.rs+++ b/crates/openhuman-core/src/agent/session_host/runtime_session.rs@@ -739,8 +739,9 @@ impl OpenHumanTurnPrelude {return;}// The dual write mirrors transcript *files* into the session store; a- // host store is already the only record, and there is no file to read.- if crate::agent::session_store::is_installed() {+ // host store that is not file-backed is already the only record, and+ // there is no file to read.+ if crate::agent::session_store::replaces_files() {return;}let Some(stem) = pathdiff --git a/crates/openhuman-core/src/agent/session_import/live.rs b/crates/openhuman-core/src/agent/session_import/live.rsindex 6acd4e7a8a..07559f6ffd 100644--- a/crates/openhuman-core/src/agent/session_import/live.rs+++ b/crates/openhuman-core/src/agent/session_import/live.rs@@ -86,12 +86,17 @@ pub fn dual_write_enabled(config_enabled: bool) -> bool {/// journal (`JsonlAppendStore`, an `AppendStore` rather than a `Store`) is not/// registrable on the `StoreRegistry`; the dual-write opens it directly.///-/// With a host session store installed it is the current agent's key-value-/// store, whatever the dual-write flag says: there are no files to mirror.+/// With a host session store that is not file-backed it is the current+/// agent's key-value store, whatever the dual-write flag says: there are no+/// files to mirror.pub async fn session_kv_store() -> Option<Arc<dyn Store>> {- if let Some(stores) = crate::agent::session_store::current() {- log::debug!("[session-store] registering the host session store's kv on RunContext.stores");- return Some(stores.kv);+ if crate::agent::session_store::replaces_files() {+ if let Some(stores) = crate::agent::session_store::current() {+ log::debug!(+ "[session-store] registering the host session store's kv on RunContext.stores"+ );+ return Some(stores.kv);+ }}let cfg = match crate::config::Config::load_or_init().await {Ok(cfg) => cfg,diff --git a/crates/openhuman-core/src/agent/session_store/mod.rs b/crates/openhuman-core/src/agent/session_store/mod.rsindex 14b2f118f5..f52aaade60 100644--- a/crates/openhuman-core/src/agent/session_store/mod.rs+++ b/crates/openhuman-core/src/agent/session_store/mod.rs@@ -4,9 +4,10 @@//! serving many users from one process) installs a//! [`SessionStoreProvider`] here once, before agents run. From then on every//! agent's transcripts, turn journal, run status, goals and todos go through-//! that agent's [`AgentStores`] instead of files under `workspace_dir`, and-//! the file-era mirrors (the session dual-write and its shadow reads) stand-//! down: the host store is the only record.+//! that agent's [`AgentStores`] instead of files under `workspace_dir`. For a+//! store that is not file-backed ([`replaces_files`]) the file-era mirrors+//! (the session dual-write and its shadow reads) stand down: the host store+//! is the only record.//!//! Like the memory engine's host binding//! ([`crate::memory::engine::install_host_engine`]), this is process-wide:@@ -77,6 +78,14 @@ pub fn is_installed() -> bool {installed().is_some()}+/// Whether the store in effect keeps conversations somewhere other than the+/// classic workspace files ([`SessionStoreProvider::workspace_dir`] is+/// `None`), so companions that read those files back have nothing to read.+#[must_use]+pub fn replaces_files() -> bool {+ installed().is_some_and(|provider| provider.workspace_dir().is_none())+}+/// `agent_id`'s stores from the installed provider, or `None` when the core/// keeps the on-disk layout.#[must_use]diff --git a/crates/openhuman-core/src/agent/session_store/mod_tests.rs b/crates/openhuman-core/src/agent/session_store/mod_tests.rsindex 71a55d125a..fee4b138bf 100644--- a/crates/openhuman-core/src/agent/session_store/mod_tests.rs+++ b/crates/openhuman-core/src/agent/session_store/mod_tests.rs@@ -29,3 +29,10 @@ async fn work_outside_an_agent_context_uses_the_default_agent() {);assert!(current().is_none() || is_installed());}++#[tokio::test]+async fn only_a_store_without_files_replaces_them() {+ assert!(!replaces_files(), "no store: the files are the record");+ let memory: Arc<dyn SessionStoreProvider> = Arc::new(InMemorySessionStores::new());+ assert!(scope(memory, async { replaces_files() }).await);+}diff --git a/crates/openhuman-core/src/agent/tinyagents/reaper.rs b/crates/openhuman-core/src/agent/tinyagents/reaper.rsindex 928cb9588f..82b91d91f5 100644--- a/crates/openhuman-core/src/agent/tinyagents/reaper.rs+++ b/crates/openhuman-core/src/agent/tinyagents/reaper.rs@@ -18,11 +18,11 @@ pub(crate) async fn reap_orphaned_runs(workspace: &Path) -> usize {"[agent] startup run sweep workspace={}",workspace.display());- // A host session store repairs its own runs (`SessionStoreProvider::recover`,- // run at boot): its status records are per agent, not in this workspace.- if crate::agent::session_store::is_installed() {- log::debug!("[agent] startup run sweep skipped: the host session store recovers its runs");- return 0;+ // With a host session store the status records live in its stores: sweep+ // the ones this process's own (default-agent) work wrote there.+ if let Some(stores) = crate::agent::session_store::current() {+ let store = FileStatusStore::over(stores.kv);+ return tinyagents_harness::observability::reap_orphaned_runs(&store).await;}let store = FileStatusStore::new(open_session_stores(workspace).kv);tinyagents_harness::observability::reap_orphaned_runs(&store).awaitdiff --git a/vendor/tinyagents b/vendor/tinyagentsindex 6a6b64892c..3625562348 160000--- a/vendor/tinyagents+++ b/vendor/tinyagents@@ -1 +1 @@-Subproject commit 6a6b64892c3a02f3274ff57f606258887b105a25+Subproject commit 3625562348ba0b81c9d72f6a0cffe4cd4e993b59