Skip to content

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

fix(session_store): fail saas boot when the config cannot be read

Steven Enamakelb654672f938e
diff --git a/crates/openhuman-rpc/src/server/shims.rs b/crates/openhuman-rpc/src/server/shims.rs
index da1a6c093e..f07fe5515f 100644
--- a/crates/openhuman-rpc/src/server/shims.rs
+++ b/crates/openhuman-rpc/src/server/shims.rs
@@ -61,16 +61,21 @@ pub async fn run_server_headless(host: Option<&str>, port: Option<u16>) -> anyho
/// Runs a SaaS core: many users behind a trusted gateway, booted from the
/// operator's config file and refused unless its boot guard passes.
///
-/// The on-disk session store is installed before boot. It resolves the
-/// workspace of the context each call runs under, so every user agent keeps
-/// its sessions, transcripts and turn states in its own workspace.
+/// The session store is installed before boot through the same host path the
+/// other servers use ([`crate::session_store::install_for_host`]). With a
+/// storage URL (`OPENHUMAN_STORAGE_URL` / `[storage] url`) every user agent's
+/// records live in that backend under the agent's own scope; without one the
+/// on-disk store resolves the workspace of the context each call runs under, so
+/// every user agent keeps its sessions, transcripts and turn states in its own
+/// workspace. A call with no acting agent (the operator plane) is refused by
+/// the storage domains instead of reaching a shared scope.
pub async fn run_server_saas(
host: Option<&str>,
port: Option<u16>,
saas_config: &std::path::Path,
) -> anyhow::Result<()> {
let config = crate::core_host::core::runtime::SaasConfig::load(saas_config)?;
- crate::session_store::install();
+ crate::session_store::install_for_host().await?;
let runtime =
crate::core_host::core::runtime::saas::build(config, host.map(str::to_owned), port).await?;
super::serve::serve(&runtime, None, None).await
diff --git a/crates/openhuman-rpc/src/session_store/mod.rs b/crates/openhuman-rpc/src/session_store/mod.rs
index 349f55c578..820d7940a5 100644
--- a/crates/openhuman-rpc/src/session_store/mod.rs
+++ b/crates/openhuman-rpc/src/session_store/mod.rs
@@ -182,10 +182,11 @@ pub fn provider() -> Arc<dyn SessionStoreProvider> {
///
/// # Errors
///
-/// When a URL is configured but cannot be parsed or opened. A deployment that
-/// asked for a backend must not quietly fall back to local files.
+/// When a URL is configured but cannot be parsed or opened, or the config
+/// that may name one cannot be loaded. A deployment that asked for a backend
+/// must not quietly fall back to local files.
pub async fn install_for_host() -> anyhow::Result<()> {
- install_for_url(configured_storage_url().await).await
+ install_for_url(configured_storage_url().await?).await
}
/// The session store the host's configuration asks for, as a provider a
@@ -201,27 +202,37 @@ pub async fn install_for_host() -> anyhow::Result<()> {
///
/// When a URL is configured but cannot be parsed or opened.
pub async fn provider_for_host() -> anyhow::Result<Arc<dyn SessionStoreProvider>> {
- provider_for_url(configured_storage_url().await).await
+ provider_for_url(configured_storage_url().await?).await
}
/// The storage URL the host asks for: `OPENHUMAN_STORAGE_URL`, else
/// `[storage] url` from the config, else `None` (the classic layout).
-async fn configured_storage_url() -> Option<String> {
- match std::env::var(crate::core_host::storage::STORAGE_URL_VAR) {
- Ok(url) if !url.trim().is_empty() => Some(url.trim().to_string()),
- _ => match crate::core_host::config::rpc::load_config_with_timeout().await {
- Ok(config) => crate::core_host::storage::configured_url(&config),
- // An unreadable config keeps the desktop booting on the classic
- // layout, as it always has. Remote deployments pin the backend
- // with `OPENHUMAN_STORAGE_URL`, which never reads the config.
- Err(error) => {
- log::warn!(
- "[rpc:session_store] config unavailable ({error}); keeping the on-disk layout"
- );
- None
- }
- },
+///
+/// # Errors
+///
+/// When no environment URL pins the backend and the config cannot be loaded:
+/// the config may name a `[storage] url`, and a deployment that asked for a
+/// backend must not quietly fall back to local files.
+async fn configured_storage_url() -> anyhow::Result<Option<String>> {
+ use anyhow::Context as _;
+
+ let env = std::env::var(crate::core_host::storage::STORAGE_URL_VAR).ok();
+ // A URL in the environment wins and never reads the config.
+ if env.as_deref().is_some_and(|url| !url.trim().is_empty()) {
+ return Ok(storage_url_from(env, &Default::default()));
}
+ let config = crate::core_host::config::rpc::load_config_with_timeout()
+ .await
+ .context("loading the config to resolve the storage url")?;
+ Ok(storage_url_from(env, &config))
+}
+
+/// The core's URL rule ([`crate::core_host::storage::url_from`]) over `config`.
+fn storage_url_from(
+ env: Option<String>,
+ config: &crate::core_host::config::Config,
+) -> Option<String> {
+ crate::core_host::storage::url_from(env, config)
}
/// [`install_for_host`] with the URL already resolved: `None` installs the