Skip to content

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

docs(storage): document profile-based scopes

Steven Enamakelb641c4008a13
diff --git a/gitbooks/developing/architecture.md b/gitbooks/developing/architecture.md
index ccf72c1b37..d07e9f67a2 100644
--- a/gitbooks/developing/architecture.md
+++ b/gitbooks/developing/architecture.md
@@ -230,7 +230,7 @@ Conversation state is separate from memory: each thread's transcript is a JSONL
## Storage
-Durable state sits on the ports of `tinystoragedrivers` (documents, streams, blobs, search, secrets), vendored through `vendor/tinyagents/vendor/tinystoragedrivers`. One URL picks the backend for the process: `OPENHUMAN_STORAGE_URL`, else `[storage] url`, else nothing, which keeps the classic per-domain files on desktop. The drivers are Cargo features (`storage-sqlite`, `storage-file`, `storage-mongodb`; `memory` is always there), and a URL for a driver the build lacks fails at boot. Records live in a scope, and the scope is the agent id: `local` for the operator in single-user mode, an error in SaaS mode when no agent acts. The host side is `crates/openhuman-core/src/storage/`. See [Storage](architecture/storage.md).
+Durable state sits on the ports of `tinystoragedrivers` (documents, streams, blobs, search, secrets), vendored through `vendor/tinyagents/vendor/tinystoragedrivers`. One URL picks the backend for the process: `OPENHUMAN_STORAGE_URL`, else `[storage] url`, else nothing, which keeps the classic per-domain files on desktop. The drivers are Cargo features (`storage-sqlite`, `storage-file`, `storage-mongodb`; `memory` is always there), and a URL for a driver the build lacks fails at boot. Records live in a scope: the tenant's profile when work runs for one, else the acting agent's id, else `local` for the operator in single-user mode. In SaaS mode a call with no profile is refused. The host side is `crates/openhuman-core/src/storage/`. See [Storage](architecture/storage.md).
## Security architecture
diff --git a/gitbooks/developing/architecture/storage.md b/gitbooks/developing/architecture/storage.md
index 373dc3295b..bf44abed36 100644
--- a/gitbooks/developing/architecture/storage.md
+++ b/gitbooks/developing/architecture/storage.md
@@ -50,13 +50,15 @@ The host opens the configured backend before the core boots and installs it with
## Scopes
-Every record lives in a scope, and two scopes on one backend never see each other's data. **The scope is the agent id.** `storage::scope_for_agent` is the single mapping, the one the session store uses, so every domain agrees.
+Every record lives in a scope, and two scopes on one backend never see each other's data. A single-user install scopes by **agent id**, and a SaaS host scopes by **profile** (the tenant). `storage::scope_for_agent` and `storage::scope_for_profile` are the single mappings, and the session store uses the same ones, so every domain agrees.
-`storage::current_scope()` resolves the scope of the current call:
+`storage::current_scope()` resolves the scope of the current call from the task's tenant (`storage::scope_from(profile, agent, saas)`), in this order:
-- Inside an agent's turn, the context names the agent (`CoreContext::session_agent`), and the scope is that agent's.
-- With no acting agent in single-user mode, the scope is `local`. This is the operator, the CLI and the desktop shell.
-- With no acting agent in SaaS mode, the call is refused instead of falling into a bucket every user would share.
+1. A **profile**, when the work runs for one: the scope is the profile's, whatever agent acts inside it. In SaaS mode the agents of one profile therefore share that profile's scope.
+2. Otherwise the acting **agent** (`CoreContext::session_agent`): the scope is that agent's.
+3. Otherwise `local`: the operator, the CLI and the desktop shell in single-user mode.
+
+In SaaS mode a call with no profile is refused instead of falling into a bucket other users could share, whether or not an agent acts.
A backend decides how it enforces the scope. SQLite and the file driver keep each scope's data apart, and `local` is the scope a single-user install uses. MongoDB injects a scope key into every filter and every index prefix.
diff --git a/tests/storage_delegation_e2e.rs b/tests/storage_delegation_e2e.rs
index 084c0d9f6d..657800d8ad 100644
--- a/tests/storage_delegation_e2e.rs
+++ b/tests/storage_delegation_e2e.rs
@@ -120,7 +120,9 @@ async fn the_delegation_checkpointer_resumes_and_keeps_scopes_apart(case: Case)
// A named checkpoint resolves in the same scope only.
let first = checkpointer.get("run-1", Some("c1")).await.unwrap();
assert_eq!(
- first.and_then(|checkpoint| checkpoint.state.plan).as_deref(),
+ first
+ .and_then(|checkpoint| checkpoint.state.plan)
+ .as_deref(),
Some(named_c1),
"the named checkpoint is this agent's own"
);