Skip to content

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

chore(memory): remove unused imports

Steven Enamakel8d9474cffc85
diff --git a/crates/openhuman-core/src/memory/backfill.rs b/crates/openhuman-core/src/memory/backfill.rs
index 5a7c4c4496..58f6acd856 100644
--- a/crates/openhuman-core/src/memory/backfill.rs
+++ b/crates/openhuman-core/src/memory/backfill.rs
@@ -99,32 +99,21 @@ struct BackfillFile {
stored: BTreeMap<String, u32>,
}
-fn file_path(workspace_dir: &Path) -> PathBuf {
- workspace_dir
- .join("memory")
- .join("conversations_backfill.json")
-}
+const STATE: &str = "conversations_backfill";
fn read_file(workspace_dir: &Path) -> BackfillFile {
- std::fs::read_to_string(file_path(workspace_dir))
- .ok()
- .and_then(|text| serde_json::from_str(&text).ok())
+ super::state_store::load(workspace_dir, STATE)
+ .unwrap_or_else(|error| {
+ tracing::warn!(error = %error, "[memory:backfill] reading state failed");
+ None
+ })
.unwrap_or_default()
}
-/// Persists `file` atomically (staged, synced, renamed), so a crash
-/// mid-write keeps the previous progress instead of losing it.
+/// Persists `file` atomically (one storage write), so a crash mid-write keeps
+/// the previous progress instead of losing it.
fn write_file(workspace_dir: &Path, file: &BackfillFile) {
- let result = serde_json::to_vec_pretty(file)
- .map_err(|error| error.to_string())
- .and_then(|json| {
- crate::security::secret_storage::file_store::write_atomic(
- &file_path(workspace_dir),
- &json,
- )
- .map_err(|error| error.to_string())
- });
- if let Err(error) = result {
+ if let Err(error) = super::state_store::save(workspace_dir, STATE, file) {
tracing::warn!(error = %error, "[memory:backfill] writing state failed");
}
}
diff --git a/crates/openhuman-core/src/memory/deletion.rs b/crates/openhuman-core/src/memory/deletion.rs
index e9bd32331a..25a4be5af9 100644
--- a/crates/openhuman-core/src/memory/deletion.rs
+++ b/crates/openhuman-core/src/memory/deletion.rs
@@ -27,50 +27,31 @@ use crate::config::Config;
use super::engine;
use super::error::{MemoryError, MemoryResult};
-fn path(workspace_dir: &Path) -> PathBuf {
- workspace_dir.join("memory").join("pending_deletions.json")
-}
+const STATE: &str = "pending_deletions";
-/// `<workspace>/memory/pending_deletions.json`: owner-only, written through a
-/// temporary file and a rename so a stop mid-write never loses the queue. An
-/// unparsable file is set aside; an empty queue removes the file.
+/// The workspace's `pending_deletions` state value: a stop mid-write never
+/// loses the queue (the storage write is atomic). An unparsable value is
+/// dropped and logged; an empty queue removes the value.
struct FileStore {
- file: PathBuf,
+ workspace_dir: PathBuf,
}
impl ListStore<PendingDeletion> for FileStore {
fn load(&self) -> Result<Vec<PendingDeletion>, StoreError> {
- let Ok(text) = std::fs::read_to_string(&self.file) else {
- return Ok(Vec::new());
- };
- Ok(serde_json::from_str(&text).unwrap_or_else(|error| {
- tracing::warn!(%error, "[memory:deletion] pending deletions unparsable; set aside");
- if let Err(error) =
- std::fs::rename(&self.file, self.file.with_extension("json.corrupt"))
- {
- tracing::warn!(%error, "[memory:deletion] could not set the file aside");
- }
- Vec::new()
- }))
+ super::state_store::load(&self.workspace_dir, STATE)
+ .map(Option::unwrap_or_default)
+ .or_else(|error| {
+ tracing::warn!(%error, "[memory:deletion] pending deletions unreadable; dropped");
+ Ok(Vec::new())
+ })
}
fn save(&self, all: &[PendingDeletion]) -> Result<(), StoreError> {
if all.is_empty() {
- return match std::fs::remove_file(&self.file) {
- Ok(()) => Ok(()),
- Err(error) if error.kind() == std::io::ErrorKind::NotFound => Ok(()),
- Err(error) => Err(StoreError(error.to_string())),
- };
+ return super::state_store::remove(&self.workspace_dir, STATE)
+ .map_err(|error| StoreError(error.to_string()));
}
- let temp = self.file.with_extension("json.tmp");
- self.file
- .parent()
- .map_or(Ok(()), super::files::create_private_dir_all)
- .and_then(|()| {
- let json = serde_json::to_vec_pretty(all).map_err(std::io::Error::other)?;
- super::files::write_private(&temp, &json)?;
- std::fs::rename(&temp, &self.file)
- })
+ super::state_store::save(&self.workspace_dir, STATE, &all)
.map_err(|error| StoreError(error.to_string()))
}
}
@@ -91,7 +72,7 @@ fn queue(workspace_dir: &Path) -> Arc<Queue> {
.or_insert_with(|| {
Arc::new(DeletionQueue::new(
FileStore {
- file: path(workspace_dir),
+ workspace_dir: workspace_dir.to_path_buf(),
},
Backoff::default(),
))
diff --git a/crates/openhuman-core/src/memory/import.rs b/crates/openhuman-core/src/memory/import.rs
index 0aacb2a924..72ae15e249 100644
--- a/crates/openhuman-core/src/memory/import.rs
+++ b/crates/openhuman-core/src/memory/import.rs
@@ -17,7 +17,6 @@ use tinymemory_integrations::import::{
};
use crate::config::Config;
-use crate::security::secret_storage::file_store::write_atomic;
use super::engine;
use super::error::{MemoryError, MemoryResult};
@@ -57,28 +56,32 @@ fn release(workspace_dir: &Path) {
/// mid-write leaves the previous state, never a torn file that reads back as
/// a fresh start and re-sends everything.
pub(crate) struct FileCheckpointStore {
- path: PathBuf,
+ workspace_dir: PathBuf,
}
+const STATE: &str = "import_state";
+
impl FileCheckpointStore {
pub(crate) fn new(workspace_dir: &Path) -> Self {
Self {
- path: workspace_dir.join("memory").join("import_state.json"),
+ workspace_dir: workspace_dir.to_path_buf(),
}
}
}
impl CheckpointStore for FileCheckpointStore {
fn load(&self) -> ImportFile {
- std::fs::read_to_string(&self.path)
- .ok()
- .and_then(|text| serde_json::from_str(&text).ok())
+ super::state_store::load(&self.workspace_dir, STATE)
+ .unwrap_or_else(|error| {
+ tracing::warn!(%error, "[memory:import] reading the checkpoint failed");
+ None
+ })
.unwrap_or_default()
}
fn save(&self, file: &ImportFile) -> Result<(), String> {
- let json = serde_json::to_vec_pretty(file).map_err(|error| error.to_string())?;
- write_atomic(&self.path, &json).map_err(|error| error.to_string())
+ super::state_store::save(&self.workspace_dir, STATE, file)
+ .map_err(|error| error.to_string())
}
}