Skip to content

fix: 修一下util里的timer_with_status的问题 #1845

Closed

Description

@CarltonXiang

Pre-submission checklist | 提交前检查

  • I have searched existing issues and this hasn't been mentioned before | 我已搜索现有问题,确认此问题尚未被提及
  • I have read the project documentation and confirmed this issue doesn't already exist | 我已阅读项目文档并确认此问题尚未存在
  • 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 | 实现意愿

  • I'm willing to implement this myself | 我愿意自己解决
  • I would like someone else to implement this | 我希望其他人来解决

Activity

  1. added
    types:bugSomething isn't working | 功能异常
    ai:taskDispatched to AI coding agent | 已派发给 AI 编码任务
    and removed
    ai:taskDispatched to AI coding agent | 已派发给 AI 编码任务
    types:bugSomething isn't working | 功能异常
    on Jun 1, 2026
  2. Memtensor-AI commented on Jun 1, 2026

    @Memtensor-AI
    Collaborator

    ✅ 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: #1846
    Assigned to: @CarltonXiang, @syzsunshine219
    Reviewers: @CarltonXiang, @syzsunshine219

  3. deleted a comment from MaiHHConnect on Jun 1, 2026
  4. added
    area:coreMOS 编排层 / 框架底座 / 跨模块问题
    ai:codingAI agent is coding | AI 正在编码
    and removed on Jun 1, 2026
  5. self-assigned this
    on Jun 4, 2026
  6. Memtensor-AI commented on Jun 4, 2026

    @Memtensor-AI
    Collaborator

    🤖 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.

  7. Memtensor-AI commented on Jun 4, 2026

    @Memtensor-AI
    Collaborator

    ✅ AutoDev task 792038493a2f4ee7 completed.

    Summary: Fixed the timed_with_status decorator bug where exceptions were silently swallowed when no fallback was provided.

    Changes made:

    1. src/memos/utils.py - Fixed timed_with_status decorator:

      • Added exception_to_raise variable to capture exceptions when no fallback is provided
      • Added re-raise logic after the finally block to propagate the original exception while still emitting the FAILED status log
      • Preserves exception identity and chain (no synthetic wrapping)
      • Also fixed timed decorator to use @functools.wraps to preserve function metadata
    2. tests/test_utils_timing.py - Updated tests:

      • Modified test_failure_logging_no_fallback to assert that exceptions propagate (added pytest.raises)
      • Added test_failure_no_fallback_preserves_original_exception to verify exception identity is preserved
      • Added test_preserves_function_metadata for the @timed decorator fix

    Root 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.

    Base branch: dev-20260604-v2.0.19
    Branch: bugfix/autodev-1845
    Commit: c3fdf3b
    PR: #1881
    Assigned to: @MatthewZhuang, @CarltonXiang, @syzsunshine219
    Reviewers: @MatthewZhuang, @CarltonXiang, @syzsunshine219

  8. added
    ai:testingAI agent is running tests | AI 正在运行测试
    and removed
    ai:codingAI agent is coding | AI 正在编码
    ai:testingAI agent is running tests | AI 正在运行测试
    ai:taskDispatched to AI coding agent | 已派发给 AI 编码任务
    on Jun 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:coreMOS 编排层 / 框架底座 / 跨模块问题types:bugSomething isn't working | 功能异常

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions