You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
prepare_reference_data crashes on dict entries with missing or non-string id #2448
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:
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.
Summary: Fix #2448: prepare_reference_data no longer crashes on dict memory entries with a missing or non-string id.
Root cause: the dict branch of prepare_reference_data in src/memos/mem_os/utils/reference_utils.py assumed every entry carried an id key and that the id was a string, so cached search results / MCP payloads that had already been serialized would raise KeyError('id') or AttributeError: 'int' object has no attribute 'split', and the exception escaped the streaming pipeline. The TextualMemoryItem branch was unaffected because pydantic guarantees the invariant there.
Fix: normalize dict entries defensively — auto-create metadata if missing, skip ref_id derivation when id is absent (keeping the id slot explicit as None), and coerce non-string ids (int, uuid.UUID, ...) with str() before the prefix split. The original id value is preserved in metadata["id"] unchanged so downstream consumers can still round-trip it. The TextualMemoryItem branch is untouched.
Tests: added 9 regression cases in tests/mem_os/utils/test_reference_utils.py covering both crash repros from the issue, string / UUID / int id shapes, missing metadata, missing memory, and the TextualMemoryItem baseline. All 9 pass; the wider tests/mem_os/ suite (45 tests) also passes with no regressions. ruff format and ruff check are clean on the touched files. Local commit created and branch pushed to origin as bugfix/autodev-2448-20260930155922241 (commit 22d8e980).
Base branch:main Branch:bugfix/autodev-2448-20260930155922241 Commit:22d8e98 PR:#2451 Assigned to:@syzsunshine219 Reviewers:@WeiminLee
Activity
Memtensor-AI commentedon Sep 30, 2026
🤖 AutoDev has picked up this issue and started working on it.
Task ID:
faf2339ea46ecf16Working branch:
bugfix/autodev-2448-20260930155922241Target branch:
latest dev* branchWorkflow: 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.
fix: harden prepare_reference_data against dict entries with missing/…
Memtensor-AI commentedon Sep 30, 2026
✅ AutoDev task
faf2339ea46ecf16completed.Summary: Fix #2448: prepare_reference_data no longer crashes on dict memory entries with a missing or non-string
id.Root cause: the dict branch of
prepare_reference_datainsrc/memos/mem_os/utils/reference_utils.pyassumed every entry carried anidkey and that the id was a string, so cached search results / MCP payloads that had already been serialized would raiseKeyError('id')orAttributeError: 'int' object has no attribute 'split', and the exception escaped the streaming pipeline. TheTextualMemoryItembranch was unaffected because pydantic guarantees the invariant there.Fix: normalize dict entries defensively — auto-create
metadataif missing, skip ref_id derivation whenidis absent (keeping the id slot explicit asNone), and coerce non-string ids (int, uuid.UUID, ...) withstr()before the prefix split. The original id value is preserved inmetadata["id"]unchanged so downstream consumers can still round-trip it. TheTextualMemoryItembranch is untouched.Tests: added 9 regression cases in
tests/mem_os/utils/test_reference_utils.pycovering both crash repros from the issue, string / UUID / int id shapes, missing metadata, missing memory, and the TextualMemoryItem baseline. All 9 pass; the widertests/mem_os/suite (45 tests) also passes with no regressions.ruff formatandruff checkare clean on the touched files. Local commit created and branch pushed to origin asbugfix/autodev-2448-20260930155922241(commit22d8e980).Base branch:
mainBranch:
bugfix/autodev-2448-20260930155922241Commit:
22d8e98PR: #2451
Assigned to: @syzsunshine219
Reviewers: @WeiminLee
fix: address OCR review findings on prepare_reference_data (MemTensor…
github-actions commentedon Nov 4, 2026
This issue has been automatically marked as stale due to inactivity.
github-actions commentedon Nov 14, 2026
This issue has been automatically closed due to inactivity.