[cherry-pick] Fix main process OOM from unconsumed buffered pty host service events - #336198
Merged
Merged
Conversation
Dmitriy Vasyura (dmitrivMS)
approved these changes
Sep 14, 2026
Dmitriy Vasyura (dmitrivMS)
enabled auto-merge (squash)
September 14, 2026 20:28
Contributor
Author
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: Robo (@deepak1556)Matched files:
Anthony Kim (@anthonykim1)Matched files:
|
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The PR description materially misstates the implemented option and lifecycle-event behavior.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Prevents unconsumed PTY process events from accumulating in the main process.
Changes:
- Selectively disables buffering for PTY process events while preserving lifecycle buffering.
- Adds unit, replay, restart, and smoke-test coverage.
File summaries
| File | Description |
|---|---|
src/vs/platform/terminal/common/localPtyChannel.ts |
Configures selective event buffering. |
src/vs/code/electron-main/app.ts |
Uses the specialized PTY channel. |
src/vs/base/parts/ipc/test/common/ipc.test.ts |
Tests buffered and unbuffered events. |
src/vs/platform/terminal/test/common/localPtyChannel.test.ts |
Tests channel subscription behavior. |
src/vs/platform/terminal/test/node/ptyHostService.test.ts |
Tests lifecycle events across restarts. |
src/vs/workbench/contrib/terminal/test/electron-browser/localPty.test.ts |
Tests direct-channel replay behavior. |
test/smoke/src/areas/terminal/terminal-persistence.test.ts |
Tests ordered replay after reconnection. |
Review details
- Files reviewed: 7/7 changed files
- Comments generated: 1
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Contributor
|
We should get manager approval |
Anthony Kim (anthonykim1)
disabled auto-merge
September 14, 2026 20:37
Anthony Kim (anthonykim1)
approved these changes
Sep 14, 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.
Cherry-pick of #323980 from
main.Fixes #234393. The crash dumps, heap snapshots, and retainer chains referenced below are in #307156, which was closed as a duplicate of it.
Problem
The main process accumulates all terminal PTY output in the V8 heap until it hits the ~4 GB heap ceiling and OOM-aborts (
Reached heap limit). Heavy ANSI producers in the integrated terminal (tmux status/pane redraws, TUI apps) crash the main process within hours; median ~4.2h across the 99 crash dumps in #307156.Root cause
ProxyChannel.fromServiceeagerly wraps every service event inEvent.buffer(..., flushAfterTimeout=true), which subscribes to the source immediately and queues each event into an array that is only flushed (and released) when a first listener attaches to the channel event.The main process registers
ILocalPtyServicethis way (app.ts) as theTerminalIpcChannels.LocalPtychannel. On desktop, the renderer consumes terminal data over the dedicated pty host connection (PtyHostWindowMessagePort, seelocalTerminalBackend.ts); theLocalPtychannel itself is only used for two method calls (getLatency,getProfiles) plus a handful of low-frequency pty-host lifecycle events (onPtyHostStart/onPtyHostExit/onPtyHostUnresponsive/onPtyHostResponsive/onPtyHostRequestResolveVariables, consumed byBaseTerminalBackend) — it never gets a listener for the high-volumeonProcessDataevent. So the eager buffer foronProcessData(one entry per PTY data chunk) grows for the lifetime of the process. Retainer chains in heap snapshots (see #307156) show ~99% of the heap held by exactly this array:Emitter._listeners → closure → Array[N] → { event: }.Fix
Adds a
disableEventBufferingoption toProxyChannel.ICreateServiceChannelOptions(naming follows the existingdisableMarshalling) that exposes service events on the channel without the eagerEvent.bufferwrapper, and applies it to theLocalPtychannel registration. Events fired before a listener attaches are dropped instead of retained. This is a whole-channel opt-out, so it also stops buffering the pty-host lifecycle eventsBaseTerminalBackendlistens to here; in practice that's low-risk (those fire only after a window's listener has attached, and the one early-fireable case — the initialonPtyHostStart— is a no-op perBaseTerminalBackend's ownhasStartedguard, see review discussion below). Per Dmitriy Vasyura (@dmitrivMS)'s plan, this PR ships as the accepted stop-gap; a follow-up telemetry pass will confirm whether any channel actually needs buffering restored before removing it fromfromServicegenerally.Testing
ipc.test.tscover the default (eager subscription, buffered) and the new option (no subscription untillisten, events delivered after).--disable-extensions, macOS arm64), measuring main-process RSS every 15 s on the same dev build with only this change toggled: