Skip to content

fix(windows): resolve native cookbook async crashes by forcing standard asyncio loop#3418

Open
clyv wants to merge 6 commits into
pewdiepie-archdaemon:devfrom
clyv:dev
Open

fix(windows): resolve native cookbook async crashes by forcing standard asyncio loop#3418
clyv wants to merge 6 commits into
pewdiepie-archdaemon:devfrom
clyv:dev

Conversation

@clyv

@clyv clyv commented Jun 8, 2026

Copy link
Copy Markdown

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.


PERSONAL NOTE FROM THE AUTHOR:
Hey everyone! This is my very first Pull Request ever. I ran into these exact cookbook crashes while trying to set up Meta Llama 3.1 on my native Windows machine. Instead of letting the app download it internally, I manually pulled it via Ollama and wired up the local endpoint to Odysseus to test. I really hope I followed instructions in making this PR, and I hope you guys can go easyon me if I did make a mistake anywhere.


Target branch

  • This PR targets dev, not main. All PRs land in dev; main is curated by the maintainer at each release. If your PR is on main by 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

  • Bug fix (non-breaking — fixes a confirmed issue)
  • New feature (non-breaking — adds new behaviour)
  • Breaking change (changes or removes existing behaviour)
  • Refactor / cleanup (behaviour unchanged)
  • Documentation only
  • CI / tooling / configuration

Checklist

  • I searched open issues and open PRs — this is not a duplicate.
  • This PR targets dev
  • My changes are limited to the scope described above — no unrelated refactors or whitespace changes mixed in.
  • I actually ran the app (docker compose up or uvicorn app:app) and verified the change works end-to-end. Type-checks and unit tests are not enough.

How to Test

  1. Launch Odysseus natively on a Windows machine using the modified script:
    powershell -ExecutionPolicy Bypass -File .\launch-windows.ps1
  2. Open a separate terminal and ensure an external local model provider engine is active (e.g., run ollama run llama3.1).
  3. In Odysseus, navigate to Settings > Ollama / Local API and connect the external model endpoint URL (http://localhost:11434/v1).
  4. Go to the Chat panel, select the loaded model, and verify that the server executes requests stably over the new standard asyncio loop 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.

  • Screenshot or short clip of the change in the running app, attached below. Mobile screenshot too if the change affects mobile.
  • Style match: the change uses Odysseus's existing visual language. Specifically:
    • Reuse existing CSS variables (--red, --fg, --bg, --card, --border, etc.) — do not introduce new color values, font sizes, or spacing units.
    • Reuse existing button/input/card/border classes. Don't invent parallel styling.
    • No Unicode emoji in UI or code. Use inline SVG (matching the monochrome icon style already in static/index.html) or plain text.
    • Monospaced font (Fira Code) for primary UI text. Don't override.
    • Dark theme is the default; any light-mode work must be wired through the existing theme system, not hard-coded.
  • No new component patterns. If a similar widget already exists in the app, extend it instead of writing a parallel one.
  • I am not an LLM agent submitting a bulk PR. If you are, please open an issue describing the problem first — bulk auto-generated PRs that don't match the project's visual style are closed on sight, even when the underlying fix is correct.

clyv added 2 commits June 8, 2026 12:30
…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!
@github-actions github-actions Bot added the ready for review Description complete — ready for maintainer review label Jun 8, 2026
@alteixeira20 alteixeira20 added the bug Something isn't working label Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ready for review Description complete — ready for maintainer review

Projects

None yet

2 participants