Fix #34: memos add 写入成功但 list/get 查不到:user_id 作用域在写入侧被静默丢弃 - #36
Fix #34: memos add 写入成功但 list/get 查不到:user_id 作用域在写入侧被静默丢弃#36Memtensor-AI wants to merge 2 commits into
Conversation
add_memory no longer drops a None user_id from the POST body; it requires a non-empty user_id and always includes it, so writes never store an unscoped memory that scoped reads (get/search) can never return. search scoping now uses is not None to stay consistent with add/get. Register memos list as an alias of get, matching MemOS CLI.md docs. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
🤖 Open Code ReviewTarget: PR #36 🔍 OpenCodeReview found 3 issue(s) in this PR. 1.
|
🔧 Open Code Review requested Agent fixOpen Code Review found 3 issue(s). I have resumed the development Agent to fix them.
The Agent will push a new commit to this PR branch. OCR will recheck after the commit is pushed. |
- search_memories: drop empty-string user_id (not just None) so the read contract matches add_memory/get_memories (both raise on falsy user_id). Sending user_id="" to /search/memory would filter by an empty scope on the server and never match memories written under a real user, silently reproducing the invisible-scope bug this PR was meant to fix. - main.py: import commands.memory.list as list_cmd so it no longer shadows the builtin list type used by CommandFirstTyperGroup.list_commands' -> list[str] annotation. - tests: replace app.registered_commands (undocumented Typer internal) with typer.main.get_command(app).commands, which uses Click's stable public API and won't break across Typer versions. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Description
Fixed the user_id scope asymmetry reported in issue #34, where
memos addwould report success but the appended memory could not be read back bymemos get/memos list/memos search.Root cause: the write path silently dropped a resolved
user_id.MemoryAPI.add_memorybuilt its POST /add/message body by iterating common fields and only including values that were notNone, so whenconfig.defaults.user_idwasNone(config explicitly nulled it, or init-time default backfill was missing) and no--user-idflag was passed, the memory was stored with no user scope. Every read path, by contrast, resolves and requires auser_id(get_memorieseven raisesAPIError("Get memory requires user_id")when missing). An unscoped record is therefore never returned by a scoped lookup, and it persists after logout/login.Changes:
memory_api.py—add_memorynow requires a non-emptyuser_idand always includes it in the request body; it raisesAPIError("Add memory requires user_id")instead of writing an unscoped memory.search_memoriesscope checks switched from truthiness tois not Nonefor user_id/conversation_id/agent_id/app_id so empty-string scopes are handled consistently with add/get.memory_cmd.py—cmd_gettakes acommand_nameparameter (defaultget) so the agent-mode envelope can label the alias correctly.memory.py— added alistcommand that delegates tocmd_getwithcommand_name="list".main.py— registeredlist(with explicitname="list"to avoid Typer inferringNonefrom the built-in-shadowing callback name) and added it to the help ordering.MemOS CLI.md— noted thatmemos listis an alias ofmemos get.tests/test_memory_scope.py— 8 new regression tests.Test results: the full suite passes (49 tests OK, up from 41). Pre-existing tests that initially appeared failing were environment/import errors resolved by
pip install -e .; after installation the whole suite is green. There is no configured linter in this repo, so validation usedpython -m py_compileon all changed modules (passed) plus the unittest suite. CLI smoke test confirmedmemos listis now discoverable:memos --helplistslist List memories for a user (alias for get)andmemos list --helpexits 0.Outputs: opsp artifacts (task file + proposal/spec/design/verification-report) were written in the working repo and archived to the specs repo at 2026-08-25-34-memos-add-写入成功但-listget-查不到userid-作用域在写入侧被静默丢弃/.
Related Issue (Required): Fixes #34
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Not run; documentation-only change.
Checklist
@lijicode please review this PR.
Reviewer Checklist