Skip to content

fix(memory): normalize OpenClaw content blocks + BM25 OR fallback + audit_log sanitization#1407

Open
zhangtaibo wants to merge 1 commit into
alibaba:mainfrom
zhangtaibo:fix/agent-memory-content-normalization
Open

fix(memory): normalize OpenClaw content blocks + BM25 OR fallback + audit_log sanitization#1407
zhangtaibo wants to merge 1 commit into
alibaba:mainfrom
zhangtaibo:fix/agent-memory-content-normalization

Conversation

@zhangtaibo

Copy link
Copy Markdown
Contributor

Fix: agent-memory auto-capture trigger + BM25 OR fallback + audit_log sanitization

Fixes #1405

Problem

Three issues in agent-memory:

  1. OpenClaw adapter auto-capture (openclaw/src/index.ts): agent_end hook used lastAsst.content directly as a string, but OpenClaw sends content as an array of content blocks [{type:"text", text:"..."}]. This caused re.test(lastAsst.content) to coerce the array to "[object Object]", so no trigger regex ever matched and auto-capture never fired.

  2. BM25 FTS5 AND-only query (src/index/store.rs): When any single query term is absent from the corpus, the implicit-AND FTS5 MATCH returns 0 results. Natural-language prompts routinely contain common words not in any memory file, causing every AND query to fail silently.

  3. audit_log query leakage (src/tools/memory_search.rs): format!("{:.120}", query) wrote the first 120 chars of user queries into the audit log path field, potentially leaking sensitive information.

Fix

  1. Normalize lastAsst.content from content-block array to string before trigger matching and hashing.
  2. Add OR-joined fallback: when AND returns 0 rows and there are multiple tokens, retry with '"token1" OR "token2" OR ...' so partial matches still surface.
  3. Replace format!("{:.120}", query) with format!("bm25:len={}", query.len()) across all audit_log calls.

Verification

  • Fresh clone + git apply patch + bash scripts/rpm-build.sh agent-memory → exit 0
  • RPM: agent-memory-0.2.1-1.alnx4.x86_64.rpm (5.0M)
  • Tests: test_auto_capture_persists_trigger_phrase, test_auto_recall_injects_without_tool_call, test_memory_get_reads_seeded_file (to be verified on ECS with installed RPM)

Test Cases

  • tests/test_openclaw_e2e.py::TestAutoCapture::test_auto_capture_persists_trigger_phrase
  • tests/test_openclaw_e2e.py::TestAutoRecall::test_auto_recall_injects_without_tool_call
  • tests/test_openclaw_e2e.py::TestMemoryGet::test_memory_get_reads_seeded_file

@zhangtaibo zhangtaibo requested a review from shiloong as a code owner July 8, 2026 21:59
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


云孟 seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[nightly][agent-memory] auto-capture trigger 正则失效 + BM5 AND 查询无 OR fallback + audit_log 泄露查询文本

2 participants