Skip to content

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

fix(security): rebind storage before other stores on credential change

Steven Enamakeledb2b0efbf67
diff --git a/crates/openhuman-core/src/security/credentials/ops/user_scope.rs b/crates/openhuman-core/src/security/credentials/ops/user_scope.rs
index 490f354827..37ae57e98e 100644
--- a/crates/openhuman-core/src/security/credentials/ops/user_scope.rs
+++ b/crates/openhuman-core/src/security/credentials/ops/user_scope.rs
@@ -124,6 +124,19 @@ pub(super) fn rebind_after_credential_change(
_reason: &str,
) -> Result<Vec<String>, String> {
let mut logs = Vec::new();
+ // Storage first: the default backend belongs to the workspace, and every
+ // store below reaches it through the installed slot, so a different user's
+ // workspace must have its own backend installed before any of them runs.
+ // A failed reopen is an error, never a quiet continue on the previous
+ // user's backend.
+ if let Some(rebound) =
+ crate::storage::rebind::rebind(config).map_err(|error| format!("{error:#}"))?
+ {
+ logs.push(format!(
+ "storage moved from {} to {}",
+ rebound.from, rebound.to
+ ));
+ }
crate::cron::seed::prune_retired_jobs(config).map_err(|error| error.to_string())?;
crate::core::runtime::context::CoreContext::rebind_default_workspace(&config.workspace_dir)
.map_err(|error| error.to_string())?;
diff --git a/crates/openhuman-embed/src/lib.rs b/crates/openhuman-embed/src/lib.rs
index 05db090897..dfd623d32f 100644
--- a/crates/openhuman-embed/src/lib.rs
+++ b/crates/openhuman-embed/src/lib.rs
@@ -249,7 +249,6 @@ pub mod session_store {
pub use tinyagents_session::testkit::conformance::{
session_store_conformance, session_store_isolation_conformance,
};
- pub use tinyagents_session::transcript::import::types::{JournalMessage, SessionDescriptor};
/// The transcript seam a provider's [`AgentStores::transcripts`] implements.
pub use tinyagents_session::transcript::{
SessionRef, SessionTranscript, TranscriptHistory, TranscriptLocator, TranscriptMessage,
diff --git a/crates/openhuman-rpc/src/server/shims.rs b/crates/openhuman-rpc/src/server/shims.rs
index f0617762d2..708f6cbb57 100644
--- a/crates/openhuman-rpc/src/server/shims.rs
+++ b/crates/openhuman-rpc/src/server/shims.rs
@@ -60,10 +60,10 @@ 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 session store is installed before boot. With no storage URL it is the
-/// on-disk store, which resolves the workspace of the context each call runs
-/// under, so every profile keeps its sessions, transcripts and turn states in
-/// its own workspace. With one (`OPENHUMAN_STORAGE_URL`, else the operator's
+/// The session store is installed before boot. With no storage URL every
+/// profile keeps its sessions, transcripts and turn states in the default
+/// database of its own workspace (the store resolves the workspace of the
+/// context each call runs under). With one (`OPENHUMAN_STORAGE_URL`, else the operator's
/// `storage_url`) the backend is opened and installed — the profile registry
/// and leases live there too — and its session store never recovers on open:
/// recovery follows the profile lease instead.
@@ -82,7 +82,7 @@ pub async fn run_server_saas(
if storage_url.is_some() {
"storage backend"
} else {
- "on-disk"
+ "one database per profile workspace"
}
);
crate::session_store::install_for_saas(storage_url).await?;
@@ -168,9 +168,10 @@ pub(crate) async fn build_and_serve(
ready_tx.is_some()
);
- // The desktop app and the CLI keep conversations in the classic on-disk
- // layout unless a storage URL is configured; the core itself carries no
- // storage. Installed before boot so its recovery sweep runs. A builder
+ // The desktop app and the CLI keep conversations in the storage backend
+ // the host's configuration names (by default `sqlite:<workspace>/storage`);
+ // the core itself carries no storage. Installed before boot so its
+ // recovery sweep runs. A builder
// that brings its own session store skips this: its provider is installed
// by `build()`, and an unrelated host storage URL must not block it.
if summary.has_session_store {
diff --git a/crates/openhuman-rpc/src/session_store/mod_tests.rs b/crates/openhuman-rpc/src/session_store/mod_tests.rs
index abe7c6d1fa..144ff0bfd6 100644
--- a/crates/openhuman-rpc/src/session_store/mod_tests.rs
+++ b/crates/openhuman-rpc/src/session_store/mod_tests.rs
@@ -205,6 +205,7 @@ async fn provider_for_url_returns_the_store_without_installing_it() {
let backend_driver = crate::core_host::storage::installed().map(|b| b.driver());
let left_uninstalled = crate::core_host::agent::session_store::installed().is_none();
+ // No URL: each workspace keeps its sessions in its own default database.
let per_workspace = provider_for_url(None).await.unwrap();
let cleared = crate::core_host::storage::installed().is_none();
@@ -222,10 +223,7 @@ async fn provider_for_url_returns_the_store_without_installing_it() {
left_uninstalled,
"the provider is handed back, not installed"
);
- assert!(
- per_workspace.destination_key().is_some(),
- "no URL keeps each workspace's sessions in its own default database"
- );
+ drop(per_workspace);
assert!(cleared, "no URL clears an earlier backend");
}