Skip to content

fix(proxy)!: support reload with multiple workers - #45909

Merged
devin-ai-integration[bot] merged 22 commits into
mainfrom
litellm_multi_worker_dev_reload
Nov 1, 2026
Merged

devin-ai-integration[bot] merged 22 commits into
mainfrom
litellm_multi_worker_dev_reload

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Hot reload with several workers used to fall back to one, so local QA missed cross-worker bugs. Now every save restarts the whole pool, and the contributor guide's example runs two workers

Breaking change: --reload with --num_workers, NUM_WORKERS, or DEFAULT_NUM_WORKERS_LITELLM_PROXY above 1 on uvicorn 0.50.0 or newer now runs that many workers outside Windows, and each reload restarts all of them. Debug with --num_workers 1. Runs without --reload are unaffected

Details

TLDR

Problem this solves:

  • Reload silently drops a requested worker pool to one

How it solves it:

  • Restart the whole uvicorn worker pool on file changes
  • Stop the pool once on a broken edit instead of respawning
  • Stop the pool and workers when their parent exits
  • AGENTS.md QA rule uses two workers, Redis, and reload

Intentional product change: development --reload honors --num_workers on uvicorn 0.50.0 or newer and restarts the whole pool together. Older uvicorn and Windows warn and keep one worker

Design decisions

AGENTS.md decision: the ask was to QA with two workers, Redis, and --reload, and Redis matters there because it is how workers share state. router_settings Redis alone keeps spend, budget, and rate-limit counters per worker, so the rule points both router_settings and general_settings.coordination_redis at the QA Redis. The other options were router_settings alone, which misses those counters, and REDIS_* environment variables, which reach coordination only through a last-resort fallback and never reach the router. The rule asks for no save-and-replace check, so later PRs never prove this reload again

Healthcheck decision: the reload pool raises uvicorn's worker healthcheck from 5 to 30 seconds unless --timeout_worker_healthcheck is passed. Under load, workers still importing the proxy missed the 5 second ping and were killed and respawned on reloads. The cost is that a worker that stops answering delays any shutdown, Ctrl-C included, by up to 30 seconds. The other options were keeping 5 seconds, which kills slow boots, and asking each developer to pass the flag

Reloader-exit decision: closing the terminal, Ctrl-\, or a killed reloader would otherwise leave the pool holding the port. The pool waits on multiprocessing.parent_process(), whose sentinel fires the moment the reloader exits, and then sets uvicorn's own exit flag, so each worker gets one SIGTERM and a normal shutdown. Terminating workers from the watcher thread would race the pool's main loop, which owns their pipes. The pool also exits on its own SIGQUIT, which uvicorn's pool ignores. Without that, Ctrl-\ left the pool waiting on a ping to a worker that was still writing its core dump, so it held the port for the full 30 second healthcheck. Each worker also stops itself when its pool parent exits, since uvicorn's workers never check it, and a killed pool parent left old workers serving beside the next pool

Reload-cost decision: saves reload slower than on base, as the Caveats section measures, because the pool parent imports litellm before it starts the workers, and the two workers then boot at the same time. The import comes from the CLI module itself, which the spawned pool parent runs again, so moving the pool code would not avoid it. The other option was having the reloader start the workers itself, which drops uvicorn's worker healthchecks and respawns

Windows decision: Windows keeps one reloading worker, since uvicorn stops Windows workers with a console-wide CTRL_BREAK_EVENT that the reloader does not handle, and nothing here ran on Windows. The other option was shipping the pool there untested

Uvicorn-args decision: the reload pool passes every uvicorn arg the CLI builds through to uvicorn, so an arg added to the CLI later reaches the workers, and a typo still fails at startup in uvicorn itself. The other option was rejecting args the pool does not list, which would crash --reload with workers the day the CLI adds one

User Flow

Before

A developer's two-worker QA proxy quietly runs one worker, so cross-worker bugs never show up locally

  1. They point the proxy config's router_settings at a dedicated Redis
  2. They run python litellm/proxy/proxy_cli.py --config config.yaml --num_workers 2 --reload
  3. The terminal prints "workers" flag is ignored when reloading is enabled. and starts one worker
  4. They edit the config YAML, a Python file, or .env, and that one worker is replaced
  5. A Python typo prints one SyntaxError, and the next good save brings the worker back

