Fix external STT server lifecycle to ensure single instance and proper cleanup #1829
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.
Fix external STT server lifecycle to prevent multiple instances
Summary
Fixes a race condition in the external STT server lifecycle management that caused multiple server processes to accumulate when switching between models (e.g., ParakeetV2 ↔ ParakeetV3).
Root Cause: When switching models,
stop_all_stt_servers()would wait for the actor to be removed from the registry, but the actual process cleanup happened asynchronously in thepost_stop()hook. This meant new servers could start spawning before old processes were fully terminated.Solution:
wait_for_process_cleanup()function that verifies external STT processes are actually terminated before returning fromstop_stt_server()hypr_hostcrate for process verificationChanges:
crates/host/src/lib.rs: Addedhas_processes_matching()andwait_for_processes_to_terminate()functionsplugins/local-stt/src/server/supervisor.rs:wait_for_process_cleanup()call after stopping external STT serversProcessCleanupDepsstruct for dependency injectionwait_for_process_cleanup_with()that accepts test dependenciescrates/host/Cargo.toml: Added tokio dependency with time feature for async sleepUpdates Since Last Revision
Added unit tests for the cleanup logic using dependency injection:
test_cleanup_process_terminates_gracefully: Verifies no force kill when process exits cleanlytest_cleanup_process_never_terminates: Verifies force kill is called and sleep happens aftertest_cleanup_process_kill_returns_zero: Verifies no sleep when kill finds no processesThe cleanup logic is now testable without spawning real processes or waiting real time.
Review & Testing Checklist for Human
The unit tests verify the cleanup logic in isolation but do NOT test the full lifecycle with real processes. Manual testing is essential.
ps aux | grep sttor Activity Monitor)owhisper/schema.jsonfile has property reordering - confirm these changes are intentional and don't break anythingRecommended Test Plan
Notes
ServerType::External(Am models), notServerType::Internal(Whisper models) since internal servers don't spawn external processesProcessCleanupDepsstruct uses function pointers withPin<Box<Future>>for testability - the type signature is verbose but necessary for async testingSession: https://app.devin.ai/sessions/0d06a16e24d441a087fec63fc1e92a45
Requested by: yujonglee (@yujonglee)