feat(memory): auto-migrate shared root memories to per-user namespace dirs - #11448
Open
Laurc2004 wants to merge 3 commits into
Open
feat(memory): auto-migrate shared root memories to per-user namespace dirs#11448Laurc2004 wants to merge 3 commits into
Laurc2004 wants to merge 3 commits into
Conversation
…ponse The stream consumer conflated 'some content was streamed' with 'the final response was delivered', causing the gateway to skip independent delivery when only tool-progress messages had been sent. Fixes in stream_consumer.py: - Line 325 (overflow split + got_done): set _final_response_sent = True directly after successfully sending chunks, instead of copying _already_sent (which was True from earlier tool-progress edits) - Lines 417-418 (CancelledError): only set _final_response_sent = True when accumulated content and an active message existed — not merely because _already_sent was set by earlier edits - got_done with empty accumulated: set _final_response_sent = True when _last_sent_text already delivered the final answer via a prior edit - _send_fallback_final: set _final_response_sent = True after sending Fix in gateway/run.py: - Propagate final_response_sent from stream consumer to agent result dict so the gateway can distinguish 'stream sent tool progress' from 'stream sent the final answer' Closes NousResearch#10748
- Add namespace parameter to MemoryStore (platform:user_id format) - Update get_memory_dir to accept namespace and resolve separate paths - Pass namespace from AIAgent using platform:user_id derivation - Add TestMemoryStoreNamespaceIsolation to verify cross-user separation - Fix monkeypatch signature mismatches for new get_memory_dir(ns) API - Remove erroneous @staticmethod from _path_for instance method Different platform/user combinations now have completely separate MEMORY.md and USER.md files, preventing cross-user memory leakage. CLI/global sessions retain shared access via empty namespace.
… dirs When a namespaced user (e.g. telegram:123456) loads memory for the first time, automatically copy shared root MEMORY.md/USER.md into their per-user directory. This prevents memory loss when enabling per-user isolation. - Add _migrate_from_shared() helper that copies shared root files only if the target namespace dir doesn't already have them - Fix duplicate load_from_disk() definition in MemoryStore (the second definition shadowed the first but the first used get_memory_dir() without namespace, breaking per-user isolation) - Fix regex escaping in get_memory_dir() (\w\-_@.\+ → \w\-_@\.\+) - Add 3 new tests covering migration happy-path, no-overwrite, and empty-namespace no-op
Author
|
相关issue引用:
此PR通过per-user namespace实现了内存隔离,解决了群聊中用户身份混淆的问题,并为后续的session搜索隔离和多Agent架构提供了基础。 |
4 tasks
Contributor
|
Thanks for tackling a real multi-user memory boundary. Problems
Suggested changes
This is an automated hermes-sweeper review; maintainers will make the final call. |
11 tasks
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.
Summary
When per-user memory isolation is enabled, users with existing shared memories (MEMORY.md / USER.md in
~/.hermes/memories/root) would lose their memories because the new namespaced directory starts empty.This PR adds automatic migration: on first load for a new namespaced user, shared root memory files are automatically copied into their per-user directory.
Changes
tools/memory_tool.py_migrate_from_shared()— helper that copies MEMORY.md and USER.md from the shared root to a namespaced user directory, only if the target files do not already exist (no overwrite)load_from_disk()inMemoryStore.__init__area — the original definition usedget_memory_dir()without the namespace parameter, which would break per-user isolation. Fixed to useget_memory_dir(self.namespace)and call migration.load_from_disk()— the second definition shadowed the first, making the fix in the first ineffectiveget_memory_dir()(@.+→@\\.+for proper literal dot matching)tests/tools/test_memory_tool.pyTestMemoryMigrationFromSharedRoot— new test class with 3 tests:test_migration_copies_shared_files_to_new_namespace— verifies happy pathtest_migration_does_not_overwrite_existing_user_files— verifies no data losstest_migration_does_nothing_for_empty_namespace— verifies CLI/global sessions unaffectedTesting
All 37 tests in
test_memory_tool.pypass, including: