feat(terminal): add IPC channel to reduce live scrollback buffers under memory pressure#3344
Merged
gregpriday merged 3 commits intodevelopfrom Mar 16, 2026
Merged
Conversation
- Add TERMINAL_REDUCE_SCROLLBACK and TERMINAL_RESTORE_SCROLLBACK channels - Add typed IpcEventMap entries for both new channels - Expose onReduceScrollback/onRestoreScrollback in preload terminal namespace - Add client and controller subscription wrappers - Add reduceScrollback/restoreScrollback methods to TerminalInstanceService - Wire up listeners in setupTerminalStoreListeners with proper cleanup - Reduce skips focused, scrolled-back, and already-reduced terminals - Restore computes correct target from getScrollbackForType + performance mode
…NELS map and update test mock The preload.cts inlines channel names rather than importing from channels.ts (to avoid ESM/CJS format conflicts). TERMINAL_REDUCE_SCROLLBACK and TERMINAL_RESTORE_SCROLLBACK were added to channels.ts but not to the inline copy in preload.cts, causing two typecheck errors. Also added onReduceScrollback and onRestoreScrollback to the terminalClient mock in the processDetectionListeners test so setupTerminalStoreListeners can call them without throwing. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Fix buffer length check to exclude viewport rows (scrollbackUsed = length - rows) - Account for project-level scrollback override in restoreScrollback - Add useProjectSettingsStore import for project override lookup - Add comprehensive unit tests for reduceScrollback and restoreScrollback
Collaborator
Author
|
Review status: Ready Well-structured IPC addition for scrollback pressure management. Safety guards (skip focused, skip scrolled-back, skip already-below-target) are all correct. Restore path properly accounts for performance mode and project-level overrides. Comprehensive test suite (207 lines). Cross-PR note: Shares |
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_REDUCE_SCROLLBACKandTERMINAL_RESTORE_SCROLLBACK) that let the main process push scrollback reduction requests to live xterm.js instances in the rendererTerminalInstanceService) handles these events by loweringterminal.options.scrollbackon targeted background terminals, skipping any that are focused, visible, or scrolled away from the bottomResolves #3287
Changes
electron/ipc/channels.ts— two new channel constantselectron/preload.cts— inlineCHANNELSmap updated; two newterminalevent listeners exposedshared/types/ipc/api.ts+maps.ts— typed payloads for the new channelssrc/clients/terminalClient.ts—reduceScrollback/restoreScrollbackclient methodssrc/services/terminal/TerminalInstanceService.ts—handleReduceScrollbackandhandleRestoreScrollbackhandlers with safety checks (focus, visibility, scroll position)src/controllers/TerminalRegistryController.ts— wires up the new IPC listenerssrc/store/terminalStore.ts—reduceScrollback/restoreScrollbackstore actionssrc/services/terminal/__tests__/TerminalInstanceService.scrollback.test.ts— 207-line test suite covering all paths including skip conditions and restore behaviourTesting
Unit tests pass (
npm run checkclean, 298 pre-existing warnings, 0 errors). The new test file covers: reducing a background terminal, skipping focused terminals, skipping visible terminals, skipping terminals scrolled away from the bottom, skipping terminals with fewer buffered lines than the new limit, and the restore path.