DocsGPT icon indicating copy to clipboard operation
DocsGPT copied to clipboard

`docsgpt dev` on Windows: first hot-reload exits the whole supervisor instead of restarting the API (pre-existing)

Open YongxinFu opened this issue 1 month ago • 7 comments

Symptom

On Windows, uv run docsgpt dev --mock-llm --no-worker starts normally (API serving, HEAD / → 302 /api/docs). Editing any watched Python file — e.g. creating docsgpt/reload_probe.py — then produces:

api       | WARNING: WatchFiles detected changes in 'docsgpt\reload_probe.py'. Reloading...
Stopping ...
api       | INFO:     Stopping reloader process [38628]

and the entire dev supervisor exits back to the shell instead of restarting the API child. No Ctrl+C was pressed; the exit is triggered purely by saving the file.

Pre-existing (not introduced by PR #3171)

Reproduced on upstream base commit 2b868a3c52ca93619158604ed435988c182f1289 in a clean checkout. To get past the unrelated GBK import crash, only the two UTF-8 encoding fixes from #3171 were temporarily applied; git diff HEAD -- docsgpt/deploy/dev.py docsgpt/cli.py was empty, i.e. the process-management and reload code was stock upstream.

Environment

  • Windows (PowerShell), Python 3.14
  • uv run docsgpt dev --mock-llm --no-worker (API child: python -m docsgpt api --host 127.0.0.1 --port 7091 --reload, so Started reloader process [...] using WatchFiles)

Workaround

docsgpt dev --no-reload — verified on the same base commit: the API starts without a reloader process, serves 302 /api/docs, and editing docsgpt/reload_probe.py no longer kills anything. Code changes then need a manual restart.

Suspected area

Under the docsgpt dev supervisor on Windows, the uvicorn WatchFiles reloader child appears to exit (rather than restart the server subprocess) on the first reload, and run()/_stop() in docsgpt/deploy/dev.py treats any child exit as fatal for the whole tree. Needs investigation; happy to help test patches on this machine.

YongxinFu avatar Oct 24 '26 19:10 YongxinFu

Related to #3171, but this is a pre-existing issue and will be addressed in a separate follow-up PR.

YongxinFu avatar Oct 24 '26 19:10 YongxinFu

Additional Windows reproduction and fix verification

I performed further testing on Windows to verify the root issue and a potential follow-up fix.

1. Reproduction on the upstream base

  • Base commit: 2b868a3c52ca93619158604ed435988c182f1289

  • docsgpt/deploy/dev.py and docsgpt/cli.py were unchanged.

  • Only two UTF-8 reading fixes from #3171 were temporarily applied to bypass an unrelated GBK startup failure.

  • The API started successfully and returned HTTP 302.

  • Saving docsgpt/reload_probe.py triggered Reloading..., followed by Stopping ..., and the whole development supervisor exited.

2. Verified workaround

Running docsgpt dev --mock-llm --no-worker --no-reload kept the API available after editing the same file. HTTP requests continued returning 302.

3. Experimental follow-up fix

I tested replacing Uvicorn's built-in API reload supervisor on Windows with the existing watchfiles function-target mechanism.

Manual results:

Event | API PID | Result -- | -- | -- Initial startup | 15208 | Successful First file change | 12664 | Restarted successfully Second file change | 20472 | Restarted successfully

Additional checks:

  • The development supervisor remained running across both reloads.

  • Previous API processes exited.

  • The API continued responding with HTTP 302.

  • After Ctrl+C, the final API process exited and ports 7091 and 8090 were released.

Status: This is a manually verified candidate fix in a separate local branch, not part of PR #3171. I plan to submit it in a separate follow-up PR.

YongxinFu avatar Oct 24 '26 19:10 YongxinFu

Additional manual evidence: before vs. after (Windows)

I reproduced the failure on the upstream base and manually verified an experimental fix in the separate fix/windows-api-reload worktree.

Before — original base (2b868a3c5)

  • The API started successfully (PID 26832) and responded to HEAD / with 302 Found.
  • Saving docsgpt/reload_probe.py produced WatchFiles detected changes ... Reloading....
  • Instead of bringing up a replacement API process, the entire docsgpt dev supervisor printed Stopping ... and exited.
  • The base's docsgpt/deploy/dev.py and docsgpt/cli.py were unchanged. Two unrelated UTF-8 file-reading fixes were temporarily applied to work around a Windows GBK startup error.

After — experimental fix (separate local worktree, not in PR #3171)

The Windows API startup command delegates reloading to watchfiles function-target mode, rather than enabling Uvicorn's own --reload.

Observed API process sequence:

  • Initial startup: PID 15208
  • First change detected: PID 12664 started successfully
  • Second change detected: PID 20472 started successfully

The earlier API PIDs were no longer running, the supervisor stayed alive across both changes, and HEAD / continued returning 302 Found. After an intentional Ctrl+C, PID 20472 was gone and neither port 7091 nor mock LLM port 8090 remained listening.

Scope: These are manual Windows verification results, not automated process-lifecycle tests. The candidate fix will be submitted separately from #3171.

YongxinFu avatar Oct 24 '26 19:10 YongxinFu

Visual Evidence — Windows API Hot Reload

1. Before Fix — Original Upstream Base

Base commit: 2b868a3c5

Steps:

  1. Start DocsGPT with uv run docsgpt dev --mock-llm --no-worker.

  2. Verify the API starts successfully and responds with HTTP 302.

  3. Modify docsgpt/reload_probe.py.

Observed result:

  • WatchFiles detects the file change and prints Reloading....

  • The supervisor unexpectedly prints Stopping ....

  • The entire development environment exits instead of restarting the API.

Screenshot — Before Fix:

Image


2. After Fix — Experimental Windows Reload Solution

Branch: fix/windows-api-reload (separate local branch)

Changes:

Use watchfiles function-target mode to manage API reloads instead of Uvicorn's built-in reload supervisor on Windows.

Observed results:

Event | API Process PID | Result -- | -- | -- Initial startup | 15208 | Success First file change | 12664 | Reload successful Second file change | 20472 | Reload successful

Additional verification:

  • Previous API processes exited successfully.

  • The DocsGPT supervisor remained running after both reloads.

  • HTTP requests returned 302 Found.

  • Ctrl+C shut down the application.

  • Ports 7091 and 8090 were released.

Screenshot — After Fix:

Image


Conclusion

The issue is reproducible on the original upstream base and is not introduced by PR #3171.

The experimental fix successfully passed manual Windows reload and shutdown verification.

This fix will be submitted in a separate follow-up PR. These screenshots document manual testing, not automated lifecycle-test results.

YongxinFu avatar Oct 24 '26 19:10 YongxinFu

Thanks for reaching out!

I've already completed the fix and tested it on Windows. I haven't opened the PR yet because I'm waiting for my previous PR (#3171) to be merged first.

I plan to submit the fix myself once that PR is merged. Thanks for your understanding!

YongxinFu avatar Oct 25 '26 09:10 YongxinFu

Hi @YongxinFu, I hit this on Windows too, and I had a similar patch (API under watchfiles on win32) that I tested locally: two reloads, supervisor stays up, clean Ctrl+C. I’ll hold off on a PR since you already have one coming. If it helps, I can test your fix/windows-api-reload branch on my Windows machine and post the result here. One thing I ran into: when watchfiles gets a shell-style command string on Windows, it keeps the quotes that shlex.join adds, so the interpreter path isn’t found. Your function-target mode avoids that, but it may be worth a regression test.

AtharvDhiman avatar Oct 25 '26 09:10 AtharvDhiman

Thanks for the offer to test!

I believe the Windows quoting/argument-passing issue is already covered. In #3171, I added regression tests that exercise the actual watchfiles CLI in function-target mode, including Windows-style interpreter paths with backslashes and spaces, and verify that the expected arguments reach docsgpt.cli.main intact. The tests pass locally.

I've also manually verified the separate fix/windows-api-reload fix on Windows: two consecutive reloads worked, the supervisor stayed running, and Ctrl+C shut everything down cleanly. I plan to submit that follow-up PR once #3171 is merged.

I'd appreciate an independent test on your Windows machine when the follow-up PR is available. Thanks again!

YongxinFu avatar Oct 25 '26 09:10 YongxinFu