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
feat(voice): reject local session tokens and classify 401 errors in cloud transcription
Steven Enamakeleb4411f95bee
diff --git a/crates/openhuman-core/src/voice/cloud_transcribe.rs b/crates/openhuman-core/src/voice/cloud_transcribe.rsindex bb22ba972d..37710f92a5 100644--- a/crates/openhuman-core/src/voice/cloud_transcribe.rs+++ b/crates/openhuman-core/src/voice/cloud_transcribe.rs@@ -18,6 +18,13 @@ pub async fn transcribe_cloud(.map_err(|error| error.to_string())?.filter(|token| !token.trim().is_empty()).ok_or_else(|| "no backend session token; sign in first".to_string())?;+ if crate::security::credentials::session_support::is_local_session_token(&token) {+ log::debug!("[voice][cloud_stt] offline local session — hosted STT unavailable");+ return Err(+ crate::security::credentials::session_support::LOCAL_SESSION_BACKEND_UNAVAILABLE+ .to_string(),+ );+ }let client = BackendOAuthClient::new(&effective_backend_api_url(&config.api_url)).map_err(|error| error.to_string())?;let url = client@@ -26,10 +33,28 @@ pub async fn transcribe_cloud(let http = client.raw_client().map_err(crate::api::flatten_authed_error)?;- let result =- tinyinference_voice::cloud::transcribe(&http, url, &token, audio_base64, options).await?;+ let result = tinyinference_voice::cloud::transcribe(&http, url, &token, audio_base64, options)+ .await+ .map_err(classify_transcribe_error)?;Ok(RpcOutcome::single_log(result,"cloud STT via POST /openai/v1/audio/transcriptions",))}++/// Tag a backend 401 with the `SESSION_EXPIRED` sentinel. The request carries+/// the app-session JWT to the hosted backend, so a 401 here is the session+/// lapsing — the JSON-RPC layer then re-auths instead of paging Sentry with+/// the raw `transcription request failed (401 …)` string.+fn classify_transcribe_error(error: String) -> String {+ if error.starts_with("transcription request failed (401") {+ log::info!("[voice][cloud_stt] backend rejected the session (401)");+ format!("SESSION_EXPIRED: {error}")+ } else {+ error+ }+}++#[cfg(test)]+#[path = "cloud_transcribe_tests.rs"]+mod tests;diff --git a/crates/openhuman-core/src/voice/cloud_transcribe_tests.rs b/crates/openhuman-core/src/voice/cloud_transcribe_tests.rsnew file mode 100644index 0000000000..3e31f1e981--- /dev/null+++ b/crates/openhuman-core/src/voice/cloud_transcribe_tests.rs@@ -0,0 +1,38 @@+use super::*;++#[test]+fn backend_401_is_tagged_as_session_expiry() {+ let tagged = classify_transcribe_error(+ "transcription request failed (401 Unauthorized): {\"error\":\"Invalid token\"}"+ .to_string(),+ );+ assert!(tagged.starts_with("SESSION_EXPIRED: "));+ assert!(crate::core::observability::is_session_expired_message(&tagged));+}++#[test]+fn other_failures_pass_through_unchanged() {+ let error = "transcription request failed (500 Internal Server Error): boom".to_string();+ assert_eq!(classify_transcribe_error(error.clone()), error);+}++#[tokio::test]+async fn offline_local_session_refuses_without_a_request() {+ let tmp = tempfile::TempDir::new().unwrap();+ let mut config = Config::default();+ config.workspace_dir = tmp.path().join("workspace");+ config.config_path = tmp.path().join("config.toml");+ crate::security::credentials::AuthService::from_config(&config)+ .store_provider_token(+ crate::security::credentials::APP_SESSION_PROVIDER,+ crate::security::credentials::DEFAULT_AUTH_PROFILE_NAME,+ "desktop.test.local",+ std::collections::HashMap::new(),+ true,+ )+ .unwrap();+ let err = transcribe_cloud(&config, "AAAA", &CloudTranscribeOptions::default())+ .await+ .unwrap_err();+ assert!(crate::core::observability::is_backend_unavailable_message(&err), "{err}");+}