MemOS icon indicating copy to clipboard operation
MemOS copied to clipboard

get_default_cube_config crashes with UnboundLocalError on invalid text_mem_type

Open simpleqt opened this issue 2 months ago • 4 comments

Bug Description

get_default_cube_config in src/memos/mem_os/utils/default_config.py only assigns text_mem_config inside the tree_text and general_text branches, but there is no else. Any other value (e.g. a typo like "tree-text" passed through MOS_NEO4J_*/env config plumbing or the MCP create_cube path) crashes with a bare UnboundLocalError:

>>> get_default_cube_config(openai_api_key="sk-x", text_mem_type="tree-text")
UnboundLocalError: cannot access local variable 'text_mem_config' where it is not associated with a value

Expected Behavior

An invalid text_mem_type should raise a clear ValueError naming the accepted values.

Environment

MemOS main, python 3.14.

Additional Context

Fix + red/green-verified test ready; PR to follow referencing this issue.

simpleqt avatar Sep 30 '26 13:09 simpleqt

🤖 AutoDev has picked up this issue and started working on it.

Task ID: eb1debf3e224d267 Working branch: bugfix/autodev-2441-20260930135356599 Target branch: latest dev* branch 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.

Memtensor-AI avatar Sep 30 '26 13:09 Memtensor-AI

✅ AutoDev task eb1debf3e224d267 completed.

Summary: 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.

Base branch: main Branch: bugfix/autodev-2441-20260930135356599 Commit: dfdca2b PR: https://github.com/MemTensor/MemOS/pull/2445 Assigned to: @syzsunshine219 Reviewers: @WeiminLee

Memtensor-AI avatar Sep 30 '26 14:09 Memtensor-AI

This issue has been automatically marked as stale due to inactivity.

github-actions[bot] avatar Nov 05 '26 02:11 github-actions[bot]

This issue has been automatically closed due to inactivity.

github-actions[bot] avatar Nov 14 '26 02:11 github-actions[bot]