fix(#82): rebuild-index 大資料 OOM — 精簡 delta cache + 惰性驅逐#87
Merged
Conversation
reconstructReq now caches only the messages array (needed for delta splicing), not the full parsedBody (system 50-100KB + tools 10-50KB per entry). After projection, entries are deleted from cache via lazy reference counting — once an ancestor's last downstream consumer finishes, the entry is evicted. Peak memory drops from O(total orphans × full body) to O(active chain depth × messages-only). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
摘要
修復
rebuild-index在大型 logs 目錄(8.3GB / 65K 檔)OOM 的問題。根因是reconstructReq的 cache Map 把每個重建的完整parsedBody(含 system prompt 50-100KB + tools 10-50KB)留在記憶體,累積到 4GB+ 觸發 V8 heap limit。Changes
Two-layer fix:
Stripped cache in
reconstructReq: Cache stores only{ parsedBody: { messages } }— the minimum needed for downstream delta splicing. FullparsedBody(system, tools, metadata) is returned to caller but NOT retained. This alone cuts cache memory ~80%.Lazy refcount eviction in Pass 2: After projecting each turn through
buildEntryFields, entries with no remaining downstream consumers are deleted from cache. AnancestorRefsMap (built fromreconentries'prevIdfields) tracks reference counts. Memory bound: O(active chain depth × messages-only size).What's NOT changed
reconstructReqinterface is additive only (returns additionalprevIdfield)Verification (per verification-principles.md)
cacheFinalSize === 0fails onmain(cache never evicted), passes on fix branchmainworktree, confirmed FAIL; confirmed PASS on fix branchTest plan
cacheFinalSize === 0🤖 Generated with Claude Code