After

The same command runs two workers, reloads both on every save, and survives a typo without a restart loop

  1. They point the proxy config's router_settings at a dedicated Redis
  2. They run python litellm/proxy/proxy_cli.py --config config.yaml --num_workers 2 --reload
  3. The terminal starts two workers with no warning, and POST http://localhost:<port>/v1/chat/completions returns 200
  4. They edit the config YAML, a Python file, or .env, and both workers are replaced and keep serving requests
  5. A Python typo prints failed to start, stopping the parent process once, and the next good save restores both workers

Pre-Submission checklist

  • I have added meaningful tests
  • The handful of test files covering my change pass locally
  • My PR passes all required CI/CD checks
  • My PR's scope is as isolated as possible
  • Every automated review on my PR's latest commit has finished, and I have addressed or replied to each of its findings before requesting a maintainer review

Delays in PR merge?

If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).

Meaningful tests

tests/integration/configuration/test_reload_worker_pool.py runs the pool in a subprocess and checks that both workers start, a broken save stops the pool until a good one, and killing the reloader frees the port. The proxy integration test checks all three reload triggers and a clean shutdown with one and two workers

What each test checks and which mutation fails it

tests/unit/proxy/test_dev_reload.py loads the app through the same config each pool worker gets. A syntax error, a missing name, a runtime error, and a missing attribute in the app module each end in a SystemExit with uvicorn's startup-failure code, which is what makes uvicorn stop the pool instead of respawning workers. A working app loads unchanged. Loading the plain app string instead fails 3 of these tests, and exiting with code 1 fails 4

An ImportError or ValueError raised while the app module imports must reach the log with its own traceback, so the logged frames must include the broken file and the line that raised. pydantic's ImportString wraps both errors in a ValidationError with no file or line, so the worker now imports the module itself before ImportString resolves the attribute. Removing that import fails both cases, and importing the attribute part of the string instead fails 3 tests

test_reload_worker_pool.py runs run_multi_worker_reload in a real subprocess with two workers on a tiny app that answers with its PID. Both workers must start, and a request must reach one of them. A broken save must log failed to start, stopping the parent process and leave no old worker alive, and the next good save must bring back two new workers that serve. SIGINT must then exit 0 with no process left. Starting one worker instead of two fails it, and so do running a single server instead of the pool and re-raising the load error instead of exiting with the startup-failure code

The real-process integration test checks the worker count, all three reload triggers, updated model configuration, old-worker exit, and clean shutdown, for one and two workers. It now edits the config file the proxy was started with. The CI job runs with worker isolation, which starts the proxy from a worker-config-<hex>.yaml copy, so editing config.yaml never triggered a reload there. Both cases pass locally with INTEGRATION_WORKER_ISOLATION=1. Its shutdown call goes through the harness helper that sends the same SIGTERM, because main's test-quality gate rejects a raw .terminate() there

test_the_pool_stops_and_frees_the_port_when_the_reloader_dies kills the reloader three ways, with SIGKILL, with the SIGHUP a closed terminal sends its process group, and with Ctrl-\'s SIGQUIT. Each time the pool parent must exit and the port must refuse connections. Removing the watcher fails all three. test_a_killed_pool_parent_takes_its_workers_with_it_so_the_next_save_serves_only_new_workers SIGKILLs the pool parent, then requires both of its workers to exit and the next save to serve from two new workers. Loading the app without the pool-parent watcher fails it. test_the_pool_is_told_to_stop_once_the_reloader_process_exits hands the watcher a real spawned process and requires no stop while it lives and a stop once it is killed. A watcher that never notices the exit, or never sets the flag, fails it. The healthcheck test requires the 30 second default and keeps an explicit value, and dropping the default fails it. A uvicorn arg the pool does not list, backlog, must reach the workers with reload off, and Windows must keep one worker. Rejecting unlisted args, passing the reload keys on, or dropping the Windows check each fails one

test_ctrl_backslash_frees_the_port_without_waiting_out_the_worker_healthcheck_when_core_dumps_are_slow sends Ctrl-\'s SIGQUIT to the process group while every process freezes for 3 seconds before it dies, the way a large process does while it writes a core dump. The pool parent must exit and the port must refuse connections within 15 seconds. Removing the pool's SIGQUIT handler fails it, since the pool then waits out its 30 second ping

