The two-layer model
MirrorNeuron enforces a hard split between its control plane and its execution plane.- Control plane (BEAM)
- Execution plane (OpenShell)
The control plane lives entirely in BEAM. It manages:
- Job orchestration and lifecycle
- Message routing between agents
- Supervision and fault recovery
- Redis-backed persistence for job state, snapshots, and event history
- Retry and backoff logic
- Aggregation and event history
- Cluster coordination via
libclusterandHorde
Logical workers vs execution leases
The most important distinction in the MirrorNeuron runtime is between a logical worker and an execution lease.Logical workers
A logical worker is a BEAM process that represents one node in your workflow graph. It:- receives messages from the router
- holds workflow state in memory
- can wait for work cheaply without consuming OS resources
- emits events to the runtime event bus
- may request external execution when it is an
executornode
Execution leases
An execution lease is permission to consume sandbox capacity. When anexecutor node handles a message, it does not immediately start a sandbox. Instead, it first requests a lease from MirrorNeuron.Execution.LeaseManager:
Request a lease
The executor emits an
executor_lease_requested event and requests a slot from its assigned pool and slot count.Wait if capacity is exhausted
If the pool has no free slots, the lease request queues until a slot is released. The logical worker waits without blocking any other BEAM process.
Run the sandbox
Once the lease is granted, the executor emits
executor_lease_acquired and runs the OpenShell command.Executor pools and slot accounting
MirrorNeuron assigns executor capacity through named pools. Each pool has a configurable slot count. Every executor node request consumes one or more slots from its assigned pool. Configure the default pool capacity using the environment variable:pool, the executor uses "default". If you omit pool_slots, it requests 1 slot.
Pools are currently enforced per runtime node. When you need more execution capacity, you scale out by adding nodes — each node brings its own bounded pool. A four-node cluster with eight slots per node supports up to 32 concurrent sandboxes, regardless of how many logical workers are waiting.
Scaling example
| Logical workers | Nodes | Slots per node | Max concurrent sandboxes |
|---|---|---|---|
| 100 | 1 | 4 | 4 |
| 1000 | 4 | 8 | 32 |
| 5000 | 10 | 8 | 80 |
Message model
Every message that flows between agents in MirrorNeuron follows a fixed four-section structure. This keeps the runtime generic: BEAM only needs to read theenvelope to route and observe messages. It never needs to parse your application payload to work correctly.
envelope
Theenvelope is runtime-owned. It carries all routing and trace metadata: the source and destination node IDs, the message type and class, a correlation chain for tracing, delivery attempt count, priority, and content negotiation fields. The runtime reads the envelope to route messages and record event history.
headers
Theheaders object is extensible routing and schema metadata. Use it for schema references, content negotiation hints, or any metadata that a downstream agent or router needs to inspect without parsing the full body.
body
Thebody is your application-owned payload. The runtime treats it as opaque. Workers running in OpenShell sandboxes read and write the body through the payload contract — BEAM only forwards it.
artifacts
Theartifacts array carries references to large externalized data objects. Pass IDs or storage references here instead of embedding large blobs directly in the body. Keeping messages small is important in a clustered runtime: small control messages route and persist much more efficiently than inline payloads.
stream
The optionalstream field carries framing metadata for streaming or chunked message flows. It is null on non-streaming messages.
Why this scales better
The alternative — launching one sandbox for every logical worker immediately — breaks down under fan-out:- Gateway connections spike and reset under launch pressure
- OS subprocess count climbs without bound
- Duplicate cleanup races emerge when sandboxes fail mid-flight
- No backpressure exists to slow down the producer side