The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
test(threads): cover memory deletion when snapshot cleanup fails
Steven Enamakel6f52ff148055
diff --git a/crates/openhuman-core/src/threads/ops_conversion_tests.rs b/crates/openhuman-core/src/threads/ops_conversion_tests.rsindex 5dee23ead2..b36a4eb4f3 100644--- a/crates/openhuman-core/src/threads/ops_conversion_tests.rs+++ b/crates/openhuman-core/src/threads/ops_conversion_tests.rs@@ -1,5 +1,85 @@use super::*;use crate::core::runtime::DispatchCtx;+use tinyagents_session::port::{InMemorySessionStores, SessionStoreProvider};++struct FailingTurnStateDelete;++impl tinyagents_session::port::TurnStates for FailingTurnStateDelete {+ fn put(&self, _: &tinyagents_session::turn_state::TurnState) -> Result<(), String> {+ unreachable!("only delete is used by this fixture")+ }++ fn put_unless_completed(+ &self,+ _: &tinyagents_session::turn_state::TurnState,+ ) -> Result<bool, String> {+ unreachable!("only delete is used by this fixture")+ }++ fn get(+ &self,+ _: &str,+ ) -> Result<Option<tinyagents_session::turn_state::TurnState>, String> {+ unreachable!("only delete is used by this fixture")+ }++ fn get_turn(+ &self,+ _: &str,+ _: &str,+ ) -> Result<Option<tinyagents_session::turn_state::TurnState>, String> {+ unreachable!("only delete is used by this fixture")+ }++ fn delete(&self, _: &str) -> Result<bool, String> {+ Err("injected turn snapshot cleanup failure".into())+ }++ fn delete_turn(&self, _: &str, _: &str) -> Result<bool, String> {+ unreachable!("only delete is used by this fixture")+ }++ fn list(&self) -> Result<Vec<tinyagents_session::turn_state::TurnState>, String> {+ unreachable!("only delete is used by this fixture")+ }++ fn list_thread(+ &self,+ _: &str,+ ) -> Result<Vec<tinyagents_session::turn_state::TurnState>, String> {+ unreachable!("only delete is used by this fixture")+ }++ fn clear_all(&self) -> Result<usize, String> {+ unreachable!("only delete is used by this fixture")+ }++ fn mark_all_interrupted(&self, _: &str) -> Result<usize, String> {+ unreachable!("only delete is used by this fixture")+ }++ fn settle_turn(+ &self,+ _: &str,+ _: &str,+ _: tinyagents_session::turn_state::TurnLifecycle,+ _: &str,+ ) -> Result<bool, String> {+ unreachable!("only delete is used by this fixture")+ }+}++struct FailingTurnStateDeleteProvider;++impl tinyagents_session::port::SessionStoreProvider for FailingTurnStateDeleteProvider {+ fn for_agent(&self, agent_id: &str) -> tinyagents_session::port::AgentStores {+ let stores = InMemorySessionStores::new().for_agent(agent_id);+ tinyagents_session::port::AgentStores {+ turn_states: std::sync::Arc::new(FailingTurnStateDelete),+ ..stores+ }+ }+}// NOTE: the title_log_fingerprint / collapse_whitespace copies were removed// here (plan.md §2.1) — threads/title.rs (the owning module) already covers@@ -404,6 +484,109 @@ async fn thread_delete_removes_persisted_turn_state_snapshot() {assert!(turn_state.value.data.unwrap().turn_state.is_none());}+#[tokio::test]+async fn thread_delete_queues_memory_before_snapshot_cleanup_error() {+ use crate::core::runtime::{ContextOverlay, CoreContext, DomainSet};+ use crate::threads::store::CreateConversationThread;+ use crate::tools::toolpacks::ToolGroups;+ use tinymemory_api::{+ ItemKind, LearningKind, ListRequest, MemoryEngine, MemoryMeta, MetaFilter, Role, StoreItem,+ Turn,+ };++ let workspace = tempfile::tempdir().expect("workspace");+ let dir = workspace.path().to_path_buf();+ let thread_id = "channel:discord/sender/chat";+ let mut config = crate::config::Config {+ workspace_dir: dir.clone(),+ action_dir: dir.clone(),+ config_path: dir.join("config.toml"),+ ..Default::default()+ };+ config.memory.engine.clear();++ let mut host_overrides = crate::agent::host_overrides::HostOverrides::default();+ host_overrides.session_store = Some(std::sync::Arc::new(FailingTurnStateDeleteProvider));+ let ctx = DispatchCtx::new(+ CoreContext::for_test(DomainSet::full(), Some(dir.clone())).derive_with(+ ContextOverlay::new(config.clone(), DomainSet::full(), ToolGroups::none())+ .profile("channel-delete-profile")+ .host_overrides(std::sync::Arc::new(host_overrides)),+ ),+ );+ crate::threads::store::blocking::ensure_thread(+ ctx.clone(),+ dir.clone(),+ CreateConversationThread {+ id: thread_id.into(),+ title: "Discord chat".into(),+ created_at: "2026-01-01T00:00:00Z".into(),+ parent_thread_id: None,+ labels: None,+ personality_id: None,+ working_dir: None,+ },+ )+ .await+ .expect("create channel thread in the profile scope");++ let error = thread_delete(+ &ctx,+ DeleteConversationThreadRequest {+ thread_id: thread_id.into(),+ deleted_at: "2026-01-01T00:02:00Z".into(),+ },+ )+ .await+ .expect_err("turn-state cleanup fails after the thread has been deleted");+ assert!(error.contains("turn-snapshot cleanup failed"));+ assert!(+ crate::threads::store::blocking::list_threads(ctx.clone(), dir.clone())+ .await+ .expect("list profile threads")+ .is_empty()+ );+ assert_eq!(+ crate::memory::deletion::pending(&dir),+ vec![crate::memory::deletion::PendingDeletion::Thread {+ thread_id: thread_id.into()+ }]+ );++ let engine = std::sync::Arc::new(tinymemory_api::conformance::ReferenceEngine::new());+ crate::memory::engine::install_test_engine(&dir, engine.clone());+ engine+ .store(StoreItem::Conversation {+ turns: vec![Turn::new(Role::User, "remote message")],+ meta: MemoryMeta {+ thread_id: Some(thread_id.into()),+ channel: Some("discord".into()),+ ..MemoryMeta::default()+ },+ })+ .await+ .unwrap();+ engine+ .store(StoreItem::learning(+ "a learned fact remains",+ LearningKind::Fact,+ 0.9,+ MemoryMeta::default(),+ ))+ .await+ .unwrap();++ assert_eq!(crate::memory::deletion::drain(&config).await, 1);+ assert!(crate::memory::deletion::pending(&dir).is_empty());+ let remaining = engine+ .list(ListRequest::new(MetaFilter::default(), 10))+ .await+ .unwrap()+ .items;+ assert_eq!(remaining.len(), 1);+ assert_eq!(remaining[0].kind, ItemKind::Learning);+}+#[tokio::test]async fn threads_purge_removes_every_turn_state_snapshot() {let _env_lock = crate::config::TEST_ENV_LOCK.lock().await;