Skip to content

Conversation

@HyeockJinKim
Copy link
Collaborator

Moved dependency initialization and configuration code from server.py into separate provider modules under providers/ directory for better separation of concerns and maintainability.

Each provider module handles a specific aspect of manager setup:

  • Database connections and models
  • Redis clients (image, live, stat, stream, etc.)
  • Event system (dispatcher, producer, hub)
  • Background tasks and message queues
  • Service discovery and leader election
  • Plugin systems (event dispatcher, hooks, network)
  • Monitoring and idle checking
  • Core repositories and services
  • Sokovan orchestrator

resolves #3931 (BA-938)

Checklist: (if applicable)

  • Milestone metadata specifying the target backport version
  • Mention to the original issue
  • Installer updates including:
    • Fixtures for db schema changes
    • New mandatory config options
  • Update of end-to-end CLI integration tests in ai.backend.test
  • API server-client counterparts (e.g., manager API -> client SDK)
  • Test case(s) to:
    • Demonstrate the difference of before/after
    • Demonstrate the flow of abstract/conceptual models with a concrete implementation
  • Documentation
    • Contents in the docs directory
    • docstrings in public interfaces and type annotations

Moved dependency initialization and configuration code from server.py
into separate provider modules under `providers/` directory for better
separation of concerns and maintainability.

Each provider module handles a specific aspect of manager setup:
- Database connections and models
- Redis clients (image, live, stat, stream, etc.)
- Event system (dispatcher, producer, hub)
- Background tasks and message queues
- Service discovery and leader election
- Plugin systems (event dispatcher, hooks, network)
- Monitoring and idle checking
- Core repositories and services
- Sokovan orchestrator

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@HyeockJinKim HyeockJinKim self-assigned this Oct 6, 2025
Copilot AI review requested due to automatic review settings October 6, 2025 05:44
@github-actions github-actions bot added size:XL 500~ LoC comp:manager Related to Manager component labels Oct 6, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the manager initialization logic by extracting dependency setup code from a monolithic server.py file into modular provider modules under the providers/ directory. This improves separation of concerns and maintainability by organizing related setup logic into focused modules.

Key changes:

  • Extracted context manager functions from server.py into 22 dedicated provider modules
  • Each provider handles initialization of specific manager subsystems (database, Redis, events, etc.)
  • Reduced the size of server.py by ~750 lines while preserving existing functionality
  • Added proper imports for all extracted providers in server.py

Reviewed Changes

Copilot reviewed 25 out of 25 changed files in this pull request and generated 2 comments.

File Description
src/ai/backend/manager/server.py Removed inline context managers and replaced with imports from provider modules
src/ai/backend/manager/providers/__init__.py Added package initialization with module description
src/ai/backend/manager/providers/*.py 22 new provider modules, each handling specific aspect of manager setup (database, Redis, events, etc.)

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.


from ai.backend.common import redis_helper
from ai.backend.common.defs import REDIS_STREAM_LOCK, RedisRole
from ai.backend.logging.utils import BraceStyleAdapter
Copy link

Copilot AI Oct 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import path inconsistency: other provider modules use from ai.backend.logging import BraceStyleAdapter while this module uses from ai.backend.logging.utils import BraceStyleAdapter. Should be consistent across all provider modules.

Suggested change
from ai.backend.logging.utils import BraceStyleAdapter
from ai.backend.logging import BraceStyleAdapter

Copilot uses AI. Check for mistakes.
from ..models.storage import StorageSessionManager

root_ctx.storage_manager = StorageSessionManager(root_ctx.config_provider.config.volumes)
yield
Copy link

Copilot AI Oct 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing cleanup logic in the storage manager context. The original code had await root_ctx.storage_manager.aclose() in the finally block, but this extracted version only has yield without proper cleanup.

Suggested change
yield
try:
yield
finally:
await root_ctx.storage_manager.aclose()

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:manager Related to Manager component size:XL 500~ LoC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Separate setup code in manager

2 participants