Skip to content

fix(memory): Chinese queries lose English terms written without spaces - #159076

Merged
roboclaw-bot merged 2 commits into
openclaw:mainfrom
Yigtwxx:fix/memory-cjk-mixed-ascii-keywords
Sep 26, 2026
Merged

roboclaw-bot merged 2 commits into
openclaw:mainfrom
Yigtwxx:fix/memory-cjk-mixed-ascii-keywords

Conversation

@Yigtwxx

@Yigtwxx Yigtwxx commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Closes #159075

What Problem This Solves

Fixes: memory search misses notes when a Chinese query contains an English term without spaces (for example 用react部署方案), because the keyword fallback throws the English term away.

User Impact

User impact: English technical terms written inside Chinese text (用React部署, 部署k8s集群) are searched as their own keywords, so matching memories are found. With memory.search.store.fts.tokenizer: "trigram", keyword-only search for 用react部署方案 now returns the note that mentions React instead of nothing. Queries without Han characters, Japanese queries, and Chinese queries without ASCII produce the same keywords as before.

Why This Change Was Made

The Chinese branch of tokenize() kept only Han characters from a segment. That dropped the ASCII term and joined the Han characters on either side of it, which produced terms that exist in no document (用部署方案 in trigram mode, 用部 / 署集 bigrams in default mode). The Japanese branch right above it already splits a segment into script runs so ASCII terms like API are kept. This change gives the Chinese branch the same split and applies the existing handling to each Han run: unigrams plus bigrams in default mode, the whole run in trigram mode. Short terms that result (部署, k8s) are already served by the trigram substring path in manager-search.ts, so no search-side change is needed.

Evidence

Tested on 71ca294e239 (current main) plus this change, Node 24.21.0, Windows 11.

Memory manager against a real SQLite FTS5 index (provider: "none", ftsTokenizer: "trigram"), notes 上周我们决定用React部署前端服务 and 午饭吃了面条, query 用react部署方案 (new test in manager-keyword-retrieval.test.ts):

arm manager.search() result
main []
this branch ["memory/deploy.md"]

Extracted fallback terms (extractKeywords):

query mode main this branch
用react部署方案 trigram ["用部署方案"] ["react", "部署方案"]
用react部署k8s集群 default ["部","署","集","群","用部","部署","署集","集群"] ["react","部","署","部署","k8s","集","群","集群"]
昨日話したAPIのバグ (Japanese sibling) default ["昨日話","日話","api","バグ"] unchanged

Tests:

  • packages/memory-host-sdk/src/host/query-expansion.test.ts: 29/29 pass. With the source change reverted, the two new cases fail and the existing 27 pass.
  • manager-keyword-retrieval.test.ts -t "unspaced Chinese": passes on this branch (fails with expected [] to deeply equal [ 'memory/deploy.md' ] when the source change is reverted). Local wall time for the single test on this Windows machine was 10-87 s, most of it manager and worker startup that the rest of the file already pays; it reuses the file's persistent-manager fixture and adds no timers or processes.
  • oxfmt --check, oxlint, git diff --check, and tsgo -p tsconfig.core.json are clean.

Local note: in this Windows environment, four existing manager-keyword-retrieval.test.ts cases (active projects group, lexical-only/hybrid/strict threshold) time out in a hook after the first test of a run. They time out identically on unmodified main in the same run order, so they are an environment issue and not related to this change; CI is the authority for the full file.

Maintainer CI follow-up

The original head 13750c60903 failed CI shard checks-node-changed-compact-large-26 in the pre-existing configured-agent Gateway test: the RPC was accepted, but its command mock was not observed before vi.waitFor expired. Acceptance precedes asynchronous task persistence and run-owner binding. The test also reset its selectors before explicitly joining the accepted run.

The landing preparation replaces that polling assertion with the existing request/execution settlement helper, keeps all acceptance assertions, requires exactly one command invocation, and joins cleanup before resetting the fixture. It changes no production code or timeout. The memory patch is unchanged.

Validation and limits:

  • All 59 memory tokenizer/retrieval tests passed locally (77.17 s combined wrapper wall time; tokenizer 0.672 s, manager 73.48 s including cold worker preparation). The new real-SQLite mixed-script retrieval case took 0.962 s.
  • The corrected Gateway file passed 20/20 standalone runs (60/60 case executions), with no retries. Subsequent wrapper wall times were 15.39–58.71 s, including one cold worker preparation; the configured-agent case took 1.335–1.761 s. This existing file exercises the real WebSocket acceptance/dispatch boundary and reuses its suite-level server.
  • Independent review of the full candidate found no actionable P0–P2 findings.
  • The original CI failure was not reproduced locally. Replaying its exact synthetic merge and 93-file selection on local Node 26, both before and after the fixture correction, produced the same 22 failing cases across 15 other Gateway files (authorization, retired database/admission, and related lifecycle failures). The configured-agent test passed in both. Original CI used Node 24 and had only the one polling failure. These local replay failures remain unresolved; three clean full-shard replays were not achieved, and no passing replay is claimed as proof of the historical cause. Further identical retries were stopped.
  • Final hosted verification: CI run 36262824217 and both enforced CI-gate forms passed for corrected head 1976ede. The formerly failing packed shard passed all 93 files. The corrected Gateway file took 5.225 s of combined reported case time in CI; the configured-agent case took 2.273 s. A completed exact-head ClawSweeper review found no findings; its public-comment publication was deferred by GitHub rate limiting. Guarded native squash landing completed as cafb3a4d1ca2.

The Chinese branch of the keyword tokenizer kept only Han characters, so
an unspaced query like "用react部署方案" lost "react" and produced terms
that match no document. Split the segment into ASCII and Han runs like
the Japanese branch already does.
@clawsweeper

clawsweeper Bot commented Sep 26, 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.

@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 Sep 26, 2026
@clawsweeper

clawsweeper Bot commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 26, 2026, 1:53 PM ET / 17:53 UTC.

ClawSweeper review

What this changes

The PR changes memory keyword extraction to keep English terms embedded in Chinese text and adds tokenizer and memory-search regression tests.

Merge readiness

✅ Ready for maintainer review

Current main still drops English terms embedded in unspaced Chinese memory queries. This focused PR addresses the linked recall defect, and the reviewed patch has no actionable correctness finding.

Priority: P2
Reviewed head: 13750c609032cdb73c490b16ff024b82ded1a37d

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The narrow repair has relevant before-and-after manager-level evidence and regression coverage, with no concrete patch defect found.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The PR body records before-and-after manager.search results on Windows with a real SQLite FTS5 index and the changed trigram query path; the test fixture uses the production manager with keyword-only configuration. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body records before-and-after manager.search results on Windows with a real SQLite FTS5 index and the changed trigram query path; the test fixture uses the production manager with keyword-only configuration. No stored-data contract changes.
Evidence reviewed 7 items PR introduction: The introduced patch splits Chinese segments into ASCII and Han runs and adds two keyword cases plus a manager-level search case.
Current main behavior: Current main filters a Chinese segment down to Han characters, removing an embedded ASCII term before fallback search.
Production search path: Memory retrieval extracts fallback terms and probes them through keyword search; the trigram search path also handles short terms with substring matching.
Findings None None.
Security None None.

How this fits together

Built-in memory search indexes notes in each agent's SQLite database. Query expansion supplies fallback terms to keyword retrieval, which returns matching memories.

flowchart LR
  A[Memory query] --> B[Query expansion]
  B --> C[Keyword fallback terms]
  C --> D[SQLite memory index]
  D --> E[Matching memories]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +5, Tests +34. Total +39 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 19 14 +5
Tests 2 34 0 +34
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 53 14 +39

Review metrics

None.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #159075
Summary: This PR is the candidate fix for the linked, still-open report of the same memory recall failure.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Technical review

Best possible solution:

Keep the repair in the existing query-expansion owner and retain a regression that checks actual memory recall while preserving Japanese and Han-only behavior.

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

Yes. The contributor reports before-and-after results from manager.search against a real SQLite FTS5 index, and current-main source still shows the term-dropping path.

Is this the best way to solve the issue?

Yes. Splitting script runs at the existing query-expansion owner repairs fallback terms without adding a search implementation or configuration option.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: The PR addresses a concrete memory recall failure for mixed Chinese and English queries, with a limited search-path scope.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body records before-and-after manager.search results on Windows with a real SQLite FTS5 index and the changed trigram query path; the test fixture uses the production manager with keyword-only configuration. No stored-data contract changes.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body records before-and-after manager.search results on Windows with a real SQLite FTS5 index and the changed trigram query path; the test fixture uses the production manager with keyword-only configuration. No stored-data contract changes.

Label justifications:

  • P2: The PR addresses a concrete memory recall failure for mixed Chinese and English queries, with a limited search-path scope.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit 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 PR body records before-and-after manager.search results on Windows with a real SQLite FTS5 index and the changed trigram query path; the test fixture uses the production manager with keyword-only configuration. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body records before-and-after manager.search results on Windows with a real SQLite FTS5 index and the changed trigram query path; the test fixture uses the production manager with keyword-only configuration. No stored-data contract changes.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Tak Hoffman: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; 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.

Join the existing request and detached-execution promises instead of polling the command mock after acceptance. Keep the acceptance assertions, require one dispatch, and settle owned work before resetting the session fixture. No timeout or production behavior change.

Co-authored-by: Tak Hoffman <[email protected]>
Co-authored-by: Takhoffman <[email protected]>
@openclaw-barnacle openclaw-barnacle Bot added the gateway Gateway runtime label Sep 26, 2026
@roboclaw-bot

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@roboclaw-bot
roboclaw-bot merged commit cafb3a4 into openclaw:main Sep 26, 2026
199 of 201 checks passed
@roboclaw-bot

Copy link
Copy Markdown
Collaborator

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 27, 2026
openclaw#159076)

Preserve English technical terms embedded in unspaced Chinese memory queries by splitting ASCII and Han script runs in the existing keyword-expansion owner. Keep default Han unigrams/bigrams and trigram runs separate, without joining characters across ASCII terms.

Add tokenizer regressions for both modes and a production memory-manager regression using a real SQLite FTS5 trigram index.

Make the configured-agent Gateway test join accepted run completion before asserting dispatch and resetting its fixture, without changing production behavior or timeouts.

Closes openclaw#159075

Co-authored-by: Yigtwxx <[email protected]>
Co-authored-by: Tak Hoffman <[email protected]>
Co-authored-by: Takhoffman <[email protected]>
@Yigtwxx
Yigtwxx deleted the fix/memory-cjk-mixed-ascii-keywords branch September 30, 2026 18:51
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 gateway Gateway runtime 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: S 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.

[Bug]: Memory keyword search drops English terms written inside Chinese text without spaces

2 participants