fix(windows): resolve native cookbook async crashes by forcing standard asyncio loop#3418
Open
clyv wants to merge 6 commits into
Open
fix(windows): resolve native cookbook async crashes by forcing standard asyncio loop#3418clyv wants to merge 6 commits into
clyv wants to merge 6 commits into
Conversation
…ncio loop ### Description This PR fixes a critical issue on Windows environments where background processes (such as Hugging Face model downloads) crash or stall unexpectedly. ### Why this happens By default, running Uvicorn on Windows without an explicit loop policy can cause issues with asynchronous background workers because native Windows terminal setups handle network and subprocess event loops differently than Linux/macOS environments (which rely on `uvloop` or `tmux`). ### Changes made 1. **`launch-windows.ps1`**: Appended `--loop asyncio` to the Uvicorn initialization command to force a stable async worker loop. 2. **`app.py`**: Added a platform check (`sys.platform == 'win32'`) at initialization to explicitly set the `WindowsSelectorEventLoopPolicy()`, preventing async routine drops during heavy background tasks like model downloads. Testing locally on Windows native setups confirms that this permanently eliminates the background routine stalls!
This was referenced Jun 11, 2026
Closed
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
This PR resolves the persistent native Windows crash where downloading or serving models inside the Cookbook panel fails instantly or stalls. On Windows setups running without Docker, the background command environment tries to execute asynchronous subprocess loops that naturally stall or break without an explicit loop selector configuration.
By applying a fallback to the native Windows Selector Event Loop policy and forcing Uvicorn to run with standard
asyncio, Windows users can run background task workflows smoothly without native crashes.Target branch
dev, notmain. All PRs land indev;mainis curated by the maintainer at each release. If your PR is onmainby accident, click "Edit" on this PR and change the base.Linked Issue
Fixes #343
Fixes #2008
Fixes #153
Fixes #2341
Fixes #2636
Related Pull Requests
Type of Change
Checklist
devdocker compose uporuvicorn app:app) and verified the change works end-to-end. Type-checks and unit tests are not enough.How to Test
powershell -ExecutionPolicy Bypass -File .\launch-windows.ps1ollama run llama3.1).http://localhost:11434/v1).asyncioloop configuration without dropping background worker threads.Visual / UI changes — REQUIRED if you touched anything that renders
Anything that changes what the UI looks like — buttons, icons, padding, colors, fonts, spacing, layout, CSS, HTML, SVG, or any
static/js/module that draws to the DOM — needs all of the following. PRs that change rendering without these WILL be closed.--red,--fg,--bg,--card,--border, etc.) — do not introduce new color values, font sizes, or spacing units.static/index.html) or plain text.Fira Code) for primary UI text. Don't override.