Skip to content

fix: prevent false 'model error' popup during startup#54

Open
wei-yao wants to merge 2 commits intoyan5xu:mainfrom
wei-yao:fix/model-status-false-error-on-startup
Open

fix: prevent false 'model error' popup during startup#54
wei-yao wants to merge 2 commits intoyan5xu:mainfrom
wei-yao:fix/model-status-false-error-on-startup

Conversation

@wei-yao
Copy link
Copy Markdown

@wei-yao wei-yao commented Mar 3, 2026

Problem

When the app starts, a false "❌ 模型错误" popup appears when the user clicks the mic button, even though:

  • FunASR models are downloaded and working
  • AI optimization is disabled in settings

Root Cause

There is a startup race condition. initializeAtStartup() runs two async Python checks (findPythonExecutable, checkFunASRInstallation) before calling preInitializeModels() which sets initializationPromise. During this brief window:

  1. checkStatus() returns initializing: false (because initializationPromise is still null)
  2. useModelStatus.js sees: models downloaded + server not ready + initializing: false
  3. Falls into the else branch → sets stage: 'error'
  4. User clicks mic → toggleRecording() sees stage === 'error' → shows popup

Fix

funasrManager.js — also report initializing: true before startup has completed:

// before
initializing: this.initializationPromise !== null

// after
initializing: this.initializationPromise !== null || !this.isInitialized

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):

// before
} else if (serverStatus.initializing) {
  stage: 'loading'
} else {
  stage: 'error'   // ← triggered too eagerly
}

// after
} else if (serverStatus.initializing || serverStatus.models_downloaded) {
  stage: 'loading' // ← models downloaded = still starting up
} else {
  stage: 'error'   // ← only when truly broken
}

yao wei and others added 2 commits March 2, 2026 23:57
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>
@wei-yao wei-yao closed this Mar 10, 2026
@wei-yao wei-yao reopened this Mar 10, 2026
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.

1 participant