Skip to content

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

feat(session): expose session accessors for web chat

Steven Enamakeleed091af8a15
diff --git a/crates/openhuman-core/src/agent/session_host/runtime/accessors.rs b/crates/openhuman-core/src/agent/session_host/runtime/accessors.rs
index 09116701d7..28299726c1 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime/accessors.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime/accessors.rs
@@ -310,7 +310,7 @@ impl OpenHumanSessionHost {
locator: std::sync::Arc<dyn tinyagents_session::transcript::TranscriptLocator>,
) {
if self.runtime_session.is_some() {
- tracing::warn!("cannot change the transcript store after runtime session initialization");
+ tracing::debug!("transcript store already bound for this session; keeping it");
return;
}
self.session_history_locator = Some(locator);
diff --git a/crates/openhuman-core/src/web_chat/session.rs b/crates/openhuman-core/src/web_chat/session.rs
index 586a544c03..3343c0b2c9 100644
--- a/crates/openhuman-core/src/web_chat/session.rs
+++ b/crates/openhuman-core/src/web_chat/session.rs
@@ -471,12 +471,11 @@ pub(crate) async fn checkout_session_agent(
),
};
- bind_transcript_store(ctx, config, thread_id, &fingerprint.target_agent_id, &mut agent).await;
-
// Every checkout re-arms the reply language from this turn's locale: a
// reused agent may have been built under a different one, and `None`
// (English, or no locale sent) must clear a stale instruction.
let mut agent = agent;
+ bind_transcript_store(ctx, config, thread_id, &fingerprint.target_agent_id, &mut agent).await;
let directive = match locale.and_then(locale_reply_directive) {
Some(directive) => Some(directive),
// Messages this session already sent carry another language's
@@ -513,6 +512,49 @@ pub(crate) async fn checkout_session_agent(
Ok(CheckedOutSession { agent, fingerprint })
}
+/// Pin the thread's transcripts to the store key they were first written under.
+///
+/// The key follows `[agent] chat_agent_id`, so after the operator changes it a
+/// session that re-derived the key would write the thread's next turns to a
+/// different store than the one holding its earlier turns, and the readers
+/// (which use the thread's recorded key) would lose them. The first session
+/// bound to a thread records its key; every later one writes there.
+async fn bind_transcript_store(
+ ctx: &crate::core::runtime::DispatchCtx,
+ config: &Config,
+ thread_id: &str,
+ target_agent_id: &str,
+ agent: &mut OpenHumanSessionHost,
+) {
+ let tenant = match crate::core::runtime::tenant::tenant_in(
+ crate::core::runtime::is_saas(),
+ ctx.resolved().as_deref(),
+ ) {
+ Ok(tenant) => tenant,
+ Err(no_tenant) => {
+ log::warn!("[web-channel] transcript key not bound thread={thread_id}: {no_tenant}");
+ return;
+ }
+ };
+ let rule_key = crate::agent::session_store::agent_key_for(&tenant, target_agent_id);
+ let key = crate::threads::store::bind_transcript_key(
+ ctx,
+ &config.workspace_dir,
+ thread_id,
+ rule_key.clone(),
+ )
+ .await;
+ if key != rule_key {
+ log::info!(
+ "[web-channel] thread={thread_id} keeps its recorded transcript store (chat agent changed since it was written)"
+ );
+ agent.set_session_history_locator(crate::agent::session_store::transcripts_or_files(
+ &key,
+ &config.workspace_dir,
+ ));
+ }
+}
+
/// Return a checked-out agent to the thread cache, replacing whatever is there.
/// The primary user-turn path: it owns the thread's `IN_FLIGHT` slot, so any
/// entry it finds was left by a turn that ran concurrently and is now stale.