Skip to content

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

chore: I don't see the actual diff content in your message — the "Diff:" section is empty, and the

Steven Enamakel3216f4ff7f7b
diff --git a/crates/openhuman-core/src/storage/config.rs b/crates/openhuman-core/src/storage/config.rs
new file mode 100644
index 0000000000..81328e4c0c
--- /dev/null
+++ b/crates/openhuman-core/src/storage/config.rs
@@ -0,0 +1,101 @@
+//! Which storage the process uses: the resolution rule behind
+//! `OPENHUMAN_STORAGE_URL`, `[storage] url` and the default.
+//!
+//! In order:
+//!
+//! 1. `OPENHUMAN_STORAGE_URL`;
+//! 2. `[storage] url` in `config.toml`;
+//! 3. the default, `sqlite:<workspace_dir>`.
+//!
+//! The first two name a backend the host opens once at startup and installs
+//! ([`super::install`]); every domain that has moved onto the ports then uses
+//! it, and the session store follows (`DriverSessionStores`). That is
+//! [`StorageMode::Url`].
+//!
+//! The default is [`StorageMode::Default`]: no backend is installed and
+//! nothing about the large stores changes (`sessions.db`, `flows.db`,
+//! `jobs.db` and `graph_checkpoints.db` are already SQLite files served as
+//! they are). The small stores (approvals, devices, notifications, task
+//! sources) keep their rows as document tables inside their own `.db` files,
+//! `<workspace>/<domain>/<name>.db`, importing the rows of their old tables
+//! once ([`super::local`]). The workspace directory is therefore the default's
+//! root, but each database is placed at its established path instead of
+//! `<workspace>/<name>.db`, so an existing install keeps one file per store.
+//!
+//! The value `classic` (alias `legacy`) opts out: no backend, the pure
+//! pre-storage layout with the legacy tables. It is the escape hatch for a
+//! build that must not touch its small-store files, and it is how a database
+//! that was imported can still be read by an older build (the imported tables
+//! are kept as `_legacy_<name>` for one release).
+
+use std::path::Path;
+
+use crate::config::Config;
+
+/// The `OPENHUMAN_STORAGE_URL` / `[storage] url` value that opts out of the
+/// default and keeps the pure legacy layout.
+pub const CLASSIC: &str = "classic";
+
+/// The value spellings that mean [`CLASSIC`].
+const CLASSIC_ALIASES: [&str; 2] = [CLASSIC, "legacy"];
+
+/// What the process's configuration asks for.
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub enum StorageMode {
+ /// A backend named by `OPENHUMAN_STORAGE_URL` or `[storage] url`.
+ Url(String),
+ /// Nothing configured: SQLite document tables inside the small stores'
+ /// own database files, everything else as it was.
+ Default,
+ /// Opted out ([`CLASSIC`]): the pure legacy layout.
+ Classic,
+}
+
+/// The mode `env` and `config` ask for. Blank values count as unset, a blank
+/// override falls through to the file, and [`CLASSIC`] in either is the
+/// opt-out.
+pub fn mode_from(env: Option<String>, config: &Config) -> StorageMode {
+ let chosen = env
+ .into_iter()
+ .chain(config.storage.url.clone())
+ .map(|url| url.trim().to_string())
+ .find(|url| !url.is_empty());
+ match chosen {
+ None => StorageMode::Default,
+ Some(url) if CLASSIC_ALIASES.iter().any(|a| url.eq_ignore_ascii_case(a)) => {
+ StorageMode::Classic
+ }
+ Some(url) => StorageMode::Url(url),
+ }
+}
+
+/// [`mode_from`] with the environment read, and a SaaS process (which has no
+/// workspace-local files to default to, and whose storage is always an
+/// explicit backend) never in [`StorageMode::Default`].
+pub fn mode(config: &Config) -> StorageMode {
+ let mode = mode_from(std::env::var(super::STORAGE_URL_VAR).ok(), config);
+ if mode == StorageMode::Default && crate::core::runtime::mode::is_saas() {
+ return StorageMode::Classic;
+ }
+ mode
+}
+
+/// The default URL for `workspace_dir`: SQLite in directory mode, one file
+/// per named database.
+pub fn default_url(workspace_dir: &Path) -> String {
+ format!("sqlite:{}", workspace_dir.display())
+}
+
+/// The URL in effect for `mode`: the configured one, the default under
+/// `workspace_dir`, or none for the legacy layout.
+pub fn effective_url(mode: &StorageMode, workspace_dir: &Path) -> Option<String> {
+ match mode {
+ StorageMode::Url(url) => Some(url.clone()),
+ StorageMode::Default => Some(default_url(workspace_dir)),
+ StorageMode::Classic => None,
+ }
+}
+
+#[cfg(test)]
+#[path = "config_tests.rs"]
+mod tests;
diff --git a/crates/openhuman-core/src/storage/config_tests.rs b/crates/openhuman-core/src/storage/config_tests.rs
new file mode 100644
index 0000000000..c38962de54
--- /dev/null
+++ b/crates/openhuman-core/src/storage/config_tests.rs
@@ -0,0 +1,72 @@
+use super::*;
+
+fn config_with(url: Option<&str>) -> Config {
+ let mut config = Config::default();
+ config.storage.url = url.map(str::to_string);
+ config
+}
+
+#[test]
+fn nothing_configured_is_the_default() {
+ assert_eq!(mode_from(None, &config_with(None)), StorageMode::Default);
+ assert_eq!(
+ mode_from(Some(" ".into()), &config_with(Some(""))),
+ StorageMode::Default
+ );
+}
+
+#[test]
+fn the_environment_beats_the_file_beats_the_default() {
+ let config = config_with(Some("sqlite:/from/config"));
+ assert_eq!(
+ mode_from(Some("memory".into()), &config),
+ StorageMode::Url("memory".into())
+ );
+ assert_eq!(
+ mode_from(None, &config),
+ StorageMode::Url("sqlite:/from/config".into())
+ );
+ assert_eq!(
+ mode_from(Some(" ".into()), &config_with(Some(" memory "))),
+ StorageMode::Url("memory".into()),
+ "a blank override falls through to the file"
+ );
+}
+
+#[test]
+fn classic_opts_out_from_either_source() {
+ assert_eq!(
+ mode_from(Some("classic".into()), &config_with(Some("memory"))),
+ StorageMode::Classic
+ );
+ assert_eq!(
+ mode_from(None, &config_with(Some("Legacy"))),
+ StorageMode::Classic
+ );
+}
+
+#[test]
+fn the_default_url_is_sqlite_on_the_workspace_directory() {
+ let workspace = Path::new("/work/space");
+ assert_eq!(default_url(workspace), "sqlite:/work/space");
+ assert_eq!(
+ effective_url(&StorageMode::Default, workspace).as_deref(),
+ Some("sqlite:/work/space")
+ );
+ assert_eq!(
+ effective_url(&StorageMode::Url("memory".into()), workspace).as_deref(),
+ Some("memory")
+ );
+ assert_eq!(effective_url(&StorageMode::Classic, workspace), None);
+}
+
+#[cfg(feature = "storage-sqlite")]
+#[tokio::test]
+async fn the_default_url_opens_in_directory_mode() {
+ let dir = tempfile::tempdir().unwrap();
+ let backend = crate::storage::open(&default_url(dir.path())).await.unwrap();
+ assert_eq!(backend.driver(), "sqlite");
+ // Directory mode: a named database is its own file in the directory.
+ backend.database("approvals").unwrap();
+ assert!(dir.path().join("approvals.db").exists());
+}
diff --git a/crates/openhuman-core/src/storage/mod.rs b/crates/openhuman-core/src/storage/mod.rs
index 5d67a8f2e1..8b12888862 100644
--- a/crates/openhuman-core/src/storage/mod.rs
+++ b/crates/openhuman-core/src/storage/mod.rs
@@ -19,7 +19,9 @@
//! misconfigured deployment stops at boot instead of at its first write.
pub mod agents;
+pub mod config;
pub mod documents;
+pub mod local;
pub mod secrets;
use std::future::Future;
@@ -68,9 +70,10 @@ impl Slot {
static BACKEND: LazyLock<Slot> = LazyLock::new(Slot::default);
-/// The storage URL in effect: [`STORAGE_URL_VAR`], else `config`'s
-/// `[storage] url`. Blank values count as unset. `None` keeps the classic
-/// on-disk layout.
+/// The storage URL a host opens at startup: [`STORAGE_URL_VAR`], else
+/// `config`'s `[storage] url`. Blank values count as unset. `None` — nothing
+/// configured, or the [`config::CLASSIC`] opt-out — opens nothing; see
+/// [`config::mode`] for the default's small-store behavior.
pub fn configured_url(config: &Config) -> Option<String> {
url_from(std::env::var(STORAGE_URL_VAR).ok(), config)
}
@@ -78,10 +81,10 @@ pub fn configured_url(config: &Config) -> Option<String> {
/// [`configured_url`] with the environment read made explicit, so the rule
/// is testable without mutating process-wide state.
pub fn url_from(env: Option<String>, config: &Config) -> Option<String> {
- env.into_iter()
- .chain(config.storage.url.clone())
- .map(|url| url.trim().to_string())
- .find(|url| !url.is_empty())
+ match config::mode_from(env, config) {
+ config::StorageMode::Url(url) => Some(url),
+ config::StorageMode::Default | config::StorageMode::Classic => None,
+ }
}
/// Parses and opens the backend `url` names.