Skip to content

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

fix(agent): handle missing credentials in harness assembly

Steven Enamakelc7fcef6bd6ad
diff --git a/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs b/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs
index 846f71be96..526ef1ea73 100644
--- a/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/harness_assembly.rs
@@ -322,15 +322,16 @@ pub(super) fn assemble_turn_harness(
.map(|h| EarlyExitHook::new(h.clone()));
let is_subagent_run = subagent_scope.is_some();
- let (tool_count, registry_diagnostics, registry_snapshot) = register_turn_tools_and_agents(
- &mut harness,
- &mut capability_registry,
- &tool_sets,
- &allowed,
- &early_exit_set,
- early_exit_hook.as_ref(),
- is_subagent_run,
- );
+ let (tool_count, candidate_names, registry_diagnostics, registry_snapshot) =
+ register_turn_tools_and_agents(
+ &mut harness,
+ &mut capability_registry,
+ &tool_sets,
+ &allowed,
+ &early_exit_set,
+ early_exit_hook.as_ref(),
+ is_subagent_run,
+ );
// SHADOW tool-exposure layer (issue #4249, 01.3 — dynamic exposure). Compose
// the OpenHuman exposure policy as a crate-native selection layer
diff --git a/crates/openhuman-core/src/agent/tinyagents/harness_tool_registration.rs b/crates/openhuman-core/src/agent/tinyagents/harness_tool_registration.rs
index f4db552407..f99aea487d 100644
--- a/crates/openhuman-core/src/agent/tinyagents/harness_tool_registration.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/harness_tool_registration.rs
@@ -34,7 +34,7 @@ pub(super) fn register_turn_tools_and_agents(
early_exit_set: &HashSet<&str>,
early_exit_hook: Option<&EarlyExitHook>,
is_subagent_run: bool,
-) -> (usize, Vec<RegistryDiagnostic>, RegistrySnapshot) {
+) -> (usize, Vec<String>, Vec<RegistryDiagnostic>, RegistrySnapshot) {
if let Some(set) = allowed {
if set.is_empty() {
tracing::warn!(
@@ -174,5 +174,5 @@ pub(super) fn register_turn_tools_and_agents(
"[registry] per-turn capability projection summary"
);
- (tool_count, registry_diagnostics, registry_snapshot)
+ (tool_count, candidate_names, registry_diagnostics, registry_snapshot)
}
diff --git a/crates/openhuman-core/src/channels/runtime/startup/credentials.rs b/crates/openhuman-core/src/channels/runtime/startup/credentials.rs
new file mode 100644
index 0000000000..dcc074a8ec
--- /dev/null
+++ b/crates/openhuman-core/src/channels/runtime/startup/credentials.rs
@@ -0,0 +1,136 @@
+//! Resolving channel secrets that live outside `config.toml` (keyring /
+//! credentials store), and per-channel HTTP client construction.
+
+use crate::config::Config;
+
+/// Best-effort fill of `yb_cfg.app_secret` from the encrypted credentials
+/// store when TOML doesn't already carry one.
+///
+/// `app_secret` is intentionally not persisted in `config.toml` (see the
+/// `yuanbao` branch in `controllers/ops.rs`). Existing TOML values still
+/// win so manually-installed deployments don't break. Returns the
+/// (possibly-modified) config; logging is the only side effect on failure.
+///
+/// The stored secret is **only** copied when the stored profile's
+/// `app_key` matches `yb_cfg.app_key`. Without that guard, editing
+/// `app_key` in `config.toml` would silently pair a fresh key with a
+/// stale secret on next startup, and the channel would fail auth until
+/// the user reconnected or cleared credentials manually.
+pub(super) fn resolve_yuanbao_app_secret(
+ mut yb_cfg: crate::channels::providers::yuanbao::YuanbaoConfig,
+ config: &Config,
+) -> crate::channels::providers::yuanbao::YuanbaoConfig {
+ if !yb_cfg.app_secret.is_empty() {
+ return yb_cfg;
+ }
+ let auth = crate::security::credentials::AuthService::from_config(config);
+ match auth.get_profile("channel:yuanbao:api_key", None) {
+ Ok(Some(profile)) => {
+ let stored_app_key = profile.metadata.get("app_key").map(String::as_str);
+ if stored_app_key != Some(yb_cfg.app_key.as_str()) {
+ tracing::warn!(
+ "[channels] yuanbao stored credentials are for a different app_key (toml={:?}, store={:?}); reconnect the channel to refresh the secret",
+ yb_cfg.app_key,
+ stored_app_key,
+ );
+ } else if let Some(secret) = profile.metadata.get("app_secret") {
+ yb_cfg.app_secret = secret.clone();
+ }
+ }
+ Ok(None) => {
+ tracing::warn!(
+ "[channels] yuanbao credentials missing — connect the channel again from the UI"
+ );
+ }
+ Err(e) => {
+ tracing::warn!("[channels] failed to load yuanbao credentials: {e}");
+ }
+ }
+ yb_cfg
+}
+
+/// Best-effort fill of `email_cfg.password` from the encrypted credentials store
+/// when TOML doesn't already carry one.
+///
+/// The IMAP/SMTP `password` is intentionally not persisted in `config.toml` (see
+/// `persist_email_config` in `controllers/ops/connect.rs`); it lives only in the
+/// credentials store under `channel:email:api_key`. Existing TOML values still
+/// win so manually-installed deployments keep working. The stored secret is only
+/// copied when the stored profile's `username` matches, so editing `username` in
+/// `config.toml` can't silently pair a fresh account with a stale password.
+pub(super) fn resolve_email_password(
+ mut email_cfg: crate::channels::email_channel::EmailConfig,
+ config: &Config,
+) -> crate::channels::email_channel::EmailConfig {
+ if !email_cfg.password.is_empty() {
+ return email_cfg;
+ }
+ let auth = crate::security::credentials::AuthService::from_config(config);
+ match auth.get_profile("channel:email:api_key", None) {
+ Ok(Some(profile)) => {
+ let stored_username = profile.metadata.get("username").map(String::as_str);
+ if stored_username != Some(email_cfg.username.as_str()) {
+ tracing::warn!(
+ "[channels] email stored credentials are for a different username (toml={:?}, store={:?}); reconnect the channel to refresh the password",
+ email_cfg.username,
+ stored_username,
+ );
+ } else if let Some(password) = profile.metadata.get("password") {
+ email_cfg.password = password.clone();
+ }
+ }
+ Ok(None) => {
+ tracing::warn!(
+ "[channels] email credentials missing — connect the channel again from the UI"
+ );
+ }
+ Err(e) => {
+ tracing::warn!("[channels] failed to load email credentials: {e}");
+ }
+ }
+ email_cfg
+}
+
+/// Supplies `tinychannels`' provider factory with this host's HTTP clients.
+///
+/// The factory is transport-agnostic on purpose: proxy configuration, TLS
+/// backend and timeouts are the embedding host's business. This is where
+/// OpenHuman's runtime proxy settings get applied, per channel, using the same
+/// `channel.<name>` identifiers the config UI shows.
+pub(super) struct RuntimeProxyClients;
+
+impl tinychannels::HttpClientFactory for RuntimeProxyClients {
+ fn client_for(&self, channel: &str) -> reqwest::Client {
+ crate::config::build_runtime_proxy_client(channel)
+ }
+
+ /// Signal talks to a local `signal-cli` HTTP bridge that may simply not be
+ /// running. Without a connect timeout that presents as a hang at startup
+ /// rather than an error, so the default is overridden to keep the 10s bound
+ /// this host has always used.
+ fn signal_client(&self) -> reqwest::Client {
+ crate::config::apply_runtime_proxy_to_builder(
+ reqwest::Client::builder().connect_timeout(std::time::Duration::from_secs(10)),
+ "channel.signal",
+ )
+ .build()
+ .unwrap_or_else(|_| reqwest::Client::new())
+ }
+}
+
+/// Resolve channel secrets that live outside the config file.
+///
+/// `tinychannels::build_channels` cannot do this: secrets may sit in the
+/// keyring, an environment variable or the config, and only this host knows
+/// which. It therefore expects an already-hydrated config, and this is where
+/// that happens — on a clone, so the persisted config is never mutated.
+pub(super) fn hydrate_channel_credentials(config: &Config) -> tinychannels::ChannelsConfig {
+ let mut hydrated = config.channels_config.clone();
+ if let Some(email_cfg) = hydrated.email.take() {
+ hydrated.email = Some(resolve_email_password(email_cfg, config));
+ }
+ if let Some(yb_cfg) = hydrated.yuanbao.take() {
+ hydrated.yuanbao = Some(resolve_yuanbao_app_secret(yb_cfg, config));
+ }
+ hydrated
+}
diff --git a/crates/openhuman-core/src/memory/sources/rpc/apply_all.rs b/crates/openhuman-core/src/memory/sources/rpc/apply_all.rs
new file mode 100644
index 0000000000..f6e76a6bb9
--- /dev/null
+++ b/crates/openhuman-core/src/memory/sources/rpc/apply_all.rs
@@ -0,0 +1,177 @@
+//! The "apply all in" sweep: enable every source, clear caps, and trigger a
+//! sync for each.
+
+use super::source_sync::{sync_dispatch, SyncDispatch};
+use crate::config::rpc as config_rpc;
+use crate::memory::sources::registry;
+use crate::memory::sources::types::MemorySourceEntry;
+use crate::rpc::RpcOutcome;
+
+/// Response returned by `memory_sources_apply_all_in`.
+#[derive(Debug, serde::Serialize)]
+pub struct AllInResponse {
+ /// All memory source entries after the "all in" transformation
+ /// (every source enabled, every cap cleared).
+ pub sources: Vec<MemorySourceEntry>,
+ /// Number of sync tasks spawned (one per enabled source).
+ pub sync_triggered: u32,
+ /// Number of enabled sources whose sync trigger FAILED (openhuman#5820).
+ ///
+ /// Additive: an older caller reading only `sync_triggered` behaves as
+ /// before, but a total failure no longer looks like a quiet 200 — in the
+ /// incident, every source failed `no memory source registered` and the
+ /// response still read as success with `sync_triggered: 0`.
+ #[serde(default)]
+ pub sync_failed: u32,
+ /// One `"<source_id>: <error>"` line per failed trigger, in sweep order.
+ #[serde(default, skip_serializing_if = "Vec::is_empty")]
+ pub sync_errors: Vec<String>,
+}
+
+/// The sweep half of [`apply_all_in_rpc`]: trigger a sync for every enabled
+/// source, aggregating failures instead of laundering them (openhuman#5820 —
+/// in the incident every trigger failed `no memory source registered` and the
+/// RPC still answered a clean success).
+///
+/// Takes the trigger as a closure rather than the driver trait object so the
+/// aggregation is unit-testable without a full `MemorySourceSync` stub; the
+/// RPC owns config/binding resolution and the response shape.
+///
+/// The closure receives the whole entry, not just the id: since openhuman#6007
+/// the caller has to route each row by [`SyncDispatch`], which reads the kind,
+/// the connection and the per-source cap. Owned rather than borrowed so the
+/// returned future does not have to borrow from the sweep's loop body.
+///
+/// `pub(super)` so `rpc`'s sibling test module can reach it through
+/// `super::*`.
+pub(super) async fn trigger_enabled_syncs<F, Fut>(
+ sources: &[MemorySourceEntry],
+ mut trigger: F,
+) -> (u32, Vec<String>)
+where
+ F: FnMut(MemorySourceEntry) -> Fut,
+ Fut: std::future::Future<Output = Result<(), String>>,
+{
+ let mut sync_triggered: u32 = 0;
+ let mut sync_errors: Vec<String> = Vec::new();
+ for source in sources {
+ if !source.enabled {
+ continue;
+ }
+ tracing::debug!(
+ source_id = %source.id,
+ kind = %source.kind.as_str(),
+ "[memory_sources] apply_all_in_rpc: triggering sync"
+ );
+ match trigger(source.clone()).await {
+ Ok(()) => {
+ sync_triggered += 1;
+ }
+ Err(e) => {
+ // Per-source failure stays non-fatal for the sweep, but it is
+ // AGGREGATED into the response rather than laundered into a
+ // clean 200.
+ tracing::warn!(
+ source_id = %source.id,
+ error = %e,
+ "[memory_sources] apply_all_in_rpc: sync trigger failed for source"
+ );
+ sync_errors.push(format!("{}: {e}", source.id));
+ }
+ }
+ }
+ (sync_triggered, sync_errors)
+}
+
+/// Enable ALL memory sources, clear all caps, and trigger a sync for
+/// every source.
+///
+/// Returns immediately with the updated source list and the number of
+/// syncs queued. Individual syncs run in the background and publish
+/// `MemorySyncStageChanged` events as they progress.
+pub async fn apply_all_in_rpc() -> Result<RpcOutcome<AllInResponse>, String> {
+ tracing::info!("[memory_sources] apply_all_in_rpc: entry");
+
+ // Enable all sources and clear caps.
+ let sources = registry::apply_all_in().await?;
+
+ // Trigger a background sync for every enabled source.
+ let config = config_rpc::load_config_with_timeout().await?;
+
+ let binding = crate::memory::binding::for_config(&config)?;
+ // Resolved once for the whole sweep, but as an `Option` rather than a hard
+ // error. A driver that serves `as_sources` without `as_source_sync` can
+ // still sync every Composio row through the connector, and failing the whole
+ // sweep over a capability those rows never use is the review finding the
+ // row-level path already carries (#5932) — for a Composio-only user it
+ // turned "sync everything" into one flat refusal. A row that genuinely needs
+ // the family reports the refusal as its own per-source error, which is
+ // exactly what this sweep aggregates.
+ let source_sync = binding.provider().as_source_sync();
+ let config_ref = &config;
+ let driver_id = binding.driver_id();
+
+ let (sync_triggered, sync_errors) = trigger_enabled_syncs(&sources, move |source| async move {
+ match sync_dispatch(&source)? {
+ // The connector-backed run IS the sync for this kind, so the sweep
+ // takes the same dispatch the per-row Sync button does. Before
+ // openhuman#6007 every Composio row came back "synced through the
+ // connector module, not this engine" here.
+ SyncDispatch::Connector {
+ connection_id,
+ max_items,
+ } => crate::integrations::composio::ops::composio_sync_budgeted(
+ config_ref,
+ &connection_id,
+ // `manual`, not a sweep-specific reason: Apply-all is a user
+ // action, and `parse_sync_reason` accepts only `manual`,
+ // `periodic` and `connection_created` — an invented reason would
+ // fail every Composio row here with "unrecognized sync reason".
+ Some("manual".to_string()),
+ Some(source.id.clone()),
+ max_items,
+ )
+ .await
+ .map(|_| ()),
+ SyncDispatch::Driver => {
+ let sync = source_sync.ok_or_else(|| {
+ format!("the bound memory driver '{driver_id}' does not serve source sync")
+ })?;
+ sync.run_source_sync(&source.id)
+ .await
+ .map(|_| ())
+ .map_err(|error| error.to_string())
+ }
+ }
+ })
+ .await;
+
+ let sync_failed = sync_errors.len() as u32;
+ if sync_failed > 0 && sync_triggered == 0 {
+ // Every enabled source failed to trigger — that is a broken sweep,
+ // not a best-effort one. Log at ERROR so it cannot hide at warn among
+ // the per-source lines.
+ tracing::error!(
+ sources = sources.len(),
+ sync_failed,
+ "[memory_sources] apply_all_in_rpc: every sync trigger failed"
+ );
+ }
+
+ tracing::info!(
+ sources = sources.len(),
+ sync_triggered,
+ sync_failed,
+ "[memory_sources] apply_all_in_rpc: complete"
+ );
+
+ Ok(RpcOutcome::new(
+ AllInResponse {
+ sources,
+ sync_triggered,
+ sync_failed,
+ sync_errors,
+ },
+ vec![],
+ ))
+}
diff --git a/crates/openhuman-core/src/search/tools/parallel/extract.rs b/crates/openhuman-core/src/search/tools/parallel/extract.rs
index 07bc8e0567..bdfc6a7e39 100644
--- a/crates/openhuman-core/src/search/tools/parallel/extract.rs
+++ b/crates/openhuman-core/src/search/tools/parallel/extract.rs
@@ -7,6 +7,40 @@ use async_trait::async_trait;
use serde::Deserialize;
use std::sync::Arc;
+#[derive(Debug, Deserialize)]
+pub(super) struct ExtractResponse {
+ #[serde(rename = "extractId", default)]
+ #[allow(dead_code)]
+ extract_id: String,
+ #[serde(default)]
+ results: Vec<ExtractResultItem>,
+ #[serde(default)]
+ errors: Vec<ExtractError>,
+ #[serde(rename = "costUsd", default)]
+ cost_usd: f64,
+}
+
+#[derive(Debug, Deserialize)]
+struct ExtractResultItem {
+ #[serde(default)]
+ url: String,
+ #[serde(default)]
+ title: Option<String>,
+ #[serde(default)]
+ excerpts: Vec<String>,
+ #[serde(default)]
+ full_content: Option<String>,
+}
+
+#[derive(Debug, Deserialize)]
+struct ExtractError {
+ #[serde(default)]
+ url: String,
+ #[serde(default)]
+ error: String,
+}
+
+
// ── ParallelExtractTool ─────────────────────────────────────────────
/// Extract content from web pages via the Parallel API.
diff --git a/crates/openhuman-core/src/search/tools/parallel/search.rs b/crates/openhuman-core/src/search/tools/parallel/search.rs
index ae4e78f3a8..09f3eede98 100644
--- a/crates/openhuman-core/src/search/tools/parallel/search.rs
+++ b/crates/openhuman-core/src/search/tools/parallel/search.rs
@@ -49,39 +49,6 @@ pub struct SearchResultItem {
pub excerpts: Vec<String>,
}
-#[derive(Debug, Deserialize)]
-struct ExtractResponse {
- #[serde(rename = "extractId", default)]
- #[allow(dead_code)]
- extract_id: String,
- #[serde(default)]
- results: Vec<ExtractResultItem>,
- #[serde(default)]
- errors: Vec<ExtractError>,
- #[serde(rename = "costUsd", default)]
- cost_usd: f64,
-}
-
-#[derive(Debug, Deserialize)]
-struct ExtractResultItem {
- #[serde(default)]
- url: String,
- #[serde(default)]
- title: Option<String>,
- #[serde(default)]
- excerpts: Vec<String>,
- #[serde(default)]
- full_content: Option<String>,
-}
-
-#[derive(Debug, Deserialize)]
-struct ExtractError {
- #[serde(default)]
- url: String,
- #[serde(default)]
- error: String,
-}
-
// ── ParallelSearchTool ──────────────────────────────────────────────
/// AI-powered web search via the Parallel API.