Skip to content

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

test(subagent_sessions): cover lifecycle key persistence and legacy fixtures

Steven Enamakel6d4025c9afa0
diff --git a/Cargo.lock b/Cargo.lock
index f9acdacd00..b1b02fb95d 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -8451,6 +8451,7 @@ dependencies = [
"dirs 6.0.0",
"flate2",
"futures",
+ "libc",
"regex",
"reqwest 0.12.28",
"serde",
diff --git a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/ops_tests.rs b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/ops_tests.rs
index 4b7e31a9ea..20d2b95244 100644
--- a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/ops_tests.rs
+++ b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/ops_tests.rs
@@ -74,6 +74,40 @@ fn compatible_session_reuses_and_incompatible_shape_spawns_new() {
assert!(find_reusable(&store, &different).unwrap().is_none());
}
+#[test]
+fn upsert_persists_the_full_lifecycle_key_without_collapsing_to_task_id() {
+ let dir = tempfile::tempdir().unwrap();
+ let store = SubagentSessionStore::new(dir.path().to_path_buf());
+ let key = tinyagents_orchestration::subagent::SubagentTaskKey {
+ root_run_id: "root-run".into(),
+ parent_run_id: "turn-run".into(),
+ thread_id: Some("parent-thread".into()),
+ task_id: "sub-1".into(),
+ };
+ let session = upsert_running(
+ &store,
+ SubagentSessionUpsert {
+ selector: selector("durable-task"),
+ display_name: None,
+ task_title: "Task".into(),
+ worker_thread_id: None,
+ task_id: "sub-1".into(),
+ lifecycle_key: Some(key.clone()),
+ },
+ None,
+ )
+ .unwrap();
+
+ let loaded = store
+ .load()
+ .unwrap()
+ .into_iter()
+ .find(|row| row.subagent_session_id == session.subagent_session_id)
+ .unwrap();
+ assert_eq!(loaded.current_task_id.as_deref(), Some("sub-1"));
+ assert_eq!(loaded.lifecycle_key, Some(key));
+}
+
#[test]
fn closed_session_is_not_reusable() {
let dir = tempfile::tempdir().unwrap();
diff --git a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store_documents_tests.rs b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store_documents_tests.rs
index 885846ceb4..3b6fa723c8 100644
--- a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store_documents_tests.rs
+++ b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store_documents_tests.rs
@@ -49,6 +49,11 @@ fn save_upserts_sessions_and_keeps_the_others() {
assert_eq!(loaded.len(), 2);
assert_eq!(loaded[0].subagent_session_id, "a");
assert_eq!(loaded[1].status, DurableSubagentStatus::Idle);
+ // The source fixture intentionally predates lifecycle_key. Its owner and
+ // task reference remain available for the scoped legacy lookup path.
+ assert_eq!(loaded[0].parent_session, "parent");
+ assert_eq!(loaded[0].current_task_id, None);
+ assert_eq!(loaded[0].lifecycle_key, None);
// A save from a stale snapshot never removes a session it does not know.
docs.save(&[session("c")]).unwrap();
let ids: Vec<_> = docs