Skip to content

Fix #1901: share_cube_with_user passes swapped args to _validate_cube_access — fails for ev#1903

Open
Memtensor-AI wants to merge 1 commit into
dev-20260604-v2.0.19from
bugfix/autodev-1901
Open

Fix #1901: share_cube_with_user passes swapped args to _validate_cube_access — fails for ev#1903
Memtensor-AI wants to merge 1 commit into
dev-20260604-v2.0.19from
bugfix/autodev-1901

Conversation

@Memtensor-AI

@Memtensor-AI Memtensor-AI commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Description

Fixes #1901: MOSCore.share_cube_with_user was broken for every well-formed call. The method called self._validate_cube_access(cube_id, target_user_id), but the validator's signature is (user_id, cube_id). The cube UUID therefore landed in the user_id slot and the first line of the validator (_validate_user_exists) raised ValueError: User '<cube_id>' does not exist or is inactive for every invocation, making the share API completely unusable in b60616d / PyPI MemoryOS==2.0.17.

The in-code comment "Validate current user has access to this cube" already documented the correct intent: the sharing user (self.user_id) — not the target — must own the cube being shared. The fix is a one-line change in src/memos/mem_os/core.py: self._validate_cube_access(self.user_id, cube_id). The target user's existence is independently checked on the next line via validate_user(target_user_id), which is unchanged.

Added three regression tests in tests/mem_os/test_memos_core.py::TestShareCubeWithUser: (1) the happy path asserts validate_user_cube_access is called with (self.user_id, cube_id) and add_user_to_cube with (target_user_id, cube_id); (2) the current user lacking cube access raises a ValueError referencing the current user (not the cube id); (3) a missing target user raises "Target user '<id>' does not exist". All three tests fail before the fix and pass after. Full mem_os test suite passes (28/28). ruff check and ruff format --check are clean on both changed files.

Related Issue (Required): Fixes #1901

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

@MatthewZhuang, @CarltonXiang, @syzsunshine219 please review this PR.

Reviewer Checklist

share_cube_with_user(cube_id, target_user_id) called
_validate_cube_access(cube_id, target_user_id), but the validator
signature is (user_id, cube_id). The cube_id therefore landed in the
user_id slot and _validate_user_exists raised
"User '<cube_id>' does not exist or is inactive" for every well-formed
call, making the API unusable.

The in-code comment "Validate current user has access to this cube"
already documented the correct intent: the sharing user (self.user_id)
must have access to the cube being shared, not the target. Switch the
call to self._validate_cube_access(self.user_id, cube_id). The target
user's existence is independently checked on the next line via
validate_user(target_user_id), so that path is unchanged.

Add regression tests in tests/mem_os/test_memos_core.py that pin down:
- validate_user_cube_access is consulted with (self.user_id, cube_id),
- add_user_to_cube is called with (target_user_id, cube_id) on success,
- a missing target raises "Target user '<id>' does not exist".

Closes #1901
@Memtensor-AI

Copy link
Copy Markdown
Collaborator Author

✅ Automated Test Results: PASSED

All tests passed (35/35 executed, 36 skipped). memos_local_plugin/smoke: 0 passed, 1 skipped, memos_local_plugin/contract: 35 passed, 35 skipped. Duration: 4s

Branch: bugfix/autodev-1901

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-generated bug Something isn't working | 功能异常

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants