Skip to content

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

fix(agent): persist goal and todo state across session reloads

Steven Enamakel342461e5146f
diff --git a/crates/openhuman-core/src/agent/goals/store.rs b/crates/openhuman-core/src/agent/goals/store.rs
index 5d5ced2cca..02a41b79b6 100644
--- a/crates/openhuman-core/src/agent/goals/store.rs
+++ b/crates/openhuman-core/src/agent/goals/store.rs
@@ -2,7 +2,7 @@
//!
//! **Crate-backed.** The per-thread goal now lives in the vendored `tinyagents`
//! crate's `graph::goals` KV store
-//! (`<workspace>/tinyagents_store/kv/graph.goals/<hex(thread_id)>.json`), not
+//! (the `graph.goals` namespace of the agent's key-value store), not
//! the legacy `<workspace>/thread_goals/` file-JSON tree. This module is a thin
//! adapter for the harness turn loop, agent tools, and post-turn accounting. It forwards each operation to the crate
//! store, converting the crate
@@ -19,15 +19,11 @@ use std::sync::Arc;
use tinyagents_graph::goals::store as crate_store;
use tinyagents_graph::goals::ThreadGoal;
use tinyagents_harness::store::Store;
-use tinyagents_session::transcript::import::ops::open_session_stores;
-/// The store thread goals live in: the current agent's host session store
-/// when one is installed, else the workspace's `tinyagents_store/kv`.
+/// The store thread goals live in: the current agent's key-value store in the
+/// storage backend ([`crate::agent::session_store::stores_for`]).
pub(crate) fn goals_store(workspace_dir: &Path) -> Arc<dyn Store> {
- if let Some(stores) = crate::agent::session_store::current() {
- return stores.kv;
- }
- Arc::new(open_session_stores(workspace_dir).kv)
+ crate::agent::session_store::stores_or_ephemeral(workspace_dir).kv
}
/// Set (create or replace) the thread's goal. A changed objective mints a fresh
diff --git a/crates/openhuman-core/src/agent/session_store/mod.rs b/crates/openhuman-core/src/agent/session_store/mod.rs
index fb21ec9712..29ae7fd593 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::{
current_documents_for, ledger_for, provider_for_workspace, release_workspace_defaults,
- run_ledger_blocking, stores_for,
+ run_ledger_blocking, stores_for, stores_or_ephemeral,
};
static PROVIDER: LazyLock<RwLock<Option<Arc<dyn SessionStoreProvider>>>> =
diff --git a/crates/openhuman-core/src/agent/session_store/workspace.rs b/crates/openhuman-core/src/agent/session_store/workspace.rs
index 837bb2d8d9..a71717dab5 100644
--- a/crates/openhuman-core/src/agent/session_store/workspace.rs
+++ b/crates/openhuman-core/src/agent/session_store/workspace.rs
@@ -125,6 +125,17 @@ pub fn stores_for(workspace_dir: &Path) -> Option<AgentStores> {
Some(provider_for_workspace(workspace_dir).for_agent(&key))
}
+/// [`stores_for`] `workspace_dir`, or throwaway in-memory stores for a call
+/// that has no tenant to act for (a SaaS task with no scope), so it neither
+/// fails nor reaches another tenant's records.
+#[must_use]
+pub fn stores_or_ephemeral(workspace_dir: &Path) -> AgentStores {
+ stores_for(workspace_dir).unwrap_or_else(|| {
+ log::warn!("[session_store] no tenant; using throwaway in-memory stores");
+ tinyagents_session::port::InMemorySessionStores::new().for_agent("ephemeral")
+ })
+}
+
/// The calling tenant's run ledger for `workspace_dir`.
///
/// The installed provider's when it keeps one, else the workspace default's.
diff --git a/crates/openhuman-core/src/agent/tinyagents/todos.rs b/crates/openhuman-core/src/agent/tinyagents/todos.rs
index f3fd21b156..3822d4a7d9 100644
--- a/crates/openhuman-core/src/agent/tinyagents/todos.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/todos.rs
@@ -1,10 +1,9 @@
//! The persisted store behind the session todo list.
//!
//! Todos are session state, the way Claude Code and Codex keep them: one list
-//! per conversation thread. Persisted under
-//! `{workspace}/tinyagents_store/kv/` — the same `FileStore` tree
-//! `open_session_stores` opens for thread goals (`agent::goals::store`) — so a
-//! list survives a core restart instead of resetting with the old
+//! per conversation thread. Persisted in the
+//! agent's key-value store — the one thread goals use
+//! (`agent::goals::store`) — so a list survives a core restart instead of resetting with the old
//! process-global `InMemoryStore`. The transcript still records every list
//! the model wrote, and the frontend renders the latest one from the turn's
//! `todo` tool call.
@@ -14,19 +13,11 @@ use std::sync::Arc;
use tinyagents_harness::store::Store;
-use tinyagents_session::transcript::import::ops::open_session_stores;
-
-/// The `workspace`-scoped store every session's list lives in, keyed by
-/// session/thread id. Opened fresh per call (cheap — `FileStore` just holds a
-/// root path) so it always reflects the caller's current workspace.
-///
-/// With a host session store installed, the current agent's key-value store
-/// instead.
+/// The store every session's list lives in, keyed by session/thread id: the
+/// current agent's key-value store in the storage backend. Resolved per call
+/// so it always reflects the caller's current workspace and tenant.
pub fn session_todos_store(workspace_dir: &Path) -> Arc<dyn Store> {
- if let Some(stores) = crate::agent::session_store::current() {
- return stores.kv;
- }
- Arc::new(open_session_stores(workspace_dir).kv)
+ crate::agent::session_store::stores_or_ephemeral(workspace_dir).kv
}
/// Synthetic key for a tool call that has no session at all (a bare