Skip to content

fix(memory-reflection): Issue #680 - serial guard, fail-open, bulkStore (B/C options)#684

Open
jlin53882 wants to merge 5 commits intoCortexReach:masterfrom
jlin53882:fix/issue680-bulkstore-tdd
Open

fix(memory-reflection): Issue #680 - serial guard, fail-open, bulkStore (B/C options)#684
jlin53882 wants to merge 5 commits intoCortexReach:masterfrom
jlin53882:fix/issue680-bulkstore-tdd

Conversation

@jlin53882
Copy link
Copy Markdown
Contributor

@jlin53882 jlin53882 commented Apr 21, 2026

Summary

Fix 3 bugs in the memory-reflection mapped-memory loop (Issue #680):

  1. [CRITICAL] Serial guard on early throw: getSerialGuardMap().set() was inside if (reflectionRan), so early throws never triggered the guard. Fixed by moving it to unconditional finally block.
  2. [CRITICAL] Fail-open on vectorSearch error: vectorSearch throw logged 'continue store' but didn't actually skip. Fixed by adding searchFailed flag + if (searchFailed) continue.
  3. [MEDIUM] N×store.store() instead of bulkStore: Loop called store.store() N times instead of bulkStore() once. Fixed with single bulkStore() call. Heading is embedded in metadata JSON (_reflectionHeading) to survive LanceDB round-trip and avoid index mismatch when bulkStore filters entries.

Changes

  • index.ts: 3 bug fixes + 100-entry cap + JSON.parse defensive try/catch + mdMirror loop comment
  • test/memory-reflection-issue680-tdd.test.mjs: 5 TDD tests covering all 3 bugs + edge cases

Test Results

5/5 tests pass

Adversarial Review

Full adversarial review performed (Claude Code, 6m23s). All findings addressed:

  • MAJOR: bulkStore error test now uses mock throwing store
  • MAJOR: Code comment added referencing Bug /lesson命令是自己添加吗 没成功 #1 test pattern
  • MINOR: JSON.parse wrapped in try/catch
  • MINOR: Added 100-entry cap on mappedEntries per run

Commits

Issue

Fixes #680

…ore (B/C options)

Fix 1 (CRITICAL): Move serial guard set() outside if(reflectionRan)
Fix 2 (CRITICAL): Add searchFailed flag - skip item on vectorSearch error
Fix 3 (MEDIUM): Replace N x store.store() loop with single bulkStore() call

TDD tests: 3/3 pass
…lkStore recovery

After bulkStore filters entries, storedEntries may be shorter than mappedEntries.
Fix: store _reflectionHeading in each entry object; retrieve from stored entry
instead of index-based lookup. Avoids heading mismatch when duplicate text
exists under different sections.
…opagation

Edge cases covered:
- mdMirror heading from metadata JSON (not index-based) after bulkStore filtering
- bulkStore error propagates (not swallowed)
- Production path coverage note explaining closure limitation

5/5 tests pass.
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Fixed issues found by adversarial review (6m23s Claude session):
1. [MAJOR] bulkStore error test: now uses mock throwing store (not valid-entry call)
2. [MINOR] JSON.parse crash: wrapped in try/catch with warn log
3. [MINOR] unbounded mappedEntries: added cap of 100 entries per run
4. [CHORE] NOTE comment in index.ts referencing Bug #1 test

Code comment added at mdMirror loop explaining why metadata-based
heading lookup is needed (index mismatch when bulkStore filters).

All 5 tests pass.
@jlin53882 jlin53882 force-pushed the fix/issue680-bulkstore-tdd branch from 507c2d8 to 1ce25b7 Compare April 21, 2026 16:53
Adds test/memory-reflection-issue680-tdd.test.mjs to the core-regression
CI group so it runs on every push and PR.
@jlin53882
Copy link
Copy Markdown
Contributor Author

CI Status for PR #684

PR #684 包含 5 个 commits,已通过本地测试 5/5。

3 个 CI 失败均为上游既有问题,与本 PR 无关:

Job 结论 原因
storage-and-schema FAIL smart-extractor-scope-filter.mjs mock 缺少 bulkStore (c52ab2b 引入)
core-regression FAIL smart-extractor-branches.mjs 需要 LLM server 端点
packaging-and-workflow FAIL manifest 路径验证问题

本 PR 的 Issue #680 测试:

  • test/memory-reflection-issue680-tdd.test.mjs: 5/5 PASS (本地)
  • 已加入 core-regression CI group

建议:3 个 CI 失败在 master 分支同样存在,应在 master 上统一修复。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor: runMemoryReflection should use bulkStore() instead of individual store.store()

1 participant