Skip to content

feat(terminal): add IPC channel to reduce live scrollback buffers under memory pressure#3344

Merged
gregpriday merged 3 commits intodevelopfrom
feature/issue-3287-no-mechanism-reduce-live
Mar 16, 2026
Merged

feat(terminal): add IPC channel to reduce live scrollback buffers under memory pressure#3344
gregpriday merged 3 commits intodevelopfrom
feature/issue-3287-no-mechanism-reduce-live

Conversation

@gregpriday
Copy link
Collaborator

Summary

  • Adds two new IPC channels (TERMINAL_REDUCE_SCROLLBACK and TERMINAL_RESTORE_SCROLLBACK) that let the main process push scrollback reduction requests to live xterm.js instances in the renderer
  • The renderer (TerminalInstanceService) handles these events by lowering terminal.options.scrollback on targeted background terminals, skipping any that are focused, visible, or scrolled away from the bottom
  • A system message is written to each affected terminal so the user knows why older history is gone, and scrollback can be restored to the user-configured default when pressure subsides

Resolves #3287

Changes

  • electron/ipc/channels.ts — two new channel constants
  • electron/preload.cts — inline CHANNELS map updated; two new terminal event listeners exposed
  • shared/types/ipc/api.ts + maps.ts — typed payloads for the new channels
  • src/clients/terminalClient.tsreduceScrollback / restoreScrollback client methods
  • src/services/terminal/TerminalInstanceService.tshandleReduceScrollback and handleRestoreScrollback handlers with safety checks (focus, visibility, scroll position)
  • src/controllers/TerminalRegistryController.ts — wires up the new IPC listeners
  • src/store/terminalStore.tsreduceScrollback / restoreScrollback store actions
  • src/services/terminal/__tests__/TerminalInstanceService.scrollback.test.ts — 207-line test suite covering all paths including skip conditions and restore behaviour

Testing

Unit tests pass (npm run check clean, 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.

gregpriday and others added 3 commits March 16, 2026 15:29
- 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
@gregpriday
Copy link
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 TerminalRegistryController.ts with PR #3343 but touches entirely different areas (scrollback IPC handlers vs prewarm theme). No semantic conflict — merge in either order relative to #3343.

@gregpriday gregpriday merged commit 69f6c0b into develop Mar 16, 2026
4 checks passed
@gregpriday gregpriday deleted the feature/issue-3287-no-mechanism-reduce-live branch March 16, 2026 05:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No mechanism to reduce live terminal scrollback buffers under memory pressure

1 participant