Repository navigation
Register PTY output processors in memory profile census - #12795
Conversation
Add a new census module that tracks pending and retained OSC sequences across all active PTY output processors. Each processor registers a gauge at creation and unregisters it on dispose, detach, or destroy — this prevents retained gauges from inflating later heap high-water profiles and allows the memory profiler to detect stalled processors as a sign of leaks.
📝 WalkthroughWalkthroughAdded bounded PTY side-effect census tracking for pending queue entries, retained entries, and live processors. Output processors now register and dispose gauges. Parked terminal watchers and local and remote PTY transports dispose gauges during teardown. Destroy paths use 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/renderer/src/components/terminal-pane/pty-transport.ts (1)
1003-1020: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winKeep reused transports registered in the census.
detach()disposes the processor gauge. Both transports can still runconnect()orattach()afterward. Neither path re-registers the gauge. A reused transport then processes PTY output without contributing toptySideEffectscounts. This contradicts the documented terminaldetach()contract.
src/renderer/src/components/terminal-pane/pty-transport.ts#L1003-L1020: enforce terminal detach behavior, or re-register the gauge before reuse.src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts#L2293-L2316: enforce the same behavior for remote transports.src/renderer/src/components/terminal-pane/pty-transport-types.ts#L186-L188: retain this contract only after both implementations enforce it.Add reuse regression coverage for the selected behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: f2d381cc-c7d1-471c-a900-c3c259ffe048
📒 Files selected for processing (9)
src/renderer/src/components/terminal-pane/parked-terminal-byte-watcher.test.tssrc/renderer/src/components/terminal-pane/parked-terminal-byte-watcher.tssrc/renderer/src/components/terminal-pane/pty-side-effect-pending-census.test.tssrc/renderer/src/components/terminal-pane/pty-side-effect-pending-census.tssrc/renderer/src/components/terminal-pane/pty-transport-types.tssrc/renderer/src/components/terminal-pane/pty-transport.test.tssrc/renderer/src/components/terminal-pane/pty-transport.tssrc/renderer/src/components/terminal-pane/remote-runtime-pty-transport.test.tssrc/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts
Add a new census module that tracks pending and retained OSC sequences across all active PTY output processors. Each processor registers a gauge at creation and unregisters it on dispose, detach, or destroy — this prevents retained gauges from inflating later heap high-water profiles and allows the memory profiler to detect stalled processors as a sign of leaks.
Problem
PTY output processors were untracked in the memory profile, causing retained gauges to inflate later high-water snapshots. When transports detached or were destroyed, processors remained registered, leaking the gauge into subsequent profiles.
Solution
Added a census system using WeakRefs to track active PTY side-effect gauges. Each processor registers its pending and retained counts at creation;
detach()anddestroy()unregister via try/finally to ensure cleanup even if disconnect throws. The census is capped at 512 entries to bound growth if disposal is missed.Screenshots
No visual change.
Testing
pnpm lintpnpm typecheckpnpm testpnpm buildAI Review Report
TODO
Security Audit
TODO
Notes
Internal diagnostic feature; no behavioral changes. Uses weak references to prevent the census itself from leaking processor state.