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(agent): memoize session_locator() to satisfy tinyagents' same-binding check
[email protected]4f4dd4ee22d7
diff --git a/crates/openhuman-core/src/agent/session_host/builder/builder_build.rs b/crates/openhuman-core/src/agent/session_host/builder/builder_build.rsindex e3c4b1b381..523520d6a0 100644--- a/crates/openhuman-core/src/agent/session_host/builder/builder_build.rs+++ b/crates/openhuman-core/src/agent/session_host/builder/builder_build.rs@@ -397,6 +397,7 @@ impl SessionHostBuilder {// `subagents` declaration against the global registry.agent_definition_id: agent_definition_name.clone(),session_history_locator: self.session_history_locator,+ session_history_locator_memo: std::sync::OnceLock::new(),session_key: {let unix_ts = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH)diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session.rs b/crates/openhuman-core/src/agent/session_host/runtime_session.rsindex 5a6f3e93ea..b5b2ab3895 100644--- a/crates/openhuman-core/src/agent/session_host/runtime_session.rs+++ b/crates/openhuman-core/src/agent/session_host/runtime_session.rs@@ -1902,11 +1902,16 @@ impl OpenHumanSessionHost {pub(in crate::agent::session_host) fn session_locator(&self,) -> Arc<dyn tinyagents_session::transcript::TranscriptLocator> {- self.session_history_locator.clone().unwrap_or_else(|| {- Arc::new(tinyagents_session::transcript::FileTranscriptLocator::new(- self.workspace_dir.clone(),- ))- })+ if let Some(injected) = self.session_history_locator.clone() {+ return injected;+ }+ self.session_history_locator_memo+ .get_or_init(|| {+ Arc::new(tinyagents_session::transcript::FileTranscriptLocator::new(+ self.workspace_dir.clone(),+ ))+ })+ .clone()}fn runtime_transcript_meta(&self) -> TranscriptMeta {diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session_tests.rs b/crates/openhuman-core/src/agent/session_host/runtime_session_tests.rsindex 71577ade52..9ab4f3cb0d 100644--- a/crates/openhuman-core/src/agent/session_host/runtime_session_tests.rs+++ b/crates/openhuman-core/src/agent/session_host/runtime_session_tests.rs@@ -78,3 +78,38 @@ async fn a_resumed_orchestrator_keeps_the_integration_actions_it_was_sent() {"only integration actions are rebuilt from the record");}++/// The incident this guards: `session_locator()` is called from more than one+/// place while assembling a session's runtime turn machinery (the+/// `before_resume` resume target and the eager construction-time+/// `builder.session(...)` bind), and tinyagents only accepts a later+/// transcript-target change when it is the exact same locator object+/// (`Arc::ptr_eq`), not merely an equivalent one over the same file. Before+/// this was memoized, each call minted a fresh `FileTranscriptLocator`, so a+/// thread's second turn was rejected with "cannot change a transcript target+/// after it is bound or committed" even though both binds agreed on the+/// destination. Pin the fix directly: every call must return the identical+/// `Arc`.+#[tokio::test]+async fn session_locator_is_memoized_across_calls() {+ let action_dir = tempfile::tempdir().expect("tempdir");+ let model: Arc<dyn tinyinference_llm::model::ChatModel<()>> =+ Arc::new(tinyagents_harness::testkit::ScriptedModel::new(Vec::new()));+ let host = crate::agent::SessionHostBuilder::new()+ .chat_model(model)+ .tools(Vec::new())+ .action_dir(action_dir.path().to_path_buf())+ .memory(crate::memory::test_support::noop_memory())+ .tool_dispatcher(Box::new(tinytools_agent::dialect::XmlDialect))+ .agent_definition_name("orchestrator")+ .build()+ .expect("session build");++ let first = host.session_locator();+ let second = host.session_locator();+ assert!(+ Arc::ptr_eq(&first, &second),+ "session_locator() must return the same Arc on every call, or tinyagents' \+ same-binding check rejects the second transcript bind"+ );+}diff --git a/crates/openhuman-core/src/agent/session_host/types.rs b/crates/openhuman-core/src/agent/session_host/types.rsindex ebd0b7a5c3..39c81d9a48 100644--- a/crates/openhuman-core/src/agent/session_host/types.rs+++ b/crates/openhuman-core/src/agent/session_host/types.rs@@ -275,6 +275,24 @@ pub struct OpenHumanSessionHost {/// reading the old directory.pub(super) session_history_locator:Option<std::sync::Arc<dyn tinyagents_session::transcript::TranscriptLocator>>,+ /// First-call memo for [`OpenHumanSessionHost::session_locator`][Self::session_locator]'s+ /// lazily-constructed `FileTranscriptLocator` (the `session_history_locator` `None` branch).+ ///+ /// tinyagents' `SessionBuilder` only accepts a later transcript-target+ /// change when it is the *same* locator object (`Arc::ptr_eq`), not merely+ /// an equivalent one — see `tinyagents_session::transcript`'s+ /// `TranscriptTarget::same_binding`. `session_locator` is called from more+ /// than one place while building a session's runtime turn machinery (the+ /// `before_resume` resume target and the eager construction-time bind), and+ /// without this memo each call minted a fresh `Arc` over the same+ /// destination, so the second bind was rejected with "cannot change a+ /// transcript target after it is bound or committed" even though both+ /// calls agreed on the file. `OnceLock` keeps the resolution lazy — still+ /// read from `workspace_dir` at first use, not frozen at struct-build time+ /// — while guaranteeing every later caller in this host's lifetime gets+ /// back the identical `Arc`.+ pub(super) session_history_locator_memo:+ std::sync::OnceLock<std::sync::Arc<dyn tinyagents_session::transcript::TranscriptLocator>>,/// Unique transcript key for this session, formatted as/// `"{unix_ts}_{agent_id}"`. Generated once at agent-build time so/// every transcript write in this session uses the same filename