Skip to content

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

refactor(storage): simplify workspace transcript retrieval

Steven Enamakela27bc404b16e
diff --git a/crates/openhuman-core/src/storage/sessions/mod.rs b/crates/openhuman-core/src/storage/sessions/mod.rs
index ad6c2f2f92..4aa9387743 100644
--- a/crates/openhuman-core/src/storage/sessions/mod.rs
+++ b/crates/openhuman-core/src/storage/sessions/mod.rs
@@ -14,8 +14,7 @@
//! OpenHuman runs one runtime per process. With nothing installed, the core
//! keeps today's on-disk layout.
-use std::collections::HashMap;
-use std::sync::{Arc, LazyLock, Mutex, PoisonError, RwLock};
+use std::sync::{Arc, LazyLock, PoisonError, RwLock};
use tinyagents_session::port::{AgentStores, SessionStoreProvider};
@@ -179,69 +178,17 @@ pub fn transcripts_or_files_in(
}
}
-/// The workspace stores this process holds open, so repeat lookups share one
-/// backend ([`release_workspace_stores`] drops them for a data reset).
-static OPEN_WORKSPACE_STORES: LazyLock<
- Mutex<HashMap<(std::path::PathBuf, String), tinyagents_session::port::WorkspaceStores>>,
-> = LazyLock::new(Mutex::default);
-
-/// Drops the workspace transcript stores held open by [`workspace_transcripts`].
-pub fn release_workspace_stores() {
- OPEN_WORKSPACE_STORES
- .lock()
- .unwrap_or_else(PoisonError::into_inner)
- .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`
-/// files once, read-only, so no file API is involved.
-///
-/// A workspace whose store cannot be opened (read-only disk) degrades to an
-/// in-memory locator for the process rather than failing the turn.
+/// `agent_id`'s transcripts for a host that has a workspace path but no
+/// separately installed provider. The workspace default backend and owner
+/// session collections are used; a refused backend returns refusing stores.
#[must_use]
pub fn workspace_transcripts(
agent_id: &str,
workspace_dir: &std::path::Path,
) -> Arc<dyn tinyagents_session::transcript::TranscriptLocator> {
- let key = (workspace_dir.to_path_buf(), agent_id.to_string());
- let mut open = OPEN_WORKSPACE_STORES
- .lock()
- .unwrap_or_else(PoisonError::into_inner);
- if let Some(stores) = open.get(&key) {
- return stores.transcripts();
- }
- match tinyagents_session::port::WorkspaceStores::open(workspace_dir, agent_id) {
- Ok(stores) => {
- log::debug!(
- "[session_store] transcripts via the workspace store agent={agent_id} import={:?}",
- stores.import_outcome()
- );
- let transcripts = stores.transcripts();
- open.insert(key, stores);
- transcripts
- }
- Err(error) => {
- log::error!(
- "[session_store] workspace store unavailable agent={agent_id} workspace={}: {error:#}; \
- transcripts are not kept",
- workspace_dir.display()
- );
- tinyagents_session::port::InMemorySessionStores::new()
- .for_agent(agent_id)
- .transcripts
- }
- }
+ super::workspace::provider_for_workspace(workspace_dir)
+ .for_agent(agent_id)
+ .transcripts
}
/// The stores of the tenant the current [`CoreContext`] works for, keyed by
diff --git a/crates/openhuman-core/src/storage/sessions/workspace.rs b/crates/openhuman-core/src/storage/sessions/workspace.rs
index c11efcde93..562c79bac9 100644
--- a/crates/openhuman-core/src/storage/sessions/workspace.rs
+++ b/crates/openhuman-core/src/storage/sessions/workspace.rs
@@ -39,7 +39,6 @@ pub fn release_workspace_defaults() {
.lock()
.unwrap_or_else(PoisonError::into_inner)
.clear();
- super::release_workspace_stores();
crate::storage::local::release_all();
}
@@ -53,7 +52,6 @@ pub fn release_workspace(workspace_dir: &Path) {
.lock()
.unwrap_or_else(PoisonError::into_inner)
.remove(workspace_dir);
- super::release_workspace_stores_for(workspace_dir);
crate::storage::local::forget(workspace_dir);
}