Repository navigation
fix(memory): keep distinct mixed-script memories in search results - #164062
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed October 3, 2026, 3:24 AM ET / 07:24 UTC (Revision 3). ClawSweeper reviewWhat this changesMemory Core’s shared similarity tokenizer retains Unicode words and combining marks so distinct mixed-script notes survive search ranking and Dreaming selection. Merge readiness✅ Ready for maintainer review This PR remains useful: current main and the latest release still exhibit the reported limitation. The prior test-cost follow-up is resolved, real behavior proof is sufficient, and no actionable patch defect remains. Priority: P2 Review scores
Verification
How this fits togetherMemory Core compares retrieved and recalled note snippets to reduce duplicate results. Its shared similarity tokenizer feeds both memory-search diversity ranking and Dreaming’s candidate selection. flowchart TD
A[Retrieved note snippets] --> C[Shared similarity tokenizer]
B[Recalled note snippets] --> C
C --> D[Unicode words and CJK tokens]
D --> E[Search diversity ranking]
D --> F[Dreaming duplicate comparison]
E --> G[Bounded search results]
F --> H[Distinct memory candidates]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +6, Tests +23. Total +29 across 2 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Technical reviewBest possible solution: Keep Unicode overlap handling in the shared tokenizer while preserving CJK token order, ranking policy, and stored note bytes. Do we have a high-confidence way to reproduce the issue? Yes: current-main source reduces both reported Russian snippets to the shared token server, and captured before/after Gateway and REM receipts demonstrate the resulting selection error. This read-only review did not execute target code. Is this the best way to solve the issue? Yes: repairing the existing shared tokenizer addresses both consumers without duplicating ranking logic or changing persisted data, configuration, or thresholds. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against fea63b009bef. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Landed as 4ec53d9. Thanks @harshitgupta31415! |
…penclaw#164062) Fixes openclaw#164053. The memory diversity tokenizer kept only ASCII and CJK text, so mixed-script notes that share one English term reduced to the same tokens and were ranked as duplicates. A relevant note could then drop out of a bounded hybrid search, and Dreaming collapsed distinct snippets. Other scripts are now tokenized too. Only the in-memory MMR/diversity tokenization changes; nothing persisted changes and no reindex is needed. Proof: on a real isolated Gateway with local stub embeddings, `memory_search` on main dropped the second of two unrelated Cyrillic notes that share "server", and this change returns both. English and CJK result paths, scores and snippets are unchanged, and true duplicates are still collapsed. The regression tests fail on base and pass here. In a live gpt-5-mini turn, `memory_search` returned both notes. Co-authored-by: Ayaan Zaidi <[email protected]>
With MMR, memory search treated canonically equivalent Korean or Japanese snippets in different Unicode normalization forms (NFC vs NFD) as distinct, so duplicates crowded out a distinct relevant result. The shared memory tokenizer now normalizes to NFC, so equivalent text tokenizes the same way. This composes with the mixed-script tokenization from #164062. In Dreaming, the same tokenizer drives recall dedupe and diary coverage, so equivalent snippets now count as one candidate. Existing memory content is never deleted or rewritten, stored index and FTS tokenization are unchanged, and no reindex is needed. Proof: in a real built Gateway, `memory_search` returned NFC/NFD duplicate pairs for Hangul and kana on base, and the primary snippet plus the distinct one with this change. The Cyrillic mixed-script case and English ordering and scores are unchanged. The Dreaming recall preview collapses the equivalent pair to one candidate and keeps an unrelated snippet. The regression tests fail on base and pass here. A live gpt-5-mini smoke call passed. Co-authored-by: Ayaan Zaidi <[email protected]>
…164660) With MMR, memory search treated canonically equivalent Korean or Japanese snippets in different Unicode normalization forms (NFC vs NFD) as distinct, so duplicates crowded out a distinct relevant result. The shared memory tokenizer now normalizes to NFC, so equivalent text tokenizes the same way. This composes with the mixed-script tokenization from openclaw#164062. In Dreaming, the same tokenizer drives recall dedupe and diary coverage, so equivalent snippets now count as one candidate. Existing memory content is never deleted or rewritten, stored index and FTS tokenization are unchanged, and no reindex is needed. Proof: in a real built Gateway, `memory_search` returned NFC/NFD duplicate pairs for Hangul and kana on base, and the primary snippet plus the distinct one with this change. The Cyrillic mixed-script case and English ordering and scores are unchanged. The Dreaming recall preview collapses the equivalent pair to one candidate and keeps an unrelated snippet. The regression tests fail on base and pass here. A live gpt-5-mini smoke call passed. Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
Fixes distinct mixed-script memories being ranked as duplicates when they share an English term. For example,
server Москва резервная копияandserver Берлин погода сегодняboth became the single tokenserver, suppressing the second note in search and REM previews.Fixes #164053.
User Impact
Memory search and Dreaming retain distinct Cyrillic, Arabic, and Indic notes while continuing to remove actual duplicates. Existing ASCII and CJK tokenization is preserved. No configuration, dependency, schema, migration, or public API changes are needed.
Why This Change Was Made
Both consumers use the same similarity tokenizer, so the repair belongs there. The word lane now retains Unicode letters, numbers, and attached combining marks, with NFC normalization. CJK stays in its existing adjacent-bigram/unigram lane, using the original text and insertion order. Ranking weights and Dreaming thresholds are unchanged.
Production delta: +6 lines; tests: +23 lines. The extra word-lane preparation preserves the existing CJK contract while retaining previously discarded words. A direct Unicode substitution for the ASCII expression would also capture CJK whole words and change that contract.
Thanks to @jarimustonen for the earlier Unicode work in #38945. That proposal closed without merging; #150968 covers keyword queries and explicitly excludes MMR. The live upstream tokenizer was still unchanged immediately before publication, and no competing implementation was found.
Evidence
Base:
be8190f2f8c4f63eb2a3831a32dfd3e127573fe7.Head:
f512c7cc7aeb0223e1f38469b038ca89707fc580.mmr.test.ts,hybrid.test.ts,hybrid.project-ranking.test.ts,temporal-decay.test.ts, anddreaming-phases.test.ts(node scripts/run-vitest.mjs extensions/memory-core/src/memory/mmr.test.ts extensions/memory-core/src/memory/hybrid.test.ts extensions/memory-core/src/memory/hybrid.project-ranking.test.ts extensions/memory-core/src/memory/temporal-decay.test.ts extensions/memory-core/src/dreaming-phases.test.ts --maxWorkers=1). Coverage includes mixed Cyrillic/Arabic/Hindi ranking, accents and combining marks, Thai, CJK adjacency/order, punctuation-only negatives, disabled MMR, true duplicates, relevance, ties, project precedence, decay, and Dreaming policies.node scripts/run-tsgo.mjs -p tsconfig.extensions.json --incremental. The focused changed-test graph also passed, extending the repository's strict extension-test config and retaining its ambient declarations.git diff --checkpassed. The complete two-file diff was manually reviewed; independent review remains pending.Runtime proof at the exact head, with no mocks:
{"head":"f512c7cc7aeb0223e1f38469b038ca89707fc580","similarity":0.14285714285714285,"selectedPaths":["memory/primary.md","memory/distinct.md"],"distinctRemCandidates":2,"trueDuplicateCount":1,"disabledOrderPreserved":true,"pass":true} {"head":"f512c7cc7aeb0223e1f38469b038ca89707fc580","flow":"real note -> recordShortTermRecalls -> SQLite -> previewRemHarness","storedEntries":2,"recallCountPerEntry":6,"recallEntryCount":2,"distinctRemCandidates":2,"pass":true}On the clean base, the persisted flow stored both entries with six recalls each but returned only one REM candidate, then failed the assertion (exit 1). At the exact head it returned both (exit 0).
The first receipt calls the real hybrid merge/selection and REM selection owners. The second writes real notes, records recalls through the real plugin state store, then calls the operator preview implementation against a fresh temporary state directory. Both processes closed successfully with exit 0.
Reproduce the ranking and persisted-preview receipts
Save each script outside the checkout and run it from the repository root with
node --import ./scripts/tsx.mjs /absolute/path/to/script.mjs. The assertions fail on the base and pass on the head. The persisted script requires current runtime database-worker artifacts, creates its own temporary fixture, and never uses the operator's state directory.Ranking/REM owner:
SQLite-backed operator preview:
The repository-wide changed-file gate did not pass: conflict-marker, line-cap, max-lines, and assertion-SAFETY checks passed, then the SQLite inventory reported
1333 -> 2077T1 calls. Runningnode --import ./scripts/tsx.mjs scripts/check-database-worker-ratchet.mts --base be8190f2f8c4f63eb2a3831a32dfd3e127573fe7on the clean, detached basebe8190f2f8c4f63eb2a3831a32dfd3e127573fe7reproduced the same failure, with no local changes. Neither changed file adds SQLite access. The combined gate stopped there, so later combined-gate stages are not claimed as executed; the independent test/type/lint/format results above are the checks that completed.The 94-test run and type/lint checks used the identical source bytes subsequently committed at the head above. Runtime receipts were rerun at that exact head. These exercise the changed ranking owner and a real isolated SQLite-backed operator preview; they do not claim a live model, embedding service, or full Gateway session was run. The full extension-test typegraph was not run locally.
Maintainer verification (exact head)
Verified
f512c7cc7aeb0223e1f38469b038ca89707fc580against current maind6b1cc8d1f7264bb7656da788204dbe874ce5047in isolated Node 24.21.0 Docker containers. The contributor's code is unchanged. Thanks to @harshitgupta31415 for the report and fix.Real Gateway path: built each runtime, seeded 15 Markdown notes (Cyrillic, English, CJK; distinct notes, distractors, and exact duplicates), indexed through
openclaw --profile <isolated-profile> memory index --force --agent main, and started an isolated Gateway with memory-core. A scripted chat-completions model issued threememory_searchtool calls withmaxResults: 2andminScore: 0.01. A local deterministic embeddings server supplied vectors; no paid embeddings were used. Normal builtin hybrid/MMR ranking remained enabled. State/config/index paths were printed by the actual CLI and confined to task-owned container directories.Observed tool results (citation suffixes omitted):
server Москва резервная копия;database connection poolserver Москва резервная копия;server Берлин погода сегодняserver Moscow backup archive;server Berlin weather todayserver 東京備份資料;server 北京天氣預報Every group contained an exact copy of its primary note. Neither runtime allowed the copy to consume the second result slot. The Cyrillic primary scored
0.7, the distinct note0.6860000133514403, and the weaker distractor0.630000004172325; only current main demoted the distinct note out of the bounded results. The candidate's first harness assertion incorrectly assumed underscores survived tool-call ID normalization and that snippets lacked citation suffixes; the saved original Gateway output passed corrected offline assertions without rerunning the Gateway.Regression:
pnpm test extensions/memory-core/src/memory/mmr.test.ts --maxWorkers=1passed all 21 tests on the exact head: 2.73 seconds wall time, 1.34 seconds Vitest duration. Running the same candidate regression file against unchanged current-main production source produced 9 failures / 12 passes (2.92 seconds wall time), including all three mixed-script ranking cases: actual primary → weak → distinct versus expected primary → distinct → weak.Available CI seconds: the exact-head changed-extension job passed in 115 seconds elapsed, including 56 seconds for its Node test shard. Those are shared job/shard measurements, not an isolated per-file CI charge. The CI gate passed. No jobs were rerun.
Live gate: the exact built candidate completed a real Gateway turn with
gpt-5-mini, reasoninglow, and a 4096-token output budget. A passive proxy forwarded two requests unchanged; both returned HTTP 200. The model calledmemory_searchonce and quoted both Cyrillic snippets in its final reply. Embeddings remained local; heartbeat, cron, autonomous workshop, compaction memory flush and utility-model jobs were disabled. The task-only API-key file and live container were removed immediately afterward.Storage boundary: only ephemeral snippet similarity tokens change. The consumers are MMR ranking and Dreaming snippet comparison. Stored Markdown, embeddings, FTS/index tokenization, index identity and schema are unchanged; no reindex or migration is needed.
No overlap with Pash/Sarah changes.