The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
docs(profiles): document profile leases and storage-backed registry
Steven Enamakeld0c2231865fc
diff --git a/crates/openhuman-core/src/profiles/README.md b/crates/openhuman-core/src/profiles/README.mdindex aab57f5287..b49bbf1585 100644--- a/crates/openhuman-core/src/profiles/README.md+++ b/crates/openhuman-core/src/profiles/README.md@@ -11,14 +11,20 @@ belong to `DomainGroup::Operator`, which only `DomainSet::saas()` enables.```text<root>/users/<profile-id>/ the desktop's users/<id> shape (config::schema::ProfileLayout)- profile.toml ProfileMeta+ profile.toml ProfileMeta (only without a storage backend)+ .lease, .lease.json the file-lock lease (only without a storage backend)config.toml the profile's config_pathworkspace/ sessions, memory, threads, cron, costsandbox/ action_dir: the only place it may act<root>/deprovisioned/<id>-<secs>-<uuid>/ an archived profile-<root>/operator/ the operator plane's own state+<root>/operator/ the operator plane's own state (operator_dir overrides it)```+With a storage backend (`storage_url` / `OPENHUMAN_STORAGE_URL`), the+registry and the leases live in the backend's `cluster` scope instead+(collections `profiles` and `leases`); a profile's files stay under+`<root>/users/<id>/`, so nodes of a cluster share `<root>` on one volume.+The desktop config loader resolves a signed-in user's `users/<id>/config.toml`and `workspace/` through the same `ProfileLayout`, so the two layouts cannotdrift. The older `<root>/agents/u-<hash>/` layout is gone; data left there is@@ -43,13 +49,15 @@ Changing the mode re-maps users onto different profiles.| --- | --- || `types.rs` | `ProfileId` and `ProfileIdMode`, `ProfileMeta`, and the operator-plane result types || `layout.rs` | The SaaS side of the shared `ProfileLayout`, archived profiles, and `profile_config`: the forced paths, memory binding (pinned to the legacy layout) and autonomy policy |-| `host.rs` | `ProfileHost`: provisioning, lazy open, LRU and idle eviction (never of a profile in use), each profile's derived `CoreContext`, `current()` |+| `host.rs` | `ProfileHost`: provisioning, lazy open behind the profile lease, LRU and idle eviction (never of a profile in use), release, fencing, each profile's derived `CoreContext`, `current()`, `ensure_hosted()` |+| `lease.rs` | The profile lease as the host uses it: `OpenError`, the lease store choice (`DocumentLeases` over a backend, else `LocalLeases`), and the heartbeat that renews every open profile's lease and fences the ones lost |+| `registry.rs` | `ProfileRegistry`: which profiles are provisioned, in the backend's `cluster` scope or as `profile.toml` files || `gateway.rs` | Which context a gateway request runs under: the operator plane, or the profile of the user named in `X-OpenHuman-User`, after the signature check || `surface.rs` | What a user may call: `USER_METHODS`, the exact allowlist applied at dispatch, in the controller list and in `/schema`; the operator scope sees only the operator plane; user thread-id rules || `background.rs` | The SaaS background loop: every minute it sweeps idle profiles and runs each profile's queued memory jobs (deferred ingests, belief builds) under that profile's context || `tools.rs` | Which agent tools a user gets: the operator's host tool groups (`host_files`, `host_shell`), the hard-deny list, the tool-list filter, the approval gate's SaaS verdict, and the container policy for a user's shell || `credentials.rs` | A profile's TinyHumans credential, stored beside its config |-| `ops.rs` | `provision` / `deprovision` / `list` / `status` / `set_credential` / `clear_credential`, returning `Outcome<T>` |+| `ops.rs` | `provision` / `deprovision` / `list` / `status` / `set_credential` / `clear_credential` / `release`, returning `Outcome<T>` || `schemas.rs` | The `profiles.*` controllers (`profile_id` in and out) |## Rules@@ -68,11 +76,22 @@ Changing the mode re-maps users onto different profiles.and would answer `org:<id>` or a minted local root instead.- The autonomy policy is on and supervised, with no auto-approval, no toolinstallation and no trusted roots.-- **The isolation boundary is the profile's `CoreContext`.** It carries the forced- config and `session_agent = <profile id>`, and the user families (threads, channels- for web chat, memory), narrowed further by `surface::USER_METHODS`. Work for a+- **The isolation boundary is the profile's `CoreContext`.** It carries the+ forced config, its own security policy (`agent_policy`, never the+ operator's), `profile = <profile id>` (the tenant key: storage scope,+ `/events`, cost, per-thread tables, via `core::runtime::current_tenant`) and+ `session_agent = <profile id>`, and the user families (threads, channels for+ web chat, memory), narrowed further by `surface::USER_METHODS`. Work for auser runs under it, which is what the config loader, the session store andthe per-thread caches key on.+- **`session_agent` stays the profile id.** The plan was for the default agent+ to run with no `session_agent`, as on the desktop. That needs every site+ that keys on the acting agent to key on the tenant instead; the approval+ gate's thread routes, the MCP host, skill homes, origin delivery and the+ transcript fallback still read `agent_scope::current_agent_id()`, so a+ profile without an agent id would share their keys with every other+ profile. Until those move to `current_tenant`, the profile id doubles as the+ agent id.- **Host tools are opt-in and confined.** A user's context has no `Platform`family, so shell and file tools are absent unless the operator lists theirgroup in `tool_allowlist`:@@ -109,7 +128,9 @@ X-OpenHuman-User-Sig: t=<unix secs>,v1=<hex hmac-sha256(token, "<t>.<user id>")>2. It checks the signature: ±60 s, bound to the user id. It is requiredunless the operator sets `require_user_signature = false`.3. It opens the user's profile, which must already be provisioned- (`403` otherwise).+ (`403` otherwise), taking its lease. A profile another core hosts+ answers `409` (see [Leases](#leases-one-core-per-profile)); a full host+ or a storage failure answers `503`.4. It runs the request under that profile's context. A user's context cannotreach the operator plane.- Routes a SaaS core never serves answer `404`: `/v1`, `/events*`, `/ws/*`,@@ -169,11 +190,57 @@ A single-user core drains memory jobs from a cron system job behind the process-Profiles with nothing queued are not opened.-On the **first** open of a profile in a process, `recover_workspace` settles anything a previous process left in that profile's workspace:--- turns that were mid-flight are marked interrupted;-- run-ledger rows left running are closed.--A re-open after an eviction never sweeps again, because this process may still be running one of that profile's turns.-User cron jobs are not served yet: the cron RPCs are not on the user surface.++## Leases: one core per profile++Exactly one process hosts a profile at a time. `ProfileHost::open` takes the+profile's lease (`storage::lease`) before opening it:++- **With a storage backend** the host uses `DocumentLeases` in the backend's+ `cluster` scope: one compare-and-swapped record per profile with an owner,+ an endpoint (`advertise_url`), an epoch and an expiry `lease_ttl_secs`+ (default 30) out. Every node sharing the backend contends for the same+ records. A clustered node (one that sets `advertise_url`) must use a driver+ whose CAS holds across processes (`storage::driver_has_cross_process_cas`:+ SQLite, MongoDB); the boot guard refuses anything else.+- **Without one** it uses `LocalLeases`: an exclusive `flock` on+ `<root>/users/<id>/.lease`, which keeps two processes on one root apart and+ drops when its holder dies.++The lease drives the rest:++- **Refusal.** A live lease held elsewhere makes `open` return+ `OpenError::HeldElsewhere(record)`; the gateway answers `409` with+ `{"error":"profile_held","owner","endpoint","retry_after_ms"}` and+ `X-OpenHuman-Profile-Owner: <owner>`. Load balancers route users stickily;+ the lease is what makes it correct.+- **Recovery.** A lease taken over from a holder that never released it+ (`previous_unclean`: it crashed, or stopped renewing) means that holder's+ turns may have died mid-flight. `recover_workspace` marks them interrupted+ and settles orphaned run-ledger rows, and a storage-backed session store+ is swept for the profile too. A clean hand-over (eviction, release,+ shutdown) recovers nothing, so a re-open never interrupts live work. This+ replaces the old once-per-process sweep, and is why the SaaS session+ store never recovers on open (`session_store::install_for_saas`).+- **Heartbeat.** `lease::heartbeat` renews every open profile's lease every+ third of the TTL. A renewal that finds the record changed (another node+ took over, or an operator released it), or that keeps failing until the+ grant would have expired, **fences** the profile: it is marked fenced, its+ in-flight turns are stopped (`web_chat::cancel_all_turns` under its+ context) and it is closed. `ensure_hosted` refuses new turns for a+ profile this node no longer hosts.+- **Release.** Idle eviction, `profiles.release {profile_id}` (refused while+ the profile is in use), deprovisioning and a clean shutdown (idle profiles+ only; a busy one keeps its lease so its successor recovers) release the+ lease, so another node can take the profile at once.+- **Node ids** (`node_id`, else `OPENHUMAN_NODE_ID`, else random per process)+ must be unique among live nodes. A stable one lets a restarted node take+ its own profiles back at once instead of waiting out their leases.++Known limits: storage writes carry no epoch fence, so a node that is+partitioned but still running could write after its lease expired; the TTL+being much longer than the renew interval, the fence check before each turn+and stopping turns on loss are the mitigations. Each node keeps its own+operator keyring (`operator_dir`), so a credential installed through one node+is only readable there unless secrets live in the storage backend.