Skip to content

prepare_reference_data: handle dict entries with missing or non-string id - #2449

Open
simpleqt wants to merge 1 commit into
MemTensor:mainfrom
simpleqt:sq/reference-data-dicts
Open

simpleqt wants to merge 1 commit into
MemTensor:mainfrom
simpleqt:sq/reference-data-dicts

Conversation

@simpleqt

Copy link
Copy Markdown

Fixes #2448

Summary

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 escape the streaming pipeline for memory entries that are not TextualMemoryItem instances (e.g. already-serialized dicts from a cache or an MCP payload).

Fix

Read the id defensively: derive ref_id from the string form when an id exists, skip it otherwise. TextualMemoryItem behavior is unchanged.

Regression test

Added tests/mem_os/test_prepare_reference_data.py:

  • red/green verified: the two crash cases fail against the old implementation and pass with the fix
  • pins the TextualMemoryItem and string-id dict paths as unchanged

ruff check (repo-pinned 0.11.8) passes on both touched files.

AI Disclosure

  • Tool(s): Claude (ZCode CLI)
  • Used for: debugging assistance, code suggestions, and drafting this PR description. All changes human-reviewed.

Already-serialized memory entries crashed with KeyError when the id
key was missing and AttributeError when the id was not a string.
Derive the ref_id from the string form when an id exists and skip
it otherwise.

Fixes MemTensor#2448
Copilot AI balanced review requested due to automatic review settings September 30, 2026 16:00
@Memtensor-AI Memtensor-AI added area:core MOS 编排层 / 框架底座 / 跨模块问题 status:in-progress Someone or AI is working on it | 人工或 AI 正在处理 labels Sep 30, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@Memtensor-AI

Copy link
Copy Markdown
Collaborator

🤖 Open Code Review

Target: PR #2449
Task: 350cec654abe26f4
Base: main
Head: sq/reference-data-dicts

✅ OpenCodeReview: Review complete: 0 finding(s) across 2 selected item(s).

Generated by cloud-assistant via Open Code Review.

@Memtensor-AI

Copy link
Copy Markdown
Collaborator

✅ Automated Test Results: PASSED

All tests passed (4/4 executed). memos_python_core/changed-repo-python: 4/4. Duration: 8s [advisory, non-gating] AI-generated tests on branch test/auto-gen-350cec654abe26f4-20261001000641: 44/44 passed — these do NOT affect the PR verdict; review the branch manually.

Branch: sq/reference-data-dicts

@Memtensor-AI Memtensor-AI added status:ready Ready for implementation; waiting for assignee or AI dispatch | 可进入实现,等待认领或派发 and removed status:in-progress Someone or AI is working on it | 人工或 AI 正在处理 labels Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core MOS 编排层 / 框架底座 / 跨模块问题 status:ready Ready for implementation; waiting for assignee or AI dispatch | 可进入实现,等待认领或派发

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

4 participants