Skip to content

perf(terminal): fix write-buffer leak on destroy + lifecycle test harness - #55

Merged
JeanBaptisteRenard merged 1 commit into
mainfrom
perf/terminal-lifecycle-leaks
Jun 11, 2026
Merged

perf(terminal): fix write-buffer leak on destroy + lifecycle test harness#55
JeanBaptisteRenard merged 1 commit into
mainfrom
perf/terminal-lifecycle-leaks

Conversation

@JeanBaptisteRenard

Copy link
Copy Markdown
Collaborator

PR 1/4 — renderer memory plan (Stage 1: lifecycle hygiene)

First of the 4-PR sequence from the renderer memory-optimization plan (.work-files/switchboard/mem-opt-go-sidecar/option1-plan.md, baseline: 789 MB RSS, 462 MB renderer).

Changes

  • destroySession now clears the session's terminalWriteBuffers entry and cancels its scheduled rAF/timeout flush. Today the stale entry mostly self-heals, but it pins up to 256 KB of chunks per closed session and becomes a use-after-dispose hazard once disposal becomes routine (PR 3 introduces an LRU cap that disposes terminals).
  • Documents audited-safe lifecycles in code comments so they aren't re-audited: OSC-52 handler (owned by the parser, freed by terminal.dispose()), DnD/search-bar listeners (die with entry.element), and the intentional guard in flushTerminalBuffer.
  • New test/terminal-manager-lifecycle.test.js — jsdom + vm.runInContext harness for terminal-manager.js (the file had no direct coverage). Asserts full teardown: maps, write buffer, DOM, single dispose(). Shared lexical-scope trick documented for reading top-level consts.

Verification

task check green — 198/198 tests, 0 lint errors. No live Electron needed (and deliberately not used: single-instance lock).

No user-visible behavior change. PR 2 (scrollback differentiation) stacks on this branch for the shared test file.

…t handler lifecycles

destroySession left the session's terminalWriteBuffers entry (and its
scheduled rAF/timeout flush) in place. Mostly self-healing today, but it
holds up to 256 KB of chunks per closed session and becomes a real
use-after-dispose hazard once terminal disposal happens routinely
(upcoming LRU cap on live xterm instances).

Also documents the audited-safe lifecycles (OSC-52 parser handler, DnD
listeners, flush guard) so they aren't re-audited, and adds lifecycle
regression tests (jsdom harness for terminal-manager.js).
@JeanBaptisteRenard
JeanBaptisteRenard merged commit ac2b0c8 into main Jun 11, 2026
7 checks passed
@JeanBaptisteRenard
JeanBaptisteRenard deleted the perf/terminal-lifecycle-leaks branch June 11, 2026 08:39
abasiri pushed a commit that referenced this pull request Aug 1, 2026
…55)

Routes terminal copy through the main-process clipboard (the renderer's navigator.clipboard is unreliable on Wayland/Ozone) and wires up OSC 52 so programs in the terminal — including Claude Code — can set the system clipboard.

OSC 52 read-back queries are deliberately refused rather than answered, so a session cannot exfiltrate the user's clipboard; decodeOsc52Payload() documents that and test/clipboard-osc52.test.js pins it.

Co-authored-by: ymajoros <yannick@valuya.be>
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.

1 participant