Skip to main content

SessionActor Pattern

The SessionActor pattern is the core of Monolex’s terminal architecture. It eliminates all locks by ensuring a single owner for all session state.

The Problem: Lock Contention

Traditional terminal architectures suffer from lock contention:
Problems:
  • Lock contention under high load
  • Potential for deadlocks
  • Complex reasoning about concurrent access
  • Performance degradation

The Solution: Single Owner

SessionActor owns all state. No locks required.

Implementation

Core Structure

Command Pattern

All operations are sent as commands through MPSC channels:

Event Loop

Benefits

GridWorker: Per-Session Processing

Each session has its own GridWorker running in a separate task:

Message Flow Example

Why Not Other Patterns?

Why not RwLock?

  • Still has contention between readers and writers
  • Deadlock potential with multiple locks
  • Complex upgrade/downgrade semantics

Why not Actor per Operation?

  • Too fine-grained, message passing overhead
  • Loses locality of related state
  • Harder to reason about ordering

Why SessionActor?

  • Natural boundary: one actor per “thing” (terminal sessions)
  • All related state co-located
  • Simple event loop, easy to understand
  • Guaranteed ordering within actor

SMPC/OFAC Applied