Skip to content

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

chore: files changed crates/openhuman-core/src/storage/import/layout_db_tests.rs,crates/openhuman-co

Steven Enamakela53caa897dc4
diff --git a/crates/openhuman-core/src/storage/import/layout_db_tests.rs b/crates/openhuman-core/src/storage/import/layout_db_tests.rs
index ece6227594..7ad0aa6f21 100644
--- a/crates/openhuman-core/src/storage/import/layout_db_tests.rs
+++ b/crates/openhuman-core/src/storage/import/layout_db_tests.rs
@@ -69,7 +69,10 @@ fn inventory_and_copy_leave_a_live_wal_source_unchanged() {
.execute_batch("CREATE TABLE records (id TEXT); INSERT INTO records VALUES ('one');")
.unwrap();
let wal = source.with_file_name("legacy.db-wal");
- assert!(wal.is_file(), "fixture must retain committed rows in its WAL");
+ assert!(
+ wal.is_file(),
+ "fixture must retain committed rows in its WAL"
+ );
let db_before = std::fs::read(&source).unwrap();
let wal_before = std::fs::read(&wal).unwrap();
diff --git a/crates/openhuman-core/src/storage/import/sessions.rs b/crates/openhuman-core/src/storage/import/sessions.rs
index 8b9b844fba..f43132eedb 100644
--- a/crates/openhuman-core/src/storage/import/sessions.rs
+++ b/crates/openhuman-core/src/storage/import/sessions.rs
@@ -71,8 +71,10 @@ fn import(backend: &Arc<dyn StorageBackend>, config: &Config) -> Result<Outcome>
if !db.is_file() && !raw.is_dir() && !turns.is_dir() {
return Ok(None);
}
- let claimed_backend =
- super::super::import_state::backend_with_condition(Arc::clone(backend), condition.clone());
+ let claimed_backend = super::super::import_state::backend_with_condition(
+ Arc::clone(backend),
+ condition.clone(),
+ );
let provider = DriverSessionStores::new(claimed_backend, Scope::local())
.map_err(|error| anyhow::anyhow!("start the session store bridge: {error}"))?
.recover_on_open(false);
@@ -200,18 +202,24 @@ fn turn_state_files(dir: &Path) -> Result<Vec<PathBuf>> {
entries.sort_by_key(std::fs::DirEntry::file_name);
for entry in entries {
let path = entry.path();
- if entry.file_type()?.is_dir() {
+ let file_type = entry.file_type()?;
+ if file_type.is_symlink() {
+ continue;
+ }
+ if file_type.is_dir() {
let mut children = std::fs::read_dir(path)?.collect::<std::io::Result<Vec<_>>>()?;
children.sort_by_key(std::fs::DirEntry::file_name);
- files.extend(
- children
- .into_iter()
- .map(|child| child.path())
- .filter(|path| {
- path.extension().and_then(|extension| extension.to_str()) == Some("json")
- }),
- );
- } else if path.extension().and_then(|extension| extension.to_str()) == Some("json") {
+ for child in children {
+ let path = child.path();
+ if child.file_type()?.is_file()
+ && path.extension().and_then(|extension| extension.to_str()) == Some("json")
+ {
+ files.push(path);
+ }
+ }
+ } else if file_type.is_file()
+ && path.extension().and_then(|extension| extension.to_str()) == Some("json")
+ {
files.push(path);
}
}
@@ -411,8 +419,8 @@ fn decode_transcript(
Option<serde_json::Value>,
Vec<DisplayRecord>,
)> {
- let bytes = std::fs::read(path)
- .with_context(|| format!("read transcript {}", path.display()))?;
+ let bytes =
+ std::fs::read(path).with_context(|| format!("read transcript {}", path.display()))?;
let mut meta = None;
let mut tools = None;
let mut records = Vec::new();
@@ -675,13 +683,19 @@ fn transcript_files(raw: &Path) -> Result<Vec<(String, PathBuf)>> {
entries.sort_by_key(std::fs::DirEntry::file_name);
for entry in entries {
let path = entry.path();
- if entry.file_type()?.is_dir() {
+ let file_type = entry.file_type()?;
+ if file_type.is_symlink() {
+ continue;
+ }
+ if file_type.is_dir() {
let mut inner: Vec<_> = std::fs::read_dir(&path)?.collect::<std::io::Result<_>>()?;
inner.sort_by_key(std::fs::DirEntry::file_name);
for entry in inner {
- push_jsonl(&mut dated, entry.path());
+ if entry.file_type()?.is_file() {
+ push_jsonl(&mut dated, entry.path());
+ }
}
- } else {
+ } else if file_type.is_file() {
push_jsonl(&mut flat, path);
}
}
diff --git a/crates/openhuman-core/src/storage/import/sessions_tests.rs b/crates/openhuman-core/src/storage/import/sessions_tests.rs
index 74b984a6a2..09295b98b2 100644
--- a/crates/openhuman-core/src/storage/import/sessions_tests.rs
+++ b/crates/openhuman-core/src/storage/import/sessions_tests.rs
@@ -53,6 +53,31 @@ fn host_jsonl_reader_preserves_meta_usage_typed_rows_and_tool_state() {
assert_eq!(row.message.tool_call_id.as_deref(), Some("call-1"));
}
+#[cfg(unix)]
+#[test]
+fn session_file_discovery_never_follows_symlinks_outside_legacy_roots() {
+ use std::os::unix::fs::symlink;
+
+ let dir = TempDir::new().unwrap();
+ let workspace = dir.path().join("workspace");
+ let raw = workspace.join("session_raw");
+ let turns = workspace.join("turn_states");
+ std::fs::create_dir_all(&raw).unwrap();
+ std::fs::create_dir_all(&turns).unwrap();
+ let external = dir.path().join("outside.jsonl");
+ std::fs::write(&external, "{}\n").unwrap();
+ symlink(&external, raw.join("external.jsonl")).unwrap();
+
+ let external_turn = dir.path().join("outside.json");
+ std::fs::write(&external_turn, "{}").unwrap();
+ let turn_dir = turns.join("thread");
+ std::fs::create_dir(&turn_dir).unwrap();
+ symlink(&external_turn, turn_dir.join("external.json")).unwrap();
+
+ assert!(transcript_files(&raw).unwrap().is_empty());
+ assert!(turn_state_files(&turns).unwrap().is_empty());
+}
+
/// Every file under `root` with a digest of its bytes.
fn tree(root: &Path) -> BTreeMap<String, String> {
fn walk(dir: &Path, root: &Path, out: &mut BTreeMap<String, String>) {