Skip to content

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

fix(doctor): the MongoDB connectivity probe sends hello and creates nothing

M3gA-Mindc6d459914c1f
diff --git a/crates/openhuman-core/Cargo.toml b/crates/openhuman-core/Cargo.toml
index a26e88e319..8e242161a5 100644
--- a/crates/openhuman-core/Cargo.toml
+++ b/crates/openhuman-core/Cargo.toml
@@ -563,7 +563,7 @@ langfuse = ["tinyagents-harness/langfuse"]
# not the core or its storage-driver feature set.
storage-sqlite = ["tinystoragedrivers/sqlite"]
legacy-import = ["dep:tinystoragedrivers-connect"]
-storage-mongodb = ["tinystoragedrivers/mongodb"]
+storage-mongodb = ["tinystoragedrivers/mongodb", "dep:tinystoragedrivers-connect", "tinystoragedrivers-connect/mongodb"]
# `s3://` blob URLs and composite storage. In neither the contributor set nor
# the product: an object-store client is only for a deployment that wants one.
storage-s3 = ["tinystoragedrivers/s3"]
diff --git a/crates/openhuman-core/src/doctor/checks/storage.rs b/crates/openhuman-core/src/doctor/checks/storage.rs
index ec6c748fcc..b1eba5bf18 100644
--- a/crates/openhuman-core/src/doctor/checks/storage.rs
+++ b/crates/openhuman-core/src/doctor/checks/storage.rs
@@ -84,10 +84,12 @@ async fn inspect_storage_config(check_id: &str, config: StorageConfig) -> Vec<Fi
StorageConfig::MongoDb { uri, database } => {
#[cfg(feature = "storage-mongodb")]
{
- let config = StorageConfig::MongoDb { uri, database };
- match tinystoragedrivers::open(&config).await {
- Ok(storage) => {
- drop(storage);
+ // `hello` only. `tinystoragedrivers::open` would create the
+ // driver's collections and indexes, which a read-only probe
+ // must not do and a read-only credential can't.
+ match tinystoragedrivers_connect::MongoConnection::connect(&uri, &database).await {
+ Ok(connection) => {
+ drop(connection);
vec![Finding::pass(
check_id,
"The selected MongoDB server answered a read-only hello request.",
diff --git a/crates/openhuman-core/src/doctor/checks/storage_tests.rs b/crates/openhuman-core/src/doctor/checks/storage_tests.rs
index 232c487883..94679d0869 100644
--- a/crates/openhuman-core/src/doctor/checks/storage_tests.rs
+++ b/crates/openhuman-core/src/doctor/checks/storage_tests.rs
@@ -68,3 +68,38 @@ async fn memory_storage_probe_reports_the_backend_as_available() {
assert_eq!(findings.len(), 1);
assert_eq!(findings[0].severity, FindingSeverity::Pass);
}
+
+/// Needs a live server: set `OPENHUMAN_TEST_MONGODB_URI` (e.g.
+/// `mongodb://127.0.0.1:27017`) and build with `storage-mongodb`.
+#[cfg(feature = "storage-mongodb")]
+#[tokio::test]
+async fn mongodb_connect_probe_creates_nothing_in_the_inspected_database() {
+ use std::io::Write as _;
+ let Ok(uri) = std::env::var("OPENHUMAN_TEST_MONGODB_URI") else {
+ let _ = writeln!(
+ std::io::stderr(),
+ "skipped: OPENHUMAN_TEST_MONGODB_URI unset"
+ );
+ return;
+ };
+ let database = format!("oh_doctor_probe_{}", std::process::id());
+ let findings = inspect_storage_config(
+ "storage/connect",
+ StorageConfig::MongoDb {
+ uri: uri.clone(),
+ database: database.clone(),
+ },
+ )
+ .await;
+ let db = tinystoragedrivers_connect::MongoConnection::connect(&uri, &database)
+ .await
+ .expect("test client")
+ .database();
+ let created = db.list_collection_names().await.expect("list collections");
+ let _ = db.drop().await;
+ assert_eq!(findings[0].severity, FindingSeverity::Pass);
+ assert!(
+ created.is_empty(),
+ "the read-only probe created {created:?}"
+ );
+}