Skip to content

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

refactor(config): split versioned write from plain write

Steven Enamakel96a50597e847
diff --git a/crates/openhuman-core/src/config/schema/load/impl_load.rs b/crates/openhuman-core/src/config/schema/load/impl_load.rs
index a09a405e57..d3bf50b45e 100644
--- a/crates/openhuman-core/src/config/schema/load/impl_load.rs
+++ b/crates/openhuman-core/src/config/schema/load/impl_load.rs
@@ -581,7 +581,7 @@ impl Config {
tracing::debug!(source = source.label(), "[config] saving config");
let expected = *config_to_save.document_version.lock().unwrap();
- let version = source.write(&toml_str, expected).await?;
+ let version = source.write_versioned(&toml_str, expected).await?;
*self.document_version.lock().unwrap() = version;
Ok(())
diff --git a/crates/openhuman-core/src/config/schema/load/source/document.rs b/crates/openhuman-core/src/config/schema/load/source/document.rs
index cfc6383f2c..31e0985be0 100644
--- a/crates/openhuman-core/src/config/schema/load/source/document.rs
+++ b/crates/openhuman-core/src/config/schema/load/source/document.rs
@@ -181,7 +181,12 @@ impl ConfigSource for DocumentConfigSource {
})
}
- async fn write(&self, toml: &str, expected: Option<tinystoragedrivers::Version>) -> Result<Option<tinystoragedrivers::Version>> {
+ async fn write(&self, toml: &str) -> Result<()> {
+ self.write_versioned(toml, None).await?;
+ Ok(())
+ }
+
+ async fn write_versioned(&self, toml: &str, expected: Option<tinystoragedrivers::Version>) -> Result<Option<tinystoragedrivers::Version>> {
let body = zeroize::Zeroizing::new(
strip_bootstrap(toml).context("strip bootstrap tables from the config")?,
);
diff --git a/crates/openhuman-core/src/config/schema/load/source/file.rs b/crates/openhuman-core/src/config/schema/load/source/file.rs
index 77f3995e84..07d2703d2e 100644
--- a/crates/openhuman-core/src/config/schema/load/source/file.rs
+++ b/crates/openhuman-core/src/config/schema/load/source/file.rs
@@ -52,11 +52,10 @@ impl ConfigSource for FileConfigSource {
contents,
recovered,
from_document: false,
- document_version: None,
})
}
- async fn write(&self, toml_str: &str, _expected: Option<tinystoragedrivers::Version>) -> Result<Option<tinystoragedrivers::Version>> {
+ async fn write(&self, toml_str: &str) -> Result<()> {
let config_path = &self.path;
let parent_dir = config_path
.parent()
@@ -151,6 +150,6 @@ impl ConfigSource for FileConfigSource {
// left behind holding the whole config.
let _ = fs::remove_file(&temp_path).await;
}
- committed.map(|()| None)
+ committed
}
}
diff --git a/crates/openhuman-core/src/config/schema/load/source/mod.rs b/crates/openhuman-core/src/config/schema/load/source/mod.rs
index 03400bd591..92de4641ba 100644
--- a/crates/openhuman-core/src/config/schema/load/source/mod.rs
+++ b/crates/openhuman-core/src/config/schema/load/source/mod.rs
@@ -83,7 +83,12 @@ pub(crate) trait ConfigSource: Send + Sync {
/// Replace the config text. Returns `Err` only while the previous config is
/// still the live one, so callers may roll back in-memory state on `Err`.
- async fn write(&self, toml: &str, expected: Option<tinystoragedrivers::Version>) -> Result<Option<tinystoragedrivers::Version>>;
+ async fn write(&self, toml: &str) -> Result<()>;
+
+ async fn write_versioned(&self, toml: &str, _expected: Option<tinystoragedrivers::Version>) -> Result<Option<tinystoragedrivers::Version>> {
+ self.write(toml).await?;
+ Ok(None)
+ }
}
/// The source for the config at `config_path`.