Skip to content

split_continuous_references leaves references merged when comma styles are mixed #2417

Description

@simpleqt

Bug Description

split_continuous_references in src/memos/mem_os/utils/reference_utils.py splits a combined reference tag [1:aaa, 4:bbb] into [1:aaa][4:bbb] via two sequential str.replace passes: one for ", " and one for ",". The first pass that matches rewrites the content substring, so the second pass can no longer find the original content. When an LLM emits mixed separator styles in one tag, only the last boundary is split:

split_continuous_references("[1:92ff35fb,4:bfe6f044, 7:abcd1234]")
# actual:   '[1:92ff35fb,4:bfe6f044][7:abcd1234]'
# expected: '[1:92ff35fb][4:bfe6f044][7:abcd1234]'

The function is on the streaming chat path (api/handlers/chat_handler.py → process_streaming_references_complete), so the merged references are rendered as literal text instead of individual reference tags.

Expected Behavior

Every comma between the brackets splits a reference boundary regardless of the whitespace that follows it.

Environment

MemOS main (a7367d0), python 3.14.

Additional Context

Fix + red/green-verified unit tests in tests/mem_os/test_reference_utils.py ready; PR to follow referencing this issue.

Activity

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

Metadata

Metadata

Labels

ai:pr-readyAI-created PR is ready for review | AI 生成的 PR 已等待评审area:coreMOS 编排层 / 框架底座 / 跨模块问题status:in-progressSomeone or AI is working on it | 人工或 AI 正在处理types:bugSomething isn't working | 功能异常

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions