Conversation
… Windows On Windows, process.exit() calls ExitProcess(), which broadcasts CTRL_CLOSE_EVENT to the whole console process group. The parent shell (pwsh/cmd) is attached to that group, so exiting the TUI (via /exit, Ctrl+C or the leader-quit bind) kills the parent terminal too (anomalyco#28673). Replace the two exit points (CLI entry skip, TUI thread) with a safeExit() helper that on Windows sets process.exitCode and lets the process end naturally, keeping the original process.exit() behavior on POSIX where it does not affect the console group.
Contributor
|
The following comment was made by an LLM, it may be inaccurate: I found a potentially related PR: #22002 - This PR appears to address the same issue: preventing the TUI exit from closing the parent terminal window on Windows. Since PR #22002 is older and seems to be addressing the exact same problem, you should verify whether it was:
Check the status and details of PR #22002 to confirm whether this is a true duplicate or a separate attempt to fix the same issue. |
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.
Issue for this PR
Closes #28673
Type of change
What does this PR do?
Since v1.14.25, exiting the TUI on Windows (via
/exit,Ctrl+C, or the leader-quit bind) also kills the parent terminal. On Windowsprocess.exit()callsExitProcess(), which broadcastsCTRL_CLOSE_EVENTto the whole console process group. The parent shell (pwsh/cmd) is attached to that same group, so it dies together with opencode. On POSIXprocess.exit()only affects the calling process, which is why the bug is Windows-only.Fix: a
safeExit()helper. On Windows it setsprocess.exitCodeand lets the process end naturally, so only opencode detaches from the console and the shell survives. On other platforms it keeps the existingprocess.exit()behaviour so the force-exit path that reaps MCP servers ignoring SIGTERM is unchanged.Applied at the two exit points of the default (server + TUI) flow:
packages/opencode/src/index.ts– CLI entryfinallyblockpackages/opencode/src/cli/cmd/tui.ts– TUI thread clean exitPrevious attempts
This is a re-submission of the same fix. Earlier PRs were auto-closed by the PR cleanup bot before CI ever ran (first-time-contributor workflows need a maintainer to approve the run):
safeExitapproach, closed by automated cleanupsafeExitapproach, closed by automated cleanupThis PR builds on #29281/#29343 with the compilation issue reported there fixed (the bare
returnin the module-levelfinallyis replaced by thesafeExit()helper call; on Windows the process now exits naturally viaprocess.exitCodeinstead of returning from module scope).How did you verify your code works?
process.exitCodepreset,safeExit()returns instead of exiting, the process ends naturally with the correct code, and the parent shell is left alive.bun run typecheckpasses for theopencodepackage (theenterprise/stats-serverfailures are pre-existing and unrelated).oxlintreports no new issues in the touched files.process.exit()is still called, preserving the force-exit behaviour for hanging subprocesses.Screenshots / recordings
Not a UI change: the shell keeps running and the prompt returns instead of the pane closing.
Checklist