Maintenance paths read uninitialized module singletons: dashboard Consolidate fails on control plane, CLI memory deduplicate reports LLM not configured
Maintenance paths read uninitialized module singletons: dashboard "Consolidate" fails on control plane, CLI memory deduplicate always reports "LLM not configured"
Environment
- memorix 1.9.1 (npm global), Node v24.15.0, Windows 11 (10.0.26200)
- Control plane:
memorix serve-http --port 3211, dashboard athttp://127.0.0.1:3211
Both bugs share one root pattern: a code path reads a module-level singleton (LLM config / observation store) that is only initialized by other code paths, so the operation fails deterministically depending on which entry point was used first. Line numbers below refer to the bundled dist/cli/index.js of the published npm package.
Bug A — Dashboard "Consolidate" on the control plane always fails
Steps:
- Start a fresh control plane:
memorix serve-http --port 3211 - Open the dashboard, click Consolidate (preview)
Actual: HTTP 500 {"error":"[memorix] ObservationStore not initialized — call initObservationStore() first"}
Root cause: In serve-http mode, handleDashApi correctly builds a per-request store (getDashboardObservationStore(dataDir)) and passes it as context.store, but the consolidation pipeline ignores it: previewConsolidate/executeConsolidate → findConsolidationCandidates/executeConsolidation/loadConsolidationPage all call the global getObservationStore() (guard throws at dist line 25601; executeConsolidation reads the global at its first line). In a control-plane process the global store is only initialized inside certain MCP tool handlers (initObservationStore(dataDir)); startDashboard() initializes it at startup, but only in standalone mode (memorix dashboard, port 3210) — the serve-http process never does. The other maintenance actions (deduplicate/cleanup/retention) work because they use context.store.
Workaround (verified): call any MCP tool that initializes the global store once (e.g. memorix_dashboard) — consolidate then works until the next control-plane restart. Standalone memorix dashboard is unaffected.
Bug B — CLI memorix memory deduplicate always reports "LLM not configured"
Steps:
- Configure the memory LLM via env (
MEMORIX_LLM_PROVIDER/BASE_URL/MODEL/API_KEY);memorix statusshows the Memory LLM lane fully resolved - Run
memorix memory deduplicate --dry-runin a project
Actual: [WARN] LLM not configured. Set MEMORIX_LLM_API_KEY or OPENAI_API_KEY to enable intelligent dedup.
Root cause: the memory deduplicate command branch checks isLLMEnabled() without calling initLLM() first (dist ~line 192262). isLLMEnabled() returns false while currentConfig is null, and nothing on this command path initializes it. The dashboard path (previewDeduplicate, dist line 222476) explicitly calls initLLM({ scope: "memory", projectRoot }) before the check, which is why the UI works with the exact same env.
Suggested fix
- Bug A: either
await initObservationStore(dataDir)during serve-http startup (mirroringstartDashboard), or make the consolidation functions consumecontext.storelike the other maintenance actions. - Bug B:
await initLLM({ scope: "memory", projectRoot })beforeisLLMEnabled()in the deduplicate command branch.
It may be worth a sweep for other maintenance/CLI branches reading these singletons without initializing them — these two look like instances of the same miss rather than isolated typos.
感谢你把两个入口都跑出来并把根因定位清楚。已经修好:控制面板的 Consolidate 改用当前请求对应的 store,CLI 的 memory deduplicate 会先加载项目级 memory LLM 配置再判断是否可用;两条路径都补了回归测试。PR #289 已通过完整 CI 并用管理员权限合并,问题关闭。