uvicorn --reload flag handling (dev mode handling)
version affected: 0.1.1 app setup: uvicorn, fastapi, openrouter
uv run wildedge run --integrations openai -- uvicorn app.main:app --reload --port 8000
- wildedge run launches uvicorn -> reloader process (PID XYZ) runs sitecustomize.py, installs WildEdge, sets WILDEDGE_AUTOLOAD_ACTIVE=1 in its env.
- Reloader spawns the actual server process (PID KAZ) — it inherits WILDEDGE_AUTOLOAD_ACTIVE=1
- Server process runs sitecustomize.py, sees the guard already set -> skips bootstrap entirely, FastAPI handles your requests in process KAZ, which never gets WildEdge. The "client initialized" messages comes from the reloader (XYZ), not the server.
I think the issue stems from the fact that the --reload flag is being passed to uvicorn before app.main:app, which causes the reloader process to run sitecustomize.py and set WILDEDGE_AUTOLOAD_ACTIVE=1 in its environment. When the actual server process is spawned, it inherits this env var and skips the WildEdge bootstrap entirely, as it sees the guard is already set. Can you try running uvicorn app.main:app --reload directly, without passing it through wildedge run, to see if that changes the behavior?
Hey @IlyasFardaouix! First of all, thank you for your interest in wildedge! 👋
As for your post, your assessment is accurate. Everything works as expected when the --reload (prod use-case) flag is skipped (that behavior was tested as part of the existing test suite).
Above is a PR with: test+fix+test app to close on that loop on this problem. Feel free to take a peak and share your thoughts before I merge!
I've reviewed the PR, and I think the fix looks good. However, I'm a bit concerned about the test coverage could you add a test to verify that the WILDEDGE_AUTOLOAD_ACTIVE environment variable is not set when running uvicorn directly without wildedge run? This would ensure we don't regress this behavior in the future.