Skip to content

Fix #2255: memos_search returns Chinese text as \uXXXX unicode escapes (Hermes adapter miss - #2256

Open
Memtensor-AI wants to merge 2 commits into
MemTensor:dev-v2.0.30from
Memtensor-AI:bugfix/autodev-2255-20260816025022257
Open

Fix #2255: memos_search returns Chinese text as \uXXXX unicode escapes (Hermes adapter miss#2256
Memtensor-AI wants to merge 2 commits into
MemTensor:dev-v2.0.30from
Memtensor-AI:bugfix/autodev-2255-20260816025022257

Conversation

@Memtensor-AI

Copy link
Copy Markdown
Collaborator

Description

Fixed #2255: Chinese memory content returned by the Hermes adapter's memos_* tools was being serialized to the host LLM as \uXXXX escapes because every json.dumps(...) inside MemTensorProvider.handle_tool_call (apps/memos-local-plugin/adapters/hermes/memos_provider/init.py) relied on Python's default ensure_ascii=True. Data in the DB was always correct; only the on-wire JSON was mangled, inflating tokens and making retrieval unreadable for Chinese users.

Added ensure_ascii=False to every json.dumps call inside handle_tool_call — both the tool-result branches called out in the issue (memos_search, memos_get trace/policy/world_model, memos_timeline, memos_skill_list, memos_environment list+query, memos_skill_get) and the error / fallthrough branches. The uniform pattern matches the three json.dumps calls elsewhere in the same file (L742/1015/1021) that already set the flag.

Added HandleToolCallEnsureAsciiTests to apps/memos-local-plugin/tests/python/test_hermes_provider_pipeline.py — 8 regression cases that assert each affected tool returns raw Chinese characters, contains no \u escape marker, and round-trips through json.loads. Confirmed the tests fail without the fix and pass with it. Full test file test_hermes_provider_pipeline.py is 35/35 green (27 pre-existing + 8 new); ruff check and ruff format --check both clean on the touched files.

Categorized as an opsp Bug quick-fix (no proposal/spec/design), one-line change per return statement. Committed on bugfix/autodev-2255-20260816025022257 and pushed to origin. Reviewers: @whipser030, @hijzy.

Related Issue (Required): Fixes #2255

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (does not change functionality, e.g. code style improvements, linting)
  • Documentation update

How Has This Been Tested?

Automated tests are pending.

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

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)
  • I have linked the issue to this PR (if applicable)
  • I have mentioned the person who will review this PR

@whipser030, @hijzy please review this PR.

Reviewer Checklist

….dumps (MemTensor#2255)

memos_search / memos_get / memos_timeline / memos_skill_list /
memos_environment / memos_skill_get in the Hermes memory provider
serialized their tool results back to the host LLM with the default
ensure_ascii=True, which escaped every non-ASCII code point (notably
Chinese memory content) to \uXXXX. The DB stored the correct UTF-8;
only the wire JSON was mangled. This inflated tokens for Chinese users
and made retrieval results unreadable when debugging.

Add ensure_ascii=False to every json.dumps inside handle_tool_call
(both the tool-result branches called out in the issue and the
error/fallthrough branches, for a uniform pattern that matches the
other json.dumps calls in this file at L742/1015/1021 that already
pass the flag).

Add HandleToolCallEnsureAsciiTests to
apps/memos-local-plugin/tests/python/test_hermes_provider_pipeline.py
with 8 regression cases (one per affected tool + both branches of
memos_environment) that assert the returned JSON contains raw Chinese
characters, contains no "\u" escape marker, and round-trips through
json.loads. Verified the tests fail without the fix and pass with it;
ruff check + ruff format clean; full test file 35/35 green.

Fixes MemTensor#2255
@Memtensor-AI Memtensor-AI added ai:generated Generated or modified by AI | 由 AI 生成或修改 area:plugin OpenClaw & Hermes status:in-progress Someone or AI is working on it | 人工或 AI 正在处理 labels Aug 16, 2026
@Memtensor-AI

Memtensor-AI commented Aug 16, 2026

Copy link
Copy Markdown
Collaborator Author

🤖 Open Code Review

Target: PR #2256
Task: 48b062ae885009c2
Base: dev-v2.0.30
Head: bugfix/autodev-2255-20260816025022257
Head SHA: 492bc8448c99fd0d444d8f2540a3b682a6454502

OpenCodeReview: No comments generated. Looks good to me.

Generated by cloud-assistant via Open Code Review.

@Memtensor-AI

Copy link
Copy Markdown
Collaborator Author

🔧 Open Code Review requested Agent fix

Open Code Review found 2 issue(s). I have resumed the development Agent to fix them.

  • Task: 48b062ae885009c2
  • Fix attempt: 1/2
  • Finding delta: 0 repeated / 2 new / 0 likely resolved

The Agent will push a new commit to this PR branch. OCR will recheck after the commit is pushed.

Address PR MemTensor#2256 OCR review findings:

1. Add `test_memos_get_world_model_returns_utf8_chinese` to cover the
   `world_model` branch of `memos_get` (routed via `memory.get_world`).
   Without this test, an accidental removal of `ensure_ascii=False` from
   the world_model branch would go undetected — the previous tests only
   exercised the `trace` and `policy` kinds.

2. Remove the fragile `assertNotIn("\\u", raw)` guard from all
   HandleToolCallEnsureAsciiTests cases. That check was prone to false
   positives (any legitimate value containing a backslash followed by
   `u`, e.g. a Windows path, would fail the test) while providing weaker
   coverage than the `assertIn(_CH_..., raw)` + `json.loads` field
   equality assertions already present. Add a header comment explaining
   why the literal-in-raw check is the robust regression guard.

Also add a parsed field-equality assertion to
`test_memos_skill_list_returns_utf8_chinese` for parity with the other
cases.

All 36 tests in tests/python/test_hermes_provider_pipeline.py pass.
@Memtensor-AI

Copy link
Copy Markdown
Collaborator Author

✅ Automated Test Results: PASSED

All tests passed (35/35 executed). memos_local_plugin/changed-repo-python: 35/35. Duration: 4s [advisory, non-gating] AI-generated tests on branch test/auto-gen-48b062ae885009c2-20260816111233: 194/196 passed, 2 failed — these do NOT affect the PR verdict; review the branch manually.

Branch: bugfix/autodev-2255-20260816025022257

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

Labels

ai:generated Generated or modified by AI | 由 AI 生成或修改 area:plugin OpenClaw & Hermes status:in-progress Someone or AI is working on it | 人工或 AI 正在处理

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants