Skip to content

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

refactor(subagent-host): fold terminal record extensions into outcome on conversion

Steven Enamakel3274fa47d2fc
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 3661f7c31d..b4c52de4bf 100644
--- a/crates/openhuman-core/src/agent/subagent_host/lifecycle/persistence.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/lifecycle/persistence.rs
@@ -14,8 +14,6 @@ struct TerminalRecord {
agent_id: String,
#[serde(default)]
elapsed_ms: u64,
- #[serde(flatten)]
- extensions: std::collections::BTreeMap<String, serde_json::Value>,
}
#[derive(serde::Deserialize)]
@@ -358,31 +356,10 @@ impl OpenHumanPersistence {
outcome,
agent_id: String::new(),
elapsed_ms: 0,
- extensions: Default::default(),
})),
}
}
- fn into_outcome(record: TerminalRecord) -> SubagentOutcome {
- let mut outcome = record.outcome;
- if !record.agent_id.is_empty() {
- outcome
- .extensions
- .entry("agent_id".into())
- .or_insert_with(|| serde_json::Value::String(record.agent_id));
- }
- if record.elapsed_ms != 0 {
- outcome
- .extensions
- .entry("elapsed_ms".into())
- .or_insert_with(|| serde_json::json!(record.elapsed_ms));
- }
- for (key, value) in record.extensions {
- outcome.extensions.entry(key).or_insert(value);
- }
- outcome
- }
-
pub(super) fn terminal_outcome(
&self,
key: &SubagentTaskKey,
@@ -390,7 +367,7 @@ impl OpenHumanPersistence {
if let Some(outcome) = self.store()?.terminal_outcome(key)? {
return Ok(Some(outcome));
}
- Ok(self.read_terminal_record(key)?.map(Self::into_outcome))
+ Ok(self.read_terminal_record(key)?.map(|record| record.outcome))
}
pub(super) fn durable_host_metadata(
@@ -600,7 +577,7 @@ impl tinyagents_orchestration::subagent::SubagentPersistence for OpenHumanPersis
if let Some(outcome) = self.store()?.terminal_outcome(key)? {
return Ok(Some(outcome));
}
- Ok(self.read_terminal_record(key)?.map(Self::into_outcome))
+ Ok(self.read_terminal_record(key)?.map(|record| record.outcome))
}
async fn load(&self, key: &SubagentTaskKey) -> Result<Option<SubagentResume>, SubagentError> {
if self.load_terminal(key).await?.is_some() {
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 368541ad70..e7fb3ea25b 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
@@ -271,6 +271,7 @@ async fn assert_legacy_terminal_fixture(format: &str) {
outcome,
agent_id: String::new(),
elapsed_ms: 0,
+ extensions: Default::default(),
};
let mut record = serde_json::to_value(record).unwrap();
if format == "bare" {
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 69f6cc53c7..134d9640d9 100644
--- a/crates/openhuman-core/src/agent/subagent_host/lifecycle_store.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/lifecycle_store.rs
@@ -33,6 +33,8 @@ pub(super) struct TerminalRecord {
pub(super) agent_id: String,
#[serde(default)]
pub(super) elapsed_ms: u64,
+ #[serde(flatten)]
+ extensions: std::collections::BTreeMap<String, serde_json::Value>,
}
/// A terminal file as older builds wrote it: the record, or the bare outcome.
@@ -46,12 +48,32 @@ enum CompatibleTerminalRecord {
impl From<CompatibleTerminalRecord> for TerminalRecord {
fn from(record: CompatibleTerminalRecord) -> Self {
match record {
- CompatibleTerminalRecord::Current(record) => record,
+ CompatibleTerminalRecord::Current(mut record) => {
+ if !record.agent_id.is_empty() {
+ record
+ .outcome
+ .extensions
+ .entry("agent_id".into())
+ .or_insert_with(|| serde_json::Value::String(record.agent_id.clone()));
+ }
+ if record.elapsed_ms != 0 {
+ record
+ .outcome
+ .extensions
+ .entry("elapsed_ms".into())
+ .or_insert_with(|| serde_json::json!(record.elapsed_ms));
+ }
+ for (name, value) in std::mem::take(&mut record.extensions) {
+ record.outcome.extensions.entry(name).or_insert(value);
+ }
+ record
+ }
CompatibleTerminalRecord::Legacy(outcome) => Self {
key: None,
outcome,
agent_id: String::new(),
elapsed_ms: 0,
+ extensions: Default::default(),
},
}
}