Fix #2255: memos_search returns Chinese text as \uXXXX unicode escapes (Hermes adapter miss - #2256
Conversation
….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
🤖 Open Code ReviewTarget: PR #2256 ✅ OpenCodeReview: No comments generated. Looks good to me. Generated by cloud-assistant via Open Code Review. |
🔧 Open Code Review requested Agent fixOpen Code Review found 2 issue(s). I have resumed the development Agent to fix them.
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.
✅ Automated Test Results: PASSEDAll 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: |
Description
Fixed #2255: Chinese memory content returned by the Hermes adapter's memos_* tools was being serialized to the host LLM as
\uXXXXescapes because everyjson.dumps(...)insideMemTensorProvider.handle_tool_call(apps/memos-local-plugin/adapters/hermes/memos_provider/init.py) relied on Python's defaultensure_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=Falseto everyjson.dumpscall insidehandle_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 threejson.dumpscalls elsewhere in the same file (L742/1015/1021) that already set the flag.Added
HandleToolCallEnsureAsciiTeststoapps/memos-local-plugin/tests/python/test_hermes_provider_pipeline.py— 8 regression cases that assert each affected tool returns raw Chinese characters, contains no\uescape marker, and round-trips throughjson.loads. Confirmed the tests fail without the fix and pass with it. Full test filetest_hermes_provider_pipeline.pyis 35/35 green (27 pre-existing + 8 new);ruff checkandruff format --checkboth 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.
How Has This Been Tested?
Automated tests are pending.
Checklist
@whipser030, @hijzy please review this PR.
Reviewer Checklist