Repository navigation
Fix #2502: fix: rejected ROOT-user deletion removes its configuration - #2503
Open
Memtensor-AI wants to merge 1 commit into
Open
Memtensor-AI wants to merge 1 commit into
Memtensor-AI wants to merge 1 commit into
Conversation
PersistentUserManager.delete_user (and its MySQL sibling) removed the persisted configuration before delegating to the parent UserManager. The parent refuses to delete a ROOT user by returning False, so the configuration row was already committed as deleted while the user stayed active -- get_user_config() returned None with validate_user() == True. Run the parent deletion first and only clean up the configuration once the user was actually deleted. Missing users likewise no longer trigger config cleanup. Add regression tests covering the protected ROOT user (default and custom ID), connection-level persistence of the config row, missing-user and ordinary-user controls, plus the MySQL ordering contract.
4 tasks done
Collaborator
Author
🤖 Open Code ReviewTarget: PR #2503 ✅ OpenCodeReview: Review partially complete: 0 finding(s); 1 of 3 selected item(s) failed. Generated by cloud-assistant via Open Code Review. |
Collaborator
Author
✅ Automated Test Results: PASSEDAll tests passed (41/41 executed). memos_github_open_source/smoke: 1/1, memos_python_core/changed-repo-python: 40/40. Duration: 15s Branch: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixed the bug where a refused ROOT-user deletion still removed the persisted user configuration.
Root cause:
PersistentUserManager.delete_user(and the byte-identicalMySQLPersistentUserManager.delete_user) calleddelete_user_config(user_id)— which commits immediately — BEFORE delegating to the parentUserManager.delete_user. The parent refuses to delete a user whose role isUserRole.ROOTand returnsFalse, so the config row was already committed as deleted while the user remained active:validate_user("root") is Truebutget_user_config("root") is None. The same held for a ROOT user with a custom ID, since the guard keys onrole, not on the ID string.Fix: reorder so the parent deletion runs first; if it refuses (protected ROOT user, or nonexistent user) return
Falseimmediately and touch nothing. Only after a successful deletion is the configuration cleaned up, as a best-effort step whose failure does not change the deletion outcome. Applied identically to both the SQLitePersistentUserManager(src/memos/mem_user/persistent_user_manager.py) and the MySQLMySQLPersistentUserManager(src/memos/mem_user/mysql_persistent_user_manager.py). The Redis manager has nodelete_useroverride and is unaffected.Tests: added
tests/mem_user/test_persistent_user_manager_delete.pycovering the protected ROOT user (defaultrootand custom-ID ROOT), config-row survival verified through a separately opened SQLite connection, missing-user and ordinary-user controls, ordinary-user config cleanup, and the MySQL ordering contract (viapatch.objectfakes, since the MySQL manager needs a live server). All 9 new cases fail on the pre-fix source and pass after it — verified by stashing the source change and re-running. Fulltests/mem_user/suite: 35 passed;tests/api/: 119 passed (154 combined);ruff checkandruff formatclean on all changed files.opsp bug path, quick-fix scope:
type: Bug, single guard-reordering fix with no schema or interface change, so no openspec change artifacts were emitted — only the task file.ai-tasks/2026-10-15-2502-fix-rejected-root-user-deletion-removes-its-configuration.md(frontmatterstatus: merged). That task file plus its Progress log were also synced and pushed to the sibling specs repo (memos-autodev-specs, commit b0b16b8).Branch pushed to origin: bugfix/autodev-2502-20261015135804529. Note for the maintainer: the issue asked whether
dev-v2.0.36is the right target givendevis absent — this task useddev-v2.0.36per the supplied base branch.Related Issue (Required): Fixes #2502
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Not run; documentation-only change.
Checklist
@WeiminLee please review this PR.
Reviewer Checklist