Keep the supervisor alive when the runtime state file is briefly locked (Windows WinError 5) - #92
Open
syrac88 wants to merge 1 commit into
Open
Conversation
On Windows, Python's open() shares files without FILE_SHARE_DELETE, so any
concurrent reader of runtime-processes.json (for example the installer
GUI's 2-second status poll) makes the supervisor's os.replace() in
_write_state() fail with WinError 5. The exception propagated through
monitor_once() and run_foreground(), tearing down every supervised
process ("all processes have exited") in the middle of long TTS runs.
Retry the replace briefly; if the file stays locked, log and skip the
update instead of crashing. The state file is informational and is
rewritten on the next monitor tick, so a skipped update is harmless.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RqeQcimSQTFvLe3NmnL5sF
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.
Fixes #91.
What:
_write_state()now retriesos.replace()up to 10× (100 ms apart) and, if the destination stays locked, logs and skips the update instead of raising. The orphaned.tmpfile is cleaned up. Two regression tests cover the transient-failure and persistent-failure paths.Why: On Windows, any concurrent reader of
runtime-processes.json(e.g. the GUI's 2-second status poll) blocksos.replace()withWinError 5because Python'sopen()doesn't shareFILE_SHARE_DELETE. The uncaught exception propagated throughmonitor_once()→run_foreground()and tore down every supervised process mid-run ("all processes have exited"). Since the state file is informational and rewritten every tick, a skipped update is harmless — crashing the whole app over it is not.Testing:
python -m unittest tests.test_web_supervisor— 9 tests pass (2 new). Battle-tested on the affected machine (Windows 11, long Chatterbox audiobook runs): multiple crashes per day before, many hours of stable generation after.