Screenshots / Proof of Fix

Last updated: 770c431. QA ran on 9f397db. Changes since QA: the pool tests moved to tests/integration/configuration. Proof remains valid because no product file changed. Verification: 11 unit and 7 pool cases pass, and the pool-parent case fails without its watcher

Both legs ran --num_workers 2 --reload in tmux with a dedicated Redis, no database, and real OpenAI and Anthropic calls. The transcripts have every case

Proxy config used by both legs
model_list:
  - model_name: qa-gpt
    litellm_params:
      model: openai/gpt-5.4-mini
      api_key: os.environ/OPENAI_API_KEY
  - model_name: qa-claude
    litellm_params:
      model: anthropic/claude-haiku-5-5
      api_key: os.environ/ANTHROPIC_API_KEY
general_settings:
  master_key: os.environ/LITELLM_MASTER_KEY
  coordination_redis:
    host: 127.0.0.1
    port: <random port>
router_settings:
  redis_host: 127.0.0.1
  redis_port: <random port>
Check Before After
Workers at launch 1, with warning 2
Endpoints answering 200 3 of 3 3 of 3
Config, Python, .env saves, workers replaced 1 of 1 each 2 of 2 each
Broken save, respawns 0 0
Fixed save, workers back 1 2
Ctrl-C, processes 0 0
Terminal closed, listeners 0 0
Ctrl-\, listeners 0 0
Ctrl-\, port free after 0.7 s 1.1 s
Pool parent killed, old workers left no pool parent 0
uvicorn 0.49.0, workers 1, with warning 1, with warning
uvicorn 0.50.0, workers 1, with warning 2
GRACEFUL_SHUTDOWN_TIMEOUT=2.5 1, chat 200 2, chat 200

Before (3c28f4b)

Worker pool at launch, before

Commands and output
  1. Booted the proxy in tmux session qa-before-1 with --num_workers 2 --reload on port 25056 and waited for /health/liveliness (ready after about 44 seconds), then printed the worker lines
$ grep -E 'Started server process' $QA/proxy-1.log | sed -E 's/^.*(INFO|WARNING|ERROR)[: ]+//' | cut -c1-160
Started server process [948519]
  1. Lifecycle lines since launch
$ tail -c +1 $QA/proxy-1.log | grep -E 'workers" flag is ignored|requires uvicorn|Started (server|parent|reloader) process|Stopping (parent|reloader) process|changes detected|detected changes|Application startup complete|Child process|failed to start|Error loading ASGI app|SyntaxError|Shutting down|Finished server process' | sed -E 's/^.*(INFO|WARNING|ERROR)[: ]+//' | cut -c1-160
"workers" flag is ignored when reloading is enabled.
Started reloader process [947489] using StatReload
Started server process [948519]
Application startup complete.
  1. Processes listening on the proxy port
$ pids=$(lsof -nP -t -iTCP:25056 -sTCP:LISTEN | paste -sd, -); if [ -n "$pids" ]; then ps -o pid,ppid,command -p "$pids" | cut -c1-110; else echo 'no listeners'; fi
    PID    PPID COMMAND
 947489  947488 $TREE/.venv/bin/python litellm/proxy/pr
 948519  947489 $TREE/.venv/bin/python -c from multipro

before launch

Proxy pane after the broken save, before

before broken save

After (9f397db)

Worker pool at launch, after

Commands and output
  1. Start the proxy in tmux pane qa779-after-1 with --num_workers 2 --reload and wait for /health/liveliness plus 2 startup lines
$ tmux new-session -d -s qa779-after-1 -x 220 -y 50 "cd $TREE && PYTHONUNBUFFERED=1 $TREE/.venv/bin/python litellm/proxy/proxy_cli.py --config $QA/config.yaml --port 29534 --num_workers 2 --reload 2>&1 | tee -i $QA/proxy-1.log; echo \$pipestatus[1] > $QA/exit-1"
$ curl -s -o /dev/null -w 'HTTP %{http_code}\n' -m 5 http://127.0.0.1:29534/health/liveliness
HTTP 200
  1. Worker Started server process lines
