openhuman icon indicating copy to clipboard operation
openhuman copied to clipboard

Support multiple isolated agents in one OpenHuman runtime: close the documented runtime-wide leaks

Open Al629176 opened this issue 1 month ago • 3 comments

Description

Make one OpenHuman runtime able to host many fully isolated agents, so a single process can serve a global chatbot — each agent with its own workspace, skills, permissions, sessions and MCP configuration.

Start here: most of this already exists

This is not a greenfield refactor, and scoping it as one would rebuild working code. openhuman-embed is already the host-facing library for running the core in-process, and agents are already the unit of multiplicity:

  • crates/openhuman-embed/tests/runtime_agents.rs — "one Runtime, several independently configured Agents" — runs three agents with different providers, access tiers, skills, MCP servers and working directories on one runtime. Each gets its own wiremock provider, so a turn leaking to another agent's provider fails the test.
  • Density is already measured: 500 agents in one process at roughly 1.77 MiB marginal cost each (gitbooks/developing/performance.md).

And one runtime per process is a deliberate design decision, not a limitation to remove. The keyring master key, the RPC bearer, the global event bus and the Once-guarded domain subscribers are process-scoped in CoreContext::init, so a second runtime "would silently share them while believing it had a separate workspace" — RuntimeBuilder::build returns RuntimeError::AlreadyRunning rather than allow that. The task is to strengthen per-agent isolation, not to allow a second runtime.

Already per-agent

Concern Mechanism
Workspace / working directory AgentSpec + Workspace
Skills AgentSpec::skills_dir, HarnessBuilder::skills_dir
MCP servers [[mcp_client.servers]] via AgentSpec::mcp
Access tier, path and command policy Access, ToolScopeSpec, SandboxModeSpec
Provider / model per-agent Provider
Memory AgentSpec::memory(MemoryBinding::new(agent_id).root("team:acme")) → team:acme/agent:<agent_id>

The actual work: close the documented leaks

crates/openhuman-embed/README.md has a section headed "Still runtime-wide", introduced as "documented rather than hidden; each is a candidate follow-up in the core." That list is this issue's backlog. Plus two more found in the code and in QA.

1 — Autonomy is read from the runtime, not the agent. autonomy.auto_approve / auto_approve_all and the memory guard's autonomy tier come from the runtime's boot config (security::live_policy), not the agent's — while path and command policy correctly use the agent's own tier. One agent's autonomy setting therefore applies to all.

2 — The approval gate is process-wide, and parked approvals are not labelled with the agent id. For a global chatbot this is a correctness problem, not a configuration one: with many agents parked on approvals, there is no way to tell whose approval is whose, or to route one user's decision to their own agent. Today a per-agent "no approvals" has to be expressed as Access::full().

