Skip to content

Register PTY output processors in memory profile census - #12795

Merged
AmethystLiang merged 1 commit into
mainfrom
crash-c1-pty-side-effect-gauge
Aug 6, 2026
Merged

AmethystLiang merged 1 commit into
mainfrom
crash-c1-pty-side-effect-gauge

Conversation

@AmethystLiang

Copy link
Copy Markdown
Contributor

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() and destroy() 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

  • Added comprehensive tests for census registration, disposal, and gauge accuracy
  • Tests verify processors drop from census on detach, destroy, and parked-watcher dispose
  • Tests verify census survives errors during teardown (destroy with IPC throw)
  • pnpm lint
  • pnpm typecheck
  • pnpm test
  • pnpm build

AI 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.

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.
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Added 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 finally blocks for cleanup when disconnect operations throw. Tests cover aggregation, queue lifecycle, gauge limits, detach, destroy, and failure paths.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the change, testing scope, screenshots, and notes, but the AI Review Report and Security Audit sections remain TODO. Complete the AI Review Report and Security Audit sections, and report the status of the repository checks required by the template.
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: registering PTY output processors in the memory profile census.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 win

Keep reused transports registered in the census.

detach() disposes the processor gauge. Both transports can still run connect() or attach() afterward. Neither path re-registers the gauge. A reused transport then processes PTY output without contributing to ptySideEffects counts. This contradicts the documented terminal detach() 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

📥 Commits

Reviewing files that changed from the base of the PR and between 2ff2a1b and bd54110.

📒 Files selected for processing (9)
  • src/renderer/src/components/terminal-pane/parked-terminal-byte-watcher.test.ts
  • src/renderer/src/components/terminal-pane/parked-terminal-byte-watcher.ts
  • src/renderer/src/components/terminal-pane/pty-side-effect-pending-census.test.ts
  • src/renderer/src/components/terminal-pane/pty-side-effect-pending-census.ts
  • src/renderer/src/components/terminal-pane/pty-transport-types.ts
  • src/renderer/src/components/terminal-pane/pty-transport.test.ts
  • src/renderer/src/components/terminal-pane/pty-transport.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.test.ts
  • src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts

@AmethystLiang
AmethystLiang merged commit 9ce9ce9 into main Aug 6, 2026
44 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
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.
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