Skip to content

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

fix(observability, security): widen visibility and reorganise test modules

Steven Enamakel4192503a9dc0
diff --git a/crates/openhuman-core/src/agent/tinyagents/observability/event_bridge.rs b/crates/openhuman-core/src/agent/tinyagents/observability/event_bridge.rs
index 3ee35b3774..e23cef9877 100644
--- a/crates/openhuman-core/src/agent/tinyagents/observability/event_bridge.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/observability/event_bridge.rs
@@ -199,7 +199,7 @@ impl OpenhumanEventBridge {
/// delivered under backpressure instead of being dropped (the old bug). A
/// `Closed` channel means the receiver is gone (turn tore down), where
/// dropping is correct.
- fn send(&self, progress: AgentProgress) {
+ pub(super) fn send(&self, progress: AgentProgress) {
use tokio::sync::mpsc::error::TrySendError;
let Some(tx) = &self.on_progress else {
return;
@@ -260,13 +260,13 @@ impl OpenhumanEventBridge {
}
}
- fn iteration(&self) -> u32 {
+ pub(super) fn iteration(&self) -> u32 {
self.cursor.load(Ordering::SeqCst)
}
/// Accumulate a usage block, feed the global cost tracker, and emit a
/// `TurnCostUpdated` so the UI footer stays live.
- fn record_usage(&self, usage: &Usage) {
+ pub(super) fn record_usage(&self, usage: &Usage) {
let iteration = self.iteration();
// Dedupe guard (W2-budget-dedupe): record a given model call's usage into
// the global cost tracker **exactly once**. Installing the observe-only
@@ -427,7 +427,7 @@ impl OpenhumanEventBridge {
/// like `chat-v1`/`burst-v1` + the vendor catalog + heuristics) — the
/// previous `cost::catalog::estimate_cost_usd` only knew concrete vendor
/// ids, so every managed-tier call priced as $0 in traces and the footer.
- fn estimate_call_cost(model: &str, usage: &Usage) -> f64 {
+ pub(super) fn estimate_call_cost(model: &str, usage: &Usage) -> f64 {
crate::agent::cost::estimate_call_cost_usd(
model,
&UsageInfo {
diff --git a/crates/openhuman-core/src/integrations/composio/schemas/params.rs b/crates/openhuman-core/src/integrations/composio/schemas/params.rs
new file mode 100644
index 0000000000..82c2b8d592
--- /dev/null
+++ b/crates/openhuman-core/src/integrations/composio/schemas/params.rs
@@ -0,0 +1,40 @@
+//! `#[derive(Deserialize)]` request-parameter shapes for the handlers in
+//! [`super::handlers_triggers`] and [`super::handlers_connections`] that
+//! take more than one or two scalar fields.
+
+use serde_json::Value;
+
+#[derive(Debug, serde::Deserialize)]
+pub(super) struct TriggerHistoryParams {
+ pub(super) limit: Option<usize>,
+}
+
+#[derive(Debug, serde::Deserialize)]
+pub(super) struct ListGithubReposParams {
+ pub(super) connection_id: Option<String>,
+}
+
+#[derive(Debug, serde::Deserialize)]
+pub(super) struct CreateTriggerParams {
+ pub(super) slug: String,
+ pub(super) connection_id: Option<String>,
+ pub(super) trigger_config: Option<Value>,
+}
+
+#[derive(Debug, serde::Deserialize)]
+pub(super) struct ListAvailableTriggersParams {
+ pub(super) toolkit: String,
+ pub(super) connection_id: Option<String>,
+}
+
+#[derive(Debug, serde::Deserialize)]
+pub(super) struct ListTriggersParams {
+ pub(super) toolkit: Option<String>,
+}
+
+#[derive(Debug, serde::Deserialize)]
+pub(super) struct EnableTriggerParams {
+ pub(super) connection_id: String,
+ pub(super) slug: String,
+ pub(super) trigger_config: Option<Value>,
+}
diff --git a/crates/openhuman-core/src/platform/doctor/core/memory_agent_checks.rs b/crates/openhuman-core/src/platform/doctor/core/memory_agent_checks.rs
new file mode 100644
index 0000000000..382703db48
--- /dev/null
+++ b/crates/openhuman-core/src/platform/doctor/core/memory_agent_checks.rs
@@ -0,0 +1,333 @@
+//! Memory-tree, embedding-model, and Claude Agent SDK checks.
+
+use crate::config::Config;
+
+use super::run::MemoryChunkCount;
+use super::types::DiagnosticItem;
+
+pub(super) fn check_memory_tree_db(
+ config: &Config,
+ memory_chunks: &MemoryChunkCount,
+ items: &mut Vec<DiagnosticItem>,
+) {
+ let cat = "memory_tree_db";
+ let db_path = config.workspace_dir.join("memory_tree").join("chunks.db");
+
+ // ── Stale side-files (checked even when chunks.db is absent) ────
+ let base_name = db_path
+ .file_name()
+ .unwrap_or_default()
+ .to_string_lossy()
+ .into_owned();
+ let shm = db_path.with_file_name(format!("{base_name}-shm"));
+ let wal = db_path.with_file_name(format!("{base_name}-wal"));
+ for sidecar in [&shm, &wal] {
+ if sidecar.exists() {
+ items.push(DiagnosticItem::warn(
+ cat,
+ format!(
+ "stale SQLite side-file present (may indicate unclean shutdown): {}",
+ sidecar.display()
+ ),
+ ));
+ }
+ }
+
+ // ── SQLite-artifact check (informational only, not a gate) ──────
+ if !db_path.exists() {
+ items.push(DiagnosticItem::warn(
+ cat,
+ format!("legacy SQLite artifact is absent: {}", db_path.display()),
+ ));
+ }
+
+ // ── Driver probe ────────────────────────────────────────────────
+ // The count used to be a `SELECT COUNT(*) FROM mem_tree_chunks` through
+ // the engine's own connection helper. It is the bound driver's answer now,
+ // which is what lets this check mean something on a workspace whose memory
+ // is not SQLite at all — and what takes the engine crate out of this file.
+ match memory_chunks {
+ Ok(count) => {
+ log::debug!(
+ "[doctor] check_memory_tree_db: driver reported {count} chunks at {}",
+ db_path.display()
+ );
+ items.push(DiagnosticItem::ok(
+ cat,
+ format!(
+ "memory driver accessible ({count} chunks); SQLite artifact: {}",
+ db_path.display()
+ ),
+ ));
+ }
+ Err(err) => {
+ log::debug!(
+ "[doctor] check_memory_tree_db: chunk-count probe failed at {}: {err}",
+ db_path.display()
+ );
+ items.push(DiagnosticItem::error(
+ cat,
+ format!("DB probe failed at {}: {err}", db_path.display()),
+ ));
+ }
+ }
+}
+
+// ── Embedding model health ───────────────────────────────────────
+
+/// Probe the configured embedding provider and model.
+///
+/// - If the intended provider is not `"ollama"` (e.g. cloud): `Ok` — no
+/// local daemon is involved and nothing to diagnose here.
+/// - If Ollama is configured but the daemon at `<base_url>/api/tags` is
+/// unreachable: `Error` with the pull command as the fix hint.
+/// - If the daemon is reachable but the configured embedding model is not
+/// listed in `/api/tags`: `Error` with `ollama pull <model>` guidance.
+/// - If both daemon and model are healthy: `Ok`.
+///
+/// This check is synchronous (uses a small blocking HTTP call) so it fits
+/// the existing `run()` contract. The timeout is capped at 3 s to avoid
+/// stalling `openhuman doctor` on a very slow Ollama daemon.
+pub(super) fn check_embedding_model_health(config: &Config, items: &mut Vec<DiagnosticItem>) {
+ let cat = "embedding_model";
+
+ // Resolve the effective (intended, non-probed) embedding settings.
+ let local_embedding_model = config.workload_local_model("embeddings");
+ let (provider, model, _dims) =
+ crate::inference::embeddings::effective_embedding_settings(
+ &config.memory,
+ local_embedding_model.as_deref(),
+ );
+
+ log::debug!("[doctor] check_embedding_model_health: provider={provider} model={model}");
+
+ if provider != "ollama" {
+ // Cloud or custom provider — no local daemon to probe.
+ items.push(DiagnosticItem::ok(
+ cat,
+ format!("embedding provider: {provider} (model: {model}) — no local daemon required"),
+ ));
+ return;
+ }
+
+ // Ollama path: probe reachability then model availability.
+ let base_url = crate::inference::local::ollama_base_url();
+ let tags_url = format!("{}/api/tags", base_url.trim_end_matches('/'));
+
+ log::debug!("[doctor] probing ollama at {tags_url} for embedding model {model}");
+
+ let client = match reqwest::blocking::Client::builder()
+ .timeout(std::time::Duration::from_secs(3))
+ .build()
+ {
+ Ok(c) => c,
+ Err(e) => {
+ items.push(DiagnosticItem::warn(
+ cat,
+ format!("could not build HTTP client for Ollama probe: {e}"),
+ ));
+ return;
+ }
+ };
+
+ let resp = match client.get(&tags_url).send() {
+ Ok(r) => r,
+ Err(e) => {
+ items.push(DiagnosticItem::error(
+ cat,
+ format!(
+ "Ollama daemon unreachable at {base_url} — embedding model `{model}` cannot be used. \
+ Start Ollama, then run: ollama pull {model} (error: {e})"
+ ),
+ ));
+ return;
+ }
+ };
+
+ if !resp.status().is_success() {
+ items.push(DiagnosticItem::error(
+ cat,
+ format!(
+ "Ollama /api/tags returned {} at {base_url} — cannot verify embedding model `{model}`. \
+ Start Ollama and run: ollama pull {model}",
+ resp.status()
+ ),
+ ));
+ return;
+ }
+
+ // Parse the tags response and look for the configured model.
+ let body = match resp.text() {
+ Ok(t) => t,
+ Err(e) => {
+ items.push(DiagnosticItem::warn(
+ cat,
+ format!("Ollama /api/tags response could not be read: {e}"),
+ ));
+ return;
+ }
+ };
+
+ // Parse the JSON and extract the `models` array. If the response is
+ // malformed or the schema changed (missing `models` key), report that
+ // explicitly instead of falling through to "model NOT installed".
+ let models_array = match serde_json::from_str::<serde_json::Value>(&body) {
+ Ok(v) => match v.get("models").and_then(|m| m.as_array()) {
+ Some(arr) => arr.clone(),
+ None => {
+ items.push(DiagnosticItem::warn(
+ cat,
+ format!(
+ "Ollama /api/tags response is missing the `models` key — \
+ cannot verify embedding model `{model}`. Ollama API may have changed."
+ ),
+ ));
+ return;
+ }
+ },
+ Err(e) => {
+ items.push(DiagnosticItem::warn(
+ cat,
+ format!(
+ "Ollama /api/tags returned invalid JSON — \
+ cannot verify embedding model `{model}`: {e}"
+ ),
+ ));
+ return;
+ }
+ };
+
+ let model_found = models_array.iter().any(|entry| {
+ entry
+ .get("name")
+ .and_then(serde_json::Value::as_str)
+ .map(|name| model_matches(name, &model))
+ .unwrap_or(false)
+ });
+
+ if model_found {
+ items.push(DiagnosticItem::ok(
+ cat,
+ format!("embedding model `{model}` is installed and reachable at {base_url}"),
+ ));
+ } else {
+ items.push(DiagnosticItem::error(
+ cat,
+ format!(
+ "embedding model `{model}` is NOT installed on Ollama at {base_url}. \
+ Run: ollama pull {model}"
+ ),
+ ));
+ }
+}
+
+// ── Claude Agent SDK check ───────────────────────────────────────
+
+pub(super) fn check_claude_agent_sdk(config: &Config, items: &mut Vec<DiagnosticItem>) {
+ let sdk = &config.claude_agent_sdk;
+ if !sdk.enabled {
+ return;
+ }
+
+ tracing::debug!("probe:claude_agent_sdk:entry binary={}", sdk.binary);
+
+ // Probe the configured binary by running `<binary> --version`.
+ let mut cmd = std::process::Command::new(&sdk.binary);
+ cmd.arg("--version")
+ .stdout(std::process::Stdio::piped())
+ .stderr(std::process::Stdio::piped());
+ #[cfg(windows)]
+ {
+ use std::os::windows::process::CommandExt;
+ cmd.creation_flags(0x0800_0000); // CREATE_NO_WINDOW
+ }
+
+ tracing::debug!(
+ "probe:claude_agent_sdk:exec binary={} cmd=--version",
+ sdk.binary
+ );
+
+ match cmd.output() {
+ Ok(output) if output.status.success() => {
+ let version = String::from_utf8_lossy(&output.stdout)
+ .lines()
+ .next()
+ .unwrap_or("(unknown version)")
+ .to_string();
+ tracing::info!(
+ "probe:claude_agent_sdk:ok binary={} version={}",
+ sdk.binary,
+ version
+ );
+ items.push(DiagnosticItem::ok(
+ "claude_agent_sdk",
+ format!("claude CLI found (binary='{}'): {version}", sdk.binary),
+ ));
+ tracing::debug!(
+ "probe:claude_agent_sdk:exit binary={} result=ok",
+ sdk.binary
+ );
+ }
+ Ok(output) => {
+ let stderr = String::from_utf8_lossy(&output.stderr);
+ let preview = stderr.lines().next().unwrap_or("(no stderr)");
+ tracing::warn!(
+ "probe:claude_agent_sdk:warn binary={} status={:?} stderr={}",
+ sdk.binary,
+ output.status,
+ truncate_for_display(preview, COMMAND_VERSION_PREVIEW_CHARS)
+ );
+ items.push(DiagnosticItem::warn(
+ "claude_agent_sdk",
+ format!(
+ "claude CLI execution failed (binary='{}', status={}). {}",
+ sdk.binary,
+ output.status,
+ truncate_for_display(preview, COMMAND_VERSION_PREVIEW_CHARS)
+ ),
+ ));
+ tracing::debug!(
+ "probe:claude_agent_sdk:exit binary={} result=warn",
+ sdk.binary
+ );
+ }
+ Err(err) => {
+ tracing::warn!(
+ "probe:claude_agent_sdk:warn binary={} err={}",
+ sdk.binary,
+ err
+ );
+ items.push(DiagnosticItem::warn(
+ "claude_agent_sdk",
+ format!(
+ "claude CLI not found or not executable (configured binary='{}'): {}. \
+ Install from https://claude.ai/code or set claude_agent_sdk.binary in config.",
+ sdk.binary, err
+ ),
+ ));
+ tracing::debug!(
+ "probe:claude_agent_sdk:exit binary={} result=warn",
+ sdk.binary
+ );
+ }
+ }
+}
+
+// ── Helpers ──────────────────────────────────────────────────────
+
+fn model_matches(installed: &str, configured: &str) -> bool {
+ if installed == configured {
+ return true;
+ }
+
+ if installed.contains(':') && configured.contains(':') {
+ return false;
+ }
+
+ model_base(installed) == model_base(configured)
+}
+
+fn model_base(model: &str) -> &str {
+ model.split(':').next().unwrap()
+}
+
diff --git a/crates/openhuman-core/src/security/keyring/encrypted_store_tests.rs b/crates/openhuman-core/src/security/keyring/encrypted_store_tests.rs
index 785e2de83e..ccb5f623f1 100644
--- a/crates/openhuman-core/src/security/keyring/encrypted_store_tests.rs
+++ b/crates/openhuman-core/src/security/keyring/encrypted_store_tests.rs
@@ -4,7 +4,7 @@ use tempfile::TempDir;
#[cfg(unix)]
use std::os::unix::fs::PermissionsExt;
-#[path = "encrypted_store_tests_part_01_tests.rs"]
-mod part_01_tests;
-#[path = "encrypted_store_tests_part_02_tests.rs"]
-mod part_02_tests;
+#[path = "encrypted_store_crypto_migration_tests.rs"]
+mod crypto_migration_tests;
+#[path = "encrypted_store_key_management_tests.rs"]
+mod key_management_tests;