Local PTY: bound write back-pressure (deadlock fix) and coalesce read callbacks#3
Merged
arach merged 1 commit intoJul 12, 2026
Conversation
Two robustness/efficiency fixes to TerminiLocalPTYProcess: send() retried EAGAIN/EWOULDBLOCK with usleep(5ms) in an unbounded loop. If the reader never drains (e.g. a stalled SSH link on the other side of the PTY), that loop runs forever and wedges the serial queue — which then deadlocks any queue.sync caller, notably terminate(), hanging the host app's shutdown. The stall is now capped at ~1s, after which the remaining bytes are dropped. drainOutput() emitted one onOutput callback (one main-thread hop + one terminal feed) per 4 KB read. All bytes readable in a drain pass are now batched into a single callback, bounded at 128 KB per emission, so output floods cost a handful of wakeups instead of hundreds per second. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RcSW6KsDkBruL1dPD63rhX
This was referenced Jul 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two
TerminiLocalPTYProcessfixes from running Termini in production in Belfry, a tmux front-end (the contributions mentioned in #2).Bounded write back-pressure (deadlock fix).
send()retriesEAGAIN/EWOULDBLOCKwithusleep(5ms)in an unbounded loop. If the PTY's reader never drains — we hit this with a stalled SSH link running under the PTY — the loop runs forever and wedges the serial queue, which then deadlocks anyqueue.synccaller, most notablyterminate(). In our case that hung app shutdown hard enough that users force-killed the app. The stall is now capped at ~1s, after which the remaining bytes are dropped.Coalesced read callbacks (perf).
drainOutput()emitted oneonOutputcallback — one main-thread hop plus one terminal feed — per 4 KBread(). A fast producer (build logs,catof a big file) caused hundreds of main-thread wakeups per second. All bytes readable in a drain pass are now batched into a single callback, bounded at 128 KB per emission so a sustained firehose still yields downstream periodically.Both changes are behavior-preserving for well-behaved peers;
swift buildclean on macOS.🤖 Generated with Claude Code
https://claude.ai/code/session_01RcSW6KsDkBruL1dPD63rhX