Skip to content

fix: quote OpenClaw FTS query terms#2043

Draft
RerankerGuo wants to merge 1 commit into
MemTensor:mainfrom
RerankerGuo:fix/quote-openclaw-fts-query-terms
Draft

fix: quote OpenClaw FTS query terms#2043
RerankerGuo wants to merge 1 commit into
MemTensor:mainfrom
RerankerGuo:fix/quote-openclaw-fts-query-terms

Conversation

@RerankerGuo

Copy link
Copy Markdown

Description

Related Issue (Required): Fixes #1247

Quotes each sanitized OpenClaw FTS token before sending it to SQLite FTS5 MATCH.

The reported query shape includes message-id tokens such as message_id and om_x... mixed with CJK text. Previously those terms were passed as bare MATCH tokens after punctuation stripping. This change keeps the existing sanitization and reserved-word filtering, then wraps every remaining token as an FTS5 phrase and escapes internal quotes. That makes the generated MATCH expression safer for ids, underscores, and mixed-language text while preserving the implicit AND behavior.

A regression case was added for the reported message_id om_x... 我要测试 query shape.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Unit Test
  • Test Script Or Test Steps (please provide)
  • Pipeline Automated API Test (please provide)

Commands run:

node - <<'NODE'
const fs = require('fs');
const source = fs.readFileSync('apps/memos-local-openclaw/src/storage/sqlite.ts', 'utf8');
const test = fs.readFileSync('apps/memos-local-openclaw/tests/storage.test.ts', 'utf8');
if (!source.includes('return tokens.map((t) => `"${t.replace(/"/g, \'""\')}"`).join(" ");')) {
  throw new Error('quoted FTS sanitizer not found');
}
if (!test.includes('message_id om_x100b544a390604b8c3e1b7d8641f08e 我要测试')) {
  throw new Error('message_id CJK regression test fixture not found');
}
console.log('static FTS sanitizer regression passed');
NODE

Result: static FTS sanitizer regression passed.

Also attempted:

cd apps/memos-local-openclaw
npm test -- --run tests/storage.test.ts
npm run build

Both are blocked in this local environment because vitest and tsc are not installed.

Checklist

  • I have performed a self-review of my own code | 我已自行检查了自己的代码
  • I have commented my code in hard-to-understand areas | 我已在难以理解的地方对代码进行了注释
  • I have added tests that prove my fix is effective or that my feature works | 我已添加测试以证明我的修复有效或功能正常
  • I have created related documentation issue/PR in MemOS-Docs (if applicable) | 我已在 MemOS-Docs 中创建了相关的文档 issue/PR(如果适用)
  • I have linked the issue to this PR (if applicable) | 我已将 issue 链接到此 PR(如果适用)
  • I have mentioned the person who will review this PR | 我已提及将审查此 PR 的人

@Memtensor-AI Memtensor-AI changed the base branch from main to dev-v2.0.22 July 2, 2026 10:57
@Memtensor-AI

Copy link
Copy Markdown
Collaborator

Automated Test Results: QUEUED

This PR was retargeted to dev-v2.0.22; cloud test-engine rerun has been queued.

  • Run: tr-9bbe4d82-a61 on cloud test-engine 10011
  • Branch tested: refs/pull/2043/head

I will post the final pass/fail result when the run completes.

@Memtensor-AI

Copy link
Copy Markdown
Collaborator

Automated Test Results: PASSED

Cloud test-engine rerun against dev-v2.0.22 completed successfully.

  • Run: tr-9bbe4d82-a61 on cloud test-engine 10011
  • memos_local_openclaw/unit: 26 passed, 0 failed, 0 skipped

Manual code review is still required before merge.

@CarltonXiang CarltonXiang deleted the branch MemTensor:main July 3, 2026 07:25
@syzsunshine219 syzsunshine219 reopened this Jul 3, 2026
@syzsunshine219 syzsunshine219 added the needs-audit Requires manual audit before merge label Jul 3, 2026
@syzsunshine219 syzsunshine219 changed the base branch from dev-v2.0.22 to main July 3, 2026 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-audit Requires manual audit before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: FTS query failed

4 participants