Bound PTY output queues under backpressure#7089
Open
brennanb2025 wants to merge 2 commits into
Open
Conversation
Co-authored-by: Orca <help@stably.ai>
Co-authored-by: Orca <help@stably.ai>
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.
Summary
This PR hardens PTY output delivery across daemon stream sockets, main-to-renderer IPC, renderer replay, and runtime/mobile terminal streams. It adds bounded backpressure queues, explicit pending-output caps, active-output priority lanes, and deterministic reliability-gate coverage.
Headline behavior status: implemented for the focused queue/backpressure slice. This does not replace broader terminal perf review or soak testing.
Stack Fit / Relationship to Other PRs
This is the high-value bounded-output/backpressure slice in the terminal reliability stack. It fits alongside #7001, #7008, #7005, #7004, #7006, and #7007 as the queue/IPC/runtime-stream hardening layer: those PRs cover adjacent terminal/session/runtime reliability work, while this PR focuses on stalled consumers, pending live output, and active-output starvation.
Perf review remains separate because these tests prove explicit byte/char/line/count contracts, not real-world keypress-to-paint latency across every TUI/provider/platform combination.
Anti-Regression Guarantees
Not an absolute no-regression guarantee. The evidence proves:
socket.write(false)and resume ondrain;ELI5
When terminals print too much text and the receiver is slow, Orca now stops piling up unlimited output. It keeps a bounded recent tail, gives the active terminal a small priority lane, and records exactly when output was dropped because a queue hit its cap.
Performance Proof
The daemon socket queue now honors drain, has both byte and line caps, and trims in one pass over a bounded queue. Main IPC uses rolling pending-output accounting instead of summing every pending PTY on each output event. Exit-time output is capped to one normal slice when the renderer lane has room; otherwise the pending tail is dropped and counted instead of bypassing ACK backpressure.
Perf audit result: initial findings on daemon tiny-line complexity, main pending total scans, and exit flush accounting were fixed and re-reviewed clean.
Usefulness / Material Impact
This makes hidden/background terminal floods less able to starve active terminal redraws or grow memory without bound. It also gives future regressions a focused gate with byte/char/line/drop evidence instead of relying on broad terminal flows.
Validation
pnpm exec vitest run --config config/vitest.config.ts src/main/daemon/daemon-stream-data-batcher.test.tspnpm exec vitest run --config config/vitest.config.ts src/main/ipc/pty.test.ts --testNamePattern "renderer backpressure|pending renderer output|interactive output|active PTY|in-flight output|PTY exit"pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/components/terminal-pane/pty-connection.test.ts --testNamePattern "remote replay"pnpm exec vitest run --config config/vitest.config.ts src/main/runtime/rpc/terminal-output-batching.test.ts src/main/runtime/rpc/terminal-subscribe-buffer.test.ts src/main/runtime/rpc/terminal-multiplex.test.tspnpm run check:reliability-gatespnpm run typecheck:nodepnpm run typecheck:webpnpm run typecheck:cligit diff --checkDesign review: completed; doc wording was corrected to distinguish main IPC char caps from runtime byte caps. Completeness/code review: completed; code review found no issues. Perf review: completed after fixes and re-review.
Residual Gaps
Merge Order
Open against
brennanb2025/fix-terminal-reliability. This can merge with the terminal reliability stack once CI/review are clean, but it should not be treated as a substitute for the separate perf review/soak work.Post-PR Stabilization
Pending automated checks and review feedback after PR creation.
Made with Orca 🐋