Skip to content

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

fix(threads): preserve mirrored turn state when observations arrive out of order

Steven Enamakel5729d3bb6944
diff --git a/crates/openhuman-core/src/threads/turn_state/mirror.rs b/crates/openhuman-core/src/threads/turn_state/mirror.rs
index 6d5f30d927..98163950a2 100644
--- a/crates/openhuman-core/src/threads/turn_state/mirror.rs
+++ b/crates/openhuman-core/src/threads/turn_state/mirror.rs
@@ -27,7 +27,7 @@ pub use observe::ObserveProgress;
#[cfg(test)]
use tinyagents_session::turn_state::mirror::MAX_PERSISTED_TRANSCRIPT_ITEM;
#[cfg(test)]
-use tinyagents_session::turn_state::store::TurnStateStore;
+use tinyagents_session::port::{InMemoryTurnStates, TurnStates};
#[cfg(test)]
use tinyagents_session::turn_state::types::{
SubagentToolCall, SubagentTranscriptItem, ToolTimelineStatus, TranscriptItem, TurnLifecycle,
diff --git a/crates/openhuman-core/src/threads/turn_state/mirror_observe_tests.rs b/crates/openhuman-core/src/threads/turn_state/mirror_observe_tests.rs
index 436e5f03cb..2d34577b90 100644
--- a/crates/openhuman-core/src/threads/turn_state/mirror_observe_tests.rs
+++ b/crates/openhuman-core/src/threads/turn_state/mirror_observe_tests.rs
@@ -445,7 +445,7 @@ fn text_delta_appends_streaming_text_without_flushing() {
#[test]
fn turn_completed_keeps_snapshot_as_completed_and_finish_is_noop() {
let dir = tempdir().expect("tempdir");
- let store = TurnStateStore::new(dir.path().to_path_buf());
+ let store = std::sync::Arc::new(InMemoryTurnStates::default()) as std::sync::Arc<dyn TurnStates>;
let mut mirror = TurnStateMirror::new(store.clone(), "t", "req-1");
mirror.observe(&AgentProgress::TurnCompleted {
iterations: 3,
@@ -469,7 +469,7 @@ fn turn_completed_keeps_snapshot_as_completed_and_finish_is_noop() {
#[test]
fn finish_without_turn_completed_marks_interrupted() {
let dir = tempdir().expect("tempdir");
- let store = TurnStateStore::new(dir.path().to_path_buf());
+ let store = std::sync::Arc::new(InMemoryTurnStates::default()) as std::sync::Arc<dyn TurnStates>;
let mut mirror = TurnStateMirror::new(store.clone(), "t", "req-1");
mirror.observe(&AgentProgress::IterationStarted {
iteration: 1,
diff --git a/crates/openhuman-core/src/threads/turn_state/mirror_tests.rs b/crates/openhuman-core/src/threads/turn_state/mirror_tests.rs
index d5b6830cdb..26b6377e1b 100644
--- a/crates/openhuman-core/src/threads/turn_state/mirror_tests.rs
+++ b/crates/openhuman-core/src/threads/turn_state/mirror_tests.rs
@@ -6,7 +6,7 @@ use tempfile::tempdir;
fn fresh(thread_id: &str) -> (tempfile::TempDir, TurnStateMirror) {
let dir = tempdir().expect("tempdir");
- let store = TurnStateStore::new(dir.path().to_path_buf());
+ let store = std::sync::Arc::new(InMemoryTurnStates::default()) as std::sync::Arc<dyn TurnStates>;
let mirror = TurnStateMirror::new(store, thread_id, "req-1");
(dir, mirror)
}
diff --git a/crates/openhuman-core/src/web_chat/progress_bridge_tests.rs b/crates/openhuman-core/src/web_chat/progress_bridge_tests.rs
index 9ae74e4e4b..9c2ed92435 100644
--- a/crates/openhuman-core/src/web_chat/progress_bridge_tests.rs
+++ b/crates/openhuman-core/src/web_chat/progress_bridge_tests.rs
@@ -103,7 +103,7 @@ async fn tool_call_completed_forwards_real_output_on_tool_result() {
config_path: tmp.path().join("config.toml"),
..Default::default()
};
- let store = TurnStateStore::new(tmp.path().join("turn_states"));
+ let store = std::sync::Arc::new(tinyagents_session::port::InMemoryTurnStates::default()) as std::sync::Arc<dyn tinyagents_session::port::TurnStates>;
let (tx, rx) = tokio::sync::mpsc::channel(16);
let mut bus = super::super::event_bus::subscribe_web_channel_events();
spawn_progress_bridge(
@@ -213,7 +213,7 @@ fn spawn_test_bridge(
) -> tokio::sync::mpsc::Sender<AgentProgress> {
let (tx, rx) = tokio::sync::mpsc::channel::<AgentProgress>(16);
let dir = tempfile::tempdir().expect("tempdir");
- let store = TurnStateStore::new(dir.path().to_path_buf());
+ let store = std::sync::Arc::new(tinyagents_session::port::InMemoryTurnStates::default()) as std::sync::Arc<dyn tinyagents_session::port::TurnStates>;
// Keep the tempdir alive for the bridge task's lifetime by leaking it —
// a test-only allocation; the OS reclaims it on process exit.
std::mem::forget(dir);
@@ -408,7 +408,7 @@ fn drain_test_config(tmp: &tempfile::TempDir) -> Config {
#[tokio::test]
async fn wait_drained_returns_after_queued_events_are_forwarded() {
let tmp = tempfile::TempDir::new().unwrap();
- let store = TurnStateStore::new(tmp.path().join("turn_states"));
+ let store = std::sync::Arc::new(tinyagents_session::port::InMemoryTurnStates::default()) as std::sync::Arc<dyn tinyagents_session::port::TurnStates>;
let (tx, rx) = tokio::sync::mpsc::channel(16);
let mut bus = super::super::event_bus::subscribe_web_channel_events();
let handle = spawn_progress_bridge(
@@ -465,7 +465,7 @@ async fn wait_drained_returns_after_queued_events_are_forwarded() {
#[tokio::test]
async fn wait_drained_is_bounded_when_the_turn_never_completes() {
let tmp = tempfile::TempDir::new().unwrap();
- let store = TurnStateStore::new(tmp.path().join("turn_states"));
+ let store = std::sync::Arc::new(tinyagents_session::port::InMemoryTurnStates::default()) as std::sync::Arc<dyn tinyagents_session::port::TurnStates>;
let (tx, rx) = tokio::sync::mpsc::channel::<AgentProgress>(16);
let handle = spawn_progress_bridge(
rx,
@@ -488,7 +488,7 @@ async fn wait_drained_is_bounded_when_the_turn_never_completes() {
#[tokio::test]
async fn short_narration_is_flushed_on_the_rounds_first_tool_call() {
let tmp = tempfile::TempDir::new().unwrap();
- let store = TurnStateStore::new(tmp.path().join("turn_states"));
+ let store = std::sync::Arc::new(tinyagents_session::port::InMemoryTurnStates::default()) as std::sync::Arc<dyn tinyagents_session::port::TurnStates>;
let (tx, rx) = tokio::sync::mpsc::channel(16);
let mut bus = super::super::event_bus::subscribe_web_channel_events();
let _handle = spawn_progress_bridge(
@@ -680,7 +680,7 @@ async fn hold_text_stream_suppresses_text_delta_but_keeps_interim() {
config_path: tmp.path().join("config.toml"),
..Default::default()
};
- let store = TurnStateStore::new(tmp.path().join("turn_states"));
+ let store = std::sync::Arc::new(tinyagents_session::port::InMemoryTurnStates::default()) as std::sync::Arc<dyn tinyagents_session::port::TurnStates>;
let (tx, rx) = tokio::sync::mpsc::channel(16);
let mut bus = super::super::event_bus::subscribe_web_channel_events();
spawn_progress_bridge(