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(security): remove unused credential ops and profile modules
Steven Enamakeld9a324f318e4
diff --git a/crates/openhuman-core/src/security/credentials/ops.rs b/crates/openhuman-core/src/security/credentials/ops.rsindex 032554d6d4..64aae1f5c3 100644--- a/crates/openhuman-core/src/security/credentials/ops.rs+++ b/crates/openhuman-core/src/security/credentials/ops.rs@@ -12,8 +12,8 @@ pub use composio::{};pub use login_tokens::{auth_create_channel_link_token, consume_login_token};pub use oauth::{- oauth_connect, oauth_fetch_client_key, oauth_fetch_integration_tokens,- oauth_list_integrations, oauth_revoke_integration,+ oauth_connect, oauth_fetch_client_key, oauth_fetch_integration_tokens, oauth_list_integrations,+ oauth_revoke_integration,};pub use provider_credentials::{list_provider_credentials, list_provider_credentials_by_prefix, remove_provider_credentials,diff --git a/crates/openhuman-core/src/security/credentials/ops/session_lifecycle.rs b/crates/openhuman-core/src/security/credentials/ops/session_lifecycle.rsindex 334dd6c476..3f2369c7dd 100644--- a/crates/openhuman-core/src/security/credentials/ops/session_lifecycle.rs+++ b/crates/openhuman-core/src/security/credentials/ops/session_lifecycle.rs@@ -610,11 +610,7 @@ async fn store_session_inner(operation = "store_session","[credentials][auth-store] scheduler gate cleared; ensuring re-embed backfill after login");- crate::memory::ops::maintenance::reembed_best_effort(- &effective_config,- "session stored",- )- .await;+ crate::memory::ops::maintenance::reembed_best_effort(&effective_config, "session stored").await;logs.push("memory re-embed backfill checked after login".to_string());// Bind the Sentry scope to this user so background events that fire@@ -735,7 +731,9 @@ fn fallback_session_user_for_deferred_validation() -> Value {json!({ "pendingBackendValidation": true })}-pub(crate) fn sanitize_stored_session_user(user: Option<serde_json::Value>) -> Option<serde_json::Value> {+pub(crate) fn sanitize_stored_session_user(+ user: Option<serde_json::Value>,+) -> Option<serde_json::Value> {match user {Some(serde_json::Value::Object(map)) if map.is_empty() => None,Some(serde_json::Value::Null) => None,@@ -743,7 +741,10 @@ pub(crate) fn sanitize_stored_session_user(user: Option<serde_json::Value>) -> O}}-pub(crate) fn normalize_local_session_user(user: serde_json::Value, local_user_id: &str) -> serde_json::Value {+pub(crate) fn normalize_local_session_user(+ user: serde_json::Value,+ local_user_id: &str,+) -> serde_json::Value {let mut map = match user {serde_json::Value::Object(map) => map,other => return other,@@ -762,8 +763,7 @@ pub(crate) fn normalize_local_session_user(user: serde_json::Value, local_user_ipub async fn clear_session(config: &Config) -> Result<RpcOutcome<serde_json::Value>, String> {let mut logs = Vec::new();let removed = {- let _session_mutation_lock = crate::desktop::app_state::- CURRENT_USER_SESSION_MUTATION_LOCK+ let _session_mutation_lock = crate::desktop::app_state::CURRENT_USER_SESSION_MUTATION_LOCK.lock().await;// Flip the scheduler-gate override first so any background worker thatdiff --git a/crates/openhuman-core/src/security/credentials/ops_tests.rs b/crates/openhuman-core/src/security/credentials/ops_tests.rsindex aecec3a820..adae0406ce 100644--- a/crates/openhuman-core/src/security/credentials/ops_tests.rs+++ b/crates/openhuman-core/src/security/credentials/ops_tests.rs@@ -134,7 +134,7 @@ fn store_live_session(user_id: &str) -> Config {config}-#[path = "ops_session_tests.rs"]-mod session_tests;#[path = "ops_provider_oauth_tests.rs"]mod provider_oauth_tests;+#[path = "ops_session_tests.rs"]+mod session_tests;diff --git a/crates/openhuman-core/src/security/credentials/profiles/lock.rs b/crates/openhuman-core/src/security/credentials/profiles/lock.rsindex 2727f0e13f..012367c230 100644--- a/crates/openhuman-core/src/security/credentials/profiles/lock.rs+++ b/crates/openhuman-core/src/security/credentials/profiles/lock.rs@@ -13,8 +13,7 @@ use std::sync::atomic::Ordering;use super::{annotate_lock_create_failure, in_process_lock_for, is_pid_alive, AuthProfileLockGuard,- AuthProfilesStore, LOCK_WAIT_MS, LOCK_TIMEOUT_MS, MALFORMED_LOCK_GRACE_MS,- STALE_LOCK_AGE_MS,+ AuthProfilesStore, LOCK_TIMEOUT_MS, LOCK_WAIT_MS, MALFORMED_LOCK_GRACE_MS, STALE_LOCK_AGE_MS,};impl AuthProfilesStore {@@ -80,18 +79,14 @@ impl AuthProfilesStore {// that without bailing at the LOCK_TIMEOUT_MS boundary.let mut next_stale_recheck_ms: u64 = 1_000;loop {- let open_result = crate::util::retry_with_backoff(- "create auth profile lock",- 6,- 100,- || {+ let open_result =+ crate::util::retry_with_backoff("create auth profile lock", 6, 100, || {OpenOptions::new().create_new(true).write(true).open(&self.lock_path).context("open lock file")- },- );+ });match open_result {Ok(mut file) => {diff --git a/crates/openhuman-core/src/security/credentials/profiles/migration.rs b/crates/openhuman-core/src/security/credentials/profiles/migration.rsindex 6a8b2266f8..49ea0a2745 100644--- a/crates/openhuman-core/src/security/credentials/profiles/migration.rs+++ b/crates/openhuman-core/src/security/credentials/profiles/migration.rs@@ -388,12 +388,9 @@ impl AuthProfilesStore {.insert(normalized_id.clone(), ap).map(|old| old.id);new_persisted_profiles.insert(normalized_id.clone(), p);+ profile_id_migration_targets.insert(id.clone(), normalized_id.clone());profile_id_migration_targets- .insert(id.clone(), normalized_id.clone());- profile_id_migration_targets.insert(- normalize_profile_id_provider(&id),- normalized_id.clone(),- );+ .insert(normalize_profile_id_provider(&id), normalized_id.clone());if self.use_keychain {if let Some(old_id) = &old_id {pending_keychain_deletes.push(old_id.clone());@@ -448,8 +445,7 @@ impl AuthProfilesStore {p.provider = original_provider;id.clone()};- profile_id_migration_targets- .insert(id.clone(), final_id.clone());+ profile_id_migration_targets.insert(id.clone(), final_id.clone());profile_id_migration_targets.insert(normalize_profile_id_provider(&id), final_id.clone());new_profiles.insert(final_id.clone(), ap);diff --git a/crates/openhuman-core/src/security/credentials/profiles/persistence.rs b/crates/openhuman-core/src/security/credentials/profiles/persistence.rsindex ba9b0f109e..0e2ce1afe9 100644--- a/crates/openhuman-core/src/security/credentials/profiles/persistence.rs+++ b/crates/openhuman-core/src/security/credentials/profiles/persistence.rs@@ -9,14 +9,14 @@ use std::fs;#[cfg(test)]use std::sync::atomic::Ordering;+#[cfg(test)]+use super::consume_one;use super::{profile_kind_to_string, quarantine_corrupt_store, retry_with_backoff, write_owner_only,AuthProfile, AuthProfileKind, AuthProfilesData, AuthProfilesStore, EncryptedProfileFields,PersistedAuthProfile, PersistedAuthProfiles, CURRENT_SCHEMA_VERSION, PERSIST_RETRY_ATTEMPTS,PERSIST_RETRY_BASE_MS, PROFILES_FILENAME,};-#[cfg(test)]-use super::consume_one;impl AuthProfilesStore {pub(super) fn save_locked(&self, data: &AuthProfilesData) -> Result<()> {diff --git a/crates/openhuman-core/src/security/credentials/profiles/store_core.rs b/crates/openhuman-core/src/security/credentials/profiles/store_core.rsindex d0624ee7b1..657e2359ca 100644--- a/crates/openhuman-core/src/security/credentials/profiles/store_core.rs+++ b/crates/openhuman-core/src/security/credentials/profiles/store_core.rs@@ -21,8 +21,7 @@ impl AuthProfilesStore {pub fn new(state_dir: &Path, encrypt_secrets: bool) -> Self {let user_id = super::user_id_from_state_dir(state_dir);let policy = crate::security::keyring_consent::policy::check_secret_access();- let use_keychain = policy- == crate::security::keyring_consent::PolicyDecision::Proceed+ let use_keychain = policy == crate::security::keyring_consent::PolicyDecision::Proceed&& crate::security::keyring::is_available();log::debug!("[auth] AuthProfilesStore::new state_dir={} user_id={user_id} use_keychain={use_keychain} policy={policy:?}",diff --git a/crates/openhuman-core/src/security/credentials/profiles_tests.rs b/crates/openhuman-core/src/security/credentials/profiles_tests.rsindex fc099254c0..52f59fa4f0 100644--- a/crates/openhuman-core/src/security/credentials/profiles_tests.rs+++ b/crates/openhuman-core/src/security/credentials/profiles_tests.rs@@ -8,10 +8,10 @@ use tempfile::TempDir;/// that has since exited.const SYNTHETIC_DEAD_PID: u32 = i32::MAX as u32;-#[path = "profiles_store_lock_tests.rs"]-mod store_lock_tests;#[path = "profiles_persistence_migration_tests.rs"]mod persistence_migration_tests;+#[path = "profiles_store_lock_tests.rs"]+mod store_lock_tests;#[path = "profiles_owner_only_tests.rs"]mod owner_only_tests;diff --git a/crates/openhuman-core/src/web_chat/ops/channel_ops.rs b/crates/openhuman-core/src/web_chat/ops/channel_ops.rsnew file mode 100644index 0000000000..1bd0b567fc--- /dev/null+++ b/crates/openhuman-core/src/web_chat/ops/channel_ops.rs@@ -0,0 +1,242 @@+//! Public RPC-facing operations for the web channel: sending a chat message,+//! cancelling in-flight turns (primary and parallel, scoped or unscoped), and+//! inspecting/clearing a thread's run queue.++use serde_json::{json, Value};++use crate::core::socketio::WebChannelEvent;+use crate::rpc::RpcOutcome;++use super::super::event_bus::publish_web_channel_event;+use super::super::types::ChatRequestMetadata;+use super::parallel_turn::{cancel_parallel_turn_by_request_id, cancel_parallel_turns_for_thread};+use super::start_chat::start_chat;+use super::state::{cancel_in_flight_gracefully, cancel_should_target, key_for, IN_FLIGHT};++/// Cancel whatever turn is currently running on a thread (unscoped stop).+///+/// Back-compat entry point (Stop button / session teardown). For a cancel that+/// must only affect a specific turn — so a stale cancel can't kill a newer turn+/// on the same thread — use [`cancel_chat_scoped`] with the target `request_id`+/// (#4760).+pub async fn cancel_chat(client_id: &str, thread_id: &str) -> Result<Option<String>, String> {+ cancel_chat_scoped(client_id, thread_id, None).await+}++/// Cancel the in-flight turn(s) for a thread.+///+/// When `request_id` is `Some`, the cancel is **scoped**: it only tears down the+/// primary turn if that exact request is still running (and only the matching+/// parallel turn), so a stale cancel for a superseded request can't kill the+/// newer turn that replaced it (#4760). When `request_id` is `None`, it stops+/// whatever is running on the thread (primary + every parallel) — the "stop+/// everything" behaviour used by session teardown / a Stop button.+pub async fn cancel_chat_scoped(+ client_id: &str,+ thread_id: &str,+ request_id: Option<&str>,+) -> Result<Option<String>, String> {+ let client_id = client_id.trim();+ let thread_id = thread_id.trim();++ if client_id.is_empty() {+ return Err("client_id is required".to_string());+ }+ if thread_id.is_empty() {+ return Err("thread_id is required".to_string());+ }++ let map_key = key_for(thread_id);+ let mut removed_request_id: Option<String> = None;++ {+ let mut in_flight = IN_FLIGHT.lock().await;+ // #4760: only tear down the primary turn when the cancel is unscoped OR+ // targets exactly the request that is running. A stale cancel for an+ // already-superseded request must be a no-op so the newer turn lives.+ let should_cancel_primary = in_flight+ .get(&map_key)+ .map(|entry| cancel_should_target(request_id, &entry.request_id))+ .unwrap_or(false);+ if should_cancel_primary {+ if let Some(existing) = in_flight.remove(&map_key) {+ removed_request_id = Some(cancel_in_flight_gracefully(existing));+ }+ } else if let Some(rid) = request_id {+ log::info!(+ "[web-channel] ignoring stale cancel request_id={} for thread_id={} — current in-flight is {:?}; newer turn preserved",+ rid,+ thread_id,+ in_flight.get(&map_key).map(|e| e.request_id.as_str())+ );+ }+ }++ // Also tear down concurrent parallel (forked) turns. A scoped cancel targets+ // only the named parallel turn (if it is one); an unscoped cancel/stop+ // covers every parallel turn on the thread, not just the primary one.+ let cancelled_parallel = match request_id {+ Some(rid) => cancel_parallel_turn_by_request_id(thread_id, rid).await,+ None => cancel_parallel_turns_for_thread(thread_id).await,+ };++ // #4760: a scoped cancel that matched only a parallel (forked) turn — not the+ // primary — still genuinely tore a turn down and emitted its cancelled event.+ // Surface that id so `channel_web_cancel` reports `cancelled: true` with the+ // right request_id instead of misreporting a no-op just because the primary+ // turn wasn't the one cancelled.+ let cancelled_any = removed_request_id+ .clone()+ .or_else(|| cancelled_parallel.first().cloned());++ // Emit a cancelled chat_error for each cancelled turn (primary + parallels)+ // so every interleaved branch's UI is resolved.+ for request_id in removed_request_id.into_iter().chain(cancelled_parallel) {+ publish_web_channel_event(WebChannelEvent {+ event: "chat_error".to_string(),+ client_id: client_id.to_string(),+ thread_id: thread_id.to_string(),+ request_id,+ message: Some("Cancelled".to_string()),+ error_type: Some("cancelled".to_string()),+ ..Default::default()+ });+ }++ Ok(cancelled_any)+}++pub async fn channel_web_chat(+ client_id: &str,+ thread_id: &str,+ message: &str,+ model_override: Option<String>,+ temperature: Option<f64>,+ profile_id: Option<String>,+ locale: Option<String>,+ queue_mode: Option<String>,+ metadata: ChatRequestMetadata,+) -> Result<RpcOutcome<Value>, String> {+ let result = start_chat(+ client_id,+ thread_id,+ message,+ model_override,+ temperature,+ profile_id,+ locale,+ queue_mode,+ metadata,+ )+ .await?;++ if let Ok(parsed) = serde_json::from_str::<Value>(&result) {+ return Ok(RpcOutcome::single_log(parsed, "web channel message queued"));+ }++ Ok(RpcOutcome::single_log(+ json!({+ "accepted": true,+ "client_id": client_id.trim(),+ "thread_id": thread_id.trim(),+ "request_id": result,+ }),+ "web channel request accepted",+ ))+}++pub async fn channel_web_queue_status(thread_id: &str) -> Result<RpcOutcome<Value>, String> {+ let map_key = key_for(thread_id);+ let in_flight = IN_FLIGHT.lock().await;+ if let Some(entry) = in_flight.get(&map_key) {+ let status = entry.run_queue.status().await;+ Ok(RpcOutcome::single_log(+ json!({+ "thread_id": thread_id.trim(),+ "active": true,+ "request_id": entry.request_id,+ "steers": status.steers,+ "followups": status.followups,+ "collects": status.collects,+ "total": status.total,+ }),+ "queue status retrieved",+ ))+ } else {+ Ok(RpcOutcome::single_log(+ json!({+ "thread_id": thread_id.trim(),+ "active": false,+ "steers": 0,+ "followups": 0,+ "collects": 0,+ "total": 0,+ }),+ "no active turn for thread",+ ))+ }+}++pub async fn channel_web_queue_clear(thread_id: &str) -> Result<RpcOutcome<Value>, String> {+ let map_key = key_for(thread_id);+ let in_flight = IN_FLIGHT.lock().await;+ if let Some(entry) = in_flight.get(&map_key) {+ let dropped = entry.run_queue.clear().await;+ log::info!(+ "[web-channel] cleared queue thread_id={} dropped={}",+ thread_id,+ dropped+ );+ Ok(RpcOutcome::single_log(+ json!({+ "thread_id": thread_id.trim(),+ "cleared": true,+ "dropped": dropped,+ }),+ "queue cleared",+ ))+ } else {+ Ok(RpcOutcome::single_log(+ json!({+ "thread_id": thread_id.trim(),+ "cleared": false,+ "dropped": 0,+ }),+ "no active turn for thread",+ ))+ }+}++pub async fn channel_web_cancel(+ client_id: &str,+ thread_id: &str,+ request_id: Option<&str>,+) -> Result<RpcOutcome<Value>, String> {+ let cancelled_request_id = cancel_chat_scoped(client_id, thread_id, request_id).await?;++ // No web-channel turn matched. Fall through to the task-dispatcher registry,+ // which holds autonomous runs that are NOT web-channel turns (so they never+ // appear in IN_FLIGHT and can only be reached here). The fallback is itself+ // request-scoped: a scoped cancel aborts the run only when its run_id+ // matches, so a stale cancel for a superseded request can't tear down a newer+ // run on the thread (#4760); an unscoped stop aborts whatever run is running.+ let cancelled = if cancelled_request_id.is_some() {+ true+ } else {+ crate::agent::task_dispatcher::cancel_session_scoped(+ thread_id.trim(),+ request_id,+ )+ .await+ };++ Ok(RpcOutcome::single_log(+ json!({+ "cancelled": cancelled,+ "client_id": client_id.trim(),+ "thread_id": thread_id.trim(),+ "request_id": cancelled_request_id,+ }),+ "web channel cancellation processed",+ ))+}