Skip to content

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

feat(subagent_sessions): add indexed single-task lookup for import adapter

Steven Enamakele085c9e70d82
diff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents/cancel.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents/cancel.rs
index b7e3437792..fa61635c7c 100644
--- a/crates/openhuman-core/src/agent/orchestration/running_subagents/cancel.rs
+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents/cancel.rs
@@ -241,7 +241,7 @@ fn terminal_legacy_session(
subagent_session_id: Some(session.subagent_session_id),
workspace_dir: workspace_dir.to_path_buf(),
parent_thread_id: session.parent_thread_id,
- parent_epoch: session.parent_epoch,
+ parent_epoch: None,
already_finished: Some(already_finished),
driver_pause: None,
driver_managed: false,
diff --git a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store.rs b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store.rs
index 2a8ba8fa74..6c37d152a4 100644
--- a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store.rs
+++ b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store.rs
@@ -78,6 +78,21 @@ impl SubagentSessionStore {
})
}
+ /// Finds one row for the TinyAgents migration adapter. Unlike `load`, this
+ /// performs an indexed read after any one-time legacy-file import and does
+ /// not rewrite the host session row.
+ pub(super) fn find_task_for_import(
+ &self,
+ task_id: &str,
+ ) -> Result<Option<DurableSubagentSession>, String> {
+ self.in_scope(|| {
+ let docs = super::store_documents::current(&self.workspace_dir)
+ .map_err(|err| format!("{err:#}"))?;
+ self.import_legacy(&docs)?;
+ docs.find_task(task_id).map_err(|err| format!("{err:#}"))
+ })
+ }
+
pub fn save(&self, sessions: &[DurableSubagentSession]) -> Result<(), String> {
self.in_scope(|| {
let docs = super::store_documents::current(&self.workspace_dir)
diff --git a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store_documents.rs b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store_documents.rs
index 2dfd42583e..a16d32de88 100644
--- a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store_documents.rs
+++ b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store_documents.rs
@@ -27,7 +27,7 @@ use anyhow::Result;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use tinyagents_session::transcript::TranscriptMessage;
-use tinystoragedrivers::{CollectionSpec, Query, Sort};
+use tinystoragedrivers::{CollectionSpec, Filter, Query, Sort};
use super::storage_schema::{SESSIONS, spec};
use super::types::{DurableSubagentSession, DurableSubagentStatus};
@@ -206,6 +206,29 @@ impl Docs {
.collect()
}
+ /// Looks up one legacy task row for the TinyAgents import adapter without
+ /// loading or rewriting the host collection. The one-time JSON import is
+ /// performed by the caller before this indexed document query.
+ pub(super) fn find_task(&self, task_id: &str) -> Result<Option<DurableSubagentSession>> {
+ let task_id = task_id.to_owned();
+ let stored = self.0.run(|docs| async move {
+ docs.query_all(
+ SESSIONS,
+ &Query::filter(Filter::eq("current_task_id", task_id)),
+ )
+ .await
+ })?;
+ let sessions = stored
+ .into_iter()
+ .map(|item| {
+ serde_json::from_value::<StoredSession>(item.doc)
+ .map(DurableSubagentSession::from)
+ .map_err(Into::into)
+ })
+ .collect::<Result<Vec<_>>>()?;
+ Ok(sessions.into_iter().next())
+ }
+
/// Atomically mutate one session from its current stored value. Live
/// lifecycle changes use this path so millisecond timestamp precision
/// cannot discard an equal-millisecond state transition. Whole-list saves