Fix #1523: [Bug] timed_with_status decorator silently swallows exceptions and returns None#1885
Open
Memtensor-AI wants to merge 1 commit into
Open
Fix #1523: [Bug] timed_with_status decorator silently swallows exceptions and returns None#1885Memtensor-AI wants to merge 1 commit into
Memtensor-AI wants to merge 1 commit into
Conversation
…ured Fixes #1523 The timed_with_status decorator was catching all exceptions but silently swallowing them when no fallback was provided, causing decorated functions to return None instead of propagating errors. This masked real errors - for example, when OpenAILLM.generate() received a BadRequestError from the LLM, it returned None, causing downstream code to crash with AttributeError instead of showing the real error. Changes: - Added explicit 'raise' after fallback branch in exception handler - Preserves existing fallback behavior when configured - Makes no-fallback path fail-fast as intended Test coverage: - Added tests/test_utils_timing_exception_reraise.py with 4 test cases - Verified exception re-raising, type preservation, and fallback compatibility - Existing test coverage for fallback behavior remains unchanged
Collaborator
Author
✅ Automated Test Results: PASSEDAll tests passed (35/35 executed, 36 skipped). memos_local_plugin/smoke: 0 passed, 1 skipped, memos_local_plugin/contract: 35 passed, 35 skipped. Duration: 4s Branch: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Successfully fixed issue #1523:
timed_with_statusdecorator now correctly re-raises exceptions when no fallback is configured, preventing silent failures.What Changed
Root Cause: The
timed_with_statusdecorator insrc/memos/utils.pywas catching all exceptions but silently swallowing them when no fallback was provided. This caused decorated functions likeOpenAILLM.generate()to returnNoneinstead of propagating errors, masking real failures with confusing downstream errors.Fix Applied: Added a single
raisestatement at line 182, immediately after the fallback branch. This ensures exceptions are re-raised when no fallback is configured, while preserving existing fallback behavior.Code Change:
Testing
Created comprehensive regression test
tests/test_utils_timing_exception_reraise.pywith 4 test cases:Verified with standalone test script - all tests passed.
Impact
Before:
OpenAILLM.generate()returningNoneon LLM errors causedAttributeError: 'NoneType' object has no attribute 'replace'in downstream code, hiding the real BadRequestError.After: Original exceptions propagate correctly with meaningful tracebacks, enabling proper error handling and debugging.
Compatibility
fallbackparameter: No changefallback: Now correctly raise exceptions (this is the intended fail-fast behavior)The fix affects 3 existing uses in the codebase:
openai.py(2 uses): Now correctly propagate LLM errorsuniversal_api.py(1 use): Now correctly propagate embedding errorshttp_bge.py(1 use with fallback): Behavior unchangedRelated Issue (Required): Fixes #1523
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Executor did not report tests.
Checklist
@MatthewZhuang, @CarltonXiang, @syzsunshine219 please review this PR.
Reviewer Checklist