feat: Phase 2 singleton state management (Issue #598)#636
Draft
jlin53882 wants to merge 1 commit intoCortexReach:masterfrom
Draft
feat: Phase 2 singleton state management (Issue #598)#636jlin53882 wants to merge 1 commit intoCortexReach:masterfrom
jlin53882 wants to merge 1 commit intoCortexReach:masterfrom
Conversation
- 新增 PluginSingletonState interface:定義所有 heavy plugin 資源的型別 - 新增 _singletonState 模組層級變數:null 直到第一次 register() 呼叫 - 新增 _initPluginState(api) factory function:建立所有資源(store、embedder、 tierManager、retriever、scopeManager、migrator、smartExtractor、 extractionRateLimiter)及 8 個 Session Maps - 替換 register() 內的 init block:改為 if (!_singletonState) guard, 後續呼叫直接 destructuring 從 singleton 取用資源 - 移除 register() 內重複的 Map 宣告(改由 singleton 擁有) - Session Maps 現在在第一次 register() 時建立並 persist,後續 scope refresh 不會重複建立導致 memory heap growth - Phase 1 dedup 機制(_hookEventDedup / _dedupHookEvent)保持不變 - Phase 3 backup timer optimization 不包含在本次實作 PR CortexReach#430 Phase 2 / Issue CortexReach#598
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Phase 2: Singleton State Management — Continuation of PR #430
Issue
Issue #598
Problem
memory-lancedb-procallsregister()multiple times per process lifecycle:Without guarding, all heavy plugin resources and session Maps are recreated on each
register()call, causing:clearInternalHooks()resets the plugin between registrationsSolution: Phase 2 Singleton State
This PR implements Phase 2 of the multi-phase fix for Issue #430 / Issue #598.
Building on Phase 1 (hook event deduplication via
_hookEventDedupSet, merged as PR #617), Phase 2 addresses resource deduplication:PluginSingletonStateinterface — defines all 18 properties returned by the factory (8 heavy resources + 8 session Maps)_singletonStatemodule-level variable —nulluntil firstregister()call, then persists for process lifetime_initPluginState(api)factory function — creates all resources and Maps exactly onceif (!_singletonState)guard inregister()— subsequent calls reuse the singleton via destructuringWhat Phase 3 Is NOT
Phase 3 (backup timer optimization) is NOT included in this PR.
Files Changed
index.ts— singleton infrastructure (PluginSingletonState, _singletonState, _initPluginState, register() refactor)Testing
npm run test:cli-smoke)test:core-regressionhas a pre-existingmigrator is not definederror in upstream (16ee3e4) — not caused by this PRCommits in This PR Branch