Skip to content

Fix #2441: get_default_cube_config crashes with UnboundLocalError on invalid text_mem_type - #2445

Open
Memtensor-AI wants to merge 2 commits into
MemTensor:dev-v2.0.36from
Memtensor-AI:bugfix/autodev-2441-20260930135356599
Open

Memtensor-AI wants to merge 2 commits into
MemTensor:dev-v2.0.36from
Memtensor-AI:bugfix/autodev-2441-20260930135356599

Conversation

@Memtensor-AI

Copy link
Copy Markdown
Collaborator

Description

Fixes issue #2441: get_default_cube_config (and its sibling get_default_config) in src/memos/mem_os/utils/default_config.py no longer crashes with a bare UnboundLocalError when a caller passes an unsupported text_mem_type such as the reported "tree-text" typo. Both helpers now call a new _validate_text_mem_type guard at entry and raise a clear ValueError naming the offending value and the accepted set ("tree_text", "general_text"), so misconfigurations coming through the MOS_TEXT_MEM_TYPE env var or the MCP create_cube path fail loudly with an actionable message. As a defence-in-depth, get_default_cube_config's if/elif chain gained an explicit else branch that re-raises the same ValueError, so a future refactor cannot silently reintroduce the fall-through.

Added tests/mem_os/utils/test_default_config.py with five cases covering the reported reproducer ("tree-text"), other unknown backends, empty strings, symmetric behavior on get_default_config, and a happy-path smoke test for "general_text". All new tests pass; the full tests/mem_os/ suite (41 tests) continues to pass; ruff check and ruff format are clean on the touched files. No public API, schema, or OpenAPI contract changes; no new dependencies.

Related Issue (Required): Fixes #2441

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (does not change functionality, e.g. code style improvements, linting)
  • Documentation update

How Has This Been Tested?

Automated tests are pending.

  • Unit Test
  • Test Script Or Test Steps (please provide)
  • Pipeline Automated API Test (please provide)

Checklist

  • I have performed a self-review of my own code
  • I have commented my code in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works
  • I have created related documentation issue/PR in MemOS-Docs (if applicable)
  • I have linked the issue to this PR (if applicable)
  • I have mentioned the person who will review this PR

@WeiminLee please review this PR.

Reviewer Checklist

get_default_cube_config only assigned text_mem_config inside the
'tree_text' and 'general_text' branches. Any other value (a typo such as
'tree-text', or an unknown value coming through the MOS_TEXT_MEM_TYPE env
var or the MCP create_cube path) fell through to the cube_config_dict
assembly and crashed with a bare UnboundLocalError:

  UnboundLocalError: local variable 'text_mem_config' referenced before
  assignment

Add a private _validate_text_mem_type helper that raises a clear
ValueError naming the offending value and the accepted set, call it at
the top of both get_default_config and get_default_cube_config so the two
entry points fail identically, and add an explicit else branch inside the
cube helper so a future refactor cannot silently reintroduce the
UnboundLocalError. Adds tests/mem_os/utils/test_default_config.py with
red-then-green cases plus a happy-path smoke test.

Fixes MemTensor#2441
@Memtensor-AI Memtensor-AI added ai:generated Generated or modified by AI | 由 AI 生成或修改 area:core MOS 编排层 / 框架底座 / 跨模块问题 status:in-progress Someone or AI is working on it | 人工或 AI 正在处理 labels Sep 30, 2026
@Memtensor-AI

Memtensor-AI commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator Author

🤖 Open Code Review

Target: PR #2445
Task: eb1debf3e224d267
Base: dev-v2.0.36
Head: bugfix/autodev-2441-20260930135356599
Head SHA: d9beabee5663cdd7b0618c200be7492e794a862e

✅ OpenCodeReview: Review complete: 0 finding(s) across 3 selected item(s).

Generated by cloud-assistant via Open Code Review.

@Memtensor-AI

Copy link
Copy Markdown
Collaborator Author

🔧 Open Code Review requested Agent fix

Open Code Review found 1 issue(s). I have resumed the development Agent to fix them.

  • Task: eb1debf3e224d267
  • Fix attempt: 1/2
  • Finding delta: 0 repeated / 1 new / 0 likely resolved

The Agent will push a new commit to this PR branch. OCR will recheck after the commit is pushed.

Extend TestGetDefaultConfigInvalidTextMemType with the same three
regression cases already exercised by TestGetDefaultCubeConfigInvalidTextMemType:
a typo, a fully unknown backend name, and the empty string.

get_default_config and get_default_cube_config each call
_validate_text_mem_type independently (there is no shared delegation
path), so symmetric coverage is required to guard both entry points
against the UnboundLocalError regression tracked in issue MemTensor#2441.

Addresses OCR review on PR MemTensor#2445.
@Memtensor-AI

Copy link
Copy Markdown
Collaborator Author

✅ Automated Test Results: PASSED

All tests passed (8/8 executed). memos_github_open_source/smoke: 1/1, memos_python_core/changed-repo-python: 7/7. Duration: 10s

Branch: bugfix/autodev-2441-20260930135356599

@Memtensor-AI Memtensor-AI added status:ready Ready for implementation; waiting for assignee or AI dispatch | 可进入实现,等待认领或派发 and removed status:in-progress Someone or AI is working on it | 人工或 AI 正在处理 labels Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai:generated Generated or modified by AI | 由 AI 生成或修改 area:core MOS 编排层 / 框架底座 / 跨模块问题 status:ready Ready for implementation; waiting for assignee or AI dispatch | 可进入实现,等待认领或派发

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants