Skip to content

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

refactor(subagent_sessions): split parent epoch helpers into own module

Steven Enamakelbdde2aff3459
diff --git a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/mod.rs b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/mod.rs
index 730508fc04..5f1e9ce10e 100644
--- a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/mod.rs
+++ b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/mod.rs
@@ -4,6 +4,7 @@ mod store;
pub use storage_schema::storage_schema;
mod store_documents;
mod tiny_port;
+mod tiny_port_epoch;
mod types;
pub use ops::{
@@ -15,9 +16,9 @@ pub use ops::{
#[cfg(test)]
pub(crate) use tiny_port::OpenHumanTinySubagentSessionStore;
pub(crate) use tiny_port::{
- host_projection, import_terminal_task_for_context, open_for_context, parent_epoch_for_context,
- set_parent_epoch_for_context,
+ host_projection, import_terminal_task_for_context, open_for_context,
};
+pub(crate) use tiny_port_epoch::{parent_epoch_for_context, set_parent_epoch_for_context};
pub use types::{
DurableSubagentStatus, SubagentSessionSelector, SubagentSessionStore, SubagentSessionUpsert,
};
diff --git a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/tiny_port.rs b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/tiny_port.rs
index 0eabeb56d4..5a9dab5dc6 100644
--- a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/tiny_port.rs
+++ b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/tiny_port.rs
@@ -4,7 +4,6 @@ use std::path::PathBuf;
use std::sync::Arc;
use async_trait::async_trait;
-use serde::{Deserialize, Serialize};
use tinyagents_orchestration::subagent::{
DriverSubagentSessionStore, DurableSubagentSession as TinySession,
DurableSubagentStatus as TinyStatus, ReuseDecision as TinyReuseDecision,
diff --git a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/tiny_port_epoch.rs b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/tiny_port_epoch.rs
new file mode 100644
index 0000000000..c2c5a422d8
--- /dev/null
+++ b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/tiny_port_epoch.rs
@@ -0,0 +1,96 @@
+//! Host-owned parent-epoch metadata for TinyAgents subagent sessions.
+
+use std::sync::Arc;
+
+use serde::{Deserialize, Serialize};
+use tinyagents_orchestration::subagent::SubagentError;
+
+use super::storage_schema::EPOCHS;
+
+#[derive(Deserialize, Serialize)]
+struct ParentEpochRecord {
+ parent_epoch: Option<u64>,
+}
+
+pub(super) fn import_parent_epoch(
+ documents: Arc<dyn crate::storage::DocumentStore>,
+ session_id: String,
+ parent_epoch: Option<u64>,
+) -> Result<(), SubagentError> {
+ crate::storage::block_on(async move {
+ documents
+ .ensure_collection(&tinystoragedrivers::CollectionSpec::new(EPOCHS))
+ .await?;
+ let repo = tinystoragedrivers::Repo::<ParentEpochRecord>::new(&documents, EPOCHS)?;
+ repo.update(&session_id, move |_| {
+ Ok(Some(ParentEpochRecord { parent_epoch }))
+ })
+ .await?;
+ Ok(())
+ })
+ .map_err(|error| SubagentError::Persistence(format!("import parent epoch: {error}")))
+}
+
+pub(crate) fn parent_epoch_from_sidecar(
+ documents: Arc<dyn crate::storage::DocumentStore>,
+ session_id: String,
+) -> Result<Option<u64>, SubagentError> {
+ crate::storage::block_on(async move {
+ documents
+ .ensure_collection(&tinystoragedrivers::CollectionSpec::new(EPOCHS))
+ .await?;
+ let repo = tinystoragedrivers::Repo::<ParentEpochRecord>::new(&documents, EPOCHS)?;
+ Ok(repo
+ .get(&session_id)
+ .await?
+ .and_then(|record| record.doc.parent_epoch))
+ })
+ .map_err(|error| SubagentError::Persistence(format!("read parent epoch: {error}")))
+}
+
+pub(crate) fn parent_epoch_for_context(
+ ctx: &crate::core::runtime::DispatchCtx,
+ workspace_dir: &std::path::Path,
+ session_id: String,
+) -> Result<Option<u64>, SubagentError> {
+ let open_documents = || {
+ let opened =
+ crate::storage::local::open("subagent_sessions", workspace_dir).map_err(|error| {
+ SubagentError::Persistence(format!("open session store: {error:#}"))
+ })?;
+ let scoped = opened.scoped().map_err(|error| {
+ SubagentError::Persistence(format!("scope session store: {error:#}"))
+ })?;
+ Ok::<_, SubagentError>(Arc::clone(scoped.documents()))
+ };
+ let context = ctx.resolved().ok_or_else(|| {
+ SubagentError::Persistence("subagent session store has no resolved owner scope".into())
+ })?;
+ parent_epoch_from_sidecar(
+ crate::core::runtime::CoreContext::sync_scope(context, open_documents)?,
+ session_id,
+ )
+}
+
+pub(crate) fn set_parent_epoch_for_context(
+ ctx: &crate::core::runtime::DispatchCtx,
+ workspace_dir: &std::path::Path,
+ session_id: String,
+ parent_epoch: Option<u64>,
+) -> Result<(), SubagentError> {
+ const DOMAIN: &str = "subagent_sessions";
+ let open_documents = || {
+ let opened = crate::storage::local::open(DOMAIN, workspace_dir).map_err(|error| {
+ SubagentError::Persistence(format!("open session store: {error:#}"))
+ })?;
+ let scoped = opened.scoped().map_err(|error| {
+ SubagentError::Persistence(format!("scope session store: {error:#}"))
+ })?;
+ Ok::<_, SubagentError>(Arc::clone(scoped.documents()))
+ };
+ let context = ctx.resolved().ok_or_else(|| {
+ SubagentError::Persistence("subagent session store has no resolved owner scope".into())
+ })?;
+ let documents = crate::core::runtime::CoreContext::sync_scope(context, open_documents)?;
+ import_parent_epoch(documents, session_id, parent_epoch)
+}