Skip to content

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

fix(subagent_sessions): make repeated close of a closed session idempotent

Steven Enamakeldf026f662b4d
diff --git a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/ops.rs b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/ops.rs
index 04b815facf..080c7ce807 100644
--- a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/ops.rs
+++ b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/ops.rs
@@ -417,14 +417,16 @@ pub fn close_if_current(
else {
return Ok(false);
};
- if session.status == DurableSubagentStatus::Closed
- || session.parent_session != observed.parent_session
+ if session.parent_session != observed.parent_session
|| session.parent_thread_id != observed.parent_thread_id
|| session.current_task_id != observed.current_task_id
|| session.lifecycle_key != observed.lifecycle_key
{
return Ok(false);
}
+ if session.status == DurableSubagentStatus::Closed {
+ return Ok(true);
+ }
session.status = DurableSubagentStatus::Closed;
session.reusable = false;
session.updated_at = now.clone();
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 a3003c80d7..eea15c284e 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
@@ -224,6 +224,10 @@ fn stale_close_and_reuse_snapshots_cannot_change_a_newer_lifecycle() {
);
assert!(close_if_current(&store, &second).unwrap());
+ assert!(
+ close_if_current(&store, &second).unwrap(),
+ "closing the same already-closed durable session remains idempotent"
+ );
assert!(
upsert_running(
&store,