Skip to content

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

fix(memory): build the migration without flows; switch the migrated person's config

M3gA-Mindf4c10aa351f3
diff --git a/crates/openhuman-core/src/memory/layout_migration/app_host.rs b/crates/openhuman-core/src/memory/layout_migration/app_host.rs
index 9ce593661f..dcefd6f123 100644
--- a/crates/openhuman-core/src/memory/layout_migration/app_host.rs
+++ b/crates/openhuman-core/src/memory/layout_migration/app_host.rs
@@ -44,8 +44,10 @@ impl LayoutHost for AppHost {
scope::layout_is_v3(config)
}
- async fn switch(&self, _config: &Config) -> MemoryResult<()> {
- scope::switch_to_v3().await
+ async fn switch(&self, config: &Config) -> MemoryResult<()> {
+ // This person's own config file, loaded fresh: never the active
+ // account's (someone else's after an account switch mid-move).
+ scope::switch_to_v3(config).await
}
async fn free_now(&self, config: &Config) -> bool {
diff --git a/crates/openhuman-core/src/memory/layout_migration/app_host_tests.rs b/crates/openhuman-core/src/memory/layout_migration/app_host_tests.rs
index 68e823bda8..e00768642e 100644
--- a/crates/openhuman-core/src/memory/layout_migration/app_host_tests.rs
+++ b/crates/openhuman-core/src/memory/layout_migration/app_host_tests.rs
@@ -101,3 +101,22 @@ fn every_account_on_a_self_hosted_engine_shares_one_claim() {
let hosted = signed_in(&tmp);
assert!(AppHost.legacy_claim(&hosted).unwrap().is_none());
}
+
+#[tokio::test]
+async fn the_switch_writes_the_migrated_persons_own_config_fresh() {
+ let tmp = tempfile::tempdir().unwrap();
+ let snapshot = signed_in(&tmp);
+ std::fs::create_dir_all(snapshot.config_path.parent().unwrap()).unwrap();
+ // A setting changed on disk after the run took its copy.
+ let mut later = snapshot.clone();
+ later.memory.agent_id = Some("changed-later".to_string());
+ later.save().await.unwrap();
+
+ AppHost.switch(&snapshot).await.unwrap();
+
+ let saved = Config::load_from_config_path(&snapshot.config_path, &snapshot.workspace_dir)
+ .await
+ .unwrap();
+ assert!(crate::memory::scope::layout_is_v3(&saved));
+ assert_eq!(saved.memory.agent_id.as_deref(), Some("changed-later"));
+}
diff --git a/crates/openhuman-core/src/memory/layout_migration/host.rs b/crates/openhuman-core/src/memory/layout_migration/host.rs
index a0c1b6c71e..5ab9efab47 100644
--- a/crates/openhuman-core/src/memory/layout_migration/host.rs
+++ b/crates/openhuman-core/src/memory/layout_migration/host.rs
@@ -35,9 +35,10 @@ pub trait LayoutHost: Send + Sync {
fn is_switched(&self, config: &Config) -> bool;
/// Moves reads and writes to the per-user tree: persists the layout
- /// setting and drops the cached engines. The real host awaits
- /// `memory::scope::switch_to_v3()`, which loads the config fresh, so a
- /// setting the user changed during a long migration is never reverted.
+ /// setting and drops the cached engines. The real host loads the migrated
+ /// person's own config file fresh, so a setting changed during a long
+ /// migration is never reverted and an account switch mid-move never
+ /// writes another person's config.
///
/// # Errors
///
diff --git a/crates/openhuman-core/src/memory/layout_migration/map.rs b/crates/openhuman-core/src/memory/layout_migration/map.rs
index 7ec6fbc68a..bb8abace98 100644
--- a/crates/openhuman-core/src/memory/layout_migration/map.rs
+++ b/crates/openhuman-core/src/memory/layout_migration/map.rs
@@ -17,10 +17,14 @@
use tinymemory_api::{ItemKind, Namespace, SegmentKind, StoreItem};
use tinymemory_tools::MemoryLayout;
-use crate::flows::FLOWS_TAG;
use crate::memory::brain::{file_into, legacy_brain_node};
use crate::memory::error::MemoryResult;
+/// The tag every workflow item carries (`crate::flows::FLOWS_TAG`). Kept here
+/// rather than imported: legacy items carry it whatever features this build
+/// has, so placing them must not depend on the `flows` feature.
+const FLOWS_TAG: &str = "flows";
+
/// Where workflow items go.
#[derive(Clone, Copy)]
pub enum FlowPlacement {
diff --git a/crates/openhuman-core/src/memory/layout_migration/map_tests.rs b/crates/openhuman-core/src/memory/layout_migration/map_tests.rs
index b91e3d90ab..8ecc259683 100644
--- a/crates/openhuman-core/src/memory/layout_migration/map_tests.rs
+++ b/crates/openhuman-core/src/memory/layout_migration/map_tests.rs
@@ -169,3 +169,9 @@ fn a_hosts_root_is_kept_below_the_wire_root() {
"a node outside the host's root is not its brain"
);
}
+
+#[cfg(feature = "flows")]
+#[test]
+fn the_workflow_tag_is_the_one_flows_writes() {
+ assert_eq!(FLOWS_TAG, crate::flows::FLOWS_TAG);
+}