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
fix(flows): stop a new flow's builder turn resuming another flow's session
M3gA-Minda2384432b660
diff --git a/crates/openhuman-core/src/agent/harness/session/session_builder_autoload_tests.rs b/crates/openhuman-core/src/agent/harness/session/session_builder_autoload_tests.rsnew file mode 100644index 0000000000..53c9304d4c--- /dev/null+++ b/crates/openhuman-core/src/agent/harness/session/session_builder_autoload_tests.rs@@ -0,0 +1,133 @@+//! `flows_build` must not open a new flow with another flow's builder session.+//!+//! Found by a real-token baseline run: a `flows_build` resumed the previous+//! day's builder session, because the empty-history fallback+//! (`try_load_session_transcript`) loads the newest transcript for the agent+//! *name*, and every flow's builder is named `workflow_builder`.++use super::*;+use crate::agent::harness::session::transcript_history::{+ SessionHistory, SessionHistoryLocator, SessionTranscriptRead,+};++const FLOW_A: &str = "flow A: forward my invoices to accounting";++/// What a brand-new flow B sees on disk: flow A's builder transcript is the+/// newest for the agent name, and nothing exists for B's thread.+struct OtherFlowOnly {+ handle: Arc<FakeSessionHistory>,+}++impl SessionHistoryLocator for OtherFlowOnly {+ fn latest_for_agent(&self, _agent_name: &str) -> Option<Arc<dyn SessionTranscriptRead>> {+ Some(self.handle.clone())+ }++ fn root_for_thread(&self, _thread_id: &str) -> Option<Arc<dyn SessionTranscriptRead>> {+ None+ }++ fn open_stem(+ &self,+ _stem: &str,+ _seed: crate::agent::harness::session::transcript::TranscriptMeta,+ ) -> Result<Arc<dyn SessionHistory>> {+ Ok(self.handle.clone())+ }+}++/// Records the text of every message sent to the model.+#[derive(Default)]+struct SeenText(Mutex<String>);++#[async_trait]+impl ChatModel<()> for SeenText {+ fn profile(&self) -> Option<&ModelProfile> {+ static PROFILE: std::sync::LazyLock<ModelProfile> =+ std::sync::LazyLock::new(ModelProfile::default);+ Some(&PROFILE)+ }++ async fn invoke(+ &self,+ _state: &(),+ request: ModelRequest,+ ) -> tinyinference::Result<ModelResponse> {+ for message in &request.messages {+ self.0.lock().push_str(&message.text());+ }+ let response = ChatResponse {+ text: Some("ok".into()),+ tool_calls: vec![],+ usage: None,+ reasoning_content: None,+ };+ Ok(crate::agent::tinyagents::model::native_model_response_for_request(&response, &request))+ }++ async fn stream(+ &self,+ state: &(),+ request: ModelRequest,+ ) -> tinyinference::Result<ModelStream> {+ let response = self.invoke(state, request).await?;+ Ok(Box::pin(futures::stream::iter(vec![+ ModelStreamItem::Started,+ ModelStreamItem::Completed(response),+ ])))+ }+}++fn builder_agent(workspace: &std::path::Path) -> (Agent, Arc<SeenText>) {+ let handle = Arc::new(FakeSessionHistory {+ path: workspace.join("session_raw").join("flow_a.jsonl"),+ canned: Some(+ crate::agent::harness::session::transcript::SessionTranscript {+ meta: fake_transcript_meta("thr_flow_a"),+ messages: vec![+ crate::agent::messages::ChatMessage::system("builder system prompt"),+ crate::agent::messages::ChatMessage::user(FLOW_A),+ crate::agent::messages::ChatMessage::assistant("proposed flow A"),+ ],+ },+ ),+ appended: Mutex::new(Vec::new()),+ });+ let model = Arc::new(SeenText::default());+ let agent = Agent::builder()+ .chat_model(model.clone())+ .tools(vec![Box::new(MockTool)])+ .memory(crate::memory::test_support::noop_memory())+ .tool_dispatcher(Box::new(NativeToolDispatcher))+ .agent_definition_name("workflow_builder")+ .workspace_dir(workspace.to_path_buf())+ .with_session_history_locator(Arc::new(OtherFlowOnly { handle }))+ .build()+ .expect("agent build should succeed");+ (agent, model)+}++#[tokio::test]+async fn a_new_flow_builder_turn_does_not_resume_another_flows_session() {+ // Control: left alone, the by-name fallback splices flow A into the turn.+ // Without this the assertion below could pass on a fixture that never+ // reaches the request at all.+ let workspace = tempfile::TempDir::new().expect("temp workspace");+ let (mut agent, model) = builder_agent(workspace.path());+ agent.turn("build flow B").await.unwrap();+ assert!(+ model.0.lock().contains(FLOW_A),+ "fixture must reach the request through the by-name fallback"+ );++ let workspace = tempfile::TempDir::new().expect("temp workspace");+ let (mut agent, model) = builder_agent(workspace.path());+ crate::flows::ops::start_builder_turn_clean(&mut agent);+ agent.turn("build flow B").await.unwrap();+ let seen = model.0.lock().clone();+ assert!(seen.contains("build flow B"), "{seen}");+ assert!(+ !seen.contains(FLOW_A),+ "a new flow's builder turn carried another flow's session:\n{seen}"+ );+}diff --git a/crates/openhuman-core/src/agent/harness/session/session_tests.rs b/crates/openhuman-core/src/agent/harness/session/session_tests.rsindex 6909fd23c0..bc8d995ea4 100644--- a/crates/openhuman-core/src/agent/harness/session/session_tests.rs+++ b/crates/openhuman-core/src/agent/harness/session/session_tests.rs@@ -555,6 +555,9 @@ fn agent_with_fake_locator(#[path = "session_builder_and_listener_tests.rs"]mod session_builder_and_listener_tests;+#[cfg(feature = "flows")]+#[path = "session_builder_autoload_tests.rs"]+mod session_builder_autoload_tests;#[path = "session_dispatch_and_resume_tests.rs"]mod session_dispatch_and_resume_tests;#[path = "session_prefix_stability_tests.rs"]diff --git a/crates/openhuman-core/src/flows/ops/builder.rs b/crates/openhuman-core/src/flows/ops/builder.rsindex 3b96c852d9..034026d089 100644--- a/crates/openhuman-core/src/flows/ops/builder.rs+++ b/crates/openhuman-core/src/flows/ops/builder.rs@@ -64,6 +64,7 @@ pub(crate) async fn flows_build_with_extra_hidden_tools(let mut agent = Agent::from_config_for_agent(config, "workflow_builder").map_err(|e| format!("failed to build workflow_builder agent: {e:#}"))?;agent.set_agent_definition_name("workflow_builder".to_string());+ start_builder_turn_clean(&mut agent);// Restrict the visible run-advancing tools per path (PR3:// flows-copilot-live-run-approval). Streaming (copilot pane, real approval@@ -457,3 +458,19 @@ pub(super) fn extract_workflow_proposal(}latest}++/// Keep the builder's first turn from auto-resuming another flow's session.+///+/// On an empty history `Agent::turn` falls back to `try_load_session_transcript`,+/// which loads the newest transcript for the agent *name*. Every flow's builder+/// shares the name `workflow_builder` and the profile's `session_raw/` dir, so+/// that fallback hands a brand-new flow the most recent builder conversation from+/// whichever flow ran last. Thread-scoped resume, where a host does it, seeds+/// `cached_transcript_messages` and is unaffected. `agent_chat` suppresses the+/// same fallback for the same reason.+pub(crate) fn start_builder_turn_clean(agent: &mut crate::agent::Agent) {+ agent.set_next_turn_overrides(crate::agent::harness::session::TurnOverrides {+ suppress_transcript_autoload: true,+ ..Default::default()+ });+}