Skip to main content

Concurrency Patterns: The 5-Pattern Pipeline

Monolex uses a synergistic pipeline of five concurrency patterns to handle high-volume terminal output. Each pattern solves its own problem AND enables the next pattern to work correctly.

The Complete Pipeline

Data Reduction Summary

All 10,000 updates are PROCESSED by the VTE parser. Only EMISSION to frontend is reduced. This is state coalescing, not data loss.

Pattern 1: Actor over Mutex

SessionActor pattern eliminates lock contention through message-passing concurrency.

The Problem

Multiple sources want terminal state simultaneously:
Without protection: DATA RACE

Why Actor Wins

Mutex Approach

  • Writers block readers
  • Lock contention under high PTY output
  • Priority inversion (resize blocks PTY)
  • Deadlock risk with multiple resources

Actor Approach

  • No blocking (async send)
  • FIFO guaranteed
  • Impossible deadlock
  • Easy to reason about

Timeline Comparison

Mutex:
Actor:
Pattern Origin: Actor model from Carl Hewitt (1973), proven in Erlang telecom systems (99.9999999% uptime).

Pattern 2: ACK Flow Control

ACK gate blocks updates when waiting for frontend confirmation.

ACK State Machine

Timeline Example


Pattern 3: EPOCH Sync (Resize Safety)

Epoch validation prevents stale GridUpdates after resize.

The Resize Problem

EPOCH Solution


Pattern 4: AtomicState Absorber

AtomicState overwrites instead of queuing, guaranteeing fixed memory.

Overwrite vs Queue

Queue Approach (BAD)

Overwrite Approach (GOOD)

Memory Calculation

Memory Comparison (1 minute of high output)

The Dual Guarantee


Pattern 5: BSU/ESU Detection

Synchronized Update detection prevents mid-frame rendering.

How It Works

Timeout Safety

If ESU never arrives, timeout releases the gate after 16ms to prevent deadlock.

Synergy Matrix

Each pattern solves its own problem AND helps others:

Reverse Dependency (Efficiency Cascade)


What If You Remove a Pattern?

  • Bounded channel would drop data when full
  • Terminal output corrupted, missing content
  • User sees incomplete results
  • No kernel-level backpressure
  • Pattern 1’s unbounded channel could grow infinitely
  • Memory explosion if Tauri is slow
  • Multiple threads accessing state simultaneously
  • Race conditions, data corruption
  • Locks required -> contention -> slowdown
  • Need queue between Actor and ACK
  • Queue grows: 10,000 - 60 = 9,940 items/sec accumulation
  • Memory grows indefinitely
  • Temporal mismatch: user sees past, not present
  • Frontend receives all ~500 coalesced states/sec
  • xterm.js event queue grows
  • Frame drops, stuttering
  • Screen instability

Pattern Origins

These are NOT new inventions. They are PROVEN patterns combined for terminal rendering:
Monolex’s innovation: Putting these patterns together in the RIGHT LAYER (VTE parsing layer, not IPC layer).

SMPC/OFAC Applied

SMPC (Simplicity is Managed Part Chaos):
  • Each pattern is SIMPLE (one purpose, one guarantee)
  • Combined, they handle COMPLEX scenarios (high output, concurrent access)
  • No single “complex” solution - 5 simple solutions working together
OFAC (Order is a Feature of Accepted Chaos):
  • Accept: PTY output is chaotic (unlimited, unpredictable)
  • Accept: Renderer is slow (60fps max)
  • Accept: Intermediate states don’t matter
  • Order emerges: User sees current state, screen is stable
The architecture doesn’t FIGHT chaos. It ACCEPTS chaos and extracts ORDER.