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_store): add workspace-scoped session storage
Steven Enamakela1d77a329478
diff --git a/crates/openhuman-core/src/agent/session_store/mod.rs b/crates/openhuman-core/src/agent/session_store/mod.rsindex d9ccc92daf..4e210a406d 100644--- a/crates/openhuman-core/src/agent/session_store/mod.rs+++ b/crates/openhuman-core/src/agent/session_store/mod.rs@@ -26,7 +26,7 @@ mod workspace;pub use rebound::{rebind_all, ReboundSessionStores};pub use workspace::{artifact_blobs_for, attachment_stash_for, current_documents_for, default_turn_states_for,- ledger_for, provider_for_workspace, release_workspace_defaults, require_ledger,+ ledger_for, provider_for_workspace, release_workspace, release_workspace_defaults, require_ledger,status_store_for, stores_for, stores_or_ephemeral, turn_states_for, with_ledger,with_ledger_async, WorkspaceSessionStores,};@@ -183,6 +183,15 @@ pub fn release_workspace_stores() {.clear();}+/// Drops the workspace transcript stores held open for `workspace_dir` (every+/// agent's), leaving other workspaces' alone.+pub fn release_workspace_stores_for(workspace_dir: &std::path::Path) {+ OPEN_WORKSPACE_STORES+ .lock()+ .unwrap_or_else(PoisonError::into_inner)+ .retain(|(dir, _), _| dir != workspace_dir);+}+/// `agent_id`'s transcripts for a host that only has a workspace directory:/// TinyAgents' `WorkspaceStores` (the driver ports over a SQLite store under/// the workspace). It imports the workspace's classic `session_raw/*.jsonl`diff --git a/crates/openhuman-core/src/agent/session_store/mod_tests.rs b/crates/openhuman-core/src/agent/session_store/mod_tests.rsindex ea8bb8777d..f9ec2a6082 100644--- a/crates/openhuman-core/src/agent/session_store/mod_tests.rs+++ b/crates/openhuman-core/src/agent/session_store/mod_tests.rs@@ -263,7 +263,7 @@ async fn a_threads_turn_state_survives_a_restart_of_the_workspace_store() {.unwrap();// A restart: every handle and cached default backend is dropped.- release_workspace_defaults();+ release_workspace(dir.path());let resumed = turn_states_for(dir.path()).get("thread-1")@@ -292,7 +292,7 @@ async fn a_stashed_attachment_survives_a_restart_of_the_workspace_store() {let stash = attachment_stash_for(dir.path()).expect("a stash for the default tenant");stash.write("att-1", data_uri).await.unwrap();- release_workspace_defaults();+ release_workspace(dir.path());let resumed = attachment_stash_for(dir.path()).expect("a stash after the restart");assert_eq!(diff --git a/crates/openhuman-core/src/agent/session_store/workspace.rs b/crates/openhuman-core/src/agent/session_store/workspace.rsindex e2e7d55903..e670dbe37d 100644--- a/crates/openhuman-core/src/agent/session_store/workspace.rs+++ b/crates/openhuman-core/src/agent/session_store/workspace.rs@@ -42,6 +42,20 @@ pub fn release_workspace_defaults() {crate::storage::local::release_all();}+/// Drops what this process holds open for `workspace_dir` alone (its fallback+/// provider, its workspace transcript stores and its default backend), so that+/// workspace's files can be deleted or reopened afresh while every other+/// workspace keeps its live handles. A restart of one workspace, not of the+/// process; [`release_workspace_defaults`] is the process-wide reset.+pub fn release_workspace(workspace_dir: &Path) {+ FALLBACKS+ .lock()+ .unwrap_or_else(PoisonError::into_inner)+ .remove(workspace_dir);+ super::release_workspace_stores_for(workspace_dir);+ crate::storage::local::forget(workspace_dir);+}+/// The provider for `workspace_dir`: the installed one, else a/// `DriverSessionStores` over the workspace's default backend.///diff --git a/crates/openhuman-core/src/agent/session_store/workspace_tests.rs b/crates/openhuman-core/src/agent/session_store/workspace_tests.rsindex a3dbc916bc..0712a023fc 100644--- a/crates/openhuman-core/src/agent/session_store/workspace_tests.rs+++ b/crates/openhuman-core/src/agent/session_store/workspace_tests.rs@@ -119,7 +119,7 @@ fn releasing_defaults_lets_the_next_call_open_afresh() {let before = fallback_provider(ws.path());let cached = fallback_provider(ws.path());assert!(Arc::ptr_eq(&before, &cached), "a repeat call reuses the provider");- release_workspace_defaults();+ release_workspace(ws.path());let after = fallback_provider(ws.path());assert!(!Arc::ptr_eq(&before, &after), "release drops the cached provider");}