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 stale lifecycle snapshots and clarify assertion

Steven Enamakel9b97497ad99b
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 c9b18de594..b123bb561a 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
@@ -148,6 +148,83 @@ fn stale_completion_cannot_overwrite_reused_or_closed_session() {
assert!(closed.latest_history.is_none());
}
+#[test]
+fn stale_close_and_reuse_snapshots_cannot_change_a_newer_lifecycle() {
+ let dir = tempfile::tempdir().unwrap();
+ let store = SubagentSessionStore::new(dir.path().to_path_buf());
+ let first = upsert_running(
+ &store,
+ SubagentSessionUpsert {
+ selector: selector("same-task"),
+ display_name: None,
+ task_title: "First run".into(),
+ worker_thread_id: None,
+ task_id: "first-task".into(),
+ lifecycle_key: None,
+ },
+ None,
+ )
+ .unwrap();
+ let second = upsert_running(
+ &store,
+ SubagentSessionUpsert {
+ selector: selector("same-task"),
+ display_name: None,
+ task_title: "Second run".into(),
+ worker_thread_id: None,
+ task_id: "second-task".into(),
+ lifecycle_key: None,
+ },
+ Some(&first),
+ )
+ .unwrap();
+
+ assert!(
+ !close_if_current(&store, &first).unwrap(),
+ "a close based on the stale first snapshot must lose the race"
+ );
+ let current = list_for_parent(&store, "parent-a", Some("thread-a"))
+ .unwrap()
+ .pop()
+ .unwrap();
+ assert_eq!(current.current_task_id.as_deref(), Some("second-task"));
+ assert_eq!(current.status, DurableSubagentStatus::Running);
+ assert!(
+ upsert_running(
+ &store,
+ SubagentSessionUpsert {
+ selector: selector("same-task"),
+ display_name: None,
+ task_title: "Stale retry".into(),
+ worker_thread_id: None,
+ task_id: "stale-task".into(),
+ lifecycle_key: None,
+ },
+ Some(&first),
+ )
+ .is_err(),
+ "a stale reuse snapshot must not replace the newer lifecycle"
+ );
+
+ assert!(close_if_current(&store, &second).unwrap());
+ assert!(
+ upsert_running(
+ &store,
+ SubagentSessionUpsert {
+ selector: selector("same-task"),
+ display_name: None,
+ task_title: "Late retry".into(),
+ worker_thread_id: None,
+ task_id: "late-task".into(),
+ lifecycle_key: None,
+ },
+ Some(&second),
+ )
+ .is_err(),
+ "a stale retry must not reopen a session closed after observation"
+ );
+}
+
#[test]
fn upsert_persists_the_full_lifecycle_key_without_collapsing_to_task_id() {
let dir = tempfile::tempdir().unwrap();
diff --git a/crates/openhuman-core/src/agent/tinyagents/tool_registration_tests.rs b/crates/openhuman-core/src/agent/tinyagents/tool_registration_tests.rs
index 2ab129d935..57524f5795 100644
--- a/crates/openhuman-core/src/agent/tinyagents/tool_registration_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/tool_registration_tests.rs
@@ -170,7 +170,11 @@ async fn static_live_harness_builder_resolves_control_aliases_from_the_execution
.await
.expect("the live control resolves its execution parent");
assert_eq!(result.results.len(), 1);
- assert!(result.results[0].text().contains("live-owned-session"));
+ assert!(
+ result.results[0].text().contains("live-owned-session"),
+ "live control query should project its scoped session, got: {}",
+ result.results[0].text()
+ );
}
#[tokio::test]