LearnNewsExamplesServices
Frontmatter
id8346
titleRefactor DatabaseService to Config-based Opt-Out Auto-Sync
stateClosed
labels
enhancementai
assigneestobiu
createdAtJan 6, 2026, 1:45 AM
updatedAtJan 6, 2026, 2:10 AM
githubUrlhttps://github.com/neomjs/neo/issues/8346
authortobiu
commentsCount1
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
contentTrust
projected
quarantined0
signals[]
blockedBy[]
blocking[]
closedAtJan 6, 2026, 2:10 AM

Refactor DatabaseService to Config-based Opt-Out Auto-Sync

tobiu
tobiu commented on Jan 6, 2026, 1:45 AM

DatabaseService currently triggers an auto-sync/embed on startup. This is correct for the Server but needs to be disabled for CLI scripts to avoid double-runs.

Goal: Use KB_Config to allow scripts to Opt-Out of Auto-Sync.

Plan:

  1. config.mjs: Add autoSync: true to the default configuration.
  2. DatabaseService.mjs: Modify initAsync to check aiConfig.data.autoSync. If false, skip the sync logic.
  3. ai/examples/sync_knowledge_base.mjs: Import config.mjs and set aiConfig.data.autoSync = false at the top level.

This maintains the "batteries included" behavior for the Server while allowing scripts to disable the side effect.

tobiu
tobiu Jan 6, 2026, 2:09 AM

Input from Gemini 3 Pro:

✦ I have successfully refactored DatabaseService to use a Config-based "Opt-Out" strategy for Auto-Sync.

Changes Implemented:

  1. ai/mcp/server/knowledge-base/config.mjs:

    • Added autoSync: true to the defaultConfig.
    • This ensures the MCP Server (and any default consumer) continues to auto-heal on startup.
  2. ai/mcp/server/knowledge-base/services/DatabaseService.mjs:

    • Updated initAsync to check aiConfig.data.autoSync.
    • If false, the automatic syncDatabase() / embedKnowledgeBase() calls are skipped.
  3. ai/services.mjs (SDK Entry Point):

    • Added KB_Config.data.autoSync = false at the top level.
    • This ensures that any script importing the AI SDK (e.g., agents, test runners) implicitly opts-out of the auto-sync behavior, preventing double-runs when they manage the database explicitly.

This solution centralizes the control, preserves "batteries-included" for the Server, and safely disables side effects for script execution.

tobiu cross-referenced by #8347 on Jan 6, 2026, 11:34 AM