Skip to content

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

fix(config): drop over-strict exists-guard + route app_state twin through shared resolver\n\nReview follow-ups (#6079):\n- Remove the exists() guard on the legacy workspace-basename arm: it regressed\n the fresh legacy layout (<proj>/workspace with no sibling yet nested the\n workspace). The new modern-layout branch already intercepts the doubled-path\n case, so the guard was unnecessary; revert that arm to its original\n unconditional return. Fixes CodeRabbit's file-vs-dir concern (no bare exists()\n probe remains) as a side effect.\n- config_dir_for_workspace_env in desktop/app_state reimplemented the same\n workspace->config-dir mapping and produced the identical doubled path, mis-\n scoping revalidated-session credentials. Route it through the shared\n resolve_config_dir_for_workspace so both agree; add regression tests.\n

shanu837b468ff8b7
diff --git a/src/openhuman/config/schema/load/dirs.rs b/src/openhuman/config/schema/load/dirs.rs
index 101438a6de..8d811f1929 100644
--- a/src/openhuman/config/schema/load/dirs.rs
+++ b/src/openhuman/config/schema/load/dirs.rs
@@ -290,17 +290,18 @@ pub(crate) fn resolve_config_dir_for_workspace(workspace_dir: &Path) -> (PathBuf
let legacy_config_dir = parent.map(|parent| parent.join(".openhuman"));
if let Some(legacy_dir) = legacy_config_dir {
- // Legacy sibling layout: `<something>/workspace` with config living in a
- // sibling `<something>/.openhuman`.
- if legacy_dir.join("config.toml").exists() {
- return (legacy_dir, workspace_config_dir);
- }
-
- // Same layout without a config.toml yet, but only when the sibling
- // `.openhuman` actually exists — never return a non-existent doubled
- // path (the original #6079 bug: this arm fired for any `workspace`
- // basename, so `~/.openhuman/workspace` produced `~/.openhuman/.openhuman`).
- if has_workspace_basename && legacy_dir.exists() {
+ // Legacy sibling layout: `<proj>/workspace` with config living in a
+ // sibling `<proj>/.openhuman`. Return the sibling unconditionally,
+ // including on a fresh volume where `<proj>/.openhuman` does not exist
+ // yet — that is where `config::load` writes and reads config for this
+ // layout, so nesting the workspace inside itself (the fall-through
+ // below) would strand it.
+ //
+ // This arm can no longer reintroduce the #6079 doubling: the modern
+ // layout above already intercepts `~/.openhuman/workspace` (parent IS
+ // the config dir) before control reaches here, so a `workspace`
+ // basename whose parent is the config dir never falls into this arm.
+ if legacy_dir.join("config.toml").exists() || has_workspace_basename {
return (legacy_dir, workspace_config_dir);
}
}
diff --git a/src/openhuman/config/schema/load_tests_part_01_tests.rs b/src/openhuman/config/schema/load_tests_part_01_tests.rs
index c61cf60afb..6edbc55f9f 100644
--- a/src/openhuman/config/schema/load_tests_part_01_tests.rs
+++ b/src/openhuman/config/schema/load_tests_part_01_tests.rs
@@ -608,19 +608,26 @@ fn resolve_config_dir_for_workspace_legacy_sibling_layout_is_preserved() {
}
#[test]
-fn resolve_config_dir_for_workspace_workspace_basename_without_config_falls_through() {
- // Basename is `workspace`, but the parent is neither `.openhuman` nor has a
- // real sibling `.openhuman/config.toml`, and nothing exists on disk. It must
- // fall through to `(ws, ws/workspace)` — never a doubled `.openhuman/.openhuman`.
+fn resolve_config_dir_for_workspace_workspace_basename_resolves_to_fresh_legacy_sibling() {
+ // Legacy layout on a fresh volume: basename is `workspace`, the parent is
+ // NOT the `.openhuman` config dir (so the modern arm does not fire), and the
+ // sibling `.openhuman` does not exist yet. This must resolve to the sibling
+ // `<proj>/.openhuman` — where `config::load` writes config for this layout —
+ // NOT nest the workspace inside itself as `ws/workspace`. Regression guard
+ // for the over-corrected `.exists()` gate (Codex P2).
let _g = env_lock();
let ws = PathBuf::from("/home/test/some-project/workspace");
let (config_dir, workspace_dir) = resolve_config_dir_for_workspace(&ws);
- assert_eq!(config_dir, ws);
- assert_eq!(workspace_dir, ws.join("workspace"));
- assert_ne!(
+ assert_eq!(
config_dir,
PathBuf::from("/home/test/some-project/.openhuman"),
- "a non-existent sibling .openhuman must not be returned"
+ "a fresh legacy workspace must resolve to its sibling .openhuman, not nest itself"
+ );
+ assert_eq!(workspace_dir, ws);
+ assert_ne!(
+ config_dir,
+ PathBuf::from("/home/test/some-project/.openhuman/.openhuman"),
+ "must never return the doubled .openhuman/.openhuman path"
);
}
diff --git a/src/openhuman/desktop/app_state/ops_part_01.rs b/src/openhuman/desktop/app_state/ops_part_01.rs
index c3e38e5bff..37097399c2 100644
--- a/src/openhuman/desktop/app_state/ops_part_01.rs
+++ b/src/openhuman/desktop/app_state/ops_part_01.rs
@@ -638,24 +638,18 @@ fn config_dir_for_workspace_env() -> Option<PathBuf> {
return None;
}
+ // Resolve through the SAME workspace→config-dir mapping `config::load` uses
+ // (`resolve_config_dir_for_workspace`), not a private reimplementation.
+ // A copy here drifts from the loader: it independently doubled
+ // `~/.openhuman/workspace` into `~/.openhuman/.openhuman`, so
+ // `config_is_workspace_env_scoped` compared that against the loader's real
+ // `~/.openhuman` and returned false, mis-scoping credentials on session
+ // revalidation (#6079). Delegating keeps the two in lockstep, including the
+ // modern-layout recognition that fixes the doubling.
let workspace_dir = PathBuf::from(workspace);
- let workspace_config_dir = workspace_dir.clone();
- if workspace_config_dir.join("config.toml").exists() {
- return Some(workspace_config_dir);
- }
-
- if let Some(parent) = workspace_dir.parent() {
- let legacy_dir = parent.join(".openhuman");
- if legacy_dir.join("config.toml").exists()
- || workspace_dir
- .file_name()
- .is_some_and(|name| name == std::ffi::OsStr::new("workspace"))
- {
- return Some(legacy_dir);
- }
- }
-
- Some(workspace_config_dir)
+ let (config_dir, _workspace_dir) =
+ crate::openhuman::config::resolve_config_dir_for_workspace(&workspace_dir);
+ Some(config_dir)
}
fn config_is_workspace_env_scoped(config: &Config) -> bool {
diff --git a/src/openhuman/desktop/app_state/ops_tests.rs b/src/openhuman/desktop/app_state/ops_tests.rs
index b25772469d..7f0f004e12 100644
--- a/src/openhuman/desktop/app_state/ops_tests.rs
+++ b/src/openhuman/desktop/app_state/ops_tests.rs
@@ -486,3 +486,63 @@ async fn current_user_fetch_carries_the_product_identity() {
crate::api::product::reset_product_identity_for_test();
}
+
+// Serialises the `OPENHUMAN_WORKSPACE` env mutations below so two of these tests
+// can't race each other on the process-global var.
+static WORKSPACE_ENV_TEST_LOCK: TestLazy<TestMutex<()>> = TestLazy::new(|| TestMutex::new(()));
+
+/// The #6079 twin: `config_dir_for_workspace_env` must resolve
+/// `~/.openhuman/workspace` to `~/.openhuman` (the real config dir), NOT the
+/// doubled `~/.openhuman/.openhuman`. The private reimplementation this replaced
+/// produced the doubled path, so `config_is_workspace_env_scoped` disagreed with
+/// the loader and mis-scoped credentials on session revalidation. Delegating to
+/// the shared `resolve_config_dir_for_workspace` keeps the two in lockstep.
+#[test]
+fn config_dir_for_workspace_env_modern_layout_does_not_double_openhuman() {
+ let _g = WORKSPACE_ENV_TEST_LOCK.lock();
+ std::env::set_var("OPENHUMAN_WORKSPACE", "/home/test/.openhuman/workspace");
+ let resolved = config_dir_for_workspace_env();
+ std::env::remove_var("OPENHUMAN_WORKSPACE");
+
+ assert_eq!(resolved, Some(PathBuf::from("/home/test/.openhuman")));
+ assert_ne!(
+ resolved,
+ Some(PathBuf::from("/home/test/.openhuman/.openhuman")),
+ "must never return the doubled .openhuman/.openhuman path"
+ );
+}
+
+/// A fresh legacy layout (`<proj>/workspace` with no sibling `.openhuman` on
+/// disk) must resolve to the sibling `<proj>/.openhuman`, matching the loader —
+/// not nest the workspace inside itself. Guards the same seam as the
+/// `dirs.rs` fresh-legacy test, one level up through the app_state resolver.
+#[test]
+fn config_dir_for_workspace_env_fresh_legacy_resolves_to_sibling() {
+ let _g = WORKSPACE_ENV_TEST_LOCK.lock();
+ std::env::set_var("OPENHUMAN_WORKSPACE", "/home/test/some-project/workspace");
+ let resolved = config_dir_for_workspace_env();
+ std::env::remove_var("OPENHUMAN_WORKSPACE");
+
+ assert_eq!(
+ resolved,
+ Some(PathBuf::from("/home/test/some-project/.openhuman")),
+ "a fresh legacy workspace must resolve to its sibling .openhuman"
+ );
+}
+
+/// An unset / empty `OPENHUMAN_WORKSPACE` yields `None` so the caller falls back
+/// to user-scoped resolution rather than treating the empty string as a path.
+#[test]
+fn config_dir_for_workspace_env_none_when_unset_or_empty() {
+ let _g = WORKSPACE_ENV_TEST_LOCK.lock();
+ std::env::remove_var("OPENHUMAN_WORKSPACE");
+ assert_eq!(config_dir_for_workspace_env(), None);
+
+ std::env::set_var("OPENHUMAN_WORKSPACE", "");
+ let resolved = config_dir_for_workspace_env();
+ std::env::remove_var("OPENHUMAN_WORKSPACE");
+ assert_eq!(
+ resolved, None,
+ "an empty override must not be treated as a path"
+ );
+}
diff --git a/src/openhuman/inference/embeddings/cloud_adapter_tests.rs b/src/openhuman/inference/embeddings/cloud_adapter_tests.rs
index ba87e49476..3b32a727d1 100644
--- a/src/openhuman/inference/embeddings/cloud_adapter_tests.rs
+++ b/src/openhuman/inference/embeddings/cloud_adapter_tests.rs
@@ -75,9 +75,12 @@ fn default_scope_falls_back_to_the_pre_login_user_dir() {
#[test]
fn env_workspace_scope_is_the_config_dir_not_the_raw_workspace() {
// Legacy sibling layout: `<X>/workspace` with credentials in `<X>/.openhuman`.
- // The resolver only maps a `workspace`-basename override to a sibling
- // `.openhuman` when that sibling actually exists (#6079 guard — it must never
- // fabricate a non-existent doubled path), so create it on a real temp dir.
+ // A `workspace`-basename override whose parent is not the `.openhuman` config
+ // dir maps to the sibling `<X>/.openhuman` (where `auth-profiles.json` lives).
+ // The modern-layout arm intercepts the `~/.openhuman/workspace` shape before
+ // this one, so this arm can no longer produce a doubled path (#6079). A real
+ // temp dir is used because `default_state_dir` operates on real filesystem
+ // layouts; the sibling need not pre-exist for resolution to pick it.
let root = tempfile::tempdir().unwrap();
let base = root.path();
let workspace = base.join("workspace");