Repository navigation
refactor(desktop): remove escape filter from terminal hot path - #497
Conversation
Remove TerminalEscapeFilter processing from the terminal session data handler. The filter was running regex on every data chunk to strip terminal query responses (device attributes, cursor reports, etc.) before storing scrollback. This complexity is unnecessary - escape sequence filtering will be handled by using xterm.js serialize addon on the cold path (session persistence) rather than processing every chunk on the hot path. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…ction Remove the TerminalEscapeFilter class and all query response filtering patterns. Keep only the clear scrollback detection functions which are still needed to detect when the user clears the terminal (Cmd+K / clear). Removed: - TerminalEscapeFilter class (stateful chunked filter) - filterTerminalQueryResponses function - All FILTER_PATTERNS for CPR, DA1, DA2, DA3, DECRPM, OSC, etc. - ~500 lines of test code for the removed functionality Kept: - containsClearScrollbackSequence() - detects ESC[3J - extractContentAfterClear() - extracts content after clear 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
Warning Rate limit exceeded@Kitenite has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 0 minutes and 39 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughSimplifies terminal escape sequence handling by replacing a stateful TerminalEscapeFilter class with two focused utility functions (containsClearScrollbackSequence, extractContentAfterClear) and removing filter usage from session management and recovery logic. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
apps/desktop/src/main/lib/terminal/session.ts (1)
29-36: Scrollback truncation approach is sound.The slice-based truncation to 500,000 characters is a pragmatic approach that avoids the per-chunk regex processing overhead. Using
slice(-MAX_SCROLLBACK_CHARS)correctly preserves the most recent content.Consider extracting
MAX_SCROLLBACK_CHARSto a configuration or constants module if this limit might need adjustment based on user feedback or memory constraints.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
apps/desktop/src/main/lib/terminal-escape-filter.test.tsapps/desktop/src/main/lib/terminal-escape-filter.tsapps/desktop/src/main/lib/terminal/session.test.tsapps/desktop/src/main/lib/terminal/session.tsapps/desktop/src/main/lib/terminal/types.ts
💤 Files with no reviewable changes (2)
- apps/desktop/src/main/lib/terminal/types.ts
- apps/desktop/src/main/lib/terminal-escape-filter.test.ts
🧰 Additional context used
📓 Path-based instructions (6)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Avoid using any type in TypeScript - maintain type safety unless absolutely necessary
Files:
apps/desktop/src/main/lib/terminal/session.tsapps/desktop/src/main/lib/terminal-escape-filter.tsapps/desktop/src/main/lib/terminal/session.test.ts
**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (AGENTS.md)
Run Biome for formatting, linting, import organization, and safe fixes at the root level using bun run lint:fix
Files:
apps/desktop/src/main/lib/terminal/session.tsapps/desktop/src/main/lib/terminal-escape-filter.tsapps/desktop/src/main/lib/terminal/session.test.ts
apps/desktop/src/{main,renderer,preload}/**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Use type-safe IPC communication - define channel types in apps/desktop/src/shared/ipc-channels.ts before implementing handlers
Files:
apps/desktop/src/main/lib/terminal/session.tsapps/desktop/src/main/lib/terminal-escape-filter.tsapps/desktop/src/main/lib/terminal/session.test.ts
apps/desktop/src/main/**/*.ts
📄 CodeRabbit inference engine (AGENTS.md)
Accept object parameters in IPC handlers - do not use positional parameters in ipcMain.handle()
Files:
apps/desktop/src/main/lib/terminal/session.tsapps/desktop/src/main/lib/terminal-escape-filter.tsapps/desktop/src/main/lib/terminal/session.test.ts
apps/desktop/**/*.{ts,tsx}
📄 CodeRabbit inference engine (apps/desktop/AGENTS.md)
apps/desktop/**/*.{ts,tsx}: For Electron interprocess communication, ALWAYS use tRPC as defined insrc/lib/trpc
Use alias as defined intsconfig.jsonwhen possible
Prefer zustand for state management if it makes sense. Do not use effect unless absolutely necessary.
For tRPC subscriptions with trpc-electron, ALWAYS use the observable pattern from@trpc/server/observableinstead of async generators, as the library explicitly checksisObservable(result)and throws an error otherwise
Files:
apps/desktop/src/main/lib/terminal/session.tsapps/desktop/src/main/lib/terminal-escape-filter.tsapps/desktop/src/main/lib/terminal/session.test.ts
**/*.test.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Place tests co-located with components using .test.ts or .test.tsx naming convention
Files:
apps/desktop/src/main/lib/terminal/session.test.ts
🧬 Code graph analysis (1)
apps/desktop/src/main/lib/terminal/session.ts (1)
apps/desktop/src/main/lib/terminal/port-manager.ts (1)
portManager(359-359)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Build
🔇 Additional comments (5)
apps/desktop/src/main/lib/terminal-escape-filter.ts (1)
1-46: Clean refactor of escape filter utilities.The simplified API with
containsClearScrollbackSequenceandextractContentAfterClearis well-designed. Good documentation explaining why RIS (ESC c) is intentionally excluded to avoid interfering with TUI applications.The dual representation (RegExp for
test()and string constant forlastIndexOf()) is appropriate for their respective use cases.apps/desktop/src/main/lib/terminal/session.test.ts (2)
32-51: Test appropriately simplified to match the refactor.The test now correctly validates that raw content is recovered from disk without escape sequence filtering. The assertion on Line 46 directly compares against
scrollbackContent, which is the expected behavior after removing the filter processing.
78-96: Test coverage reduced but aligned with simplifiedflushSession.The test now only verifies
dataBatcher.dispose()is called, which matches the simplified implementation. The localdisposedflag approach is clean and straightforward.apps/desktop/src/main/lib/terminal/session.ts (2)
152-178: Hot path optimization looks correct.The data handler now:
- Correctly detects clear scrollback sequences and resets scrollback
- Stores raw
dataToStoredirectly without regex filtering per chunk- Scans for ports in raw output
This aligns with the PR objective to remove per-chunk regex processing. The trade-off (storing terminal query responses in scrollback) is acceptable since xterm.js serialize addon handles cleanup on the cold path during session save/restore.
220-222: Flush logic correctly simplified.With the escape filter removed,
flushSessionnow only needs to dispose the data batcher. This is cleaner and matches the refactored architecture.
32f09db to
fb1a8bc
Compare
Summary
TerminalEscapeFilterfrom terminal session data handler - no more regex processing on every PTY data chunkterminal-escape-filter.tsfrom ~300 lines to 46 lines, keeping only clear scrollback detection (ESC[3J)The escape filter was designed to strip terminal query responses (device attributes, cursor reports, color responses) before storing scrollback. This prevented "garbage" characters on session replay, but added complexity:
New approach: Store raw scrollback during runtime. For clean persistence, xterm.js serialize addon can be used on the cold path (session save/restore) rather than filtering every chunk.
Test plan
bun testpasses for session and escape filter testsbun run typecheckpassesclearcommand / Cmd+K still clears scrollback correctly🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes
Refactor
Tests
✏️ Tip: You can customize this high-level summary in your review settings.