Skip to content

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

Open
syzsunshine219 wants to merge 2 commits into
MemTensor:mainfrom
Memtensor-AI:bugfix/autodev-2441-20260930135356599
Open

syzsunshine219 wants to merge 2 commits into
MemTensor:mainfrom
Memtensor-AI:bugfix/autodev-2441-20260930135356599

Conversation

@syzsunshine219

@syzsunshine219 syzsunshine219 commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Restores the change proposed in #2445 for review against main after its former base branch, dev-v2.0.36, was deleted. The source commits and authors are preserved.

Source head: d9beabee5663cdd7b0618c200be7492e794a862e

This PR is open for review. Review and CI against the current base are pending; validation claims in the original description below refer to the earlier snapshot. The original discussion and evidence remain in #2445.


Original change description

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

MemOS AutoDev added 2 commits September 30, 2026 22:08
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
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.
@syzsunshine219
syzsunshine219 marked this pull request as ready for review November 9, 2026 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

get_default_cube_config crashes with UnboundLocalError on invalid text_mem_type

1 participant