fix(terminal): prevent infinite reconnect loop on Windows hosts#336
Merged
tiann merged 1 commit intotiann:mainfrom Mar 21, 2026
Merged
fix(terminal): prevent infinite reconnect loop on Windows hosts#336tiann merged 1 commit intotiann:mainfrom
tiann merged 1 commit intotiann:mainfrom
Conversation
On Windows, the Bun PTY API is POSIX-only, so the CLI emits a terminal:error immediately. Two bugs caused the web UI to flash "Terminal ID is already in use." in an infinite loop: 1. Hub: the terminal:error handler forwarded the error without removing the terminalId from the registry, causing subsequent create attempts to be rejected as duplicates. 2. Web: terminal.tsx reset connectOnceRef on every error/exit, and the ResizeObserver continuously re-triggered connect(). Fixes: - Hub: clean up terminalRegistry on terminal:error (matching the pattern used by terminal:exit). - Web: stop resetting connectOnceRef on error/exit to break the reconnect loop. - Web: detect Windows hosts via session metadata and show a static "unsupported" message instead of attempting connection. - Web: disable the Terminal button in the composer for Windows hosts with an explanatory tooltip. - CLI: improve the Windows error message wording. - Docs: update FAQ to note Windows terminal limitation. Made-with: Cursor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On Windows hosts, the remote terminal UI flashes "Terminal ID is already in use." in an infinite loop, making the terminal page unusable.
Root cause
The Bun PTY API (
Bun.Terminal) is POSIX-only. When the CLI runs on Windows, it immediately emitsterminal:error. Two bugs then create an infinite loop:Hub (
terminalHandlers.ts): Theterminal:errorhandler forwarded the error to the frontend without removing theterminalIdfrom the registry. The nextterminal:createattempt was rejected as a duplicate.Web (
terminal.tsx): The component resetconnectOnceRefon every error, and theResizeObservercontinuously re-triggeredconnect()— each attempt hitting the stale registry entry.Fix
terminalHandlers.tsterminalRegistryonterminal:error(same pattern asterminal:exit)terminal.tsxconnectOnceRefon error/exit to break the reconnect loopterminal.tsxSessionChat.tsx,HappyComposer.tsx,ComposerButtons.tsxterminalSupport.tssession.metadata.osen.ts,zh-CN.tsterminal.unsupportedWindowsi18n keyTerminalManager.tsfaq.mdTest plan
terminalSupporthelpersterminalRegistry.remove()is called onterminal:errorMade with Cursor