fix: prevent false 'model error' popup during startup#54
Open
wei-yao wants to merge 2 commits intoyan5xu:mainfrom
Open
fix: prevent false 'model error' popup during startup#54wei-yao wants to merge 2 commits intoyan5xu:mainfrom
wei-yao wants to merge 2 commits intoyan5xu:mainfrom
Conversation
When three model-loading threads run in parallel, each calls suppress_stdout() which saves and restores sys.stdout. Due to interleaving, one thread could capture another thread's devnull as its old_stdout, and later restore to a closed file — causing `ValueError: I/O operation on closed file` when the server tried to print the init result. Fix by restoring to sys.__stdout__ (Python's original stdout) instead of the locally saved reference, which is always stable regardless of thread order. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
When the app starts, initializeAtStartup() runs async Python checks before calling preInitializeModels() (which sets initializationPromise). During this brief window, checkStatus() returns initializing: false even though FunASR is just starting up, causing useModelStatus to set stage:'error' → popup fires on mic click even with AI optimization disabled. Two fixes: 1. funasrManager.checkStatus(): also return initializing:true when !this.isInitialized (startup not yet complete), not just when initializationPromise is set. 2. useModelStatus.js: when models are downloaded but server not yet ready, treat as 'loading' instead of 'error'. Only show error when models are genuinely missing or FunASR isn't installed. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Problem
When the app starts, a false "❌ 模型错误" popup appears when the user clicks the mic button, even though:
Root Cause
There is a startup race condition.
initializeAtStartup()runs two async Python checks (findPythonExecutable,checkFunASRInstallation) before callingpreInitializeModels()which setsinitializationPromise. During this brief window:checkStatus()returnsinitializing: false(becauseinitializationPromiseis stillnull)useModelStatus.jssees: models downloaded + server not ready +initializing: falseelsebranch → setsstage: 'error'toggleRecording()seesstage === 'error'→ shows popupFix
funasrManager.js— also reportinitializing: truebefore startup has completed:useModelStatus.js— when models are downloaded but server isn't ready yet, treat as'loading'not'error'. Reserve'error'for genuine failures (FunASR not installed, models missing):