Skip to content

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

feat(subagent_sessions): record cancellation reason on driver job cancel

Steven Enamakelf63112acbd01
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 421f239202..26c7c19e2f 100644
--- a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/ops.rs
+++ b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/ops.rs
@@ -187,6 +187,7 @@ pub fn cancel_driver_job_by_task(
checkpoint_dir: &Path,
jobs: &tinyagents_orchestration::subagent::SubAgentJobRegistry,
task_id: &str,
+ reason: Option<&str>,
) -> Option<DriverTaskCancellation> {
let mut matches = store
.load()
@@ -207,6 +208,17 @@ pub fn cancel_driver_job_by_task(
DurableSubagentStatus::Running | DurableSubagentStatus::AwaitingUser => None,
DurableSubagentStatus::Closed => return None,
};
+ if already_finished.is_none()
+ && reason.is_some()
+ && !record_cancel_reason(
+ store,
+ &session.subagent_session_id,
+ task_id,
+ reason.expect("checked above").trim(),
+ )
+ {
+ return None;
+ }
if already_finished.is_none()
&& !cancel_driver_job_for_observed_session(
store,
@@ -217,6 +229,9 @@ pub fn cancel_driver_job_by_task(
session.parent_thread_id.as_deref(),
)
{
+ if reason.is_some() {
+ clear_cancel_reason(store, &session.subagent_session_id, task_id);
+ }
return None;
}
Some(DriverTaskCancellation {
@@ -229,6 +244,35 @@ pub fn cancel_driver_job_by_task(
})
}
+/// Persist an optional RPC cancellation reason before signaling TinyAgents so
+/// the awaited completion callback can include it in the single cancellation
+/// notice. The current task check prevents a stale cancel from annotating a
+/// later reuse of the same durable session.
+fn record_cancel_reason(
+ store: &SubagentSessionStore,
+ subagent_session_id: &str,
+ task_id: &str,
+ reason: &str,
+) -> bool {
+ if reason.is_empty() {
+ return true;
+ }
+ update_session_for_task(store, subagent_session_id, task_id, |session, now| {
+ if matches!(session.status, DurableSubagentStatus::Running | DurableSubagentStatus::AwaitingUser) {
+ session.latest_error = Some(reason.to_owned());
+ session.updated_at = now;
+ }
+ })
+ .unwrap_or(false)
+}
+
+fn clear_cancel_reason(store: &SubagentSessionStore, subagent_session_id: &str, task_id: &str) {
+ let _ = update_session_for_task(store, subagent_session_id, task_id, |session, now| {
+ session.latest_error = None;
+ session.updated_at = now;
+ });
+}
+
/// Resolve a saved product session to its exact TinyAgents lifecycle key.
///
/// The product session lookup is scoped by the authenticated parent session,