Skip to content

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

fix(config): resolve relative paths against the config file directory

Steven Enamakelcd361886e03f
diff --git a/crates/openhuman-core/src/config/ops/loader/load.rs b/crates/openhuman-core/src/config/ops/loader/load.rs
index 6e27f20a7f..ccec132018 100644
--- a/crates/openhuman-core/src/config/ops/loader/load.rs
+++ b/crates/openhuman-core/src/config/ops/loader/load.rs
@@ -27,15 +27,18 @@ const CONFIG_LOAD_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(
/// itself would still run against whatever the process-global workspace
/// resolution found. Normalization still runs, because that is a shaping step
/// handlers depend on, not a re-read.
-pub async fn load_config_with_timeout() -> Result<Config, String> {
- // SaaS reads only the task's own scope, as `Config::load_or_init` does, so
- // a task that lost its user scope fails rather than getting the operator's.
- let scoped = if crate::core::runtime::is_saas() {
- crate::core::runtime::CoreContext::scoped().and_then(|ctx| ctx.embedder_config().cloned())
- } else {
- crate::core::runtime::context::CoreContext::current_embedder_config()
- };
- if let Some(mut config) = scoped {
+pub async fn load_config_with_timeout(
+ ctx: &crate::core::runtime::DispatchCtx,
+) -> Result<Config, String> {
+ // SaaS reads only the call's own context, as `Config::load_or_init` does, so
+ // work that lost its user context fails rather than getting the operator's.
+ if crate::core::runtime::is_saas() && ctx.core().is_none() {
+ return Err(
+ "[saas] no config in scope: SaaS work must run under a user agent's or the operator's context"
+ .to_owned(),
+ );
+ }
+ if let Some(mut config) = ctx.embedder_config() {
normalize_loaded_config(&mut config).await;
return Ok(config);
}
@@ -61,8 +64,10 @@ pub async fn load_config_with_timeout() -> Result<Config, String> {
/// The context-aware counterpart of [`Config::load_or_init`] for code that
/// runs inside a turn: [`load_config_with_timeout`] with the context's
/// inference route applied.
-pub async fn load_current_or_init() -> anyhow::Result<Config> {
- let mut config = load_config_with_timeout()
+pub async fn load_current_or_init(
+ ctx: &crate::core::runtime::DispatchCtx,
+) -> anyhow::Result<Config> {
+ let mut config = load_config_with_timeout(ctx)
.await
.map_err(anyhow::Error::msg)?;
if let Some(route) = config.ephemeral_route.clone() {
@@ -96,6 +101,7 @@ pub async fn load_current_or_init() -> anyhow::Result<Config> {
/// the process-global load with `workspace_dir` re-anchored — the previous
/// behaviour, and still correct for a single-workspace host.
pub async fn load_config_for_workspace_with_timeout(
+ ctx: &crate::core::runtime::DispatchCtx,
workspace_dir: &Path,
) -> Result<Config, String> {
let candidate = [
@@ -133,7 +139,7 @@ pub async fn load_config_for_workspace_with_timeout(
workspace = %workspace_dir.display(),
"[config] no config.toml beside workspace; falling back to the process-global load"
);
- let mut config = load_config_with_timeout().await?;
+ let mut config = load_config_with_timeout(ctx).await?;
config.workspace_dir = workspace_dir.to_path_buf();
Ok(config)
}
diff --git a/crates/openhuman-core/src/core/runtime/dispatch_ctx.rs b/crates/openhuman-core/src/core/runtime/dispatch_ctx.rs
index 9559a04619..16c5ce1438 100644
--- a/crates/openhuman-core/src/core/runtime/dispatch_ctx.rs
+++ b/crates/openhuman-core/src/core/runtime/dispatch_ctx.rs
@@ -59,6 +59,28 @@ impl DispatchCtx {
}
}
+ /// The context readers act under: the bound one, else (outside SaaS) the
+ /// process default, else none.
+ ///
+ /// An unbound context outside SaaS stands for the host's one context, as an
+ /// unscoped task always did, so tests and pre-boot callers that never bound
+ /// one read the default. In SaaS an unbound context stays `None`: work that
+ /// lost its tenant must fail closed rather than act as the operator.
+ pub fn resolved(&self) -> Option<Arc<CoreContext>> {
+ match &self.core {
+ Some(core) => Some(Arc::clone(core)),
+ None if super::is_saas() => None,
+ None => CoreContext::default_context(),
+ }
+ }
+
+ /// The configuration an embedder supplied for the context this call runs
+ /// under, if any. See [`CoreContext::embedder_config`].
+ pub fn embedder_config(&self) -> Option<crate::config::Config> {
+ self.resolved()
+ .and_then(|core| core.embedder_config().cloned())
+ }
+
/// The context this call runs under, if any.
pub fn core(&self) -> Option<&Arc<CoreContext>> {
self.core.as_ref()