Skip to content

fix(desktop): batch PTY output to prevent bun dev crashes in terminal#3001

Merged
Kitenite merged 1 commit into
mainfrom
bun-dev-crashing-in-terminal-pty-issue
Mar 30, 2026
Merged

fix(desktop): batch PTY output to prevent bun dev crashes in terminal#3001
Kitenite merged 1 commit into
mainfrom
bun-dev-crashing-in-terminal-pty-issue

Conversation

@Kitenite
Copy link
Copy Markdown
Collaborator

@Kitenite Kitenite commented Mar 30, 2026

Summary

  • Replace setImmediate with a 16ms setTimeout for PTY output flushing, coalescing rapid TUI redraws into coherent ~60fps frames instead of flooding the renderer with tiny per-turn frames
  • Extract workspaceRunRestartCommand computation outside the ref assignment in Terminal.tsx for clarity

Test plan

  • Run bun dev in the desktop terminal and verify it no longer crashes
  • Confirm interactive terminal echo still feels responsive (no perceptible lag from the 16ms batching)
  • Test TUI apps (e.g. htop, vim) render correctly without flickering

Summary by cubic

Batch PTY output every 16ms (~60fps) to stop flooding the renderer and fix crashes in the desktop terminal when running bun dev. Also moved workspaceRunRestartCommand computation out of the ref assignment in Terminal.tsx for clarity.

Written for commit b119527. Summary will update on new commits.

Summary by CodeRabbit

  • Refactor
    • Optimized terminal output batching with improved flush interval timing for better performance
    • Refactored workspace run pane restart command initialization for cleaner configuration handling

Replace setImmediate with 16ms setTimeout for PTY output flushing to
coalesce rapid TUI redraws into coherent frames (~60fps), preventing
renderer flooding that caused bun dev to crash.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 30, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5feab2c9-4b6d-4454-9971-1fcbc7282ad2

📥 Commits

Reviewing files that changed from the base of the PR and between 28d58d6 and b119527.

📒 Files selected for processing (2)
  • apps/desktop/src/main/terminal-host/pty-subprocess.ts
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx

📝 Walkthrough

Walkthrough

The PR modifies PTY output batching by switching from event-loop-based flushing via setImmediate() to timer-based flushing with a fixed 16ms interval, while preserving immediate and size-based flush behaviors. Additionally, terminal restart command construction is refactored to compute workspace-run commands separately with null-coalescing fallback logic.

Changes

Cohort / File(s) Summary
PTY Output Flushing
apps/desktop/src/main/terminal-host/pty-subprocess.ts
Changed output batching flush mechanism from setImmediate() to setTimeout(..., OUTPUT_FLUSH_INTERVAL_MS) with new constant OUTPUT_FLUSH_INTERVAL_MS = 16, altering burst coalescing from callback-cycle boundary to fixed timer interval.
Terminal Restart Command
apps/desktop/src/renderer/screens/main/components/.../Terminal/Terminal.tsx
Refactored defaultRestartCommandRef.current construction to compute workspaceRunRestartCommand separately when in workspace-run pane mode, replacing inline ternary with null-coalescing fallback logic.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A timer ticks, sixteen swift hops,
No more racing on event-loop stops,
Commands flow smooth, restart commands shine,
With fallback logic, everything's fine!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: replacing setImmediate with a timed flush to fix PTY output batching and prevent crashes.
Description check ✅ Passed The description covers the key changes and includes a test plan, but lacks formal sections from the template (Type of Change, Testing details, Related Issues).

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bun-dev-crashing-in-terminal-pty-issue

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 and usage tips.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 2 files

@Kitenite Kitenite merged commit ce88250 into main Mar 30, 2026
6 of 7 checks passed
@Kitenite Kitenite deleted the bun-dev-crashing-in-terminal-pty-issue branch March 30, 2026 03:05
@github-actions
Copy link
Copy Markdown
Contributor

🧹 Preview Cleanup Complete

The following preview resources have been cleaned up:

  • ⚠️ Neon database branch
  • ⚠️ Electric Fly.io app

Thank you for your contribution! 🎉

siarhei-belavus pushed a commit to siarhei-belavus/localset that referenced this pull request Mar 30, 2026
…superset-sh#3001)

Replace setImmediate with 16ms setTimeout for PTY output flushing to
coalesce rapid TUI redraws into coherent frames (~60fps), preventing
renderer flooding that caused bun dev to crash.

(cherry picked from commit ce88250)
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