Skip to content

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

docs(architecture): document process state in shared cores

Steven Enamakel0c7bbe49dc6f
diff --git a/gitbooks/SUMMARY.md b/gitbooks/SUMMARY.md
index 35d157bc8f..000d92a258 100644
--- a/gitbooks/SUMMARY.md
+++ b/gitbooks/SUMMARY.md
@@ -78,6 +78,7 @@
- [Flows on TinyAgents](developing/architecture/flows-on-tinyagents.md)
- [Memory](developing/architecture/memory.md)
- [Storage](developing/architecture/storage.md)
+ - [Process state in shared cores](developing/architecture/process-state.md)
- [MCP Registry](developing/architecture/mcp-registry.md)
- [Security](developing/architecture/security.md)
- [Frontend](developing/architecture/frontend.md)
diff --git a/gitbooks/developing/architecture/process-state.md b/gitbooks/developing/architecture/process-state.md
new file mode 100644
index 0000000000..308a25f1f8
--- /dev/null
+++ b/gitbooks/developing/architecture/process-state.md
@@ -0,0 +1,70 @@
+---
+description: Process state, tenant ownership and routing requirements for shared cores.
+icon: layers
+---
+
+# Process state in shared cores
+
+This inventory tracks the named singleton candidates in [#7433](https://github.com/tinyhumansai/openhuman/issues/7433), under the [cloud-storage epic](https://github.com/tinyhumansai/openhuman/issues/7419). It records source review at `3dbdd07e5f07d917dabbbc93fb0a9dd2a24a4347`. It does not cover every static in the core or certify a cloud deployment.
+
+## Classification
+
+The categories describe the required ownership boundary. A row can require more than one:
+
+- **A — process:** bootstrap settings, local execution handles or process capabilities.
+- **B — scoped:** state must retain its tenant, agent, session or connection owner.
+- **C — durable:** records need a backend document, stream, blob or claim.
+- **D — routing:** requests must reach the process that owns a live handle, or use an explicit executor-routing protocol.
+
+“Pending” means the boundary still needs a regression or implementation. A process-local table cannot provide a distributed claim just because a related record is durable.
+
+### Configuration and identity
+
+Paths in the table are relative to `crates/openhuman-core/src/`.
+
+| State | Class | Current boundary and remaining work |
+| ----------------------------------------------------------- | ----- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| `credentials/identity.rs` `CURRENT_USER` | B | One process slot supplies prompt and tracing identity. Pending: trace authenticated profile admission and test interleaved identities before treating it as profile-owned state. |
+| `config/schema/load/active_workspace.rs` `ACTIVE_WORKSPACE` | A | Process bootstrap cache. Pending: verify profile operations cannot select another workspace through this fallback. |
+| `core/runtime/context.rs` `DEFAULT_CONTEXT` | A | Bootstrap context. SaaS tenant resolution uses the actual scoped context and refuses missing profile context; the default is not a tenant authority. |
+| `agent/multimodal.rs` `ATTACHMENTS_DIR` | B, C | First-initialized local attachment directory. Attachment bytes and indexes need scoped blob ownership and an import path; see #7425. |
+| `threads/store/bus.rs` `CONVERSATION_PERSISTENCE_WORKSPACE` | A | Desktop subscriber installation explicitly refuses SaaS. This supplies no shared-core persistence or routing. |
+| `mcp/host.rs` `DEFAULT_CONFIG` | A, B | Replaces the issue's former `DEFAULT_WORKSPACE` name. Scoped clients capture configuration; missing SaaS context currently falls through to the process default. Pending refusal regression and fix. |
+| `core/logging.rs` `LOG_DIR` | A | Process logging destination. Cloud logging should use process output or a collector; directory state is not a tenant store. |
+| `config/schema/proxy.rs` proxy settings and clients | A, B | Process proxy policy and cached HTTP clients. Pending: establish operator-only mutation or capture profile policy; tenant configuration must not silently change another caller's routing. |
+| `config/schema/cli_overrides/ops.rs` `CLI_INFERENCE_STATE` | A | Launch overrides; persisted configuration is restored separately. This is process configuration, not durable tenant inference state. |
+| `agent/tinyagents/discovery` `SETTINGS` | B | Session construction overwrites one process policy, and turn assembly reads that slot. Pending interleaved-session regression; discovery policy needs a captured session owner. |
+| `storage/secrets.rs` `KEYS` | A | Caches the master provider. Native secret operations capture scope and derive scoped data keys. Pending production `current()` isolation controls; changing the master source requires restarting the process. Legacy adoption needs separate source-ownership admission. |
+| Connected-integration cache | B | Credential-only snapshots and global invalidation are corrected in [PR #7513](https://github.com/tinyhumansai/openhuman/pull/7513). Six scope controls, 361 Composio tests and five scoped-spawn controls pass. This is a pending PR, not released behavior. |
+
+### Live execution and delivery
+
+| State | Class | Current boundary and remaining work |
+| ----------------------------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| `orchestration/busy_guard.rs` | B, D | Profile-keyed live-turn guards with exact guard cleanup. A second core cannot observe these guards; live turns need owner routing or durable claims. |
+| `orchestration/completion_owners.rs` | B, D | Bounded IDs map to recorded profiles; delivery reopens trusted profile contexts. Restart or eviction can lose routing triggers. |
+| `orchestration/background_completions.rs` | B, C, D | Workspace routers and profile-keyed gates; completion records still use workspace JSONL with a memory fallback. Shared delivery requires durable records and claims. |
+| `orchestration/background_delivery.rs` | B, D | Profile-keyed local slots and scoped delivery tasks. Multiple executors need a shared delivery claim before publishing the same completion. |
+| `orchestration/running_subagents` | B, C, D | The durable ledger captures storage scope, but live registry ownership compares raw parent-session strings. Task-ID-only cancellation and steering also bypass tenant ownership. Seven host regressions are prepared; baseline execution and correction remain pending. Live handles still need executor routing. |
+| `workflow_runs/engine/cancel.rs` | A, D | UUID run IDs index generation-protected local signals. Public stop loads a scoped durable record first. Remote stop needs routing to the executing process; a durable row does not carry the signal. |
+| `threads/store/bus.rs` `CLAIMED_TURNS` | A | Bounded desktop channel/message deduplication; registration and claims are disabled in SaaS. No distributed or SaaS turn claim is provided. |
+
+### Capabilities and module connections
+
+| State | Class | Current boundary and remaining work |
+| ----------------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
+| `core/event_bind_tokens.rs` `STORE` | A, D | Random one-shot client-bound capabilities with expiry. SaaS SSE rejects desktop tokens or missing profiles before consumption and filters events by the captured profile. Route consumption to the minting process; do not copy token tables into tenant documents. |
+| `desktop/control/confirmation.rs` `TABLE` | B, D | Thread-bound local confirmations; SaaS excludes this domain. Pending tests for two embedded actors sharing a thread and for cancellation after module replacement. Ownership must include the original module instance. |
+| `security/approval/gate.rs` `GLOBAL_GATE` | B, C, D | Routes already include tenant/agent scope; waiters retain original document handles. Pending missing-policy fallback controls. Normal profile hosts supply their own policy; cross-core waiter delivery still needs routing. |
+| `composio/trigger_history.rs` | B, C | Process lifecycle owner of an opaque module archive lease. Workspace changes release the old captured client before opening another. The module owns durable history; native archive consumption and trustworthy event-profile propagation remain owner/host integration work. |
+| Browser `THREAD_SESSIONS` | B, D | Keys include scope directory and thread; sessions retain their original browser client. Normal profiles have distinct workspaces. Pending explicit same-workspace/different-profile collision test; route live browser handles to their owner. |
+| RPC HTTP host `REGISTRY` | A, D | UUID listener handles capture task and auth state; list/get/stop lack tenant ownership. SaaS excludes the Platform surface. Pin that exclusion; exposing listeners to tenants would require an explicit owner capability. |
+| Voice `IN_FLIGHT_CORRELATIONS` | B, D | Global correlation IDs and deferred replies through the current socket manager. SaaS headless services disable Socket.IO. Pending desktop reconnect/identity-switch controls: old work must retain its connection or refuse delivery. |
+
+## Deployment constraints
+
+A load balancer must preserve the owner of live streams, approvals, workers, browser sessions and local capabilities. Reconnecting to another core requires an explicit handoff or typed refusal. Shared storage alone does not transfer an in-memory task, socket, cancellation signal or module handle.
+
+Desktop-only surfaces excluded by the SaaS preset must remain excluded until their ownership tests pass. Removing an exclusion is a capability change, even when its store has moved to a shared backend.
+
+Outstanding acceptance includes reproducing each leak candidate, shrinking the storage-bypass baseline, adding a reviewed lint or allowlist for new mutable singletons, driver-matrix verification, and regression-tested desktop import. Prepared tests and source review do not satisfy those execution requirements.
diff --git a/gitbooks/developing/architecture/storage.md b/gitbooks/developing/architecture/storage.md
index 0c427ef41d..352a7c18fb 100644
--- a/gitbooks/developing/architecture/storage.md
+++ b/gitbooks/developing/architecture/storage.md
@@ -62,6 +62,12 @@ In SaaS mode a call with no profile is refused instead of falling into a bucket
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.
+### Process state
+
+The [process-state inventory](process-state.md) classifies the named shared-core
+singleton candidates and records their tenant, durability and routing boundaries.
+It also identifies pending regressions and implementation work.
+
### Background work
Background work runs under the process default context, which names no agent, and on its own would only see `local`. `storage::agents` closes the gap. Agents are known when they are live (`AgentContextRegistry`) or when an earlier process recorded their id in the `local` scope (`storage_agents`). `for_each_scope` runs a step once for `local` and once under each known agent. The cron scheduler's agent pass (`cron::scheduler::tick_live_agents`, driven in tests through the public `cron::scheduler::run_live_agent_pass`) runs each live agent's due jobs under that agent's own context, so their results are recorded in the agent's own scope. A recorded agent that is not live waits until it is live again, because its jobs need its host tools and prompt.