Skip to content

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

fix(threads): propagate subagent cancellation errors on thread delete

Steven Enamakelb290b21ae121
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 1568682686..6a99b126a5 100644
--- a/crates/openhuman-core/src/agent/orchestration/running_subagents/cancel.rs
+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents/cancel.rs
@@ -300,9 +300,9 @@ pub(crate) async fn cancel_for_thread(
let Some(core_context) = ctx.resolved() else {
return Err("cannot resolve core context to cancel thread-owned driver jobs".into());
};
- let workspace_dir = core_context
- .workspace_dir()
- .map_err(|error| format!("cannot resolve workspace for thread-owned driver jobs: {error}"))?;
+ let workspace_dir = core_context.workspace_dir().map_err(|error| {
+ format!("cannot resolve workspace for thread-owned driver jobs: {error}")
+ })?;
let scopes = crate::agent::orchestration::completion_owners::driver_tasks_for_thread(
ctx,
&workspace_dir,
@@ -344,7 +344,9 @@ pub(crate) async fn cancel_for_thread(
cancelled += usize::from(!cancelled_job.status.is_terminal());
}
Err(error) => {
- failures.push(format!("driver thread deletion cancellation failed: {error}"));
+ failures.push(format!(
+ "driver thread deletion cancellation failed: {error}"
+ ));
}
}
if let Err(error) = jobs.wait_owned(job.id.as_str(), &owner_key).await {
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 bc340b8000..7baac0ab9e 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
@@ -316,7 +316,7 @@ async fn deleting_parent_thread_cancels_driver_child_before_discarding_completio
use crate::agent::orchestration::background_completions::{self, BackgroundAgentOutcome};
use crate::agent::tinyagents::host::OpenHumanRunContext;
use crate::core::runtime::{ContextOverlay, CoreContext, DomainSet};
- use crate::threads::store::{CreateConversationThread, blocking};
+ use crate::threads::store::{blocking, CreateConversationThread};
use crate::tools::toolpacks::ToolGroups;
use tinyagents_harness::context::RunContext;
use tinyagents_harness_tools::subagents::SubAgentJobRegistry;
diff --git a/crates/openhuman-core/src/threads/ops/crud.rs b/crates/openhuman-core/src/threads/ops/crud.rs
index 2d537066e8..12286d9935 100644
--- a/crates/openhuman-core/src/threads/ops/crud.rs
+++ b/crates/openhuman-core/src/threads/ops/crud.rs
@@ -5,11 +5,11 @@ use super::support::{
counts, envelope, message_to_record, record_to_message, run_to_completion, thread_to_summary,
workspace_dir,
};
-use crate::core::Outcome;
use crate::core::runtime::DispatchCtx;
-use crate::threads::ThreadsError;
+use crate::core::Outcome;
use crate::threads::store as conversations;
use crate::threads::store::{ConversationMessagePatch, CrossThreadHit};
+use crate::threads::ThreadsError;
use crate::threads::{
ApiEnvelope, AppendConversationMessageRequest, ConversationMessageRecord,
ConversationMessagesRequest, ConversationMessagesResponse, ConversationThreadSummary,
@@ -491,7 +491,7 @@ async fn thread_delete_inner(
// nowhere left to deliver to — abort + cleanup is the whole behavior.
let cancelled_legacy =
crate::agent::orchestration::running_subagents::cancel_for_thread(&ctx, &request.thread_id)
- .await;
+ .await?;
let jobs = crate::core::runtime::slot_for::<
tinyagents_harness_tools::subagents::SubAgentJobRegistry,
>(&ctx);
diff --git a/crates/openhuman-core/src/threads/ops/crud_message_append_tests.rs b/crates/openhuman-core/src/threads/ops/crud_message_append_tests.rs
index 964dda7317..1eff122c93 100644
--- a/crates/openhuman-core/src/threads/ops/crud_message_append_tests.rs
+++ b/crates/openhuman-core/src/threads/ops/crud_message_append_tests.rs
@@ -111,55 +111,47 @@ async fn user_append_stages_original_strips_upload_bytes_and_reuses_returned_con
.await
.unwrap();
assert_eq!(persisted.len(), 2);
- assert!(
- !serde_json::to_string(&persisted)
- .unwrap()
- .contains("base64,")
- );
+ assert!(!serde_json::to_string(&persisted)
+ .unwrap()
+ .contains("base64,"));
}
#[tokio::test]
async fn rejected_upload_never_appends_a_message() {
let (_temp, mut config) = setup().await;
config.multimodal_files.max_files = 0;
- assert!(
- append_with_test_config(
- request(
- "disabled",
- "[IMAGE:data:image/png;base64,iVBORw0KGgo=]",
- "user"
- ),
- &config,
- None,
- )
- .await
- .is_err()
- );
+ assert!(append_with_test_config(
+ request(
+ "disabled",
+ "[IMAGE:data:image/png;base64,iVBORw0KGgo=]",
+ "user"
+ ),
+ &config,
+ None,
+ )
+ .await
+ .is_err());
config.multimodal_files.max_files = 3;
- assert!(
- append_with_test_config(
- request("bad", "[FILE:data:application/zip;base64,!]", "user"),
- &config,
- None,
- )
- .await
- .is_err()
- );
+ assert!(append_with_test_config(
+ request("bad", "[FILE:data:application/zip;base64,!]", "user"),
+ &config,
+ None,
+ )
+ .await
+ .is_err());
assert!(
append_with_test_config(request("missing", "image.png", "user"), &config, None)
.await
.is_err()
);
- assert!(
- conversations::blocking::get_messages(
- crate::core::runtime::DispatchCtx::ambient(),
- config.workspace_dir.clone(),
- "uploads".into()
- )
- .await
- .unwrap()
- .is_empty()
- );
+ assert!(conversations::blocking::get_messages(
+ crate::core::runtime::DispatchCtx::ambient(),
+ config.workspace_dir.clone(),
+ "uploads".into()
+ )
+ .await
+ .unwrap()
+ .is_empty());
}
#[tokio::test]
@@ -187,16 +179,14 @@ async fn external_origin_cannot_reuse_an_existing_attachment_marker() {
.await
.is_err()
);
- assert!(
- conversations::blocking::get_messages(
- crate::core::runtime::DispatchCtx::ambient(),
- config.workspace_dir,
- "uploads".into()
- )
- .await
- .unwrap()
- .is_empty()
- );
+ assert!(conversations::blocking::get_messages(
+ crate::core::runtime::DispatchCtx::ambient(),
+ config.workspace_dir,
+ "uploads".into()
+ )
+ .await
+ .unwrap()
+ .is_empty());
}
#[tokio::test]
@@ -265,16 +255,14 @@ async fn append_uses_host_persistence_workspace_separate_from_rpc_config() {
.await
.unwrap();
assert_eq!(persisted.len(), 1);
- assert!(
- conversations::blocking::get_messages(
- crate::core::runtime::DispatchCtx::ambient(),
- config.workspace_dir,
- "uploads".into()
- )
- .await
- .unwrap()
- .is_empty()
- );
+ assert!(conversations::blocking::get_messages(
+ crate::core::runtime::DispatchCtx::ambient(),
+ config.workspace_dir,
+ "uploads".into()
+ )
+ .await
+ .unwrap()
+ .is_empty());
}
#[tokio::test]
@@ -285,21 +273,17 @@ async fn poster_only_user_metadata_is_rejected_before_persistence() {
"attachmentNames": ["video.mp4"],
"attachmentPosters": ["data:image/png;base64,iVBORw0KGgo="]
});
- assert!(
- append_with_test_config(upload, &config, None)
- .await
- .is_err()
- );
- assert!(
- conversations::blocking::get_messages(
- crate::core::runtime::DispatchCtx::ambient(),
- config.workspace_dir.clone(),
- "uploads".into()
- )
+ assert!(append_with_test_config(upload, &config, None)
.await
- .unwrap()
- .is_empty()
- );
+ .is_err());
+ assert!(conversations::blocking::get_messages(
+ crate::core::runtime::DispatchCtx::ambient(),
+ config.workspace_dir.clone(),
+ "uploads".into()
+ )
+ .await
+ .unwrap()
+ .is_empty());
}
#[tokio::test]