Fix Windows MCP startup with silent stdin - #132
Merged
Merged
Conversation
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.
Summary
Fixes Windows GUI startup hanging when
--mcp-serveris launched with an open but silent stdin pipe. The window should appear without requiring the MCP client to send a message first.The early MCP reader can block in stdin before VICE calls
_setmode. That later call can wait on the CRT descriptor lock held by the read, preventing startup from progressing until input arrives.Change
Initialize stdin/stdout binary mode at the beginning of Windows
MT_PreInit, before starting the MCP reader. UseInitOnceExecuteOnceso VICE reuses that initialization instead of repeating_setmode.This keeps MCP startup early: no sleeps, emulator-readiness waits, or parser/backend changes.
_fmodestays at its original initialization point; stderr and non-Windows startup are unchanged. Binary stdio now applies earlier to other Windows startup paths too, including redirected help/version output.Reproduction
c64d.exe --mcp-serverfrom the normal application working directory with stdin/stdout/stderr redirected. Keep stdin open and drain both output streams, but send no input for 30 seconds. Use a freshMT_SETTINGS_DIRto avoid changing normal settings.{"jsonrpc":"2.0","method":"retro_headful_unknown_notification_probe","params":{}}. Startup resumes and the window appears.Launching from an ordinary console or immediately sending initialize can hide the problem.
Validation
Matched native MSVC x64 Debug builds, using the same engine revision and build options:
The fixed GUI responded in 3.1–3.3 seconds. All five visible MCP instances and the normal-GUI control exited normally. Separate native helper tests passed across
/MDand/MT, covering legacy/fixed ordering, concurrent initialization and byte preservation.Headless initialize also passed; headless cleanup was forced in both control and candidate. One earlier normal-GUI harness run was inconclusive after reporting a zero-size window; the subsequent focused diagnostic and full comparison passed, and that earlier observation remains unexplained.
The PR contains only the three-file startup fix, separate from the MSVC build-compatibility changes used for local testing. Linux/macOS/Windows CI remains to be checked for this PR; initialize-at-launch timing and live bridge/menu operation were reviewed statically, not separately exercised.