Skip to content

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

chore: merge upstream main; org: prefix on the recorded local install id; pin tinymemory v1.24.0

Steven Enamakeldd82f24beb1b
diff --cc crates/openhuman-core/src/memory/scope.rs
index b43beb7bb6,49b98dcfbd..45a7d55710
--- a/crates/openhuman-core/src/memory/scope.rs
+++ b/crates/openhuman-core/src/memory/scope.rs
@@@ -187,12 -187,12 +187,15 @@@ pub fn layout_is_v3(config: &Config) -
config.memory.layout == MemoryLayoutMode::V3
}
-/// The engine scope root of the person `config` belongs to: `user:<id>`
-/// for a TinyHumans account (its 24-hex id), `user:local-<install id>` for a
+/// The engine scope root of the person `config` belongs to: `org:<id>`
- /// for a TinyHumans account (its 24-hex id), `org:local-<digest>` for a
- /// local session (hashed, so no device name reaches the engine), and `None`
- /// before anyone signs in. Read from where the config lives
- /// (`<root>/users/<id>/config.toml`). One root per person, with no `user:`
- /// segment below it: `user:` names the person's actor ([`actor_of_root`]).
++/// for a TinyHumans account (its 24-hex id), `org:local-<install id>` for a
+ /// local session (a random id recorded in the workspace, or the older
-/// hostname-derived root an existing install already keeps memory under;
-/// see [`super::local_root`]), and `None` before anyone signs in. Read from
-/// where the config lives (`<root>/users/<id>/config.toml`).
++/// hostname-derived id an existing install already keeps memory under; see
++/// [`super::local_root`]), and `None` before anyone signs in. Read from
++/// where the config lives (`<root>/users/<id>/config.toml`). One root per
++/// person, with no `user:` segment below it: `user:` names the person's
++/// actor ([`actor_of_root`]), which is also the retired root an existing
++/// install's memory is still read from during the move.
#[must_use]
pub fn user_root(config: &Config) -> Option<String> {
let dir = config.config_path.parent()?;
@@@ -208,34 -203,13 +206,46 @@@
if id.is_empty() || id == crate::config::PRE_LOGIN_USER_ID {
return None;
}
- account_root(id).or_else(|| super::local_root::resolve(config, id))
++ account_root(id).or_else(|| {
++ super::local_root::resolve(config, id).map(|recorded| org_of_recorded(&recorded))
++ })
+ }
+
-/// `user:<id>` when `id` is a TinyHumans account id (24 hex digits).
++/// `org:<id>` when `id` is a TinyHumans account id (24 hex digits).
+ fn account_root(id: &str) -> Option<String> {
let account = id.len() == 24 && id.bytes().all(|b| b.is_ascii_hexdigit());
- if account {
- return Some(format!("{ROOT_TYPE}:{}", id.to_ascii_lowercase()));
- }
- let digest: String = Sha256::digest(id.as_bytes())
- .iter()
- .take(8)
- .map(|byte| format!("{byte:02x}"))
- .collect();
- Some(format!("{ROOT_TYPE}:local-{digest}"))
- account.then(|| format!("user:{}", id.to_ascii_lowercase()))
++ account.then(|| format!("{ROOT_TYPE}:{}", id.to_ascii_lowercase()))
+}
+
+/// The scope type of a person's root.
+const ROOT_TYPE: &str = "org";
+
++/// A recorded local root (`user:local-<id>`, the form the record file keeps
++/// so installs recorded before `org:` roots read back) as the person's
++/// `org:local-<id>` root. The `user:local-<id>` it came from is exactly the
++/// actor [`actor_of_root`] names, so memory an existing install keeps under
++/// that root (the old hostname-derived one included) is the retired root
++/// read during the move.
++fn org_of_recorded(recorded: &str) -> String {
++ match recorded.strip_prefix("user:") {
++ Some(id) => format!("{ROOT_TYPE}:{id}"),
++ None => recorded.to_string(),
++ }
++}
++
+/// The actor that owns the person's root `root` (`org:<id>` → `user:<id>`).
+/// It is also where layout v3 rooted that person before `org:` roots: the
+/// retired root read during the move, and the account a legacy-tree claim
+/// names.
+#[must_use]
+pub fn actor_of_root(root: &str) -> String {
+ match root
+ .strip_prefix(ROOT_TYPE)
+ .and_then(|rest| rest.strip_prefix(':'))
+ {
+ Some(id) => format!("user:{id}"),
+ None => root.to_string(),
+ }
}
/// Switches the memory of the person `config` belongs to to layout v3:
diff --cc crates/openhuman-core/src/memory/scope_tests.rs
index 0ccd5607a8,9dc9479939..8019870a77
--- a/crates/openhuman-core/src/memory/scope_tests.rs
+++ b/crates/openhuman-core/src/memory/scope_tests.rs
@@@ -113,21 -113,33 +113,53 @@@ fn validate_root_accepts_nodes_and_refu
}
#[test]
- fn a_user_root_is_the_account_id_or_a_hashed_local_id() {
+ fn an_account_root_is_the_lowercased_account_id() {
assert_eq!(
- user_root_for("6512AB0F6512ab0f6512ab0f").as_deref(),
+ account_root("6512AB0F6512ab0f6512ab0f").as_deref(),
- Some("user:6512ab0f6512ab0f6512ab0f")
+ Some("org:6512ab0f6512ab0f6512ab0f")
);
- let local = user_root_for("local-megamind-macbook").unwrap();
- assert!(local.starts_with("org:local-"), "{local}");
- assert_eq!(local.len(), "org:local-".len() + 16);
- assert!(!local.contains("user:"), "{local}");
- assert!(!local.contains("megamind"), "no device name: {local}");
- assert_eq!(Some(local), user_root_for("local-megamind-macbook"));
- assert_eq!(user_root_for(crate::config::PRE_LOGIN_USER_ID), None);
- assert_eq!(user_root_for(""), None);
+ assert_eq!(account_root("local-megamind-macbook"), None);
+ assert_eq!(account_root(""), None);
+ }
+
+ #[test]
+ fn a_local_session_root_is_a_recorded_install_id_not_the_hostname() {
+ let tmp = tempfile::tempdir().unwrap();
+ let user_dir = tmp.path().join("users").join("local-megamind-macbook");
+ let mut config = Config::default();
+ config.config_path = user_dir.join("config.toml");
+ config.workspace_dir = user_dir.join("workspace");
+ let root = user_root(&config).unwrap();
- assert!(root.starts_with("user:local-"), "{root}");
- assert!(!root.contains("megamind"), "{root}");
++ assert!(root.starts_with("org:local-"), "{root}");
++ assert!(
++ !root.contains("user:") && !root.contains("megamind"),
++ "{root}"
++ );
+ assert_ne!(
- root,
++ actor_of_root(&root),
+ crate::memory::local_root::legacy_root("local-megamind-macbook"),
+ "a fresh install does not derive its root from the hostname"
+ );
+ assert_eq!(user_root(&config).as_deref(), Some(root.as_str()));
+ }
+
++#[test]
++fn an_install_with_a_recorded_legacy_root_keeps_resolving_to_it() {
++ let tmp = tempfile::tempdir().unwrap();
++ let user_dir = tmp.path().join("users").join("local-megamind-macbook");
++ let mut config = Config::default();
++ config.config_path = user_dir.join("config.toml");
++ config.workspace_dir = user_dir.join("workspace");
++ let legacy = crate::memory::local_root::legacy_root("local-megamind-macbook");
++ let file = crate::memory::local_root::path(&config.workspace_dir);
++ std::fs::create_dir_all(file.parent().unwrap()).unwrap();
++ std::fs::write(&file, format!(r#"{{"root":"{legacy}","origin":"legacy"}}"#)).unwrap();
++ let root = user_root(&config).unwrap();
++ assert!(root.starts_with("org:local-"), "{root}");
++ // The old root is the actor: the retired root that is still read.
++ assert_eq!(actor_of_root(&root), legacy);
+}
+
#[test]
fn the_user_root_is_read_from_where_the_config_lives() {
let mut config = Config::default();
@@@ -168,22 -180,3 +200,17 @@@ fn layout_v3_pools_every_agents_chats_a
let team = MemoryIdentity::team_member("acme", "writer").resolve(&config);
assert_eq!(chat_node(&team.layout), ns("team:acme/ws:main"));
}
+
+#[test]
+fn a_roots_actor_is_its_user_spelling() {
+ assert_eq!(
+ actor_of_root("org:6512ab0f6512ab0f6512ab0f"),
+ "user:6512ab0f6512ab0f6512ab0f"
+ );
+ assert_eq!(
+ actor_of_root("org:local-0011223344556677"),
+ "user:local-0011223344556677"
+ );
- // The actor of the earlier root is the same account.
- assert_eq!(
- actor_of_root(&user_root_for("local-megamind-macbook").unwrap()),
- user_root_for("local-megamind-macbook")
- .unwrap()
- .replacen("org:", "user:", 1)
- );
++ // A non-org root is its own actor.
++ assert_eq!(actor_of_root("user:local-aa"), "user:local-aa");
+}