mem0 icon indicating copy to clipboard operation
mem0 copied to clipboard

fix(memory): resolve unreachable code and improve error handling #2867 #2868

Open johnwlockwood opened this issue 10 months ago • 0 comments

Description

This PR addresses issues #2867 and #2868 with critical fixes and improvements:

Critical Fixes:

  • Moved unreachable error logging statements in AsyncMemory._add_to_vector_store
    • logging.error(f"Error in new_retrieved_facts: {e}) was after a return
    • logging.error(f"Invalid JSON response: {e}) was in unreachable code block
  • Fixed error handling flow in both sync and async memory operations

Key Improvements:

  • Restructured conditional logic for LLM calls to only execute when facts are available
  • Standardized logging levels (changed info to debug for non-critical messages)
  • Improved error handling sequence to ensure all errors are properly logged
  • Removed redundant returns that could skip error logging

Test Enhancements:

  • Added telemetry event capture assertions in all test cases
  • Improved test coverage for error scenarios
  • Added mock return values for vector store operations
  • Updated test assertions to match new behavior

Impact:

  • Eliminates unreachable code that could mask error conditions
  • More reliable error reporting in production
  • Better debugging capabilities through consistent logging
  • Improved test coverage for edge cases

Fixes #2867 and #2868

Type of change

Please delete options that are not relevant.

  • [x] Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Testing:

  • Verified all test cases pass with updated assertions
  • Confirmed proper error logging in both sync and async flows
  • Validated telemetry event capture in error scenarios
  • Tested with various LLM response scenarios

Please delete options that are not relevant.

  • [x] Unit Test

Checklist:

  • [x] My code follows the style guidelines of this project
  • [x] I have performed a self-review of my own code
  • [x] I have commented my code, particularly in hard-to-understand areas
  • [x] I have made corresponding changes to the documentation
  • [x] My changes generate no new warnings
  • [x] I have added tests that prove my fix is effective or that my feature works
  • [x] New and existing unit tests pass locally with my changes
  • [x] Any dependent changes have been merged and published in downstream modules
  • [x] I have checked my code and corrected any misspellings

Maintainer Checklist

  • [ ] closes #xxxx (Replace xxxx with the GitHub issue number)
  • [ ] Made sure Checks passed

johnwlockwood avatar May 29 '25 07:05 johnwlockwood