fix: Issue #675 #676 complete batch mode implementation#782
fix: Issue #675 #676 complete batch mode implementation#782jlin53882 wants to merge 2 commits intoCortexReach:masterfrom
Conversation
…#693) - Adds countBefore/countAfter validation in smart-extractor.ts after bulkStore - Adds ExtractionValidation type and callback interface in memory-categories.ts - Adds extraction-validation.test.mjs (6 scenarios, all pass) - Adds dedup-false-alarm.test.mjs (P0 regression: bulkStore does NOT dedup) - Registers new tests in CI manifest - Adds store.count() mock to existing tests (preference-slots, batch-embed, bulk-store)
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d1611572aa
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (inv.bulkIndex !== undefined && inv.bulkIndex < bulkResults.length) { | ||
| const newEntryId = bulkResults[inv.bulkIndex].id; |
There was a problem hiding this comment.
Keep supersede backfill indices aligned with bulkStore results
When any earlier queued create entry is invalid (for example the embedding-failure path queues vector || []), MemoryStore.bulkStore filters it out before assigning IDs (src/store.ts 532-535), so bulkResults is a compressed array. In that case this bulkIndex can point at the wrong persisted memory or fall past the end, leaving the old memory with a missing or incorrect superseded_by after it is invalidated. Consider filtering/validating createEntries before recording indices, or carrying an explicit placeholder-to-result mapping from bulkStore.
Useful? React with 👍 / 👎.
PR 782 Fixes Follow-upFixed Issues
P0 Fix Details
P1 Fix Details
Not Fixed (Known Limitations)
Commit: d4ab579 |
PR 782 Known LimitationsDocumented Limitations
Why These Are Acceptable
Not Blockers
These are documented here for transparency. The PR can be merged with these known limitations documented. |
… batch mode implementation - Tests for handleSupersede batch mode (bulkStore + update invalidation) - Tests for decision-degradation guard (contradict with invalid match_index → create) - Tests for rollback behavior when update fails (delete new entries from bulkStore) - Fix src/smart-extractor.ts to PR CortexReach#782 commit d161157 (1844 lines, 4 InvalidateEntry) - Register test in CI manifest (core-regression group) - Use jiti for TypeScript import in test files
Unit Test Coverage for PR #782Add unit tests for New tests:
|
| Test | Verifies |
|---|---|
batch mode: uses bulkStore for new entry and calls update to invalidate old entry |
supersede decision → bulkStore creates new + update sets superseded_by on old |
batch mode: preserves original valid_from when invalidating old entry |
Invalidated entry retains original valid_from (history preserved) |
standalone path (no existing entry): uses bulkStore (batch mode) |
Empty store → create → bulkStore (not store) |
skips contradiction when getById returns null — no entry created, no update |
contradict + match_index: 1 + empty topSimilar → degrades to create (defensive) |
bulkStore succeeds, update fails: deletes new entries (rollback) |
update throws → rollback deletes entries from bulkStore |
Key behavioral findings
1. Destructive-decision guard
When topSimilar is empty and match_index points beyond the array, hasValidIndex = false triggers decision degradation — supersede/contradict becomes create. Prevents spurious invalidations against empty result sets.
2. Decision routing by category
handleSupersede vs handleContradict determined by category ∈ TEMPORAL_VERSIONED_CATEGORIES (preferences | entities). Non-TEMPORAL_VERSIONED categories route to handleContradict.
3. Rollback behavior
When bulkStore succeeds but update fails, only new entries (from bulkStore) are deleted. stats.rolledBack is not set by production code — rollback is logged but no stat emitted.
Execution
node --test test/pr678-pr723-batch-invalidation.test.mjs
# → # tests 5, # pass 5, # fail 0CI
Registered in scripts/ci-test-manifest.mjs (core-regression group). Branch: jlinfork/test/pr-782-unit-tests.
d4ab579 to
be1ef34
Compare
PR: Issue #675 + #676 完整實現 - 延續 PR #678 與 PR #723
摘要
本 PR 完整實現了 Issue #675(regex fallback bulkStore優化)和 Issue #676(handleSupersede batch mode),並基於 PR #723 的基礎上增加了完整的 batch invalidation 支援。
與 PR #678 的關係
與 PR #723 的差異
PR #723 的限制
PR #723 實現了:
但缺少:
本 PR 填補了這些缺口。
變更內容
index.ts
AUTO_CAPTURE_DEDUP_THRESHOLD = 0.90src/smart-extractor.ts
InvalidateEntryinterfacehandleSupersede:invalidateEntries參數extractAndPersist:invalidateEntries陣列queuedSupersedeMatchIdsSet(MR2 guard)processCandidate:supersedecase 加入 MR2 guardcontradictcase 加入 MR2 guard(當作為 supersede 時)handleContradict:測試
相關測試檔案:
test/invalidate-error-regression.test.mjstest/supersede-existing-found-bulk.test.mjs預期行為
關聯 Issue: