Frontmatter
| id | 7836 |
| title | Refactor: Robust Hybrid Database Lifecycle for AI Services |
| state | Closed |
| labels | enhancementairefactoring |
| assignees | tobiu |
| createdAt | Nov 21, 2025, 2:31 AM |
| updatedAt | Nov 21, 2025, 3:14 AM |
| githubUrl | https://github.com/neomjs/neo/issues/7836 |
| author | tobiu |
| commentsCount | 1 |
| parentIssue | null |
| subIssues | [] |
| subIssuesCompleted | 0 |
| subIssuesTotal | 0 |
| blockedBy | [] |
| blocking | [] |
| closedAt | Nov 21, 2025, 3:14 AM |
Refactor: Robust Hybrid Database Lifecycle for AI Services
tobiu assigned to @tobiu on Nov 21, 2025, 3:13 AM

tobiu
Nov 21, 2025, 3:13 AM
Input from Gemini 3.0 Preview:
✦ I have successfully refactored the AI Service lifecycle to support a robust hybrid database model.
Key Changes:
- Eliminated Circular Dependencies:
DatabaseLifecycleServiceno longer statically importsChromaManager. It uses dynamic imports to access the client for heartbeat checks, preventing startup crashes.- Enforced Initialization Order:
DatabaseLifecycleService: Starts the process and waits for a heartbeat (viahttpor dynamic client).ChromaManager: AwaitsDatabaseLifecycleService.ready()before attempting to connect.SessionService/DatabaseService: AwaitChromaManager.ready()before performing operations.- Simplified Agent SDK: The
self-healing.mjsdemo now simply awaitsKB_LifecycleService.ready()andKB_ChromaManager.ready()(or just the manager) without manual retry loops.This resolves the race conditions and supports external/shared database instances.
Closing ticket.
tobiu closed this issue on Nov 21, 2025, 3:14 AM
tobiu cross-referenced by #7837 on Nov 21, 2025, 10:14 AM
Objective Refactor the
DatabaseLifecycleServiceandChromaManagerto robustly support a hybrid database model (External, Managed, Shared) without race conditions or deadlocks.Context The current lifecycle implementation (
ai/mcp/server/knowledge-base/services/DatabaseLifecycleService.mjs) has a potential circular dependency and timing issue:DatabaseLifecycleServicewaits forChromaManagerto be ready.ChromaManagerattempts to connect immediately.ChromaManagerfails to connect, butDatabaseLifecycleServicehasn't started it yet.We need to support:
Tasks
DatabaseLifecycleServiceshould check for an existing DB before waiting forChromaManager.Neo.ai.ServiceBaseto standardize theready()contract across all services (KB, Memory, GitHub), ensuring consumers (Agents) can justawait Service.ready().Deliverables
DatabaseLifecycleService.mjs(KB & Memory).ChromaManager.mjs(KB & Memory).ai/core/ServiceBase.mjs.