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(voice): persist live session transcripts across reconnects
Steven Enamakel6d964cdd2bfc
diff --git a/crates/openhuman-core/src/voice/live/persist.rs b/crates/openhuman-core/src/voice/live/persist.rsindex 65b814207c..571a3d39f2 100644--- a/crates/openhuman-core/src/voice/live/persist.rs+++ b/crates/openhuman-core/src/voice/live/persist.rs@@ -16,6 +16,7 @@ use crate::threads::store::ConversationMessage;/// Writes final transcripts for one session.#[derive(Debug)]pub(crate) struct TranscriptPersister {+ ctx: DispatchCtx,workspace_dir: PathBuf,thread_id: String,session_id: String,@@ -25,12 +26,14 @@ pub(crate) struct TranscriptPersister {impl TranscriptPersister {pub(crate) fn new(+ ctx: DispatchCtx,workspace_dir: PathBuf,thread_id: String,session_id: String,provider: String,) -> Self {Self {+ ctx,workspace_dir,thread_id,session_id,@@ -76,7 +79,7 @@ impl TranscriptPersister {};let id = message.id.clone();match crate::threads::store::blocking::append_message(- DispatchCtx::ambient(),+ self.ctx.clone(),self.workspace_dir.clone(),self.thread_id.clone(),message,diff --git a/crates/openhuman-core/src/voice/live/persist_tests.rs b/crates/openhuman-core/src/voice/live/persist_tests.rsindex c94f275567..bb8a879579 100644--- a/crates/openhuman-core/src/voice/live/persist_tests.rs+++ b/crates/openhuman-core/src/voice/live/persist_tests.rs@@ -1,7 +1,7 @@use super::*;fn persister(dir: &std::path::Path) -> TranscriptPersister {- TranscriptPersister::new(dir.to_path_buf(), "t1".into(), "s1".into(), "sarvam".into())+ TranscriptPersister::new(DispatchCtx::ambient(), dir.to_path_buf(), "t1".into(), "s1".into(), "sarvam".into())}#[test]diff --git a/crates/openhuman-core/src/voice/live/session.rs b/crates/openhuman-core/src/voice/live/session.rsindex d5cc0fce00..b019adbf81 100644--- a/crates/openhuman-core/src/voice/live/session.rs+++ b/crates/openhuman-core/src/voice/live/session.rs@@ -95,6 +95,7 @@ pub(crate) fn system_prompt(recent: &[ConversationMessage]) -> String {/// Makes sure the session's thread exists, creating a voice thread when the/// client is not on one.async fn ensure_thread(+ ctx: &DispatchCtx,config: &Config,thread_id: Option<String>,) -> Result<String, LiveVoiceError> {@@ -102,7 +103,7 @@ async fn ensure_thread(.filter(|t| !t.trim().is_empty()).unwrap_or_else(|| format!("voice-{}", uuid::Uuid::new_v4()));crate::threads::store::blocking::ensure_thread(- DispatchCtx::ambient(),+ ctx.clone(),config.workspace_dir.clone(),CreateConversationThread {id: id.clone(),@@ -121,12 +122,13 @@ async fn ensure_thread(/// Starts a live session.pub(crate) async fn start(+ ctx: &DispatchCtx,config: Arc<Config>,request: LiveStartRequest,session_id: &str,) -> Result<StartedLiveSession, LiveVoiceError> {let provider = resolve_provider(&config, request.provider.as_deref())?;- let thread_id = ensure_thread(&config, request.thread_id).await?;+ let thread_id = ensure_thread(ctx, &config, request.thread_id).await?;tracing::debug!(session_id,provider = %provider,@@ -135,7 +137,7 @@ pub(crate) async fn start();let mut host = OpenHumanSessionHost::from_config_for_agent(- &crate::core::runtime::DispatchCtx::ambient(),+ ctx,&config,LIVE_AGENT_ID,)@@ -145,7 +147,7 @@ pub(crate) async fn start(let harness = assemble_live_tool_harness(host.live_tool_surface());let recent = crate::threads::store::blocking::get_messages(- DispatchCtx::ambient(),+ ctx.clone(),config.workspace_dir.clone(),thread_id.clone(),)diff --git a/crates/openhuman-core/src/voice/live/ws.rs b/crates/openhuman-core/src/voice/live/ws.rsindex d4e2bf9bb2..c689f41aad 100644--- a/crates/openhuman-core/src/voice/live/ws.rs+++ b/crates/openhuman-core/src/voice/live/ws.rs@@ -166,6 +166,9 @@ pub(crate) fn parse_start(message: &Message) -> Result<LiveStartRequest, LiveVoi/// Runs one live voice WebSocket to completion.pub async fn handle_live_voice_ws(socket: WebSocket, config: Arc<Config>) {let session_id = uuid::Uuid::new_v4().to_string();+ // The socket is an entry point with no captured core: the session runs+ // under the context of the task that accepted it.+ let ctx = crate::core::runtime::DispatchCtx::ambient();let (mut sink, mut stream) = socket.split();let first = match tokio::time::timeout(START_TIMEOUT, stream.next()).await {@@ -185,7 +188,7 @@ pub async fn handle_live_voice_ws(socket: WebSocket, config: Arc<Config>) {}};- let started = match session::start(config.clone(), request, &session_id).await {+ let started = match session::start(&ctx, config.clone(), request, &session_id).await {Ok(started) => started,Err(error) => {tracing::warn!(@@ -211,6 +214,7 @@ pub async fn handle_live_voice_ws(socket: WebSocket, config: Arc<Config>) {tracing::info!(session_id, provider = %provider, "{LOG_PREFIX} session started");let sender = session.sender();let mut persister = TranscriptPersister::new(+ ctx.clone(),config.workspace_dir.clone(),thread_id.clone(),session_id.clone(),