Skip to content

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

test(session_store): cover per-agent isolation on driver-backed stores

Steven Enamakelc5d8e6e682a4
diff --git a/crates/openhuman-rpc/src/session_store/mod_tests.rs b/crates/openhuman-rpc/src/session_store/mod_tests.rs
index d0d1db7d4f..c2ac990c46 100644
--- a/crates/openhuman-rpc/src/session_store/mod_tests.rs
+++ b/crates/openhuman-rpc/src/session_store/mod_tests.rs
@@ -100,6 +100,93 @@ async fn a_storage_url_installs_the_driver_backed_store() {
crate::core_host::agent::session_store::restore(previous);
}
+/// A storage URL installs the driver-backed store, and two agents on the one
+/// backend keep their turn states apart. Run once per driver the build has.
+async fn driver_backed_store_keeps_agents_apart(url: String, driver: &str) {
+ let _turn = SLOTS.lock().await;
+ let previous = crate::core_host::agent::session_store::installed();
+ let previous_backend = crate::core_host::storage::installed();
+ install_for_url(Some(url)).await.unwrap();
+
+ assert_eq!(
+ crate::core_host::storage::installed().map(|b| b.driver()),
+ Some(driver)
+ );
+ let provider = crate::core_host::agent::session_store::installed().unwrap();
+ let alice = provider.for_agent("alice");
+ alice
+ .turn_states
+ .put(&TurnState::started("t", "r", 8, "2026-01-01T00:00:00Z"))
+ .unwrap();
+ assert!(alice.turn_states.get("t").unwrap().is_some());
+ assert!(provider
+ .for_agent("bob")
+ .turn_states
+ .get("t")
+ .unwrap()
+ .is_none());
+
+ restore_backend(previous_backend);
+ crate::core_host::agent::session_store::restore(previous);
+}
+
+#[cfg(feature = "storage-sqlite")]
+#[tokio::test(flavor = "multi_thread")]
+async fn the_sqlite_backend_keeps_agents_apart() {
+ let dir = tempfile::tempdir().unwrap();
+ let url = format!("sqlite:{}", dir.path().join("sessions").display());
+ driver_backed_store_keeps_agents_apart(url, "sqlite").await;
+}
+
+#[cfg(feature = "storage-file")]
+#[tokio::test(flavor = "multi_thread")]
+async fn the_file_backend_keeps_agents_apart() {
+ let dir = tempfile::tempdir().unwrap();
+ let url = format!("file:{}", dir.path().join("files").display());
+ driver_backed_store_keeps_agents_apart(url, "file").await;
+}
+
+/// Runs against `TSD_MONGO_URL` (a throwaway local replica set, as the
+/// `Storage (MongoDB)` workflow starts) in a database of its own; skipped
+/// when it is unset or names a host other than this machine.
+#[cfg(feature = "storage-mongodb")]
+#[tokio::test(flavor = "multi_thread")]
+async fn the_mongodb_backend_keeps_agents_apart() {
+ let Some(base) = std::env::var("TSD_MONGO_URL")
+ .ok()
+ .filter(|url| !url.trim().is_empty())
+ else {
+ eprintln!("skipped mongodb: TSD_MONGO_URL is not set");
+ return;
+ };
+ let rest = base.split_once("://").map_or(base.as_str(), |(_, r)| r);
+ let host = rest.split(['/', '?']).next().unwrap_or_default();
+ let host = host.rsplit_once('@').map_or(host, |(_, h)| h);
+ if !(host.starts_with("127.0.0.1")
+ || host.starts_with("localhost")
+ || host.starts_with("[::1]"))
+ {
+ eprintln!("skipped mongodb: TSD_MONGO_URL must name a local server");
+ return;
+ }
+ let (head, query) = match base.split_once('?') {
+ Some((head, query)) => (head, format!("?{query}")),
+ None => (base.as_str(), String::new()),
+ };
+ let authority_end = head[head.find("://").map_or(0, |at| at + 3)..]
+ .find('/')
+ .map_or(head.len(), |at| head.find("://").map_or(0, |i| i + 3) + at);
+ let nanos = std::time::SystemTime::now()
+ .duration_since(std::time::UNIX_EPOCH)
+ .map_or(0, |d| d.as_nanos());
+ let url = format!(
+ "{}/oh_rpc_{nanos:x}_{}{query}",
+ &head[..authority_end],
+ std::process::id()
+ );
+ driver_backed_store_keeps_agents_apart(url, "mongodb").await;
+}
+
#[tokio::test]
async fn no_url_keeps_the_classic_layout() {
let _turn = SLOTS.lock().await;