Skip to content

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

fix(orchestration): treat terminal durable sessions as settled during cancel

Steven Enamakel12e666d8f3d0
diff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents/cancel.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents/cancel.rs
index 0ce2bbccf4..a1fd96879c 100644
--- a/crates/openhuman-core/src/agent/orchestration/running_subagents/cancel.rs
+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents/cancel.rs
@@ -339,8 +339,45 @@ pub(crate) async fn cancel_for_thread(
}
};
if matching_jobs.is_empty() {
+ let terminal_session = match crate::agent::orchestration::subagent_sessions::open_for_context(
+ ctx,
+ owner.workspace_dir.clone(),
+ owner.parent_session.clone(),
+ owner.parent_thread_id.clone(),
+ Some((*jobs).clone()),
+ ) {
+ Ok(sessions) => match sessions
+ .list_for_parent(&owner.parent_session, Some(parent_thread_id))
+ .await
+ {
+ Ok(sessions) => sessions.into_iter().find(|session| {
+ session.current_task_id.as_deref() == Some(task_id.as_str())
+ && matches!(
+ session.status,
+ tinyagents_orchestration::subagent::DurableSubagentStatus::Idle
+ | tinyagents_orchestration::subagent::DurableSubagentStatus::Failed
+ | tinyagents_orchestration::subagent::DurableSubagentStatus::Closed
+ )
+ }),
+ Err(error) => {
+ failures.push(format!(
+ "failed to read durable session for indexed task {task_id}: {error}"
+ ));
+ continue;
+ }
+ },
+ Err(error) => {
+ failures.push(format!(
+ "failed to open durable session scope for indexed task {task_id}: {error}"
+ ));
+ continue;
+ }
+ };
+ if terminal_session.is_some() {
+ continue;
+ }
failures.push(format!(
- "owner index task {task_id} has no matching driver job in its parent scope"
+ "owner index task {task_id} has no live driver job or terminal durable session in its parent scope"
));
continue;
}
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/tools_e2e_driver_tests.rs b/crates/openhuman-core/src/agent/orchestration/tools/tools_e2e_driver_tests.rs
index 16fa5ac6fb..f9ed59ce91 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools/tools_e2e_driver_tests.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools/tools_e2e_driver_tests.rs
@@ -651,6 +651,54 @@ async fn thread_delete_keeps_completions_when_driver_task_scope_cannot_be_resolv
1,
"thread deletion retains queued completions when a selected child cannot be settled"
);
+
+ let terminal_legacy_row = serde_json::from_value(
+ serde_json::json!({
+ "subagentSessionId": "pruned-terminal-session",
+ "parentSession": parent_session,
+ "parentThreadId": thread_id,
+ "workerThreadId": null,
+ "agentId": "task_manager_agent",
+ "displayName": null,
+ "model": null,
+ "sandboxMode": "workspace",
+ "actionRoot": null,
+ "taskKey": "pruned-terminal-task",
+ "taskTitle": "Completed before registry pruning",
+ "currentTaskId": "stale-driver-task",
+ "status": "idle",
+ "reusable": true,
+ "latestHistory": [],
+ "latestError": null,
+ "createdAt": "2026-01-01T00:00:00Z",
+ "updatedAt": "2026-01-01T00:00:00Z",
+ "lastUsedAt": "2026-01-01T00:00:00Z",
+ "parentEpoch": null,
+ "lifecycleKey": null
+ }),
+ )
+ .expect("deserialize terminal legacy session");
+ crate::agent::orchestration::subagent_sessions::SubagentSessionStore::new_in_context(
+ &dispatch,
+ workspace.clone(),
+ )
+ .expect("open explicit legacy session scope")
+ .save(&[terminal_legacy_row])
+ .expect("save terminal legacy session for import");
+
+ crate::threads::ops::thread_delete(
+ &dispatch,
+ crate::threads::DeleteConversationThreadRequest {
+ thread_id: thread_id.into(),
+ deleted_at: "2026-01-01T00:02:00Z".into(),
+ },
+ )
+ .await
+ .expect("terminal durable session proves the missing registry snapshot is settled");
+ assert!(
+ background_completions::pending_for(&workspace, thread_id).is_empty(),
+ "terminal durable session permits queued completion cleanup after registry pruning"
+ );
}
#[tokio::test]