perf(terminal): defer MessagePort ACK to xterm write callback#4862
Merged
gregpriday merged 4 commits intodevelopfrom Apr 2, 2026
Merged
perf(terminal): defer MessagePort ACK to xterm write callback#4862gregpriday merged 4 commits intodevelopfrom
gregpriday merged 4 commits intodevelopfrom
Conversation
- Split ACK in installPortDataHandler: defer when live callbacks exist, immediate for early-buffered data (no xterm involved yet) - Add acknowledgePortData() method routing ACK via active MessagePort - Call acknowledgePortData in writeToTerminal for all three paths: hibernated, deferred-restore, and normal xterm write callback - Update tests: verify no immediate ACK on live-callback path, immediate ACK preserved for early-buffer, deferred ACK works
- Add pendingPortAckBytes FIFO queue preserving msg.bytes from pty-host - acknowledgePortData pops from queue to avoid UTF-16 vs UTF-8 mismatch - Skip port ACK when queue is empty (IPC data or early-buffer flush), preventing double-ACK for early-buffered data - Add tests for byte count preservation and empty-queue no-op behavior
…ce tests - Add acknowledgePortData: vi.fn() to terminalClient mock in 9 test files that mock the terminalClient module
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
terminal.write()callback, matching the IPC path's behaviour and making the watermark system the actual flow control gate as intended.Resolves #4849
Changes
src/clients/terminalClient.ts: removed immediate ACK in the MessagePortmessageevent handler; callbacks now receiveidandbyteCountso callers can defer ACK to after xterm consumptionsrc/services/terminal/TerminalInstanceService.ts: passesidandbyteCountthrough to the existingterminal.write()callback alongside the IPC path's ACK callsrc/clients/__tests__/terminalClient.test.ts: updated and extended tests covering deferred ACK behaviour, byte count passthrough, and the multi-callback fan-outTesting
Unit tests updated and passing. The change aligns MessagePort backpressure semantics with the existing IPC path, which has been stable in production.