fix: 修一下util里的timer_with_status的问题
Pre-submission checklist | 提交前检查
- [x] I have searched existing issues and this hasn't been mentioned before | 我已搜索现有问题,确认此问题尚未被提及
- [x] I have read the project documentation and confirmed this issue doesn't already exist | 我已阅读项目文档并确认此问题尚未存在
- [x] This issue is specific to MemOS and not a general software issue | 该问题是针对 MemOS 的,而不是一般软件问题
Bug Description | 问题描述
修一下util里的timer_with_status的问题
How to Reproduce | 如何重现
修一下util里的timer_with_status的问题
Environment | 环境信息
修一下util里的timer_with_status的问题
Additional Context | 其他信息
No response
Willingness to Implement | 实现意愿
- [x] I'm willing to implement this myself | 我愿意自己解决
- [ ] I would like someone else to implement this | 我希望其他人来解决
✅ AutoDev task 792038493a2f4ee7 completed.
Summary: 修复 src/memos/utils.py::timed_with_status 的静默吞异常 bug。原行为:当未传 fallback 时,被装饰函数抛出的异常会被 except 捕获后丢失,包装器返回 None——这正是 format_utils.py:1410-1415 里那条"clean_json_response received None — upstream LLM call likely failed silently"防御注释指控的源头。新行为:未传 fallback 时,先在 finally 内照常打 [TIMER_WITH_STATUS] ... status: FAILED 日志,再把原异常重新抛出,traceback / __cause__ / __context__ 保持不变;传了 fallback 时路径完全不变。顺手给 timed 装饰器补了 functools.wraps,停止把 __name__ / __doc__ 弄丢。
生产侧受影响的两个调用点 OpenAILLM.generate / generate_stream 函数体内本来就有 raise,装饰器现在终于把这个意图传到上层;另外三个用了 fallback 的调用点 (UniversalAPIEmbedder.get_embeddings、HttpBGEReranker.rerank) 行为零变化。
测试改动:把原 test_failure_logging_no_fallback(之前以"应静默"为契约)改成断言异常需向上传播且 FAILED 日志仍要打;新增 test_failure_no_fallback_preserves_original_exception(同对象身份 + 无合成链)和 test_preserves_function_metadata (@timed 元数据)。沙箱内无法跑 make test(缺 transformers 等大依赖),用最小化 memos 命名空间桩跑 pytest tests/test_utils_timing.py 得 33 passed;并把修复回滚为旧实现重跑两条新用例,两条均按预期 DID NOT RAISE 红——TDD 证据完整。ruff check / ruff format --check 在改动文件上均通过;本地分支已 push 到 origin/autodev/MemOS-1845。specs 仓库归档了 00-decision.md / 01-clarification.md / 03-fix.md / 04-integration-report.md。
Base branch: dev-20260604-v2.0.19
Branch: autodev/MemOS-1845
Commit: 77eeb31
PR: https://github.com/MemTensor/MemOS/pull/1846
Assigned to: @CarltonXiang, @syzsunshine219
Reviewers: @CarltonXiang, @syzsunshine219
🤖 AutoDev has picked up this issue and started working on it.
Task ID: 792038493a2f4ee7
Working branch: bugfix/autodev-1845
Target branch: dev-20260604-v2.0.19
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.
✅ AutoDev task 792038493a2f4ee7 completed.
Summary: Fixed the timed_with_status decorator bug where exceptions were silently swallowed when no fallback was provided.
Changes made:
-
src/memos/utils.py - Fixed
timed_with_statusdecorator:- Added
exception_to_raisevariable to capture exceptions when no fallback is provided - Added re-raise logic after the
finallyblock to propagate the original exception while still emitting the FAILED status log - Preserves exception identity and chain (no synthetic wrapping)
- Also fixed
timeddecorator to use@functools.wrapsto preserve function metadata
- Added
-
tests/test_utils_timing.py - Updated tests:
- Modified
test_failure_logging_no_fallbackto assert that exceptions propagate (addedpytest.raises) - Added
test_failure_no_fallback_preserves_original_exceptionto verify exception identity is preserved - Added
test_preserves_function_metadatafor the@timeddecorator fix
- Modified
Root cause: The previous fix (commit 77eeb311 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.
Base branch: dev-20260604-v2.0.19
Branch: bugfix/autodev-1845
Commit: c3fdf3b
PR: https://github.com/MemTensor/MemOS/pull/1881
Assigned to: @MatthewZhuang, @CarltonXiang, @syzsunshine219
Reviewers: @MatthewZhuang, @CarltonXiang, @syzsunshine219