fix #21: [12] uvicorn.run(reload=True) is hardcoded regardless of environment - #45
Merged
Merged
Conversation
main.py hardcoded reload=True in uvicorn.run(), so production always spawned a file-system watcher over the whole project tree: CPU overhead, broken graceful shutdown, interference with container/PaaS restart policies, and potential source-path disclosure via watcher errors. Add a pure, importable helper resolve_reload() that reads the RELOAD env var and defaults OFF (only case-insensitive "true" enables reload), and wire uvicorn.run(reload=resolve_reload()). env.example already defined RELOAD but it was never read; document the newly-wired behavior there. Regression coverage: tests/unit/test_uvicorn_reload_regression.py (hermetic, stdlib-only) locks the default-off semantics, case-insensitive true variants, non-true values, bool return type, and static guards that main.py no longer hardcodes reload=True. Added a named CI step in the unit-tests job (3-job shape preserved; no code-graph job). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Closes #21
Problem
main.pycalleduvicorn.run("api.app:app", reload=True, ...)unconditionally. In production,reload=Truemakes uvicorn spawn a file-system watcher over the whole project tree and restart workers on any file change — wasting CPU, breaking graceful shutdown, interfering with container/PaaS restart policies, and potentially exposing source paths through watcher errors.env.examplealready definedRELOADbut it was never read.Fix
resolve_reload() -> boolinmain.py=os.getenv("RELOAD", "false").lower() == "true"(defaults OFF; only case-insensitive"true"enables reload).uvicorn.run(reload=resolve_reload()); no other kwargs changed.env.example: document the now-wiredRELOADbehavior and the production expectation (leave unset/false in prod).Tests & CI
tests/unit/test_uvicorn_reload_regression.py(17 cases): default-off when unset, case-insensitive true variants, non-true values stay off, bool return type, and static guards thatmain.pyno longer hardcodesreload=Trueand is wired toresolve_reload().Run uvicorn reload gating regressionstep in theunit-testsjob. The existing 3-job CI shape (unit-tests / regressions / build) is preserved — no code-graph job (repo has no graph).Local gates (all green)
17 passed.226 passed, 1 skipped, 8 deselected.import mainis side-effect-free;resolve_reload()defaults toFalse.npm run build: success.Scope
Focused on environment-driven uvicorn reload behavior and its regression/documentation/config coverage. No unrelated changes. Graphify: not applicable (repo has no
.mcp.json/graphify-out).🤖 Generated with Claude Code