Skip to content

fix(memory): diversify canonically equivalent CJK snippets - #164660

Merged
obviyus merged 3 commits into
openclaw:mainfrom
ly85206559:codex/fix-memory-cjk-nfc-20261003
Oct 4, 2026
Merged

obviyus merged 3 commits into
openclaw:mainfrom
ly85206559:codex/fix-memory-cjk-nfc-20261003

Conversation

@ly85206559

@ly85206559 ly85206559 commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Memory search can return duplicate Korean or Japanese snippets ahead of a distinct relevant result when the same characters use different Unicode normalization forms.

User Impact

Canonically equivalent Hangul and kana snippets now receive the same MMR similarity tokens. With a two-result limit, the distinct relevant memory is no longer crowded out by an NFC/NFD duplicate. Snippet bytes and relevance scores are unchanged.

The shared similarity tokenizer also serves Dreaming recall deduplication and diary coverage matching. Canonically equivalent snippets now count as the same there too. Normalization is in-memory: it does not delete or rewrite existing source memory content, stored chunks, embeddings, or FTS tokens. Future derived Dreaming candidate/coverage decisions can differ because equivalent snippets match. No reindex or migration is needed.

Why This Change Was Made

Normalize once before both the word-token and adjacent-CJK lanes. Preserve the mixed-script tokenization from #164062. The contributor's commits are retained, with current main merged for the shared-tokenizer base change.

Thanks to @ly85206559 for the fix and regression cases. No overlap with Pash/Sarah changes.

Evidence

Baseline: e28f1c00d89dacafa4794bd8773d994a0100437c. Candidate: 03e9db176ff54fd28a43336c528bf9f63d6803d6.

  • Built, isolated Gateway with memory-core, real file indexing and SQLite retrieval, a local deterministic embedding endpoint, and scripted model memory_search calls with maxResults: 2:
    • Hangul baseline: 각, 각; candidate: 각, 나.
    • Kana baseline: が, が; candidate: が, な.
    • Mixed-script Cyrillic control keeps both server Москва резервная копия and server Берлин погода сегодня on both versions.
    • English control returns the same snippets, ordering, and component/relevance scores on both versions.
  • Disabled-MMR adapter control preserves original ordering on both versions. Current main always enables runtime MMR, so this is explicitly an adapter-level control, not a configurable Gateway MMR-off claim.
  • Dreaming's production previewRemDreaming recall-deduplication path: the NFC/NFD pair contributes two candidates on baseline and one on candidate; unrelated 나 remains. Input recall records are unchanged.
  • Focused MMR regression: baseline fails exactly the two added Hangul/kana cases (21 pass, 2 fail); candidate passes all 23 cases. Candidate Vitest duration 1.78s; baseline 2.90s. This extends the existing result matrix rather than adding suite setup.
  • git diff --check passes. Contributor code, installs, builds, tests, and Gateway executions ran only in task-owned Docker isolation.

Gateway fixture setup corrections were limited to disabling lazy tool discovery for direct scripted calls and lowering the weak Cyrillic distractor's embedding relevance; the same final fixture and scores were used for baseline and candidate. This proves the normal Gateway/model-tool/index/search path, not a live embeddings-provider API.

Live gate on the candidate: one real gpt-5-mini request through a passive proxy, reasoning low, output budget 4096, HTTP 200, and the expected final Gateway response. Memory-core was enabled with stub embeddings; no live embedding-provider claim. Task credentials were removed and the proxy stopped.

@clawsweeper

clawsweeper Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@ly85206559
ly85206559 marked this pull request as ready for review October 4, 2026 01:19
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 4, 2026
@clawsweeper

clawsweeper Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 4, 2026, 7:27 AM ET / 11:27 UTC (Revision 2).

ClawSweeper review

What this changes

Normalize memory similarity text before word and CJK tokenization so equivalent Korean and Japanese snippets no longer crowd out distinct search results.

Merge readiness

✅ Ready for maintainer review

This PR remains useful: current main and the latest release still distinguish canonically equivalent CJK snippets. The pinned patch has no actionable correctness findings, and the recorded Gateway and Dreaming before/after evidence sufficiently demonstrates the repair.

Priority: P2
Reviewed head: 03e9db176ff54fd28a43336c528bf9f63d6803d6

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with meaningful ranking regressions and convincing recorded production-path proof.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The captured exact-head evidence exercises the changed tokenizer through real Gateway memory_search with file indexing and SQLite retrieval, showing distinct Hangul and kana results replacing normalization-form duplicates. Dreaming preview and English/mixed-script controls support the shared-owner behavior. Local deterministic embeddings are appropriate for this ranking repair; no stored-data contract changes or migration are introduced.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured exact-head evidence exercises the changed tokenizer through real Gateway memory_search with file indexing and SQLite retrieval, showing distinct Hangul and kana results replacing normalization-form duplicates. Dreaming preview and English/mixed-script controls support the shared-owner behavior. Local deterministic embeddings are appropriate for this ranking repair; no stored-data contract changes or migration are introduced.
Evidence reviewed 9 items Pinned introduced change: The verified merge-base-to-head delta moves NFC normalization before both tokenizer lanes and adds two cases to the existing MMR ranking matrix. No indexing, storage, configuration, dependency, or public API changes are introduced.
Current main still needs the repair: Fetched main normalizes only the word lane after removing CJK runs; CJK bigrams and unigrams still consume unnormalized text. The proposed normalization therefore addresses behavior absent from current main.
Latest release comparison: The v2026.9.8 tokenizer also passes unnormalized text to the CJK lane. Its source was inspected through GitHub after the local release blob could not be retrieved.
Findings None None.
Security None None.

