Skip to content

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

test(subagent): cover typed terminal outcomes for idle sessions

Steven Enamakeld34dcb6e9a6f
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 f5062be89c..82f0b95564 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
@@ -150,36 +150,10 @@ fn stale_completion_cannot_overwrite_reused_or_closed_session() {
}
#[test]
-fn driver_task_cancel_reports_durable_finished_outcomes_and_refuses_ambiguous_ids() {
+fn driver_task_cancel_reports_legacy_failure_and_refuses_ambiguous_ids() {
let dir = tempfile::tempdir().unwrap();
let store = SubagentSessionStore::new(dir.path().to_path_buf());
let jobs = SubAgentJobRegistry::default();
- let completed = upsert_running(
- &store,
- SubagentSessionUpsert {
- selector: selector("completed"),
- display_name: None,
- task_title: "Completed child".into(),
- worker_thread_id: None,
- task_id: "finished-completed".into(),
- lifecycle_key: None,
- },
- None,
- )
- .unwrap();
- mark_finished(
- &store,
- &completed.subagent_session_id,
- "finished-completed",
- &SubagentRunStatus::Completed,
- Vec::new(),
- )
- .unwrap();
- let selected = cancel_driver_job_by_task(&store, dir.path(), &jobs, "finished-completed", None)
- .unwrap()
- .expect("completed public task remains reportable");
- assert_eq!(selected.already_finished, Some(FinishedOutcome::Completed));
-
let failed = upsert_running(
&store,
SubagentSessionUpsert {
diff --git a/crates/openhuman-core/src/agent/subagent_host/lifecycle_tests.rs b/crates/openhuman-core/src/agent/subagent_host/lifecycle_tests.rs
index c27f2b91c5..69f59511d9 100644
--- a/crates/openhuman-core/src/agent/subagent_host/lifecycle_tests.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/lifecycle_tests.rs
@@ -473,6 +473,97 @@ async fn driver_inline_projection_returns_the_durable_winner_not_a_local_loser()
);
}
+#[tokio::test]
+async fn driver_cancel_uses_the_typed_terminal_for_lossy_idle_sessions() {
+ use crate::agent::orchestration::subagent_sessions::{
+ cancel_driver_job_by_task, mark_finished, upsert_running, DurableSubagentStatus,
+ SubagentSessionSelector, SubagentSessionStore, SubagentSessionUpsert,
+ };
+
+ let directory = tempfile::tempdir().unwrap();
+ let workspace = directory.path();
+ let store = SubagentSessionStore::new(workspace.to_path_buf());
+ let jobs = tinyagents_orchestration::subagent::SubAgentJobRegistry::default();
+ let persistence = OpenHumanPersistence::new(
+ workspace.join(".openhuman/subagent_checkpoints"),
+ );
+
+ for (task_id, terminal, expected) in [
+ (
+ "typed-completed",
+ SubagentOutcomeKind::Completed,
+ Some(tinyagents_orchestration::subagent::FinishedOutcome::Completed),
+ ),
+ (
+ "typed-incomplete",
+ SubagentOutcomeKind::Incomplete(
+ tinyagents_orchestration::subagent::SubagentIncomplete::new("iteration cap"),
+ ),
+ Some(tinyagents_orchestration::subagent::FinishedOutcome::Failed),
+ ),
+ ] {
+ let key = SubagentTaskKey {
+ root_run_id: "root-typed-finished".into(),
+ parent_run_id: "parent-typed-finished".into(),
+ thread_id: Some("thread-typed-finished".into()),
+ task_id: task_id.into(),
+ };
+ let session = upsert_running(
+ &store,
+ SubagentSessionUpsert {
+ selector: SubagentSessionSelector {
+ parent_session: "parent-typed-finished".into(),
+ parent_thread_id: key.thread_id.clone(),
+ agent_id: "researcher".into(),
+ model: None,
+ sandbox_mode: "read_only".into(),
+ action_root: None,
+ task_key: task_id.into(),
+ },
+ display_name: None,
+ task_title: task_id.into(),
+ worker_thread_id: None,
+ task_id: task_id.into(),
+ lifecycle_key: Some(key.clone()),
+ },
+ None,
+ )
+ .unwrap();
+ let mut outcome = SubagentOutcome::cancelled(task_id);
+ outcome.status = terminal;
+ persistence.record_terminal(&key, &outcome, None).await.unwrap();
+ mark_finished(
+ &store,
+ &session.subagent_session_id,
+ task_id,
+ &match task_id {
+ "typed-completed" => SubagentRunStatus::Completed,
+ _ => SubagentRunStatus::Incomplete {
+ reason: "iteration cap".into(),
+ },
+ },
+ Vec::new(),
+ )
+ .unwrap();
+ assert_eq!(
+ store.load().unwrap()[0].status,
+ DurableSubagentStatus::Idle,
+ "both typed terminal outcomes share the legacy Idle session state"
+ );
+
+ let selected = cancel_driver_job_by_task(
+ &store,
+ workspace,
+ &jobs,
+ task_id,
+ None,
+ )
+ .unwrap()
+ .expect("typed terminal remains reportable");
+ assert_eq!(selected.already_finished, expected, "{task_id}");
+ }
+}
+
#[tokio::test]
async fn continuation_replaces_only_the_pause_it_loaded_and_stale_duplicate_gets_winner() {
let directory = tempfile::tempdir().unwrap();