3 — The sub-agent catalogue is runtime-wide. Built-ins plus <workspace>/agents/*.toml are shared; embedded agents cannot be delegate_* targets of one another; and built-in ids (orchestrator, summarizer, …) must not be reused, which is a collision hazard when agent ids come from user data.

4 — Several subsystems re-read the runtime's on-disk config instead of the agent's overlay — sub-agents an agent spawns, the tinyagents journal, and the experience store. An agent's overlay is therefore not authoritative for the work it causes.

5 — Agents sharing a workspace share the dynamic MCP registry. mcp_registry_* is shared, and the host-seeded documentation server is visible to every agent. The user's ask is for per-agent MCP instances, so this is the gap: static per-agent servers work, the dynamic registry does not.

6 — Session and in-flight state live in process-global statics. web_chat/ops/state.rs:

pub(crate) static THREAD_SESSIONS: Lazy<Mutex<HashMap<String, SessionEntry>>> = …;
pub(crate) static IN_FLIGHT:       Lazy<Mutex<HashMap<String, InFlightEntry>>> = …;

Keys are composite strings — invalidate_thread_sessions matches k == thread_id || k.ends_with("::{thread_id}") — so there is some namespacing, but the state is not owned by an agent and every agent's sessions contend on one mutex. At 500 agents that is both an isolation boundary enforced by string convention and a scalability concern. This should become per-agent state the runtime owns.

7 — The memory module's source registry cannot be rebound in-process. Observed in a running build:

[core-context] workspace rebound to ~/.openhuman/users/<id>/workspace while the memory module is
already loaded. The module keeps the source registry it was given when it loaded and cannot be
rebound in this process, so memory sources registered under this profile will not be visible to
it until the app is restarted.

A runtime that hosts agents created at different times cannot restart to pick up a new agent's memory sources. This is the one item that may force a module-loading change rather than a config change, and it should be investigated first because it could reshape the rest.

Agent lifecycle

The current tests build their agents up front. A global chatbot creates and destroys agents while the runtime is live, so this issue should also settle:

  • Can an agent be added to a running runtime, and removed, with its sessions, MCP clients and skills torn down cleanly?
  • What happens to an agent's parked approvals and in-flight turns when it is removed?
  • Is there a cap, and what happens past it? 500 agents is measured, not a documented limit.

Keep it abstracted for library use

openhuman-embed is the right seam and already owns the typed facade — AgentSpec, Access, MemoryBinding, Workspace, ToolScopeSpec. Each leak above should close by moving the setting onto AgentSpec and having the core read it from the agent, not by adding host-side workarounds. tests/public_api.rs pins the host-facing contract at compile time, so any surface change shows up there deliberately.

Where a concern genuinely belongs to the process rather than an agent — the keyring, the RPC bearer, the event bus — it stays where it is and gets documented as such, exactly as "One runtime per process" does today.

Related

  • #7002 — per-user scoping on CortexDB. Same shape of problem one layer down: memory already isolates per agent via MemoryBinding, but the engine beneath it does not enforce isolation itself.
  • #6718 — memory engine stabilisation; per-agent memory sources are affected by item 7.
  • OpenCompany is the existing consumer of openhuman-embed and already runs many agents through it, so it is the natural proving ground — opencompany#2465 moves orchestration into TinyHiveMind on the same seam.

Acceptance Criteria

  • [ ] Item 7 — the memory source registry rebinding limit — is investigated first, and its finding recorded here, since it may change the approach for everything else
  • [ ] autonomy.auto_approve / auto_approve_all and the memory guard's autonomy tier are read from the agent, not the runtime boot config
  • [ ] Parked approvals carry the agent id, and an approval decision can be routed to one agent without affecting another
  • [ ] A per-agent "no approvals" is expressible without resorting to Access::full()
  • [ ] The sub-agent catalogue is resolvable per agent, and an agent id colliding with a built-in is rejected with a clear error rather than silently shadowing it
  • [ ] Sub-agents, the tinyagents journal and the experience store read the agent's overlay rather than the runtime's on-disk config
  • [ ] The dynamic MCP registry is per agent; two agents sharing a workspace do not see each other's dynamically registered servers
  • [ ] Session and in-flight state is owned per agent rather than held in process-global Lazy statics, and agents no longer contend on a single mutex
  • [ ] Agents can be added to and removed from a live runtime, with sessions, MCP clients and skills torn down — and defined behaviour for in-flight turns and parked approvals on removal
  • [ ] An isolation test in the style of runtime_agents.rs covers every item above — each asserted by a leak failing the test, not by inspection
  • [ ] tests/public_api.rs reflects any surface change deliberately
  • [ ] The "Still runtime-wide" section of the embed README is reduced to only what genuinely belongs to the process, with the rest moved to the per-agent table
  • [ ] Density is re-measured after the change — the ~1.77 MiB marginal cost per agent must not regress materially

Al629176 avatar Oct 06 '26 12:10 Al629176

Close the documented runtime-wide isolation leaks in openhuman-embed so one runtime can host many fully isolated agents (per-agent autonomy, approval routing, sub-agent catalogue, config overlays, dynamic MCP registry, session state, memory source rebinding), plus settle agent add/remove lifecycle on a live runtime, with isolation tests per leak.

Labelled priority: p2.

tinysweeper avatar Oct 06 '26 13:10 tinysweeper

Findings from the investigation before implementation. These items in the issue no longer match main:

Item 7: the memory source registry rebinding limit is gone on main. The warning came from the memory module, which was a TinyBus cdylib loaded once per process with the boot config_path. TinyBus never unloads a module, so a later profile could not rebind it. Two commits removed both the module and the warning:

  • 3cfae43d69 removed the memory module (there is no modules/memory.rs and no tinymemory registry record).
  • 6020c7e548 removed warn_if_memory_module_outlived_its_profile together with the context's memory binding.

Memory now links the tinymemory crates directly and resolves its engine on each call. The engine cache is keyed by a config fingerprint (engine, endpoint, credential identity and layout), so an agent created late gets its own namespace without a restart. No module-loading change is needed, and the rest of the plan does not depend on this item.

What was left of item 7 is handled in the PR:

  • The memory_sources_sync cron job now syncs the sources of every live agent under that agent's own context. Before, it ran once against the boot config.
  • An agent's memory.sources is still a snapshot taken when the agent is created. An API to add a source to a running agent is out of scope because nothing needs it yet.

The experience store. There is no agent/experience module on main. The turn runner passes no experience capability (experience: None), so no experience store re-reads the boot config. The agent README row that pointed at it has been removed.

The host-seeded documentation server. The documentation tools are hard-coded deferred tools in the tool registry, not an MCP server, so no shared server exists for agents to see. MCP servers are now per agent in any case: each agent has its own host and dynamic registry under <workspace>/agents/<id>/.

The memory guard's autonomy tier. No memory-guard code reads the tier. The security README pointed at memory/guard/policy.rs, which does not exist. The only caller of enforce_write_tier is the policy's own enforce_tool_operation, and that reads the agent's policy. The stale reference has been removed from the README.

oxoxDev avatar Oct 09 '26 14:10 oxoxDev

Filed #7500 — a production-readiness and security audit covering session persistence, context storage, restart recovery and cross-user isolation.

It leans on this issue heavily: the runtime-wide leaks documented here (sub-agent catalogue, process-wide approval gate with unlabelled approvals, shared dynamic MCP registry, autonomy read from boot config, session state in process-global maps) are most of what #7500 would be verifying. This issue implements; that one proves, adversarially, with two users deliberately trying to reach each other.

The urgency is chottu-core, which puts a separate user behind every agent in one runtime and promises outright that "users never share an agent, a conversation thread, a memory subtree, or a lock held during a turn." That promise is made by Chottu and kept — or not — here.

Al629176 avatar Oct 12 '26 08:10 Al629176