How this fits together

Memory Core retrieves saved notes and orders results using relevance and snippet similarity. Its shared similarity tokenizer also helps Dreaming deduplicate recalled memories and identify diary coverage.

flowchart TD
 A[Retrieved memory snippets] --> C[Shared similarity tokenizer]
 B[Dreaming recall and diary text] --> C
 C --> D[NFC normalization]
 D --> E[Word and CJK tokens]
 E --> F[Diversity ranking]
 E --> G[Recall deduplication and diary matching]
 F --> H[Bounded search results]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -4, Tests +20. Total +16 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 2 6 -4
Tests 1 20 0 +20
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 22 6 +16

Review metrics

None.

Technical review

Best possible solution:

Keep canonical-equivalence handling in the shared in-memory similarity tokenizer while preserving stored memory bytes and existing ranking contracts.

Do we have a high-confidence way to reproduce the issue?

Yes: current-main source and the two ranking fixtures establish the normalization mismatch, and the captured baseline Gateway runs demonstrate duplicate snippets displacing distinct results. This read-only review did not execute the reproduction.

Is this the best way to solve the issue?

Yes: moving the existing normalization ahead of both tokenizer lanes repairs the shared owner without adding another implementation or changing stored data.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against e318434756f9.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This repairs a bounded memory-ranking defect affecting canonically equivalent Korean and Japanese snippets.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured exact-head evidence exercises the changed tokenizer through real Gateway memory_search with file indexing and SQLite retrieval, showing distinct Hangul and kana results replacing normalization-form duplicates. Dreaming preview and English/mixed-script controls support the shared-owner behavior. Local deterministic embeddings are appropriate for this ranking repair; no stored-data contract changes or migration are introduced.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured exact-head evidence exercises the changed tokenizer through real Gateway memory_search with file indexing and SQLite retrieval, showing distinct Hangul and kana results replacing normalization-form duplicates. Dreaming preview and English/mixed-script controls support the shared-owner behavior. Local deterministic embeddings are appropriate for this ranking repair; no stored-data contract changes or migration are introduced.

Evidence

What I checked:

  • Pinned introduced change: The verified merge-base-to-head delta moves NFC normalization before both tokenizer lanes and adds two cases to the existing MMR ranking matrix. No indexing, storage, configuration, dependency, or public API changes are introduced. (extensions/memory-core/src/memory/tokenize.ts:8, 03e9db176ff5)
  • Current main still needs the repair: Fetched main normalizes only the word lane after removing CJK runs; CJK bigrams and unigrams still consume unnormalized text. The proposed normalization therefore addresses behavior absent from current main. (extensions/memory-core/src/memory/tokenize.ts:8, e318434756f9)
  • Latest release comparison: The v2026.9.8 tokenizer also passes unnormalized text to the CJK lane. Its source was inspected through GitHub after the local release blob could not be retrieved. (extensions/memory-core/src/memory/tokenize.ts:7, fc23bc864e45)
  • Existing search contract: The documented MMR pass reduces redundant snippets without changing scores or threshold eligibility. Production search calls the hybrid merger and then bounds the ordered results; the patch preserves those owners and their contracts. Public docs: docs/concepts/memory-search.md. (docs/concepts/memory-search.md:106, 03e9db176ff5)
  • Shared Dreaming behavior and storage boundary: Dreaming imports the same similarity helper for recall deduplication and diary matching. Deduplication builds derived copies and retains source entry keys; the introduced patch changes similarity preparation rather than stored snippets, embeddings, FTS tokens, or schemas. No existing-state migration is required. (extensions/memory-core/src/dreaming-phases.ts:988, 03e9db176ff5)
  • After-fix production behavior proof: The captured PR body identifies baseline e28f1c0 and candidate 03e9db1. An isolated built Gateway exercised real file indexing, SQLite retrieval, and model memory_search calls with two-result limits: Hangul changed from 각/각 to 각/나, and kana from が/が to が/な. English and mixed-script controls remained stable. Production Dreaming preview collapsed the equivalent pair from two candidates to one while retaining unrelated 나 and unchanged input records. Deterministic local embeddings limit the claim to retrieval and ranking, which is the changed behavior. (03e9db176ff5)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-04T01:25:18.512Z sha 3e7fa45 :: needs maintainer review before merge. :: none

@obviyus

obviyus commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

Please review exact head 03e9db1. Current main including #164062 is merged. The PR body records real Gateway memory_search before/after proof, mixed-script and English controls, disabled-MMR adapter control, shared Dreaming recall-dedupe proof, and the exact-head live gate. Normalization changes only shared in-memory similarity, not stored index/FTS tokenization; no reindex is required.

@clawsweeper

clawsweeper Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@obviyus
obviyus merged commit 214bb47 into openclaw:main Oct 4, 2026
101 of 104 checks passed
@obviyus

obviyus commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator

Landed as 214bb47. Thanks @ly85206559!

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 5, 2026
…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]>
@ly85206559
ly85206559 deleted the codex/fix-memory-cjk-nfc-20261003 branch October 5, 2026 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: memory-core Extension: memory-core P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants