Fix #1845: fix: 修一下util里的timer_with_status的问题#1881
Open
Memtensor-AI wants to merge 1 commit into
Open
Conversation
…1845) timed_with_status previously swallowed exceptions silently when no fallback was supplied, returning None to the caller. This caused upstream code to fail silently instead of raising the actual error. Behavior after the fix: - fallback supplied → unchanged: fallback's return value is returned, status is logged as FAILED. - fallback is None → original exception is re-raised after the finally block has emitted the [TIMER_WITH_STATUS] ... status: FAILED log line. Exception identity and chain preserved. Also added @functools.wraps to the timed decorator to preserve function metadata (__name__ / __doc__). Tests: - test_failure_logging_no_fallback updated to assert exception propagates - test_failure_no_fallback_preserves_original_exception (new): asserts same-object identity + no synthetic chaining - test_preserves_function_metadata (new) for @timed
5 tasks
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
Fixed the
timed_with_statusdecorator bug where exceptions were silently swallowed when no fallback was provided.Changes made:
src/memos/utils.py - Fixed
timed_with_statusdecorator:exception_to_raisevariable to capture exceptions when no fallback is providedfinallyblock to propagate the original exception while still emitting the FAILED status logtimeddecorator to use@functools.wrapsto preserve function metadatatests/test_utils_timing.py - Updated tests:
test_failure_logging_no_fallbackto assert that exceptions propagate (addedpytest.raises)test_failure_no_fallback_preserves_original_exceptionto verify exception identity is preservedtest_preserves_function_metadatafor the@timeddecorator fixRoot cause: The previous fix (commit 77eeb31 on branch autodev/MemOS-1845) was never merged into dev-20260604-v2.0.19. This fix reapplies that solution.
Verification: Manual logic testing confirms the fix works correctly - exceptions now propagate when no fallback is provided, while fallback behavior remains unchanged. Python syntax validation passed.
Related Issue (Required): Fixes #1845
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