Skip to content

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

test(agent): search decompressed session store rows for persisted nudges

Steven Enamakel1ba5dbfb3427
diff --git a/Cargo.lock b/Cargo.lock
index d9a71f320f..682c947eb0 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -5517,6 +5517,7 @@ dependencies = [
"x25519-dalek 2.0.1",
"zeroize",
"zip 2.4.2",
+ "zstd 0.13.3",
]
[[package]]
diff --git a/crates/openhuman-core/Cargo.toml b/crates/openhuman-core/Cargo.toml
index b5e978e97b..bc8d417f3f 100644
--- a/crates/openhuman-core/Cargo.toml
+++ b/crates/openhuman-core/Cargo.toml
@@ -519,6 +519,8 @@ windows-sys = { version = "0.61", features = [
tokio-tungstenite = { version = "0.29", default-features = false, features = ["connect", "handshake", "rustls-tls-webpki-roots"] }
[dev-dependencies]
+# Transcript entries are stored zstd-compressed; a persistence test reads them back.
+zstd = "0.13"
# Legacy TinyChannels provider/runtime fixtures remain available to tests only;
# production channel execution uses the TinyBus module contract above.
tinychannels = { path = "../../vendor/tinychannels", features = ["relay-websocket", "email", "lark", "whatsapp-web"] }
diff --git a/crates/openhuman-core/src/agent/agent_turn_loop_nudge_tests.rs b/crates/openhuman-core/src/agent/agent_turn_loop_nudge_tests.rs
index ed89ebffd2..6aa8aad6d1 100644
--- a/crates/openhuman-core/src/agent/agent_turn_loop_nudge_tests.rs
+++ b/crates/openhuman-core/src/agent/agent_turn_loop_nudge_tests.rs
@@ -225,8 +225,10 @@ fn committed_rows_mentioning_nudge(history: &[TranscriptEntry]) -> Vec<String> {
.collect()
}
-/// Every persisted file under the workspace, as (lossy) text: the session
-/// store's database files included, so a row written there is searched too.
+/// Every persisted file under the workspace, as (lossy) text. A session
+/// store database is also read row by row, because the storage layer keeps
+/// transcript entries zstd-compressed and a byte search of the file would
+/// never see them.
fn persisted_text(root: &std::path::Path) -> Vec<(std::path::PathBuf, String)> {
walkdir::WalkDir::new(root)
.into_iter()
@@ -234,12 +236,42 @@ fn persisted_text(root: &std::path::Path) -> Vec<(std::path::PathBuf, String)> {
.filter(|entry| entry.file_type().is_file())
.filter_map(|entry| {
let bytes = std::fs::read(entry.path()).ok()?;
- let text = String::from_utf8_lossy(&bytes).into_owned();
+ let mut text = String::from_utf8_lossy(&bytes).into_owned();
+ if entry.path().extension().and_then(|e| e.to_str()) == Some("db") {
+ text.push_str(&database_rows_text(entry.path()));
+ }
Some((entry.into_path(), text))
})
.collect()
}
+/// The document bodies of the storage database at `path`, decompressed.
+fn database_rows_text(path: &std::path::Path) -> String {
+ use crate::storage::rusqlite::{types::Value, Connection, OpenFlags};
+ let Ok(conn) = Connection::open_with_flags(path, OpenFlags::SQLITE_OPEN_READ_ONLY) else {
+ return String::new();
+ };
+ let Ok(mut statement) = conn.prepare("SELECT body FROM docs") else {
+ return String::new();
+ };
+ let Ok(rows) = statement.query_map([], |row| row.get::<_, Value>(0)) else {
+ return String::new();
+ };
+ let mut out = String::new();
+ for value in rows.filter_map(Result::ok) {
+ match value {
+ Value::Text(text) => out.push_str(&text),
+ Value::Blob(bytes) => {
+ let decoded = zstd::decode_all(bytes.as_slice()).unwrap_or(bytes);
+ out.push_str(&String::from_utf8_lossy(&decoded));
+ }
+ _ => {}
+ }
+ out.push('\n');
+ }
+ out
+}
+
#[tokio::test]
async fn a_failed_nudged_request_does_not_persist_the_nudge() {
// When the nudged request itself fails, the driver persists a display-only