Skip to content

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

feat(subagent): adopt legacy owner terminal records into native storage

Steven Enamakelb6b2e7000d1e
diff --git a/crates/openhuman-core/src/agent/subagent_host/lifecycle/legacy_terminal.rs b/crates/openhuman-core/src/agent/subagent_host/lifecycle/legacy_terminal.rs
new file mode 100644
index 0000000000..479d230cc4
--- /dev/null
+++ b/crates/openhuman-core/src/agent/subagent_host/lifecycle/legacy_terminal.rs
@@ -0,0 +1,15 @@
+//! Read retired owner terminal formats through the owner's compatibility port.
+
+use super::*;
+
+/// A native document-only task must not create file-era directories or locks.
+pub(in crate::agent::subagent_host) fn owner_terminal(
+ checkpoint_dir: &std::path::Path,
+ key: &SubagentTaskKey,
+) -> Result<Option<SubagentOutcome>, SubagentError> {
+ if !checkpoint_dir.join("lifecycle").is_dir() {
+ return Ok(None);
+ }
+ tinyagents_orchestration::subagent::FileSubagentPersistence::new(checkpoint_dir)
+ .terminal_outcome(key)
+}
diff --git a/crates/openhuman-core/src/agent/subagent_host/lifecycle/persistence.rs b/crates/openhuman-core/src/agent/subagent_host/lifecycle/persistence.rs
index 72618fb044..6374be4362 100644
--- a/crates/openhuman-core/src/agent/subagent_host/lifecycle/persistence.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/lifecycle/persistence.rs
@@ -1,6 +1,9 @@
use super::*;
use crate::agent::subagent_host::types::SubagentCheckpointData;
+#[path = "legacy_terminal.rs"]
+pub(super) mod legacy_terminal;
+
pub(in crate::agent::subagent_host) struct OpenHumanPersistence {
checkpoint_dir: std::path::PathBuf,
dispatch: crate::core::runtime::DispatchCtx,
@@ -196,6 +199,9 @@ impl OpenHumanPersistence {
&self,
key: &SubagentTaskKey,
) -> Result<Option<SubagentCheckpointData>, SubagentError> {
+ if self.read_terminal_record(key)?.is_some() {
+ return Ok(None);
+ }
let store = self.store()?;
if store.terminal_outcome(key)?.is_some() {
return Ok(None);
@@ -340,6 +346,24 @@ impl OpenHumanPersistence {
&self,
key: &SubagentTaskKey,
) -> Result<Option<TerminalRecord>, SubagentError> {
+ if let Some(outcome) = legacy_terminal::owner_terminal(&self.checkpoint_dir, key)? {
+ self.open_store(true)?
+ .import_record(key, None, Some(outcome.clone()))?;
+ return Ok(Some(TerminalRecord {
+ agent_id: outcome
+ .extensions
+ .get("agent_id")
+ .and_then(serde_json::Value::as_str)
+ .unwrap_or_default()
+ .to_owned(),
+ elapsed_ms: outcome
+ .extensions
+ .get("elapsed_ms")
+ .and_then(serde_json::Value::as_u64)
+ .unwrap_or_default(),
+ outcome,
+ }));
+ }
let raw = match std::fs::read_to_string(self.terminal_path(key)) {
Ok(raw) => raw,
Err(error) if error.kind() == std::io::ErrorKind::NotFound => return Ok(None),
@@ -623,6 +647,7 @@ impl tinyagents_orchestration::subagent::SubagentPersistence for OpenHumanPersis
&self,
mut pause: tinyagents_orchestration::subagent::PersistedSubagentPause,
) -> Result<SubagentPausePersistenceDisposition, SubagentError> {
+ let _ = self.read_terminal_record(&pause.key)?;
let host_elapsed = self
.host_outcome
.lock()
@@ -672,6 +697,7 @@ impl tinyagents_orchestration::subagent::SubagentPersistence for OpenHumanPersis
outcome: &SubagentOutcome,
replaces: Option<&SubagentResume>,
) -> Result<SubagentTerminalPersistenceDisposition, SubagentError> {
+ let _ = self.read_terminal_record(key)?;
let host = self
.host_outcome
.lock()
diff --git a/crates/openhuman-core/src/agent/subagent_host/lifecycle_storage_adoption_tests.rs b/crates/openhuman-core/src/agent/subagent_host/lifecycle_storage_adoption_tests.rs
index 53d91d49a3..568faa2f57 100644
--- a/crates/openhuman-core/src/agent/subagent_host/lifecycle_storage_adoption_tests.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/lifecycle_storage_adoption_tests.rs
@@ -49,6 +49,10 @@ async fn production_lifecycle_persistence_follows_the_explicit_actor_scope_on_re
CoreContext::scope(alice.clone(), async {
let adapter = super::super::persistence::OpenHumanPersistence::new(checkpoints.clone());
adapter.save_pause(paused(&key)).await.unwrap();
+ assert!(
+ !checkpoints.join("lifecycle").exists(),
+ "native storage creates no file-era persistence"
+ );
assert_eq!(
adapter.checkpoint_for_task(&key.task_id).unwrap().output,
"durable partial"
@@ -293,6 +297,7 @@ async fn assert_legacy_owner_terminal(format: &str) {
let stale_bytes = serde_json::to_vec(&stale).unwrap();
std::fs::write(&stale_path, &stale_bytes).unwrap();
+ assert!(super::super::load_subagent_checkpoint(workspace.path(), &key.task_id).is_err());
let terminal = adapter
.load_terminal(&key)
.await
diff --git a/crates/openhuman-core/src/agent/subagent_host/lifecycle_store.rs b/crates/openhuman-core/src/agent/subagent_host/lifecycle_store.rs
index e62cf08819..444ff5b411 100644
--- a/crates/openhuman-core/src/agent/subagent_host/lifecycle_store.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/lifecycle_store.rs
@@ -323,7 +323,15 @@ fn import_legacy(kv: &StateKv, dir: &Path) -> anyhow::Result<()> {
} else if let Some(component) = file.strip_suffix(".terminal.json") {
match serde_json::from_slice::<CompatibleTerminalRecord>(&bytes) {
Ok(terminal) => {
- let terminal = TerminalRecord::from(terminal);
+ let mut terminal = TerminalRecord::from(terminal);
+ if let Some(key) = terminal.key.as_ref() {
+ if let Some(outcome) = super::persistence::legacy_terminal::owner_terminal(
+ dir.parent().unwrap_or(dir),
+ key,
+ )? {
+ terminal.outcome = outcome;
+ }
+ }
kv.update::<LifecycleRecord, ()>(&format!("record/{component}"), move |r| {
if r.terminal.is_none() {
r.terminal = Some(terminal.clone());