How cmux stays responsive
cmux runs many Claude Code and Codex sessions side by side, and the window has to keep up with all of them. A hang, a spinning cursor, or a row that stutters as it opens almost always has one cause: something ran on the main thread and had to wait. These are the fixes that mattered most.
The top fixes
- A pipe write can block for minutes. Sending a prompt to a Claude Code or Codex process waits when the agent stops reading its input. Done on the main thread, that froze a Nightly for 391 seconds. The write now runs off the main thread (#39998).
- Small loops grow. Putting idle workspaces to sleep walked every listed chat once for every tab, a 3 to 4.6 second hang with many Claude Code and Codex chats open. One index built per pass fixed it (#40031).
- Starting a process is a blocking call too. Spawning one while closing a screen stalled the main thread for 807 ms. Process launches now go through the same checked seams as file and socket reads.
- Saving state wrote files on the main thread. Every store now writes through one background writer that keeps only the newest bytes for each file, writes once per window, and flushes at quit (#54456).
What we borrowed from Chrome
- The UI thread never blocks. Chrome's browser UI thread handles input and paints. Disk, network, waits on other processes and long computation run elsewhere, because time the UI thread spends busy is time the person sees.
- Work is posted, and the answer comes back as a task. Chrome posts work to sequences that run one task at a time on whichever pool thread is free. PostTaskAndReply runs the work there and posts the reply back to the thread that asked. Messages take the place of shared memory and locks.
- The rule is checked in code. ScopedBlockingCall marks every call that may block, ThreadRestrictions asserts in debug builds when one runs on a thread that must not block, and HangWatcher reports hangs with their stacks.
- A slow process can't freeze the browser. Renderer, GPU and utility processes run on their own, and the browser process never waits on one synchronously.
The rule behind them
The main thread dispatches input, makes the smallest change to visible state, and commits the frame. Disk, network, child processes, waits and long work run on named lanes off the main thread, and their results come back to it as a message, the way Chrome's PostTaskAndReply does:
let text = try await work.run(.userVisible, mayBlock: .files) {
try String(blockingContentsOf: url)
}
model.apply(text)Each lane has an owner, a priority and a bound, so a slow disk or a busy agent queues work instead of freezing the window.
How they stay fixed
Blocking calls go through checked seams that record any call made on the main thread, a watchdog reports stalls and hangs, and a pre-push check refuses new blocking calls in main-thread code. Nightly builds keep the seam checks on, so a hang someone hits points at the line that caused it.
Seeing a hang in a cmux NEXT Nightly?
Stream the blocking log while you reproduce it, then attach the lines to your report:
log stream --predicate 'category == "blocking"'