fix: flush stdin on POSIX exit to prevent stale bytes leaking to shell#17083
Open
altendky wants to merge 49 commits intoanomalyco:devfrom
Open
fix: flush stdin on POSIX exit to prevent stale bytes leaking to shell#17083altendky wants to merge 49 commits intoanomalyco:devfrom
altendky wants to merge 49 commits intoanomalyco:devfrom
Conversation
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
# Conflicts: # packages/opencode/src/cli/cmd/tui/app.tsx
# Conflicts: # packages/opencode/src/cli/cmd/tui/app.tsx
# Conflicts: # packages/opencode/src/cli/cmd/tui/component/error-component.tsx
6 tasks
# Conflicts: # packages/app/src/context/layout.tsx # packages/app/src/pages/layout/sidebar-items.tsx
6 tasks
# Conflicts: # packages/opencode/src/cli/cmd/tui/app.tsx # packages/opencode/src/cli/cmd/tui/component/error-component.tsx
# Conflicts: # packages/opencode/test/cli/tui/thread.test.ts
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 #17081
Type of change
What does this PR do?
When opencode exits on POSIX systems (Linux/macOS), stale bytes left in the terminal's stdin buffer leak to the parent shell, typically manifesting as an extra space character on the prompt or blocking ctrl+d. This happens because the existing
FlushConsoleInputBuffercall only works on Windows.This PR:
tcflush(STDIN_FILENO, TCIFLUSH)call via Bun's libc FFI to discard pending tty input bytes on exitwin32.ts→console.tsand consolidates platform-specific FFI (Windows kernel32 + POSIX libc) under a unifiedload()functionwin32prefix fromflushInputBuffersince it is now cross-platform; Windows-only functions (win32DisableProcessedInput,win32InstallCtrlCGuard) retain their prefixHow did you verify your code works?
Tested on Linux by running opencode, pressing space several times before exiting, and confirming no stale bytes appear on the shell prompt after exit. Also verified Windows codepath is unchanged by reviewing the conditional logic.
Screenshots / recordings
N/A — terminal behavior fix, no UI change.
Checklist