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
Pattern 1: Actor over Mutex
SessionActor pattern eliminates lock contention through message-passing concurrency.The Problem
Multiple sources want terminal state simultaneously: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: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
Synergy Matrix
Each pattern solves its own problem AND helps others:Reverse Dependency (Efficiency Cascade)
What If You Remove a Pattern?
Without Pattern 1 (Unbounded Channel)
Without Pattern 1 (Unbounded Channel)
- Bounded channel would drop data when full
- Terminal output corrupted, missing content
- User sees incomplete results
Without Pattern 2 (Socket Buffer)
Without Pattern 2 (Socket Buffer)
- No kernel-level backpressure
- Pattern 1’s unbounded channel could grow infinitely
- Memory explosion if Tauri is slow
Without Pattern 3 (Actor)
Without Pattern 3 (Actor)
- Multiple threads accessing state simultaneously
- Race conditions, data corruption
- Locks required -> contention -> slowdown
Without Pattern 4 (AtomicState)
Without Pattern 4 (AtomicState)
- 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
Without Pattern 5 (ACK)
Without Pattern 5 (ACK)
- 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
- 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