Skip to content

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

chore(storage): remove unused module declaration

Steven Enamakel9de647fa336e
diff --git a/crates/openhuman-core/src/storage/mod.rs b/crates/openhuman-core/src/storage/mod.rs
index 2de3d94e7a..cbaa8ccd89 100644
--- a/crates/openhuman-core/src/storage/mod.rs
+++ b/crates/openhuman-core/src/storage/mod.rs
@@ -1,20 +1,23 @@
//! The process's storage backend on the `tinystoragedrivers` ports.
//!
-//! One URL picks where durable state that has moved onto the storage ports
-//! lives: `OPENHUMAN_STORAGE_URL`, else `[storage] url` in `config.toml`
-//! ([`crate::config::StorageConfig`]), else the default
-//! ([`config::StorageMode`]). The default installs no backend: the large
-//! stores keep their SQLite files, and the small ones (approvals, devices,
-//! notifications, task sources) keep document tables inside their own `.db`
-//! files, importing their old tables on first open ([`local`]). The value
-//! `classic` opts out to the pure legacy layout.
+//! One URL picks where all durable state lives: `OPENHUMAN_STORAGE_URL`, else
+//! `[storage] url` in `config.toml` ([`crate::config::StorageConfig`]), else
+//! the default, `sqlite:<workspace>/storage` ([`config::default_url`]). There
+//! is no second layout: the per-domain `.db` files, JSONL transcripts and JSON
+//! stores older installs wrote are imported once, read-only, by [`import`].
//!
-//! When a URL is set, the host opens it once at startup ([`open`]) and
-//! installs it ([`install`]); domains reach it through [`installed`] and bind
-//! their records to an agent with [`scope_for_agent`]. The first consumer is
-//! the session store: the host installs TinyAgents' `DriverSessionStores`
-//! over this backend, so transcripts, turn states, records and journals live
-//! in it, one scope per agent.
+//! The host opens the URL once at startup ([`open`]) and installs it
+//! ([`install_for_url`]); domains reach it through [`installed`] and bind
+//! their records to an agent with [`scope_for_agent`]. The session store is
+//! TinyAgents' `DriverSessionStores` over this backend, so transcripts, turn
+//! states, records, the run ledger and journals live in it, one scope per
+//! agent. The default follows the workspace, so a different workspace is a
+//! different database: [`rebind`] re-resolves and reinstalls it when the
+//! desktop switches user.
+//!
+//! With nothing installed (a unit test, an embedder that skipped the host
+//! boot) a domain falls back to the same default for its own workspace,
+//! opened lazily ([`local`]); a SaaS process never does and refuses instead.
//!
//! Drivers are Cargo features of this crate: `storage-sqlite`,
//! `storage-mongodb`, `storage-file` (memory is always available). A URL for a
@@ -31,14 +34,17 @@ pub mod lease;
mod lease_documents;
mod lease_local;
pub mod local;
+pub mod rebind;
pub mod secrets;
use std::future::Future;
-use std::sync::{Arc, LazyLock, OnceLock, RwLock};
+use std::sync::{Arc, LazyLock, Mutex, OnceLock, RwLock};
-/// SQLite bindings re-exported by the storage driver crate, for the readers
-/// of legacy per-domain SQLite files. The core has no `rusqlite` dependency
-/// of its own: tinystoragedrivers owns the one copy.
+/// SQLite bindings re-exported by the storage driver crate, for the one
+/// consumer left: the read-only legacy importers ([`import`]), which open the
+/// old per-domain files. Nothing else in the core opens a SQLite file; the
+/// core has no `rusqlite` dependency of its own, tinystoragedrivers owns the
+/// one copy.
pub use tinystoragedrivers::sqlite::rusqlite;
pub use tinystoragedrivers::{
Blocking, CollectionSpec, DocumentStore, DocumentStoreExt, MemoryStorage, Precondition, Scope,
@@ -83,10 +89,30 @@ impl Slot {
static BACKEND: LazyLock<Slot> = LazyLock::new(Slot::default);
+/// The URL the installed backend was opened from, when the host installed it
+/// by URL ([`install_for_url`]). [`rebind`] compares against it; a backend
+/// installed without one (a test's, an embedder's own) is never rebound.
+static INSTALLED_URL: Mutex<Option<String>> = Mutex::new(None);
+
+fn set_installed_url(url: Option<String>) {
+ *INSTALLED_URL
+ .lock()
+ .unwrap_or_else(std::sync::PoisonError::into_inner) = url;
+}
+
+/// The URL the installed backend was opened from, if the host installed it by
+/// URL.
+pub fn installed_url() -> Option<String> {
+ INSTALLED_URL
+ .lock()
+ .unwrap_or_else(std::sync::PoisonError::into_inner)
+ .clone()
+}
+
/// 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.
+/// `config`'s `[storage] url`, else the default for `config`'s workspace
+/// ([`config::default_url`]). `None` only in SaaS mode with nothing
+/// configured: a SaaS process has no workspace-local state to default to.
pub fn configured_url(config: &Config) -> Option<String> {
url_from(std::env::var(STORAGE_URL_VAR).ok(), config)
}
@@ -96,7 +122,18 @@ pub fn configured_url(config: &Config) -> Option<String> {
pub fn url_from(env: Option<String>, config: &Config) -> Option<String> {
match config::mode_from(env, config) {
config::StorageMode::Url(url) => Some(url),
- config::StorageMode::Default | config::StorageMode::Classic => None,
+ config::StorageMode::Default if crate::core::runtime::mode::is_saas() => None,
+ config::StorageMode::Default => Some(config::default_url(&config.workspace_dir)),
+ }
+}
+
+/// The URL the operator named (`OPENHUMAN_STORAGE_URL`, else `[storage] url`),
+/// with no default applied. For hosts with no workspace (a stateless embed)
+/// that must be told where to store things.
+pub fn explicit_url(config: &Config) -> Option<String> {
+ match config::mode(config) {
+ config::StorageMode::Url(url) => Some(url),
+ config::StorageMode::Default => None,
}
}
@@ -124,6 +161,7 @@ pub async fn open(url: &str) -> Result<Arc<dyn StorageBackend>, StorageError> {
/// Makes `backend` the process's storage backend; returns the previous one.
pub fn install(backend: Arc<dyn StorageBackend>) -> Option<Arc<dyn StorageBackend>> {
+ set_installed_url(None);
let previous = BACKEND.install(backend);
// What was recorded described the previous backend.
agents::reset_recorded();
@@ -132,6 +170,17 @@ pub fn install(backend: Arc<dyn StorageBackend>) -> Option<Arc<dyn StorageBacken
previous
}
+/// [`install`] for a backend [`open`]ed from `url`, remembering the URL so
+/// [`rebind`] can tell when the workspace's default has moved.
+pub fn install_for_url(
+ url: &str,
+ backend: Arc<dyn StorageBackend>,
+) -> Option<Arc<dyn StorageBackend>> {
+ let previous = install(backend);
+ set_installed_url(Some(url.to_string()));
+ previous
+}
+
/// The installed backend, when the host configured one.
pub fn installed() -> Option<Arc<dyn StorageBackend>> {
BACKEND.installed()
@@ -139,6 +188,7 @@ pub fn installed() -> Option<Arc<dyn StorageBackend>> {
/// Removes the installed backend; returns whether there was one.
pub fn clear() -> bool {
+ set_installed_url(None);
agents::reset_recorded();
BACKEND.clear()
}
@@ -182,8 +232,8 @@ pub fn scope_from(
}
}
-/// The installed backend bound to [`current_scope`], or `None` when the host
-/// configured no backend (the classic on-disk layout).
+/// The installed backend bound to [`current_scope`], or `None` when no backend
+/// is installed.
///
/// # Errors
///