Skip to content

split_continuous_references leaves references merged when comma styles are mixed #2417

Closed as not planned

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

  1. added
    ai:taskDispatched to AI coding agent | 已派发给 AI 编码任务
    area:coreMOS 编排层 / 框架底座 / 跨模块问题
    status:in-progressSomeone or AI is working on it | 人工或 AI 正在处理
    types:bugSomething isn't working | 功能异常
    on Sep 28, 2026
  2. Memtensor-AI commented on Sep 28, 2026

    @Memtensor-AI
    Collaborator

    🤖 AutoDev has picked up this issue and started working on it.

    Task ID: 75c34c73ae1d5ded
    Working branch: bugfix/autodev-2417-20260928032002157
    Target branch: latest dev* branch
    Workflow: opsp (analysis → coding → testing → PR)

    I will post the PR link here once done. If I need more information, I will ask in the comments.

  3. self-assigned this
    on Sep 28, 2026
  4. Memtensor-AI commented on Sep 28, 2026

    @Memtensor-AI
    Collaborator

    ✅ AutoDev task 75c34c73ae1d5ded completed.

    Summary: Fixes #2417: split_continuous_references in src/memos/mem_os/utils/reference_utils.py no longer strands bare commas when a reference tag mixes , and , separator styles. The two sequential str.replace passes (one for ", ", one for ",") mutated the text on the first pass, so the second pass could not find the original content substring and any surviving bare commas were left un-split — producing merged references like [1:92ff35fb,4:bfe6f044][7:abcd1234] that render as literal text on the streaming chat path.

    The fix replaces the two passes with a single re.sub(r",\s*", "][", content_between_brackets), so every comma between the brackets becomes a split boundary regardless of trailing whitespace. All guard clauses (single [, single ], comma present between brackets) are preserved bit-for-bit; multi-tag and non-reference inputs are unaffected.

    Tests: added tests/mem_os/test_reference_utils.py with 17 cases covering the exact reproduction from the issue plus other separator variants (bare, comma-space, multi-space, tab) and the existing guard clauses. All 17 pass; the full tests/mem_os/ regression suite (53 tests) also passes; ruff check and ruff format are clean on the touched files. Before the fix, 5 of the new cases (including the issue's exact reproduction) failed red as expected.

    Base branch: main
    Branch: bugfix/autodev-2417-20260928032002157
    Commit: fa495aa
    PR: #2419
    Assigned to: @syzsunshine219
    Reviewers: @WeiminLee

  5. added
    ai:testingAI agent is running tests | AI 正在运行测试
    ai:pr-readyAI-created PR is ready for review | AI 生成的 PR 已等待评审
    and removed
    ai:codingAI agent is coding | AI 正在编码
    ai:testingAI agent is running tests | AI 正在运行测试
    ai:taskDispatched to AI coding agent | 已派发给 AI 编码任务
    on Sep 28, 2026
  6. github-actions commented on Nov 1, 2026

    @github-actions
    Contributor

    This issue has been automatically marked as stale due to inactivity.

  7. added
    status:staleAuto-marked stale after 30d inactivity; closes 7d later unless exempt.
    on Nov 1, 2026
  8. github-actions commented on Nov 9, 2026

    @github-actions
    Contributor

    This issue has been automatically closed due to inactivity.

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 正在处理status:staleAuto-marked stale after 30d inactivity; closes 7d later unless exempt.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