Skip to content

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

fix(config): preserve legacy memory migration source

Steven Enamakel7b25f107544c
diff --git a/crates/openhuman-core/src/config/schema/load/branches.rs b/crates/openhuman-core/src/config/schema/load/branches.rs
index 88940eb61f..2001465c6b 100644
--- a/crates/openhuman-core/src/config/schema/load/branches.rs
+++ b/crates/openhuman-core/src/config/schema/load/branches.rs
@@ -7,7 +7,9 @@
use super::super::Config;
use super::dirs::{default_action_dir, resolve_action_dir, ConfigResolutionSource};
use super::env::EnvLookup;
-use super::impl_load::{parse_config_boxed, read_config_with_recovery_or_default};
+use super::impl_load::{
+ migration_source, parse_config_boxed, read_config_with_recovery_or_default,
+};
use super::migrate::{
migrate_cloud_provider_slugs, migrate_legacy_inference_url, migrate_legacy_memory_backend,
migrate_legacy_memory_sources, migrate_search_settings,
@@ -169,7 +171,8 @@ impl Config {
// later override can never mask that recovery happened.
config.recovered_from_corruption = config_was_corrupted;
migrate_legacy_inference_url(&mut config);
- migrate_legacy_memory_backend(&mut config, &contents);
+ let migration_raw = migration_source(&config_path, &contents).await;
+ migrate_legacy_memory_backend(&mut config, &migration_raw);
migrate_cloud_provider_slugs(&mut config);
migrate_search_settings(&mut config);
migrate_legacy_memory_sources(&mut config);
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 d7a115347f..ad4b87015b 100644
--- a/crates/openhuman-core/src/config/schema/load/impl_load.rs
+++ b/crates/openhuman-core/src/config/schema/load/impl_load.rs
@@ -209,6 +209,19 @@ pub(super) async fn parse_config_boxed(config_path: &Path, contents: &str) -> (B
(default_config_boxed(), true)
}
+/// Return the source text that should be inspected by migrations. A readable
+/// backup may be the source used to build the config when the primary TOML is
+/// malformed.
+pub(super) async fn migration_source(config_path: &Path, contents: &str) -> String {
+ if toml::from_str::<toml::Value>(contents).is_ok() {
+ return contents.to_owned();
+ }
+ let backup_path = config_path.with_extension("toml.bak");
+ fs::read_to_string(backup_path)
+ .await
+ .unwrap_or_else(|_| contents.to_owned())
+}
+
async fn parse_toml_off_worker(contents: String) -> Result<Box<Config>, String> {
match tokio::task::spawn_blocking(move || toml::from_str::<Config>(&contents).map(Box::new))
.await
@@ -370,10 +383,11 @@ impl Config {
let (raw, _read_was_recovered) =
Box::pin(read_config_with_recovery_or_default(&config_path)).await?;
let (mut config, _was_corrupted) = parse_config_with_recovery(&config_path, &raw).await;
- config.config_path = config_path;
+ config.config_path = config_path.clone();
config.workspace_dir = workspace_dir;
config.action_dir = resolve_action_dir(&config.action_dir_override);
- migrate_legacy_memory_backend(&mut config, &raw);
+ let migration_raw = migration_source(&config_path, &raw).await;
+ migrate_legacy_memory_backend(&mut config, &migration_raw);
config.apply_env_overrides();
// Debug-dump path is read-only; ignore the migration signal (the
// authoritative `load_or_init` path persists upgraded secrets).
@@ -423,12 +437,13 @@ impl Config {
parse_config_with_recovery(&config_path, &raw).await
};
let config_was_corrupted = config_was_corrupted || read_was_recovered;
- config.config_path = config_path;
+ config.config_path = config_path.clone();
config.workspace_dir = workspace_dir;
config.action_dir = resolve_action_dir(&config.action_dir_override);
config.recovered_from_corruption = config_was_corrupted;
migrate_legacy_inference_url(&mut config);
- migrate_legacy_memory_backend(&mut config, &raw);
+ let migration_raw = migration_source(&config_path, &raw).await;
+ migrate_legacy_memory_backend(&mut config, &migration_raw);
migrate_cloud_provider_slugs(&mut config);
migrate_search_settings(&mut config);
config.apply_env_overrides_from(&ProcessEnvWithoutWorkspace);
diff --git a/crates/openhuman-core/src/config/schema/load/migrate.rs b/crates/openhuman-core/src/config/schema/load/migrate.rs
index fe1f2c34ca..5828203130 100644
--- a/crates/openhuman-core/src/config/schema/load/migrate.rs
+++ b/crates/openhuman-core/src/config/schema/load/migrate.rs
@@ -256,7 +256,6 @@ pub(crate) fn migrate_legacy_memory_backend(config: &mut Config, raw: &str) {
config.memory.engine.clear();
config.memory.legacy_backend = Some(backend.to_string());
tracing::warn!(
- backend,
"[config] legacy memory backend is unsupported; select an explicit v2 memory engine"
);
}
diff --git a/crates/openhuman-core/src/config/schema/memory.rs b/crates/openhuman-core/src/config/schema/memory.rs
index c5c0ceadb7..b8fcd94f6b 100644
--- a/crates/openhuman-core/src/config/schema/memory.rs
+++ b/crates/openhuman-core/src/config/schema/memory.rs
@@ -72,7 +72,7 @@ pub const DEFAULT_MEMORY_ENGINE: &str = "tinyhumans";
pub struct MemoryConfig {
/// The selected engine id (`tinyhumans` or `cortexdb`).
pub engine: String,
- #[serde(skip)]
+ #[serde(rename = "backend", default, skip_serializing)]
#[schemars(skip)]
pub(crate) legacy_backend: Option<String>,
/// Per-engine settings, keyed by engine id.