Phase 4.7b: Extract service init + remove globals (#581)#585
Merged
Conversation
Phase 4.7b: Move all inline service initialization from startup_event() into domain startup modules. Remove 8 global service variables — the ServiceContainer in app/dependencies.py is now the single source of truth. New/extended startup modules: - modules/speech/startup.py: init_tts_services(), init_stt_service(), init_streaming_tts_manager() — TTS/STT with GPU availability checks - modules/llm/startup.py: init_llm_service() — LLM with fallback chain, create_llm_switch_callback() — InternetMonitor callback factory - modules/knowledge/startup.py: init_wiki_rag() — Wiki RAG + embeddings - modules/core/startup.py: init_internet_monitor(), check_legacy_files(), graceful_shutdown() — monitor, legacy warnings, bot/bridge cleanup - modules/telephony/startup.py: init_gsm_services() — GSM + voice calls orchestrator.py: 805 → 321 lines (−60%). Zero global service variables, zero inline init logic — pure wiring (imports, middleware, router registration, startup/shutdown orchestration, static files). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
19 tasks
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.
Summary
startup_event()into domainstartup.pymodules:modules/speech/startup.py—init_tts_services(),init_stt_service(),init_streaming_tts_manager()modules/llm/startup.py—init_llm_service()(full fallback chain),create_llm_switch_callback()(InternetMonitor callback factory)modules/knowledge/startup.py—init_wiki_rag()(tiered embedding provider + task registration)modules/core/startup.py—init_internet_monitor(),check_legacy_files(),graceful_shutdown()modules/telephony/startup.py—init_gsm_services()(GSM + voice calls)voice_service,anna_voice_service,piper_service,openvoice_service,stt_service,llm_service,streaming_tts_manager,current_voice_config)ServiceContainer(app/dependencies.py) is now the single source of truth — no more dual state_switch_llmcallback refactored: closure factory inmodules/llm/startup.py, writes only tocontainer.llm_service+os.environ["LLM_BACKEND"](no globals)VLLM_AVAILABLE,PIPER_AVAILABLE, etc.) moved to domain startup modulesTest plan
ruff check .— all checks passedruff format— formattedpytest tests/— 65 tests passedcurl /healthCloses #581
🤖 Generated with Claude Code