The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
docs(config): document config loading pipeline
Steven Enamakel1af28e5c4789
diff --git a/crates/openhuman-core/src/config/README.md b/crates/openhuman-core/src/config/README.mdindex fa996e1248..f09d2577a4 100644--- a/crates/openhuman-core/src/config/README.md+++ b/crates/openhuman-core/src/config/README.md@@ -124,7 +124,10 @@ Overrides are applied after parsing and never written back to disk.`SecretStore` ([`schema/load/secrets.rs`](./schema/load/secrets.rs), `enc2:` ChaCha20-Poly1305 values), serializes to TOML, andwrites a temp file that is chmod 0600 before any secret byte is written. It then fsyncs and hands off to[`schema/load/atomic_commit.rs`](./schema/load/atomic_commit.rs), which copies the old file to `config.toml.bak` and renames the temp file-into place. The live config is untouched unless the commit succeeds.+into place. The live config is untouched unless the commit succeeds. That is the file source. On a shared (multi-tenant) storage+backend `save` writes the scope's `config/{scope}` document instead: the secrets are not field-encrypted (the whole body is sealed with+the scope's data key), there is no temp file or `.bak`, and the `[storage]` table is never stored. See+[`schema/load/source/`](./schema/load/source/mod.rs).### Migrationsdiff --git a/crates/openhuman-core/src/config/schema/load/branches.rs b/crates/openhuman-core/src/config/schema/load/branches.rsindex b3ecb5e07a..d1a17eb9c9 100644--- a/crates/openhuman-core/src/config/schema/load/branches.rs+++ b/crates/openhuman-core/src/config/schema/load/branches.rs@@ -7,7 +7,7 @@use super::super::Config;use super::dirs::{default_action_dir, resolve_action_dir, ConfigResolutionSource};use super::env::EnvLookup;-use super::impl_load::{migration_source, parse_config_boxed};+use super::impl_load::migration_source;use super::migrate::{migrate_cloud_provider_slugs, migrate_legacy_inference_url, migrate_legacy_memory_backend,migrate_legacy_memory_sources, migrate_search_settings,diff --git a/crates/openhuman-core/src/config/schema/load/source/document.rs b/crates/openhuman-core/src/config/schema/load/source/document.rsindex be4282546b..189d0d0184 100644--- a/crates/openhuman-core/src/config/schema/load/source/document.rs+++ b/crates/openhuman-core/src/config/schema/load/source/document.rs@@ -70,15 +70,18 @@ impl DocumentConfigSource {.get(CONFIG_COLLECTION, self.scope.as_str()).await.context("read the config document")?;- let Some(sealed) = stored.and_then(|versioned| {- versioned- .doc- .get(BODY_FIELD)- .and_then(|body| body.as_str())- .map(str::to_string)- }) else {+ let Some(versioned) = stored else {return Ok(None);};+ // A document that exists but has no sealed body is corruption, not+ // absence: reading the file instead would let the next save overwrite+ // the tenant's record with stale data.+ let sealed = versioned+ .doc+ .get(BODY_FIELD)+ .and_then(|body| body.as_str())+ .ok_or_else(|| anyhow!("the config document has no sealed `{BODY_FIELD}` body"))?+ .to_string();let key = self.key()?;let plain = crypto::decrypt_enc2(&key, &sealed).map_err(|error| anyhow!("the config document does not decrypt: {error}"))?;@@ -122,12 +125,12 @@ impl ConfigSource for DocumentConfigSource {return self.file.read().await;};// Bootstrap tables come from the file, whatever the document says.- let file_text = match tokio::fs::read_to_string(self.file.path()).await {- Ok(text) => Some(text),- Err(error) if error.kind() == std::io::ErrorKind::NotFound => None,- Err(error) => {- return Err(anyhow!(error).context("read the bootstrap config file"));- }+ // Through the file source, so its corruption recovery (a `.bak`, a+ // non-UTF-8 file renamed aside) applies to the bootstrap read too.+ let file_text = if self.file.exists().await? {+ Some(self.file.read().await?.contents)+ } else {+ None};let contents = apply_bootstrap(&body, file_text.as_deref()).context("apply the bootstrap tables to the config document")?;diff --git a/crates/openhuman-core/src/config/schema/load/source/file.rs b/crates/openhuman-core/src/config/schema/load/source/file.rsindex f02ec65500..a314e7e42b 100644--- a/crates/openhuman-core/src/config/schema/load/source/file.rs+++ b/crates/openhuman-core/src/config/schema/load/source/file.rs@@ -41,7 +41,9 @@ impl ConfigSource for FileConfigSource {}async fn exists(&self) -> Result<bool> {- Ok(self.path.exists())+ fs::try_exists(&self.path)+ .await+ .with_context(|| format!("Failed to check the config file: {}", self.path.display()))}async fn read(&self) -> Result<ConfigRead> {@@ -140,6 +142,14 @@ impl ConfigSource for FileConfigSource {// `commit_replacement` owns the swap, and returns `Err` only while the// old config is still in place — see its docs for why callers that roll// back on `Err` depend on that.- commit_replacement(&temp_path, config_path, parent_dir, &backup_path).await+ let committed =+ commit_replacement(&temp_path, config_path, parent_dir, &backup_path).await;+ if committed.is_err() {+ // The helper removes the staged file after a failed rename but can+ // return earlier (directory recreation); either way it must not be+ // left behind holding the whole config.+ let _ = fs::remove_file(&temp_path).await;+ }+ committed}}