LearnNewsExamplesServices
Frontmatter
id9731
titleStabilize Memory Core Backend Initialization
stateClosed
labels
bugairefactoring
assigneestobiu
createdAtApr 6, 2026, 3:35 AM
updatedAtApr 6, 2026, 3:35 AM
githubUrlhttps://github.com/neomjs/neo/issues/9731
authortobiu
commentsCount1
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtApr 6, 2026, 3:35 AM

Stabilize Memory Core Backend Initialization

Closedbugairefactoring
tobiu
tobiu commented on Apr 6, 2026, 3:35 AM

Problem

The Memory Core initialization lifecycle suffered from critical race conditions caused by manual await instance.initAsync() calls firing alongside the framework's native constructor microtask loop. This triggered duplicate concurrent backend bootstraps (specifically in the SQLite graph database), breaking the WAL and resulting in severe locking errors during automated test execution. Additionally, the StorageRouter was being unnecessarily exposed and example scripts relied on legacy hardcoded backup directories.

Proposed Solution

  1. Fix Initialization Race Condition: Replace explicit .initAsync() calls on newly instantiated services with .ready() to guarantee single-pass thread safety.
  2. Encapsulate Storage Router: Update MemoryService, DatabaseService, and SummaryService to handle await StorageRouter.ready() within their own initAsync overrides, decoupling the public API.
  3. Refactor Example Scripts: Standardize ai/examples/ (like db-backup.mjs and db-restore.mjs) to boot specifically via the core services instead of exposing internal managers, and point to the centralized aiConfig.backupPath instead of hardcoded dist directories.
tobiu added the bug label on Apr 6, 2026, 3:35 AM
tobiu added the ai label on Apr 6, 2026, 3:35 AM
tobiu added the refactoring label on Apr 6, 2026, 3:35 AM
tobiu assigned to @tobiu on Apr 6, 2026, 3:35 AM
tobiu referenced in commit ae9f6b8 - "fix: Stabilize memory core backend init sequences (#9731)" on Apr 6, 2026, 3:35 AM
tobiu
tobiu Apr 6, 2026, 3:35 AM

Fixed the race conditions across Agent, examples, and services by relying on standard .ready() lifecycles. Pushed the changes.

tobiu closed this issue on Apr 6, 2026, 3:35 AM