Skip to content

Phase 4.7b: Extract service init + remove globals (#581)#585

Merged
shikhalev merged 1 commit intomainfrom
server/phase-4.7b-service-init
Mar 16, 2026
Merged

Phase 4.7b: Extract service init + remove globals (#581)#585
shikhalev merged 1 commit intomainfrom
server/phase-4.7b-service-init

Conversation

@shikhalev
Copy link
Collaborator

Summary

  • All inline service initialization extracted from startup_event() into domain startup.py modules:
    • modules/speech/startup.pyinit_tts_services(), init_stt_service(), init_streaming_tts_manager()
    • modules/llm/startup.pyinit_llm_service() (full fallback chain), create_llm_switch_callback() (InternetMonitor callback factory)
    • modules/knowledge/startup.pyinit_wiki_rag() (tiered embedding provider + task registration)
    • modules/core/startup.pyinit_internet_monitor(), check_legacy_files(), graceful_shutdown()
    • modules/telephony/startup.pyinit_gsm_services() (GSM + voice calls)
  • 8 global service variables removed from orchestrator.py (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_llm callback refactored: closure factory in modules/llm/startup.py, writes only to container.llm_service + os.environ["LLM_BACKEND"] (no globals)
  • Optional imports (VLLM_AVAILABLE, PIPER_AVAILABLE, etc.) moved to domain startup modules
  • orchestrator.py: 805 → 321 lines (−60%) — pure wiring, zero domain logic

Test plan

  • ruff check . — all checks passed
  • ruff format — formatted
  • pytest tests/ — 65 tests passed
  • Manual: Docker deploy + curl /health
  • Manual: verify bot auto-start, LLM init, FAQ/presets reload
  • Manual: verify InternetMonitor callback (if applicable)

Closes #581

🤖 Generated with Claude Code

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>
@shikhalev shikhalev merged commit a057397 into main Mar 16, 2026
3 checks passed
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.

Phase 4.7b: Модульная инициализация сервисов + удаление глобалов

1 participant