$ tail -c +1 $QA/proxy-1.log | grep -oE 'Started server process \[[0-9]+\]'
Started server process [1455564]
Started server process [1455563]
  1. Lifecycle lines since launch
$ tail -c +1 $QA/proxy-1.log | grep -E 'workers" flag is ignored|requires uvicorn|Started (server|parent|reloader) process|Stopping (parent|reloader) process|changes detected|detected changes|Application startup complete|Child process|failed to start|Error loading ASGI app|SyntaxError|Shutting down|Finished server process' | sed -E 's/^.*(INFO|WARNING|ERROR)[: ]+//' | cut -c1-160
Started reloader process [1455472] using StatReload
Started parent process [1455549]
Started server process [1455564]
Started server process [1455563]
Application startup complete.
Application startup complete.
  1. Listeners on the proxy port
$ if lsof -nP -t -iTCP:29534 -sTCP:LISTEN >/dev/null; then ps -o pid,ppid,command -p "$(lsof -nP -t -iTCP:29534 -sTCP:LISTEN | paste -sd, -)" | cut -c1-110; else echo 'no listeners'; fi
    PID    PPID COMMAND
1455472 1455471 $TREE/.venv/bin/python litellm/proxy/p
1455549 1455472 $TREE/.venv/bin/python -c from multipr
1455563 1455549 $TREE/.venv/bin/python -c from multipr
1455564 1455549 $TREE/.venv/bin/python -c from multipr

pr45909-9f397dbbf0-launch.png

Proxy pane after the broken save, after

pr45909-9f397dbbf0-broken.png

Observations from the run

  • Broken save leaves the reloader holding the port, as before
  • A killed pool parent serves nothing until a save
  • Its workers stay zombies until exit, via litellm's subreaper

Type

Bug Fix, Documentation, Test

Caveats (if any)

Medium

  • --reload now starts every worker that --num_workers, NUM_WORKERS, or DEFAULT_NUM_WORKERS_LITELLM_PROXY asks for, .env included. Without Redis, rate-limit counters, cooldowns, and MCP sessions split per worker, and breakpoint() needs --num_workers 1
  • Saves reload slower, 23 to 41 seconds against 16 to 19 on base in the QA transcripts, since the pool parent imports litellm, about 190 MB, before its workers start
  • A worker paused over 30 seconds, as by a debugger that suspends every thread, is replaced, like plain --num_workers 2 on base after 5 seconds

Low

  • Ctrl-\ during a ping to a worker writing its core dump can still wait 30 seconds
  • Windows keeps one reloading worker as before. macOS has not run the pool tests yet
  • The pool tests now live in tests/integration, which CI runs only on main
  • No test checks that both workers answer after a reload
  • The AGENTS.md example keeps dev_config.yaml, which has no Redis
  • The pool uses uvicorn internals, tested only at the locked 0.51.0

Final Attestation

  • /qa passes at 9f397db
  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

Link to Devin session: https://app.devin.ai/sessions/61c0cbdf73bb4fca9738df44537d47c7
Open in Devin Desktop: https://app.devin.ai/desktop/session/61c0cbdf73bb4fca9738df44537d47c7?variant=devin

Bugbot summary

[!NOTE]
Medium Risk
Changes dev-only process supervision and multiprocessing lifecycle (including uvicorn internals), with intentional breaking behavior when combining --reload and multiple workers.

Overview
Dev hot reload now honors --num_workers on uvicorn ≥0.50 outside Windows, instead of silently running a single worker. Each config, Python, or .env change restarts the full worker pool via a new litellm/proxy/dev_reload.py path wired from proxy_cli.py when both --reload and --num_workers > 1 are set

The reload stack wraps uvicorn's ChangeReload around a shared socket and a custom ReloadWorkerPool that loads the same child-process app factory as normal multi-worker runs, stops the pool on a bad save (startup-failure exit), tears down when the reloader or pool parent exits (including faster SIGQUIT handling so the port is not held for the worker healthcheck), and defaults timeout_worker_healthcheck to 30 seconds unless overridden

AGENTS.md adds a concrete two-worker, Redis-backed --reload QA command and when to relax those checks. Tests cover pool lifecycle, proxy reload for one and two workers, and unit coverage for app load failures and CLI arg passthrough. Older uvicorn and Windows still warn and keep single-worker reload

