Skip to content

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

Read the write-audit health from the log the writer writes to

Shanu13eee153c9fa
diff --git a/src/openhuman/tools/registry/ops.rs b/src/openhuman/tools/registry/ops.rs
index 0b0c91c7ba..1a839973fd 100644
--- a/src/openhuman/tools/registry/ops.rs
+++ b/src/openhuman/tools/registry/ops.rs
@@ -5,9 +5,9 @@ use serde_json::{json, Map, Value};
use crate::core::all;
use crate::core::{ControllerSchema, FieldSchema, TypeSchema};
use crate::openhuman::config::Config;
+use crate::openhuman::mcp::audit::McpWriteListQuery;
use crate::openhuman::mcp::server::McpToolSpec;
use crate::rpc::RpcOutcome;
-use tinymemory_core::store::chunks::store as chunk_store;
use super::providers::capability_provider_diagnostics;
use super::types::{
@@ -150,18 +150,35 @@ fn mcp_allowlists_from_config(config: &Config) -> McpAllowlistDiagnostics {
}
}
+/// How many recent writes the audit log is asked for.
+///
+/// The store has no count method, so the probe lists and counts. The value is
+/// therefore a floor: `recent_rows` saturates here rather than reporting a
+/// true total, which is enough for the question this health field answers —
+/// is the audit log receiving writes at all.
+const RECENT_WRITE_SAMPLE: u64 = tinymcp_bus::MAX_LIST_LIMIT;
+
+/// Whether the write-audit log is recording, and roughly how much.
+///
+/// Reads through `mcp::audit`, which is where the writer puts rows. It used to
+/// query the `mcp_writes` table inside the memory engine's chunk database
+/// directly; when the log moved to its own store, that query stayed behind and
+/// began counting a table nothing writes any more — so this reported zero
+/// writes in the last 24 hours on every install, indefinitely, while the log
+/// underneath it was healthy. A diagnostic that cannot fail loudly must at
+/// least read the same place the writer wrote.
fn mcp_write_audit_health(config: &Config) -> McpWriteAuditHealth {
- let result = chunk_store::with_connection(config, |conn| {
- let since_ms = chrono::Utc::now()
- .timestamp_millis()
- .saturating_sub(24 * 60 * 60 * 1000);
- let count: i64 = conn.query_row(
- "SELECT COUNT(*) FROM mcp_writes WHERE timestamp_ms >= ?1",
- rusqlite::params![since_ms],
- |row| row.get::<_, i64>(0),
- )?;
- Ok(u64::try_from(count).unwrap_or(0))
- });
+ let since_ms = chrono::Utc::now()
+ .timestamp_millis()
+ .saturating_sub(24 * 60 * 60 * 1000);
+ let query = McpWriteListQuery {
+ limit: Some(RECENT_WRITE_SAMPLE),
+ offset: None,
+ since_ms: u64::try_from(since_ms).ok(),
+ ..Default::default()
+ };
+ let result =
+ crate::openhuman::mcp::audit::list_writes(config, &query).map(|writes| writes.len() as u64);
match result {
Ok(count) => McpWriteAuditHealth {
diff --git a/src/openhuman/tools/registry/ops_tests.rs b/src/openhuman/tools/registry/ops_tests.rs
index dc54f54cbb..0343bbf0f9 100644
--- a/src/openhuman/tools/registry/ops_tests.rs
+++ b/src/openhuman/tools/registry/ops_tests.rs
@@ -321,6 +321,53 @@ fn capability_provider(
}
}
+/// The health probe must read the store the writer writes to.
+///
+/// This is the invariant that broke: the audit log moved to its own database
+/// and the probe kept querying the old table inside the memory engine's chunk
+/// store, which nothing writes any more. Nothing failed — it reported zero
+/// writes forever while the log underneath was healthy. Asserting a count
+/// alone would not have caught that (zero is what a quiet install reports
+/// too), so this writes a row first and requires the probe to see it.
+#[cfg(feature = "mcp")]
+#[test]
+fn the_write_audit_probe_reads_the_store_the_writer_wrote_to() {
+ let workspace = tempfile::tempdir().expect("tempdir");
+ let config = Config {
+ workspace_dir: workspace.path().to_path_buf(),
+ ..Config::default()
+ };
+
+ let before = diagnostics_for_config(&config)
+ .value
+ .mcp_write_audit
+ .recent_rows;
+ assert_eq!(before, Some(0), "a fresh workspace has recorded nothing");
+
+ crate::openhuman::mcp::audit::record_write(
+ &config,
+ crate::openhuman::mcp::audit::NewMcpWriteRecord {
+ timestamp_ms: chrono::Utc::now().timestamp_millis(),
+ client_info: "probe-test".to_string(),
+ tool_name: "memory_write".to_string(),
+ args_summary: serde_json::json!({}),
+ resulting_chunk_id: None,
+ success: true,
+ error_message: None,
+ },
+ )
+ .expect("record a write");
+
+ let after = diagnostics_for_config(&config).value.mcp_write_audit;
+ assert_eq!(
+ after.recent_rows,
+ Some(1),
+ "the probe must see a row the writer just recorded; last_error={:?}",
+ after.last_error
+ );
+ assert!(after.enabled, "the log is enabled when it is readable");
+}
+
struct EnvRestore {
key: &'static str,
previous: Option<std::ffi::OsString>,