Skip to content

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

refactor(threads): extract queued message persistence into its own module

Steven Enamakel50aab59f0c3e
diff --git a/crates/openhuman-core/src/threads/ops.rs b/crates/openhuman-core/src/threads/ops.rs
index e619fd853c..3f76049894 100644
--- a/crates/openhuman-core/src/threads/ops.rs
+++ b/crates/openhuman-core/src/threads/ops.rs
@@ -8,6 +8,7 @@ mod crud;
mod edit;
mod live_state;
mod purge;
+mod queued_attachments;
mod search;
mod support;
mod title_generation;
@@ -16,35 +17,35 @@ mod turn_state_ops;
mod usage;
mod working_dir;
-pub(crate) use crud::persist_queued_user_message;
pub use crud::{
delete_after, message_append, message_update, messages_list, thread_create_new, thread_delete,
thread_update_labels, thread_update_title, thread_upsert, threads_list, transcript_search,
};
pub use edit::{
- edit_message, regenerate, EditMessageRequest, EditOrRegenerateResponse, RegenerateRequest,
+ EditMessageRequest, EditOrRegenerateResponse, RegenerateRequest, edit_message, regenerate,
};
pub use live_state::{
- goal_get, todos_get, ThreadGoalGetResponse, ThreadLiveStateRequest, ThreadTodosGetResponse,
+ ThreadGoalGetResponse, ThreadLiveStateRequest, ThreadTodosGetResponse, goal_get, todos_get,
};
pub use purge::threads_purge;
-pub use search::{thread_search, ThreadSearchHit, ThreadSearchRequest, ThreadSearchResponse};
+pub(crate) use queued_attachments::persist_queued_user_message;
+pub use search::{ThreadSearchHit, ThreadSearchRequest, ThreadSearchResponse, thread_search};
pub use title_generation::thread_generate_title;
-pub use transcript::{transcript_get, TranscriptGetRequest};
+pub use transcript::{TranscriptGetRequest, transcript_get};
pub use turn_state_ops::{
turn_state_clear, turn_state_get, turn_state_get_turn, turn_state_history, turn_state_list,
};
-pub use usage::{token_usage, SubagentUsageDto, ThreadTokenUsageRequest, ThreadTokenUsageResponse};
+pub use usage::{SubagentUsageDto, ThreadTokenUsageRequest, ThreadTokenUsageResponse, token_usage};
pub use working_dir::thread_update_working_dir;
pub(crate) use working_dir::thread_working_dir;
// Test-only re-exports so `use super::*;` in the split-out test modules below
// keeps resolving the shared helpers that now live in `support`.
#[cfg(test)]
-use crate::threads::store::{ConversationMessage, ConversationThread, CreateConversationThread};
-#[cfg(test)]
use crate::threads::THREAD_TITLE_LOG_PREFIX;
#[cfg(test)]
+use crate::threads::store::{ConversationMessage, ConversationThread, CreateConversationThread};
+#[cfg(test)]
use crate::threads::{
AppendConversationMessageRequest, ConversationMessageRecord, DeleteConversationThreadRequest,
EmptyRequest, GenerateConversationThreadTitleRequest,
diff --git a/crates/openhuman-core/src/threads/ops/crud.rs b/crates/openhuman-core/src/threads/ops/crud.rs
index e158261246..4e3270f63b 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::runtime::DispatchCtx;
use crate::core::Outcome;
+use crate::core::runtime::DispatchCtx;
+use crate::threads::ThreadsError;
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,
@@ -196,104 +196,7 @@ pub async fn message_append(
message_append_with_config(ctx, request, &config, origin.as_ref(), &persistence_dir).await
}
-/// Persist an admitted queued web user message under its stable request ID.
-///
-/// This is called from the trusted turn runner with the same scoped dispatch
-/// context used to admit and resolve the queued attachments. The row is
-/// appended once in turn order; retries return it only when its text and
-/// opaque attachment references match exactly.
-pub(crate) async fn persist_queued_user_message(
- ctx: &DispatchCtx,
- thread_id: &str,
- request_id: &str,
- text: &str,
- opaque_parts: &[tinychannels_bus::ContentPart],
-) -> Result<ConversationMessageRecord, String> {
- if thread_id.trim().is_empty() || request_id.trim().is_empty() {
- return Err("queued message thread and request IDs must be non-empty".into());
- }
- if !opaque_parts.is_empty() {
- crate::threads::attachments::validate_opaque_parts(opaque_parts)?;
- }
- let config = ctx
- .load_config()
- .await
- .map_err(|error| format!("load queued message configuration: {error}"))?;
- persist_queued_user_message_with_config(ctx, thread_id, request_id, text, opaque_parts, &config)
- .await
-}
-
-async fn persist_queued_user_message_with_config(
- ctx: &DispatchCtx,
- thread_id: &str,
- request_id: &str,
- text: &str,
- opaque_parts: &[tinychannels_bus::ContentPart],
- config: &crate::config::Config,
-) -> Result<ConversationMessageRecord, String> {
- let row_id = format!("user:{request_id}");
- let existing = conversations::get_messages(ctx, config.workspace_dir.clone(), thread_id)?
- .into_iter()
- .find(|message| message.id == row_id);
- if let Some(existing) = existing {
- let stored_parts = crate::threads::attachments::public_refs(&existing.extra_metadata);
- if existing.sender != "user" || existing.content != text || stored_parts != opaque_parts {
- return Err("queued message request ID conflicts with an existing row".into());
- }
- if !opaque_parts.is_empty() {
- crate::threads::attachments::consume_staged_parts(
- ctx,
- thread_id,
- opaque_parts,
- &row_id,
- )
- .await?;
- }
- return Ok(message_to_record(existing));
- }
-
- let origin = ctx.turn_origin_or_scoped();
- let request = AppendConversationMessageRequest {
- thread_id: thread_id.to_string(),
- message: ConversationMessageRecord {
- id: row_id.clone(),
- content: text.to_string(),
- attachments: Vec::new(),
- message_type: "text".into(),
- extra_metadata: serde_json::json!({}),
- sender: "user".into(),
- created_at: chrono::Utc::now().to_rfc3339(),
- },
- attachments: opaque_parts.to_vec(),
- };
- let outcome = message_append_with_config(
- ctx,
- request,
- &config,
- origin.as_ref(),
- &config.workspace_dir,
- )
- .await
- .map_err(|error| error.to_string())?;
- let persisted = outcome
- .value
- .data
- .ok_or_else(|| "queued message append returned no row".to_string())?;
- if persisted.id != row_id
- || persisted.sender != "user"
- || persisted.content != text
- || persisted.attachments != opaque_parts
- {
- if !opaque_parts.is_empty() {
- let _ = crate::threads::attachments::discard_staged_parts(ctx, thread_id, opaque_parts)
- .await;
- }
- return Err("queued message request ID conflicts with a concurrently persisted row".into());
- }
- Ok(persisted)
-}
-
-async fn message_append_with_config(
+pub(super) async fn message_append_with_config(
ctx: &DispatchCtx,
mut request: AppendConversationMessageRequest,
config: &crate::config::Config,
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 89c28d5b9b..4674c60e0a 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
@@ -125,47 +125,55 @@ 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]
@@ -193,14 +201,16 @@ 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]
@@ -269,14 +279,16 @@ 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]
@@ -287,17 +299,21 @@ 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)
+ 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()
+ )
.await
- .is_err());
- assert!(conversations::blocking::get_messages(
- crate::core::runtime::DispatchCtx::ambient(),
- config.workspace_dir.clone(),
- "uploads".into()
- )
- .await
- .unwrap()
- .is_empty());
+ .unwrap()
+ .is_empty()
+ );
}
#[tokio::test]
@@ -352,10 +368,12 @@ async fn append_cannot_forge_private_attachment_storage_metadata() {
.data
.unwrap();
assert!(saved.attachments.is_empty());
- assert!(saved
- .extra_metadata
- .get("__openhumanStoredAttachments")
- .is_none());
+ assert!(
+ saved
+ .extra_metadata
+ .get("__openhumanStoredAttachments")
+ .is_none()
+ );
let mut user_req = request("forged-user", "hello", "user");
user_req.message.extra_metadata = json!({});
user_req.message.extra_metadata["__openhumanStoredAttachments"] = json!([{
@@ -369,10 +387,12 @@ async fn append_cannot_forge_private_attachment_storage_metadata() {
.data
.unwrap();
assert!(saved_user.attachments.is_empty());
- assert!(saved_user
- .extra_metadata
- .get("__openhumanStoredAttachments")
- .is_none());
+ assert!(
+ saved_user
+ .extra_metadata
+ .get("__openhumanStoredAttachments")
+ .is_none()
+ );
let stored = crate::threads::store::get_messages(
&crate::core::runtime::DispatchCtx::ambient(),
config.workspace_dir.clone(),
@@ -380,10 +400,12 @@ async fn append_cannot_forge_private_attachment_storage_metadata() {
)
.unwrap();
assert_eq!(stored.len(), 2);
- assert!(stored.iter().all(|message| message
- .extra_metadata
- .get("__openhumanStoredAttachments")
- .is_none()));
+ assert!(stored.iter().all(|message| {
+ message
+ .extra_metadata
+ .get("__openhumanStoredAttachments")
+ .is_none()
+ }));
let update = UpdateConversationMessageRequest {
thread_id: "uploads".into(),
@@ -432,10 +454,12 @@ async fn typed_attachment_is_staged_like_a_marker_and_leaves_the_text_clean() {
);
assert_eq!(saved.content, "look");
assert_eq!(saved.attachments.len(), 1);
- assert!(saved
- .extra_metadata
- .get("__openhumanStoredAttachments")
- .is_none());
+ assert!(
+ saved
+ .extra_metadata
+ .get("__openhumanStoredAttachments")
+ .is_none()
+ );
let opaque_id = match &saved.attachments[0] {
ContentPart::Image { media, .. } => {
assert!(media.path.is_none());
diff --git a/crates/openhuman-core/src/threads/ops/edit.rs b/crates/openhuman-core/src/threads/ops/edit.rs
index 86fe77ff61..7bc21c72aa 100644
--- a/crates/openhuman-core/src/threads/ops/edit.rs
+++ b/crates/openhuman-core/src/threads/ops/edit.rs
@@ -39,19 +39,19 @@
//! turn.
use serde::{Deserialize, Serialize};
-use serde_json::{json, Value};
+use serde_json::{Value, json};
use tinyagents_session::transcript::{
SessionRef, SessionTranscript, TranscriptLocator, TranscriptMessage, TranscriptMeta,
TruncateCut,
};
-use crate::core::runtime::DispatchCtx;
use crate::core::Outcome;
-use crate::threads::store::{self as conversations, reply_run_id, run_reply_message_id};
+use crate::core::runtime::DispatchCtx;
use crate::threads::ThreadsError;
+use crate::threads::store::{self as conversations, reply_run_id, run_reply_message_id};
-use super::support::{transcript_store, workspace_dir, TranscriptStore};
+use super::support::{TranscriptStore, transcript_store, workspace_dir};
#[derive(Debug, Clone, Deserialize)]
#[serde(deny_unknown_fields)]
diff --git a/crates/openhuman-core/src/threads/ops/edit_turn_state_tests.rs b/crates/openhuman-core/src/threads/ops/edit_turn_state_tests.rs
index 64eb56a87e..57adf0631f 100644
--- a/crates/openhuman-core/src/threads/ops/edit_turn_state_tests.rs
+++ b/crates/openhuman-core/src/threads/ops/edit_turn_state_tests.rs
@@ -6,7 +6,7 @@
//! truncation tests do.
use super::*;
-use crate::threads::store::{self as conversations, run_reply_message_id, ConversationMessage};
+use crate::threads::store::{self as conversations, ConversationMessage, run_reply_message_id};
use serde_json::json;
use std::sync::Arc;
use tempfile::TempDir;
diff --git a/crates/openhuman-core/src/threads/ops/purge.rs b/crates/openhuman-core/src/threads/ops/purge.rs
index 550ea415b5..f2799c0b88 100644
--- a/crates/openhuman-core/src/threads/ops/purge.rs
+++ b/crates/openhuman-core/src/threads/ops/purge.rs
@@ -1,8 +1,8 @@
//! Workspace-wide conversation purge.
use super::support::{envelope, run_to_completion, workspace_dir};
-use crate::core::runtime::DispatchCtx;
use crate::core::Outcome;
+use crate::core::runtime::DispatchCtx;
use crate::threads::store as conversations;
use crate::threads::{ApiEnvelope, EmptyRequest, PurgeConversationThreadsResponse};
use std::path::PathBuf;
diff --git a/crates/openhuman-core/src/threads/ops/queued_attachments.rs b/crates/openhuman-core/src/threads/ops/queued_attachments.rs
new file mode 100644
index 0000000000..c53b44a46c
--- /dev/null
+++ b/crates/openhuman-core/src/threads/ops/queued_attachments.rs
@@ -0,0 +1,105 @@
+//! Persistence helpers for admitted queued web-chat user messages.
+
+use super::support::message_to_record;
+use crate::core::Outcome;
+use crate::core::runtime::DispatchCtx;
+use crate::threads::ops::support::envelope;
+use crate::threads::store::{self as conversations, ConversationMessage};
+use crate::threads::{AppendConversationMessageRequest, ConversationMessageRecord, ThreadsError};
+
+/// Persist an admitted queued web user message under its stable request ID.
+///
+/// This is called from the trusted turn runner with the same scoped dispatch
+/// context used to admit and resolve the queued attachments. The row is
+/// appended once in turn order; retries return it only when its text and
+/// opaque attachment references match exactly.
+pub(crate) async fn persist_queued_user_message(
+ ctx: &DispatchCtx,
+ thread_id: &str,
+ request_id: &str,
+ text: &str,
+ opaque_parts: &[tinychannels_bus::ContentPart],
+) -> Result<ConversationMessageRecord, String> {
+ if thread_id.trim().is_empty() || request_id.trim().is_empty() {
+ return Err("queued message thread and request IDs must be non-empty".into());
+ }
+ if !opaque_parts.is_empty() {
+ crate::threads::attachments::validate_opaque_parts(opaque_parts)?;
+ }
+ let config = ctx
+ .load_config()
+ .await
+ .map_err(|error| format!("load queued message configuration: {error}"))?;
+ persist_queued_user_message_with_config(ctx, thread_id, request_id, text, opaque_parts, &config)
+ .await
+}
+
+async fn persist_queued_user_message_with_config(
+ ctx: &DispatchCtx,
+ thread_id: &str,
+ request_id: &str,
+ text: &str,
+ opaque_parts: &[tinychannels_bus::ContentPart],
+ config: &crate::config::Config,
+) -> Result<ConversationMessageRecord, String> {
+ let row_id = format!("user:{request_id}");
+ let existing = conversations::get_messages(ctx, config.workspace_dir.clone(), thread_id)?
+ .into_iter()
+ .find(|message| message.id == row_id);
+ if let Some(existing) = existing {
+ let stored_parts = crate::threads::attachments::public_refs(&existing.extra_metadata);
+ if existing.sender != "user" || existing.content != text || stored_parts != opaque_parts {
+ return Err("queued message request ID conflicts with an existing row".into());
+ }
+ if !opaque_parts.is_empty() {
+ crate::threads::attachments::consume_staged_parts(
+ ctx,
+ thread_id,
+ opaque_parts,
+ &row_id,
+ )
+ .await?;
+ }
+ return Ok(message_to_record(existing));
+ }
+
+ let origin = ctx.turn_origin_or_scoped();
+ let request = AppendConversationMessageRequest {
+ thread_id: thread_id.to_string(),
+ message: ConversationMessageRecord {
+ id: row_id.clone(),
+ content: text.to_string(),
+ attachments: Vec::new(),
+ message_type: "text".into(),
+ extra_metadata: serde_json::json!({}),
+ sender: "user".into(),
+ created_at: chrono::Utc::now().to_rfc3339(),
+ },
+ attachments: opaque_parts.to_vec(),
+ };
+ let outcome = super::crud::message_append_with_config(
+ ctx,
+ request,
+ &config,
+ origin.as_ref(),
+ &config.workspace_dir,
+ )
+ .await
+ .map_err(|error| error.to_string())?;
+ let persisted = outcome
+ .value
+ .data
+ .ok_or_else(|| "queued message append returned no row".to_string())?;
+ if persisted.id != row_id
+ || persisted.sender != "user"
+ || persisted.content != text
+ || persisted.attachments != opaque_parts
+ {
+ if !opaque_parts.is_empty() {
+ let _ = crate::threads::attachments::discard_staged_parts(ctx, thread_id, opaque_parts)
+ .await;
+ }
+ return Err("queued message request ID conflicts with a concurrently persisted row".into());
+ }
+ Ok(persisted)
+}
diff --git a/crates/openhuman-core/src/threads/ops/search.rs b/crates/openhuman-core/src/threads/ops/search.rs
index cd98401ef8..1e6e5fe5b8 100644
--- a/crates/openhuman-core/src/threads/ops/search.rs
+++ b/crates/openhuman-core/src/threads/ops/search.rs
@@ -7,8 +7,8 @@
use super::crud::transcript_search;
use super::support::envelope;
-use crate::core::runtime::DispatchCtx;
use crate::core::Outcome;
+use crate::core::runtime::DispatchCtx;
use crate::threads::ApiEnvelope;
/// Hits returned when the caller does not ask for a number.
diff --git a/crates/openhuman-core/src/threads/ops/support.rs b/crates/openhuman-core/src/threads/ops/support.rs
index 1a97668cd1..c201b37aaa 100644
--- a/crates/openhuman-core/src/threads/ops/support.rs
+++ b/crates/openhuman-core/src/threads/ops/support.rs
@@ -3,11 +3,11 @@
//! store-type <-> wire-type conversions every handler needs.
use crate::config::Config;
-use crate::core::runtime::context::CoreContext;
use crate::core::runtime::DispatchCtx;
+use crate::core::runtime::context::CoreContext;
+use crate::threads::THREAD_TITLE_LOG_PREFIX;
use crate::threads::store as conversations;
use crate::threads::store::{ConversationMessage, ConversationThread};
-use crate::threads::THREAD_TITLE_LOG_PREFIX;
use crate::threads::{ConversationMessageRecord, ConversationThreadSummary};
use std::path::PathBuf;
use tinyagents_harness::title::{title_from_user_message, title_log_fingerprint};
diff --git a/crates/openhuman-core/src/threads/ops/title_generation.rs b/crates/openhuman-core/src/threads/ops/title_generation.rs
index 136f523a28..f1cd662b6c 100644
--- a/crates/openhuman-core/src/threads/ops/title_generation.rs
+++ b/crates/openhuman-core/src/threads/ops/title_generation.rs
@@ -3,12 +3,12 @@
use super::support::{counts, envelope, thread_to_summary, update_thread_with_fallback_title};
use crate::config::Config;
-use crate::core::runtime::DispatchCtx;
use crate::core::Outcome;
+use crate::core::runtime::DispatchCtx;
use crate::inference::provider;
-use crate::threads::store as conversations;
-use crate::threads::ThreadsError;
use crate::threads::THREAD_TITLE_LOG_PREFIX;
+use crate::threads::ThreadsError;
+use crate::threads::store as conversations;
use crate::threads::{
ApiEnvelope, ConversationThreadSummary, GenerateConversationThreadTitleRequest,
};
diff --git a/crates/openhuman-core/src/threads/ops/transcript.rs b/crates/openhuman-core/src/threads/ops/transcript.rs
index 52253ec857..228a4528f1 100644
--- a/crates/openhuman-core/src/threads/ops/transcript.rs
+++ b/crates/openhuman-core/src/threads/ops/transcript.rs
@@ -1,9 +1,9 @@
//! Paginated projection of a thread's settled transcript.
use super::support::{counts, envelope, transcript_store};
-use crate::core::runtime::DispatchCtx;
use crate::core::Outcome;
-use crate::threads::{store as conversations, ApiEnvelope, PaginationMeta};
+use crate::core::runtime::DispatchCtx;
+use crate::threads::{ApiEnvelope, PaginationMeta, store as conversations};
use tinyagents_session::transcript::view::DisplayItem;
/// Request for [`transcript_get`]: the thread to project, plus newest-first
diff --git a/crates/openhuman-core/src/threads/ops/transcript_tests.rs b/crates/openhuman-core/src/threads/ops/transcript_tests.rs
index 4aee62e855..f71b7b1cea 100644
--- a/crates/openhuman-core/src/threads/ops/transcript_tests.rs
+++ b/crates/openhuman-core/src/threads/ops/transcript_tests.rs
@@ -125,7 +125,7 @@ async fn write_thread(ctx: &DispatchCtx) {
#[tokio::test]
async fn transcript_projection_includes_voice_metadata_from_persisted_thread_rows() {
- use crate::threads::store::{blocking, ConversationMessage, CreateConversationThread};
+ use crate::threads::store::{ConversationMessage, CreateConversationThread, blocking};
use serde_json::json;
let dir = tempfile::tempdir().unwrap();
diff --git a/crates/openhuman-core/src/threads/ops/usage.rs b/crates/openhuman-core/src/threads/ops/usage.rs
index 42183542f1..c19f6d8623 100644
--- a/crates/openhuman-core/src/threads/ops/usage.rs
+++ b/crates/openhuman-core/src/threads/ops/usage.rs
@@ -1,8 +1,8 @@
//! Aggregated token/cost usage for a thread, re-audited at current pricing.
use super::support::{counts, envelope, transcript_store};
-use crate::core::runtime::DispatchCtx;
use crate::core::Outcome;
+use crate::core::runtime::DispatchCtx;
use crate::threads::ApiEnvelope;
use tinyagents_session::transcript::spend::thread_spend_in;
diff --git a/crates/openhuman-core/src/threads/ops/usage_tests.rs b/crates/openhuman-core/src/threads/ops/usage_tests.rs
index 1024ff8ce6..db8f2212f9 100644
--- a/crates/openhuman-core/src/threads/ops/usage_tests.rs
+++ b/crates/openhuman-core/src/threads/ops/usage_tests.rs
@@ -1,7 +1,7 @@
use super::*;
use tinyagents_harness::cost::CostSource;
-use tinyagents_session::transcript::spend::CostSplit;
use tinyagents_session::transcript::UsageCostSource;
+use tinyagents_session::transcript::spend::CostSplit;
const UNCATALOGUED: &str = "openrouter/z-ai/glm-5.3-flash";
const CATALOGUED: &str = "claude-sonnet-4-6";
diff --git a/crates/openhuman-core/src/threads/ops/working_dir.rs b/crates/openhuman-core/src/threads/ops/working_dir.rs
index 725784f57e..fe097fd374 100644
--- a/crates/openhuman-core/src/threads/ops/working_dir.rs
+++ b/crates/openhuman-core/src/threads/ops/working_dir.rs
@@ -8,11 +8,11 @@
//! in another.
use super::support::{counts, envelope, thread_to_summary, workspace_dir};
-use crate::core::runtime::DispatchCtx;
use crate::core::Outcome;
+use crate::core::runtime::DispatchCtx;
use crate::security::SecurityPolicy;
-use crate::threads::store as conversations;
use crate::threads::ThreadsError;
+use crate::threads::store as conversations;
use crate::threads::{
ApiEnvelope, ConversationThreadSummary, UpdateConversationThreadWorkingDirRequest,
};
diff --git a/crates/openhuman-core/src/threads/ops_tests.rs b/crates/openhuman-core/src/threads/ops_tests.rs
index b5a70cb205..9fc9b9d778 100644
--- a/crates/openhuman-core/src/threads/ops_tests.rs
+++ b/crates/openhuman-core/src/threads/ops_tests.rs
@@ -6,11 +6,11 @@ use super::*;
// Re-imported here rather than through `ops`: `ops` itself no longer names
// these, so importing them there would be an unused import in a non-test build.
use crate::config::test_env::EnvVarGuard;
+use crate::threads::ThreadsError;
use crate::threads::store as conversations_store;
use crate::threads::turn_state::{ClearTurnStateRequest, GetTurnStateRequest};
-use crate::threads::ThreadsError;
-use serde_json::{json, Value};
-use tinyagents_harness::title::{build_title_prompt, THREAD_TITLE_SYSTEM_PROMPT};
+use serde_json::{Value, json};
+use tinyagents_harness::title::{THREAD_TITLE_SYSTEM_PROMPT, build_title_prompt};
use tinyagents_session::turn_state::TurnState;
// ── thread_to_summary / message_to_record / record_to_message ─
diff --git a/crates/openhuman-core/src/threads/ops_title_and_cancellation_tests.rs b/crates/openhuman-core/src/threads/ops_title_and_cancellation_tests.rs
index 59656f869d..bb0b76da78 100644
--- a/crates/openhuman-core/src/threads/ops_title_and_cancellation_tests.rs
+++ b/crates/openhuman-core/src/threads/ops_title_and_cancellation_tests.rs
@@ -61,8 +61,8 @@ async fn thread_update_title_returns_error_for_missing_thread() {
/// cleanup in one spawned task, so the tail runs regardless of the caller.
#[tokio::test]
async fn run_to_completion_runs_the_tail_after_the_caller_is_dropped() {
- use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
+ use std::sync::atomic::{AtomicBool, Ordering};
let tail_ran = Arc::new(AtomicBool::new(false));
let flag = Arc::clone(&tail_ran);