Skip to content

prepare_reference_data crashes on dict entries with missing or non-string id #2448

Description

@simpleqt

Bug Description

prepare_reference_data in src/memos/mem_os/utils/reference_utils.py handles TextualMemoryItem objects and raw dicts, but the dict branch assumes every key exists and that id is a string:

>>> prepare_reference_data([{"metadata": {"memory": "m"}}])
KeyError: 'id'
>>> prepare_reference_data([{"id": 12345, "memory": "m", "metadata": {}}])
AttributeError: 'int' object has no attribute 'split'

Both come from memory entries that are not TextualMemoryItem instances (e.g. already-serialized dicts from a cache or an MCP payload), and the exception escapes the streaming pipeline.

Expected Behavior

Dict entries should be normalized safely: a missing id should skip the ref_id derivation (or use the raw value), and a non-string id should be stringified before .split("-").

Environment

MemOS main, python 3.14.

Additional Context

Fix + red/green-verified test 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:taskDispatched to AI coding agent | 已派发给 AI 编码任务ai:testingAI agent is running tests | AI 正在运行测试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