Skip to content

add_memory 返回成功但立即查询同一 memory_id 404 #2329

Closed as not planned

Description

@Memtensor-AI

问题描述

调用 add_memory 接口返回成功并获得 memory_id,但立即使用相同 memory_id 查询时固定返回 404,预期可以查询到刚写入的数据,实际数据不存在。

复现信息

  • trace_id=575fe27de896ca4f095ed3594f57e69f
  • xiaoyi:af5452dacec926cf17b86d97
  • issue:10a3e370a9306cb018d44213

现象

  • add_memory 接口成功返回 memory_id
  • 立刻用同一 memory_id 查询返回 404
  • 稳定复现

Activity

  1. added
    ai:taskDispatched to AI coding agent | 已派发给 AI 编码任务
    status:in-progressSomeone or AI is working on it | 人工或 AI 正在处理
    ai:codingAI agent is coding | AI 正在编码
    on Sep 2, 2026
  2. Memtensor-AI commented on Sep 2, 2026

    @Memtensor-AI
    CollaboratorAuthor

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

    Task ID: c738ad199edc554f
    Working branch: bugfix/autodev-2329-20260902085902328
    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 2, 2026
  4. added
    area:databasegraph_db + vector_db | 图数据库与向量数据库
    types:bugSomething isn't working | 功能异常
    on Sep 2, 2026
  5. added a commit that references this issue on Sep 2, 2026
    b36f301
  6. Memtensor-AI commented on Sep 2, 2026

    @Memtensor-AI
    CollaboratorAuthor

    ✅ AutoDev task c738ad199edc554f completed.

    Summary: Fixed the add_memory → get_memory 404 race condition in async mode.

    Root cause: In async mode, add_memory writes fast-mode LongTermMemory nodes and immediately returns their IDs (IDs_A) to the caller. The scheduler's MemReadMessageHandler._process_memories_with_reader would then call fine_transfer_simple_mem which produces brand-new UUID nodes (IDs_B), write those, and hard-delete IDs_A. Any get_memory(IDs_A) call issued after the scheduler ran would return 404 because the original nodes no longer existed.

    Fix applied in src/memos/mem_scheduler/task_schedule_modules/handlers/mem_read_handler.py: when fine_transfer_simple_mem produces exactly one enhanced memory per input item (the common 1:1 case), the enhanced item's .id is overwritten with the original node's ID before writing. Neo4j uses MERGE semantics, so the graph node is updated in-place and the caller's handle remains permanently valid. Reused IDs are then excluded from the subsequent delete list so the freshly-updated node is never destroyed. The existing delete-and-replace behavior is fully preserved for 1:N expansions and zero-output cases.

    Tests: 4 new unit tests added in tests/mem_scheduler/test_mem_read_handler_id_stability.py covering the 1:1 reuse path (ID assigned, ID not deleted), the 1:N expansion fallback (old ID still deleted), and the zero-output fallback. All 50 scheduler tests pass. Ruff clean.

    Base branch: main
    Branch: bugfix/autodev-2329-20260902085902328
    Commit: b36f301
    PR: #2330
    Assigned to: @whipser030
    Reviewers: @MatthewZhuang, @CarltonXiang, @syzsunshine219, @World-controller

  7. added
    ai:testingAI agent is running tests | AI 正在运行测试
    and removed
    ai:codingAI agent is coding | AI 正在编码
    on Sep 2, 2026
  8. github-actions commented on Oct 4, 2026

    @github-actions
    Contributor

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

  9. added
    status:staleAuto-marked stale after 30d inactivity; closes 7d later unless exempt.
    on Oct 4, 2026
  10. github-actions commented on Oct 14, 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:taskDispatched to AI coding agent | 已派发给 AI 编码任务ai:testingAI agent is running tests | AI 正在运行测试area:databasegraph_db + vector_db | 图数据库与向量数据库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