fix(server): detect bare uvicorn --workers N for per-worker rate-limit warning (#680)#689
Conversation
…mit warning (#680) The per-worker in-memory rate-limit WARNING (#678) only fired when worker count came from WEB_CONCURRENCY/UVICORN_WORKERS. A bare `uvicorn ... --workers N` on the CLI (no env var) went undetected, so a genuinely multi-worker, in-memory deployment stayed silent. Add a best-effort, dependency-free signal: walk this process's ancestors via /proc and read a `--workers N` / `-w N` flag off a recognized uvicorn/gunicorn command line. `_detect_worker_count()` now takes the max of the env-based and process-tree results. Detection is gated to ASGI-server cmdlines so an unrelated wrapper's `--workers` flag can't false-positive, and degrades silently to the env result on non-Linux or any error (never raises). Linux-only (via /proc); macOS/Windows fall back to the env-var result.
|
Warning Review limit reached
More reviews will be available in 39 minutes. Learn how PR review limits work. Your organization has reached its usage spending cap. Adjust your spending cap in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Code Review — fix/680-detect-bare-uvicorn-workersThis is a clean, well-targeted fix. The implementation is appropriately conservative given that this is an advisory-only startup warning. What's goodRefactoring is clean. Renaming the old Never-raise contract is honored at every level. Each function either handles its own errors or wraps the call in a bare Test coverage is thorough. The argv parser matrix covers all four flag forms ( Binary vs. text mode is used correctly. Minor observations
VerdictNo correctness issues, no security concerns, no missing error paths. The implementation matches the documented behavior exactly. The observations above are cosmetic and don't block merge. Approved — good to merge once CI is green. |
Follow-up reviewThe second commit (
The third observation (test name not advertising the second assertion in All three minor observations are resolved or accepted. No outstanding concerns. Still approved — ready to merge. |
Summary
Closes #680.
The per-worker in-memory rate-limit
WARNING(#678) only fired when the worker count came fromWEB_CONCURRENCY/UVICORN_WORKERS. A bareuvicorn ... --workers Non the command line (no env var) went undetected, so a genuinely multi-worker, in-memory deployment stayed silent even though auth brute-force protection was weakened.What changed
codeframe/ui/server.py:/procand read a--workers N/--workers=N/-w N/-w=Nflag off a recognized uvicorn/gunicorn command line._detect_worker_count()now returnsmax(env-based, process-tree)._is_asgi_server_cmdline) so an unrelated wrapper/test-runner's--workersflag can't false-positive (raised by cross-familycodexreview).Worker subprocesses are spawned, so their own
sys.argvdoesn't carry--workers; the flag lives on the supervisor (parent) process, which is why the ancestor walk is the reliable signal. psutil was deliberately not added — it isn't a current dependency and this is an advisory-only warning.Acceptance criteria — all demonstrated
uvicorn ... --workers 2(no env vars) triggers the WARNING — verified with a live server run (logged "in-memory storage with 2 workers").tests/ui/test_rate_limit_worker_warning.pymatrix still passes.Tests
tests/ui/test_rate_limit_worker_warning.py— 42 passing (11 pre-existing + 31 new): argv parser matrix, ASGI-server recognition,/procancestor walk via a faked proc tree, env+tree integration, and graceful-degradation paths.uv run ruff check .clean; fulltests/ui/suite green.Known limitations
/procancestor walk is Linux-only (the deployment target). On macOS/Windows, detection falls back to the env-var result — bare-CLI--workerswon't be detected there, but the conventionalWEB_CONCURRENCYpath (used by production process managers) is unaffected.