bug: ctrl+c exiting app even when prompt input isn't empty
Description
see screen recording: https://discord.com/channels/1391832426048651334/1394667004979445931/1446206223396634715
OpenCode version
1.0.132
Operating System
Windows
Terminal
Windows Terminal
This issue might be a duplicate of existing issues. Please check:
- #2999: Provide means to disable Ctrl-C (Windows users unable to use Ctrl+C without crashing)
- #4997: Keybinds (explicitly lists: 'Windows ctrl+c quits app instead of copy')
- #5070: exiting tui on windows has improper exit sequence handling (similar Windows terminal symptoms)
- #3675: Keybind doesn't work in 1.0.7 (Windows 11, Windows Terminal - custom keybinds not working)
- #4938: Keyboard shortcuts to edit prompts suck so much! (comprehensive keyboard/input issues)
- #3213: Bug:
opencode runand TUI exits hang on v0.15+ (Ctrl+C doesn't return shell prompt on Windows)
Feel free to ignore if none of these address your specific case.
Hi! I’d like to work on this issue if it’s still available. I'm able to reproduce the issue on Windows Terminal on both last release version and last commit version.
@val-2 that'd be great, note that opencode is built on opentui, so you may find that the bug lies at that lower level.
Ok I think I found the issue but I'm not exactly sure how to resolve it.
Basically the bug starts manifesting when client.call("checkUpgrade",...) gets called, which happens 1 second after start.
I think the commands that get called for the check in some way "steal" ctrl-c handling of opencode and thus the normal exit path doesn't get followed but it just exits without clean-up. Might be partially related to #5070 as well.
So the reason why the bug happened in the video is not the start of the request but the start of checkUpgrade.
If I remove the checkUpgrade call the bug doesn't happen anymore.
Another thing I noticed is that the commands modify the name of the terminal tab when they get called, so it becomes "npm list", "npm config get registry"...
A possible fix I found is to use Bun.spawn instead of Bun shell $, for example:
$`npm list -g --depth=0`
becomes
Bun.spawn(["npm", "list", "-g", "--depth=0"])
With all the relative adjustments to get stdout and such.
I don't know enough about Bun internals to tell why this fixes the bug though. Or if it's more of a Bun issue than an OpenCode one.
Let me know if you'd like me to open a PR for the change or if you prefer a different approach.