Skip to content

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

fix: correct thread state handling in chat suggestions and channel ops

Steven Enamakelc4910da25fc8
diff --git a/app/src/features/conversations/aui/ChatScheduleCard.test.tsx b/app/src/features/conversations/aui/ChatScheduleCard.test.tsx
index ec31e59b7d..cfb8f43952 100644
--- a/app/src/features/conversations/aui/ChatScheduleCard.test.tsx
+++ b/app/src/features/conversations/aui/ChatScheduleCard.test.tsx
@@ -79,6 +79,6 @@ describe('cron tool call renders', () => {
toggle.click();
expect(spy).toHaveBeenCalledWith('job-1', { enabled: false });
- await vi.waitFor(() => expect(toggle).toHaveAttribute('aria-checked', 'false'));
+ await waitFor(() => expect(toggle).toHaveAttribute('aria-checked', 'false'));
});
});
diff --git a/app/src/features/conversations/aui/zzsanity.test.ts b/app/src/features/conversations/aui/zzsanity.test.ts
new file mode 100644
index 0000000000..75a98b4528
--- /dev/null
+++ b/app/src/features/conversations/aui/zzsanity.test.ts
@@ -0,0 +1,9 @@
+import { describe, it } from 'vitest';
+
+describe('sanity', () => {
+ it('a pre-caught rejection does not fail the test', async () => {
+ const p = Promise.reject(new Error('x'));
+ p.catch(() => {});
+ await new Promise(r => setTimeout(r, 10));
+ });
+});
diff --git a/crates/openhuman-core/src/threads/transcript_view/subagents.rs b/crates/openhuman-core/src/threads/transcript_view/subagents.rs
index 358ed6f396..dd11ac1a59 100644
--- a/crates/openhuman-core/src/threads/transcript_view/subagents.rs
+++ b/crates/openhuman-core/src/threads/transcript_view/subagents.rs
@@ -149,9 +149,8 @@ fn build_child(
// sub-agent transcripts carry no back-link to a delegating request, so
// there is no per-message `ts` to inherit the way the root projector
// pulls one from `DisplayMessage.ts`.
- let ts = spawn_unix.and_then(|unix| {
- chrono::DateTime::from_timestamp(unix, 0).map(|dt| dt.to_rfc3339())
- });
+ let ts = spawn_unix
+ .and_then(|unix| chrono::DateTime::from_timestamp(unix, 0).map(|dt| dt.to_rfc3339()));
Some(ChildRun {
spawn_unix,
agent_id: agent_id.clone(),
@@ -191,14 +190,17 @@ fn find_exact_spawning_call(
.ok()
.flatten()?;
let parent_call_id = run.metadata.get("parentCallId")?.as_str()?;
- items.iter().enumerate().find_map(|(index, item)| match item {
- DisplayItem::ToolCall { call_id, .. }
- if !claimed[index] && call_id == parent_call_id =>
- {
- Some(index)
- }
- _ => None,
- })
+ items
+ .iter()
+ .enumerate()
+ .find_map(|(index, item)| match item {
+ DisplayItem::ToolCall { call_id, .. }
+ if !claimed[index] && call_id == parent_call_id =>
+ {
+ Some(index)
+ }
+ _ => None,
+ })
}
/// What the child's own transcript says about how it ended.
@@ -237,10 +239,11 @@ fn place(
for (order, mut child) in children.into_iter().enumerate() {
let request_id = anchor_request_id(child.spawn_unix, segments);
let (start, end) = turn_range(items, request_id.as_deref());
- let pick = find_exact_spawning_call(items, &claimed, child.task_id.as_deref(), workspace_dir)
- .or_else(|| {
- find_spawning_call(items, &claimed, start, end, child.agent_id.as_deref())
- });
+ let pick =
+ find_exact_spawning_call(items, &claimed, child.task_id.as_deref(), workspace_dir)
+ .or_else(|| {
+ find_spawning_call(items, &claimed, start, end, child.agent_id.as_deref())
+ });
let (position, call) = match pick {
Some(index) => {
claimed[index] = true;
diff --git a/crates/openhuman-core/src/tools/impl/system/install_tool_tests.rs b/crates/openhuman-core/src/tools/impl/system/install_tool_tests.rs
index ed2255bc84..fe76ff0cc1 100644
--- a/crates/openhuman-core/src/tools/impl/system/install_tool_tests.rs
+++ b/crates/openhuman-core/src/tools/impl/system/install_tool_tests.rs
@@ -17,7 +17,7 @@ fn chat_ctx() -> ApprovalChatContext {
ApprovalChatContext {
thread_id: "t-test".into(),
client_id: "c-test".into(),
- request_id: None,
+ request_id: None,
}
}
diff --git a/crates/openhuman-core/src/web3/wallet/execution_tests.rs b/crates/openhuman-core/src/web3/wallet/execution_tests.rs
index 8ec9108eb9..6d8879059f 100644
--- a/crates/openhuman-core/src/web3/wallet/execution_tests.rs
+++ b/crates/openhuman-core/src/web3/wallet/execution_tests.rs
@@ -450,7 +450,7 @@ fn chat_ctx_from(owner: &QuoteOwner) -> crate::security::approval::ApprovalChatC
crate::security::approval::ApprovalChatContext {
thread_id: owner.thread_id.clone(),
client_id: owner.client_id.clone(),
- request_id: None,
+ request_id: None,
}
}
diff --git a/crates/openhuman-core/src/web_chat/ops.rs b/crates/openhuman-core/src/web_chat/ops.rs
index 2d12784099..c20d3eac77 100644
--- a/crates/openhuman-core/src/web_chat/ops.rs
+++ b/crates/openhuman-core/src/web_chat/ops.rs
@@ -27,7 +27,9 @@ pub use channel_ops::{
// RPC-layer classifier (mirrors `is_backend_unavailable_message`) — nothing
// in-crate consumes them yet, hence the allow.
#[allow(unused_imports)]
-pub use start_chat::{is_guardrail_error_message, start_chat, StartChatError, GUARDRAIL_ERROR_PREFIX};
+pub use start_chat::{
+ is_guardrail_error_message, start_chat, StartChatError, GUARDRAIL_ERROR_PREFIX,
+};
pub use system_turn::{run_system_turn_on_thread, SESSION_CHECKOUT_FAILURE, SYSTEM_CLIENT_ID};
#[cfg(test)]
diff --git a/crates/openhuman-core/src/web_chat/ops/channel_ops.rs b/crates/openhuman-core/src/web_chat/ops/channel_ops.rs
index 4e8957d0c6..a9a5d6a902 100644
--- a/crates/openhuman-core/src/web_chat/ops/channel_ops.rs
+++ b/crates/openhuman-core/src/web_chat/ops/channel_ops.rs
@@ -210,7 +210,10 @@ pub async fn channel_web_chat(
/// Render one snapshotted queue item as the wire shape `web_queue_status` and
/// `queue_item_*` socket events share: `{ id, lane, text_preview }`.
-fn queue_item_json(lane: tinyagents_harness::run_queue::QueueLane, item: &crate::agent::queued_turn::QueuedTurn) -> Value {
+fn queue_item_json(
+ lane: tinyagents_harness::run_queue::QueueLane,
+ item: &crate::agent::queued_turn::QueuedTurn,
+) -> Value {
json!({
"id": item.id,
"lane": lane.as_str(),
@@ -287,12 +290,13 @@ pub async fn channel_web_queue_remove(
"no active turn for thread",
));
};
- let removed = entry.run_queue.remove_where(|item| item.id == item_id).await;
+ let removed = entry
+ .run_queue
+ .remove_where(|item| item.id == item_id)
+ .await;
drop(in_flight);
if removed > 0 {
- log::info!(
- "[web-channel] removed queued item thread_id={thread_id} item_id={item_id}"
- );
+ log::info!("[web-channel] removed queued item thread_id={thread_id} item_id={item_id}");
publish_web_channel_event(WebChannelEvent {
event: "queue_item_removed".to_string(),
client_id: client_id.to_string(),
diff --git a/crates/openhuman-core/src/web_chat/suggestions.rs b/crates/openhuman-core/src/web_chat/suggestions.rs
index 49d7c710d8..140c4fa99b 100644
--- a/crates/openhuman-core/src/web_chat/suggestions.rs
+++ b/crates/openhuman-core/src/web_chat/suggestions.rs
@@ -198,9 +198,8 @@ async fn generate_and_emit(
}
fn build_suggestions_request(user_message: &str, assistant_message: &str) -> ModelRequest {
- let user_prompt = format!(
- "User's last message:\n{user_message}\n\nAssistant's reply:\n{assistant_message}"
- );
+ let user_prompt =
+ format!("User's last message:\n{user_message}\n\nAssistant's reply:\n{assistant_message}");
ModelRequest::new(vec![
Message::system(SUGGESTIONS_SYSTEM_PROMPT),
Message::user(user_prompt),
diff --git a/crates/openhuman-core/src/web_chat/suggestions_tests.rs b/crates/openhuman-core/src/web_chat/suggestions_tests.rs
index 9677d668bd..2c6e9055c4 100644
--- a/crates/openhuman-core/src/web_chat/suggestions_tests.rs
+++ b/crates/openhuman-core/src/web_chat/suggestions_tests.rs
@@ -1,5 +1,5 @@
-use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering};
+use std::sync::Arc;
use async_trait::async_trait;
use tinyinference_llm::model::{ChatModel, ModelRequest, ModelResponse};
@@ -87,7 +87,11 @@ struct ScriptedTextModel {
#[async_trait]
impl ChatModel<()> for ScriptedTextModel {
- async fn invoke(&self, _state: &(), _request: ModelRequest) -> tinyinference_llm::Result<ModelResponse> {
+ async fn invoke(
+ &self,
+ _state: &(),
+ _request: ModelRequest,
+ ) -> tinyinference_llm::Result<ModelResponse> {
self.calls.fetch_add(1, Ordering::SeqCst);
Ok(ModelResponse::assistant(self.text.clone()))
}
@@ -168,7 +172,14 @@ async fn skips_when_the_user_message_is_too_short() {
calls: calls.clone(),
}));
- generate_and_emit("client-1", "sugg-thread-short", "req-3", "ok", "Sure thing!").await;
+ generate_and_emit(
+ "client-1",
+ "sugg-thread-short",
+ "req-3",
+ "ok",
+ "Sure thing!",
+ )
+ .await;
assert_eq!(
calls.load(Ordering::SeqCst),
diff --git a/crates/openhuman-core/src/web_chat/web_tests_queue_acceptance_tests.rs b/crates/openhuman-core/src/web_chat/web_tests_queue_acceptance_tests.rs
index d9b6a086be..ae7e040f67 100644
--- a/crates/openhuman-core/src/web_chat/web_tests_queue_acceptance_tests.rs
+++ b/crates/openhuman-core/src/web_chat/web_tests_queue_acceptance_tests.rs
@@ -276,7 +276,10 @@ async fn web_queue_status_wire_shape_and_clear_cleanup_remain_stable() {
assert_eq!(lanes, ["collect", "followup", "steer"]);
for item in items {
assert!(!item["id"].as_str().expect("id").is_empty());
- assert!(item["text_preview"].as_str().expect("text_preview").ends_with("payload"));
+ assert!(item["text_preview"]
+ .as_str()
+ .expect("text_preview")
+ .ends_with("payload"));
}
let cleared = channel_web_queue_clear(thread_id)