Reviewed by Cursor Bugbot for commit ee4f337. Bugbot is set up for automated code reviews on this repo. Configure here.

Update after merging main at 7e0728c

Merged main and kept its light CLI imports and startup output, with the reload pool now loading the same child process app factory and overrides as plain multi-worker runs. AGENTS.md keeps main's proof rules and states the two-worker Redis reload QA command inline

Ctrl-\ now kills the pool workers right away instead of following the graceful path. Before the fix the strengthened ctrl-backslash case of test_the_pool_stops_and_frees_the_port_when_the_reloader_dies took 31.6s to free the port, over its 10s bound. After the fix a live --num_workers 2 --reload proxy refused connections 0.6s after SIGQUIT

Live run at the merged tip with Redis on both settings blocks. Two worker PIDs served, four real Anthropic /v1/chat/completions calls returned 200, and a config save replaced workers 52634 and 52635 with 53090 and 53091 that both loaded the new alias

The reload pool now calls the worker app factory inside the same startup-failure handler as the import, so a broken save to the proxy server makes workers exit as startup failures and the pool waits for the next save instead of restarting them. test_dev_reload.py covers a factory with a missing import and one that raises, and both failed before the fix

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

devin-ai-integration Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@codspeed

codspeed Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

1 warning

⚠️ 1 benchmark is dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 43 untouched benchmarks


Comparing litellm_multi_worker_dev_reload (ee4f337) with main (a1c5829)

Open in CodSpeed

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@codecov

codecov Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 69.29825% with 35 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
litellm/proxy/dev_reload.py 71.69% 30 Missing ⚠️
litellm/proxy/proxy_cli.py 37.50% 5 Missing ⚠️

📢 Thoughts on this report? Let us know!

@mateo-berri

Copy link
Copy Markdown
Contributor

@litereview code-review

@litereview

litereview Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

✅ code-review

5/5 · Ready for human review

Scope: full · Full PR review.

No correctness findings. I fixed the scope of this review to the full PR (3c28f4b..770c431). On uvicorn 0.51.0, a local run of proxy_cli.py --num_workers 2 --reload started two workers. Both answered /health/liveliness. A YAML edit replaced both workers and the pool parent. The earlier finding about subprocess tests in tests/unit is fixed: those cases now live in tests/integration/configuration.

