wildedge-python icon indicating copy to clipboard operation
wildedge-python copied to clipboard

uvicorn --reload flag handling (dev mode handling)

Open piotrekno1 opened this issue 8 months ago • 3 comments

version affected: 0.1.1 app setup: uvicorn, fastapi, openrouter

uv run wildedge run --integrations openai -- uvicorn app.main:app --reload --port 8000
  1. wildedge run launches uvicorn -> reloader process (PID XYZ) runs sitecustomize.py, installs WildEdge, sets WILDEDGE_AUTOLOAD_ACTIVE=1 in its env.
  2. Reloader spawns the actual server process (PID KAZ) — it inherits WILDEDGE_AUTOLOAD_ACTIVE=1
  3. 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.

piotrekno1 avatar Mar 18 '26 16:03 piotrekno1

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?

IlyasFardaouix avatar Mar 19 '26 04:03 IlyasFardaouix

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!

piotrekno1 avatar Mar 19 '26 09:03 piotrekno1

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.

IlyasFardaouix avatar Mar 19 '26 09:03 IlyasFardaouix