Skip to content

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

feat(config): add saas-scoped config loading

Steven Enamakel1db04dedc914
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 e3e2013467..16f86030df 100644
--- a/crates/openhuman-core/src/config/schema/load/impl_load.rs
+++ b/crates/openhuman-core/src/config/schema/load/impl_load.rs
@@ -270,6 +270,9 @@ async fn describe_config_ownership(_path: &Path) -> String {
impl Config {
pub async fn load_or_init() -> Result<Self> {
+ if let Some(scoped) = super::saas_scope::saas_scoped_config() {
+ return scoped;
+ }
let (default_openhuman_dir, default_workspace_dir) = default_config_and_workspace_dirs()?;
Self::load_or_init_with_env_lookup(
&default_openhuman_dir,
diff --git a/crates/openhuman-core/src/config/schema/load/mod.rs b/crates/openhuman-core/src/config/schema/load/mod.rs
index cb99bf5607..ec4eee078b 100644
--- a/crates/openhuman-core/src/config/schema/load/mod.rs
+++ b/crates/openhuman-core/src/config/schema/load/mod.rs
@@ -7,6 +7,7 @@ mod env;
mod env_overlay;
mod impl_load;
mod migrate;
+mod saas_scope;
mod secrets;
pub use active_workspace::active_workspace_dir_cached;
diff --git a/crates/openhuman-core/src/config/schema/load/saas_scope.rs b/crates/openhuman-core/src/config/schema/load/saas_scope.rs
new file mode 100644
index 0000000000..2310eb2f2e
--- /dev/null
+++ b/crates/openhuman-core/src/config/schema/load/saas_scope.rs
@@ -0,0 +1,37 @@
+//! Where `Config::load_or_init` gets its config in SaaS mode.
+//!
+//! A single-user process resolves its config from the process: the
+//! `OPENHUMAN_WORKSPACE` override, `active_user.toml`, the workspace marker.
+//! A SaaS process serves many users, so any of those would hand one user's
+//! work another's state — or the host's. There, the config is always the
+//! one the current context carries: a user agent's forced config inside that
+//! agent's scope, the operator's under the operator plane. With no context at
+//! all, loading fails instead of guessing.
+
+use super::super::Config;
+
+/// The config a SaaS process loads, or `None` in single-user mode.
+pub(super) fn saas_scoped_config() -> Option<anyhow::Result<Config>> {
+ resolve(
+ crate::core::runtime::is_saas(),
+ crate::core::runtime::CoreContext::current_embedder_config(),
+ )
+}
+
+/// [`saas_scoped_config`] as a pure function of the mode and the context's
+/// config, so the rule is testable without locking the test process to SaaS.
+pub(super) fn resolve(saas: bool, scoped: Option<Config>) -> Option<anyhow::Result<Config>> {
+ if !saas {
+ return None;
+ }
+ Some(scoped.ok_or_else(|| {
+ log::error!("[saas][config] Config::load_or_init called outside any agent or operator scope");
+ anyhow::anyhow!(
+ "[saas] no config in scope: SaaS work must run under a user agent's or the operator's context"
+ )
+ }))
+}
+
+#[cfg(test)]
+#[path = "saas_scope_tests.rs"]
+mod tests;
diff --git a/crates/openhuman-core/src/config/schema/load/saas_scope_tests.rs b/crates/openhuman-core/src/config/schema/load/saas_scope_tests.rs
new file mode 100644
index 0000000000..125539d990
--- /dev/null
+++ b/crates/openhuman-core/src/config/schema/load/saas_scope_tests.rs
@@ -0,0 +1,26 @@
+use super::*;
+
+#[test]
+fn single_user_mode_keeps_process_resolution() {
+ assert!(resolve(false, None).is_none());
+ assert!(resolve(false, Some(Config::default())).is_none());
+}
+
+#[test]
+fn saas_mode_returns_the_scoped_config() {
+ let scoped = Config {
+ workspace_dir: "/srv/oh/agents/u-1/workspace".into(),
+ ..Config::default()
+ };
+ let loaded = resolve(true, Some(scoped)).unwrap().unwrap();
+ assert_eq!(
+ loaded.workspace_dir,
+ std::path::PathBuf::from("/srv/oh/agents/u-1/workspace")
+ );
+}
+
+#[test]
+fn saas_mode_without_a_scope_fails_instead_of_guessing() {
+ let err = resolve(true, None).unwrap().unwrap_err();
+ assert!(err.to_string().contains("no config in scope"), "{err}");
+}