Checks and execution details
  • Passed · Real testing evidence (required): Not applicable: no LLM translation changes in the scoped paths. The PR changes AGENTS.md, litellm/proxy/dev_reload.py, litellm/proxy/proxy_cli.py and test files. It touches nothing under litellm/llms/** or litellm/litellm_core_utils/prompt_templates/**.
  • Passed · Compatibility requirements (required): There is a breaking change. Before: --reload --num_workers 2 printed "workers" flag is ignored... and ran one worker. After, on uvicorn>=0.50 outside Windows, it runs N workers and restarts all of them on each reload. It also raises the default worker healthcheck to 30s for that pool. The title carries fix(proxy)!:. The body has a Breaking change: paragraph that explains the impact, gives --num_workers 1 as the migration, and states that runs without --reload are unaffected. Non-reload paths still reach the same uvicorn.run(**uvicorn_args, workers=num_workers) call.
  • Passed · Changed behavior and result consistency (required): Standards checked: root AGENTS.md (Final, ReadOnly TypedDict fields, the suppression-reason rule) and tests/unit/AGENTS.md (in-process, no subprocess or network). The new unit file now has no subprocess, socket, httpx or sleep. tests/integration/AGENTS.md: the configuration directory is in the management group in run.py.

Path traced: run_server builds uvicorn_args, then configure_dev_reload adds reload_dirs and reload_includes, then the reload and num_workers > 1 branch runs RELOAD_OPTIONS.validate_python. From there it reaches run_multi_worker_reload, which hands off to ChangeReload, then the spawned _run_worker_pool, then ReloadWorkerPool(Multiprocess), and finally load_worker_app in each worker.

Boundary cases covered by tests:

  • An explicit timeout_worker_healthcheck versus the default (unit test).
  • CLI args not listed in the TypedDict pass through via extra=allow (the backlog test).
  • Windows fallback, and uvicorn without STARTUP_FAILURE.
  • A broken app exits with STARTUP_FAILURE instead of respawning.
  • A killed reloader stops the pool.

Run: pytest tests/unit/proxy/test_dev_reload.py tests/integration/configuration/test_reload_worker_pool.py gave 18 passed in 101s on uvicorn 0.51.0.

Manual E2E: I ran proxy_cli.py --config c.yaml --num_workers 2 --reload --port 4412 with a non-default master key. The log shows Started server process [6704] and [6705], and liveliness returned 200 four times. Editing c.yaml logged StatReload detected changes in 'c.yaml', Finished server process [6704]/[6705] and Stopping parent process, then new workers [6731]/[6732] started. With no master key, a broken boot logged Child process failed to start, stopping the parent process once. It did not loop.

test_multi_worker_reload.py needs the integration gateway env, and I did not run it. My manual run covered its config-reload path.

  • Passed · Prior finding 24736a3b…:0 recheck (optional): The subprocess and network pool cases moved to tests/integration/configuration/test_reload_worker_pool.py. tests/unit/proxy/test_dev_reload.py now holds only in-process cases.

View review · Reviewed 770c4319beb0

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Devin Review: 1 flag

Not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)

Devin Review

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

…espawning it

Workers now load the app through a factory that exits with uvicorn's
STARTUP_FAILURE code on any import error, so the pool stops and the
reloader waits for the next save, the same as single-worker reload.
Multi-worker reload needs uvicorn>=0.50.0 for that, so older versions
keep the single-worker reload with a warning.
…hutdown helper

Main's TQ010 rule rejects a raw .terminate() under tests/integration, so the multi-worker reload test now calls OwnedProxy.begin_shutdown(), which sends the same SIGTERM
@mateo-berri

Copy link
Copy Markdown
Contributor

@litereview code-review

@litereview

litereview Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@mateo-berri

Copy link
Copy Markdown
Contributor

@litereview code-review

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@mateo-berri

Copy link
Copy Markdown
Contributor

@litereview code-review

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@mateo-berri

Copy link
Copy Markdown
Contributor

@litereview code-review

@mateo-berri

Copy link
Copy Markdown
Contributor

@litereview code-review

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

@litereview code-review

Comment thread tests/unit/proxy/test_dev_reload.py Outdated
raise AssertionError(log.read_text())


def _start_pool(app_dir: Path, port: int, log: Path, runner: str = POOL_RUNNER) -> subprocess.Popen[bytes]:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low · Subprocess and network pool tests placed in tests/unit, which forbids both

  1. tests/unit/AGENTS.md opens with: "In-process. No network or subprocess". It also says unit tests must not depend on execution speed.
  2. tests/unit/proxy/test_dev_reload.py starts real uvicorn pools with subprocess.Popen, binds sockets, and sends httpx.get to the workers.
  3. It also polls logs with time.sleep(0.2) against 30 to 120 second timeouts.
  4. The unit shard now carries an 18-case suite that took 107 s locally. It depends on free ports and machine speed, which is what the guide's split is meant to keep out of unit runs.

The smallest fix keeps the in-process cases (load_app_or_exit, pool_config, multi_worker_reload_supported) in tests/unit/proxy. Move the subprocess pool cases under tests/integration/configuration, next to test_multi_worker_reload.py.

Evidence

tests/unit/AGENTS.md line 3: In-process. No network or subprocess

tests/unit/AGENTS.md: Unit tests must not depend on the current time or execution speed

test_dev_reload.py:225 subprocess.Popen(, :251 httpx.get(f"http://127.0.0.1:{port}/", :203/:243 socket.socket(), :219/:309/:332/:356 time.sleep(0.2)

Local run: pytest tests/unit/proxy/test_dev_reload.py -> 18 passed in 106.92s

This breaks a documented repo standard, so it is not a smell judgement. Older files in tests/unit also break it, but this PR adds a new file.

Latest summary by code-review · View this review · Reviewed 9f397dbbf065

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file only holds in-process tests now. The subprocess and socket pool tests already live in tests/integration/configuration/test_reload_worker_pool.py

The unit test guide keeps tests/unit in-process, so the subprocess pool cases now live in tests/integration/configuration and use the harness port allocator and process helpers
@mateo-berri

Copy link
Copy Markdown
Contributor

@litereview code-review

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@mateo-berri

Copy link
Copy Markdown
Contributor

@litereview guide

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@litereview

litereview Bot commented Oct 21, 2026

Copy link
Copy Markdown

⚠️ guide

Open preview

Scope: full · Full PR review.

Completed · Some checks not run.

Today, a developer who runs the proxy with --num_workers 2 --reload gets one worker. The only sign is a single warning line in the startup log, so bugs that need two workers sharing Redis never show up when they test locally.

Walkthrough, one QA proxy start:

  1. Run the command: --num_workers 2 --reload. Same both ways.
  2. Build the server options: the proxy watches *.py, .env and the config file. Same both ways.
  3. Hand off to uvicorn (breaks here): the proxy asks uvicorn for reload and two workers in one call. uvicorn keeps reload and prints "workers" flag is ignored when reloading is enabled.
  4. Start the workers: one server process starts, not two.
  5. Serve a request: callers get 200s, so the missing worker goes unnoticed.
  6. Save a file: the one worker reloads.
  7. Save a typo: the one worker fails, then comes back on the next good save.

After the fix: stop 3 is fixed here. The proxy runs its own reload pool: a reloader on top, a pool parent under it, and the workers under that. I ran it locally:

  • Two server processes start.
  • Four /v1/chat/completions requests all return 200.
  • A config save terminates both workers and starts two new ones.
  • A typo makes the workers exit with uvicorn's startup failure code, so the pool stops once instead of respawning broken workers in a loop.

What changes for the caller: on uvicorn 0.50.0 or newer, outside Windows, --reload now runs the worker count they asked for, and every save restarts all of the workers together. On older uvicorn or on Windows, the proxy prints a clearer warning and keeps one worker. Runs without --reload are unchanged.

Tests added: two integration files and one unit file.

  • test_multi_worker_reload.py starts a real proxy with 1 or 2 workers and checks config, Python and .env saves.
  • test_reload_worker_pool.py checks a broken save, a killed reloader or pool parent, and Ctrl-.
  • The unit tests check how the app loads, which uvicorn options reach the workers, the 30 second healthcheck default, and that Windows keeps one worker.

I ran 11 unit tests and 7 pool tests locally; all passed.

Black box coverage: Nay. The two-worker reload path is covered. The one-worker fallback on uvicorn older than 0.50.0 or on Windows is not: the locked uvicorn is 0.51.0 and the tests run on Linux, so that fallback could break without anyone noticing.

Checks and execution details
  • Passed · Unit tests: tests/unit/proxy/test_dev_reload.py (optional): .venv/bin/python -m pytest -q tests/unit/proxy/test_dev_reload.py gave 11 passed, 2 warnings in 1.54s. The warnings are Pydantic notes that ReadOnly items are not protected from mutation.

  • Passed · Integration tests: tests/integration/configuration/test_reload_worker_pool.py (optional): 7 passed in 103.49s on uvicorn 0.51.0, Linux.

  • Passed · Live proxy run on the PR head with --num_workers 2 --reload (optional): Used a mock_response model, no database and no Redis.

  • The log shows a reloader, a pool parent and two server processes.

  • Four /v1/chat/completions requests returned 200.

  • Appending to config.yaml terminated both workers and started a new pool parent with two new workers.

The page uses these log lines.

  • Passed · Live run of the old path for comparison (optional): I temporarily turned off the new if reload and num_workers > 1 branch in proxy_cli.py, then restored the file. With the branch off, the same command printed "workers" flag is ignored when reloading is enabled. and started one server process. This simulates base behavior on the PR checkout; it is not a run of the base commit.
  • Not run · tests/integration/configuration/test_multi_worker_reload.py (optional): Not run. It needs the integration gateway harness and Redis, and the black box coverage verdict only needs the code read.
  • Passed · Preview structure checks (required): 14 radios for 7 stops, exactly one checked, and every for= matches an id. No em dashes, scripts or buttons.

View review · Reviewed 770c4319beb0

mateo-berri and others added 2 commits October 31, 2026 23:58
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…command

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

Comment thread litellm/proxy/dev_reload.py Resolved
…ory raises

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

Comment thread tests/unit/proxy/test_dev_reload.py Resolved
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit ee4f337. Configure here.

@mateo-berri mateo-berri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants