Skip to content

fix(feedback): handle empty added_ids in _single_add_operation#1143

Closed
lailoo wants to merge 1 commit intoMemTensor:mainfrom
lailoo:fix/feedback-empty-added-ids-1122
Closed

fix(feedback): handle empty added_ids in _single_add_operation#1143
lailoo wants to merge 1 commit intoMemTensor:mainfrom
lailoo:fix/feedback-empty-added-ids-1122

Conversation

@lailoo
Copy link
Copy Markdown
Contributor

@lailoo lailoo commented Feb 28, 2026

Summary

  • Bug: IndexError in _single_add_operation when memory_manager.add() returns empty list
  • Root cause: feedback.py:254 accesses added_ids[0] without checking if the list is empty
  • Fix: Add empty-list guard that returns {"id": None, ...} gracefully

Fixes #1122 (Part 2 of 2 — the IndexError on empty added_ids)

Problem

When the graph DB silently fails (e.g. due to the CypherTypeError in Part 1), _add_memories_parallel() catches the exception, logs it, but returns an empty list. Then _single_add_operation crashes:

added_ids = self._retry_db_operation(
    lambda: self.memory_manager.add([to_add_memory], user_name=user_name, use_batch=False)
)
return {
    "id": added_ids[0],  # IndexError: list index out of range
    ...
}

Before fix:

added_ids = []
added_ids[0]  ->  IndexError: list index out of range

Changes

  • src/memos/mem_feedback/feedback.py — Add empty-list guard before accessing added_ids[0]
  • tests/mem_feedback/test_feedback_empty_added_ids.py — Regression tests

After fix:

added_ids = []
-> returns {"id": None, "text": "...", "source_doc_id": None}  (no crash)

Test plan

  • New test: test_single_add_returns_none_id_when_added_ids_empty — verifies graceful handling
  • New test: test_single_add_returns_id_when_added_ids_present — verifies normal path

Effect on User Experience

Before: /product/feedback endpoint crashes with 500 Internal Server Error when the underlying graph DB add fails silently.
After: The endpoint returns a response with "id": null, allowing the caller to detect and handle the failure.

…nsor#1122)

When memory_manager.add() returns an empty list due to a silent graph DB
failure, accessing added_ids[0] raises IndexError. Add a guard to return
{"id": None, ...} gracefully instead of crashing.
@lailoo lailoo closed this Feb 28, 2026
@lailoo lailoo deleted the fix/feedback-empty-added-ids-1122 branch February 28, 2026 20:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: Feedback API fails with Neo4j CypherTypeError - Property values cannot be Map types

1 participant