fix: resolve working memory key via search index when user_id/namespace omitted#239
Open
fix: resolve working memory key via search index when user_id/namespace omitted#239
Conversation
🛡️ Jit Security Scan Results✅ No security findings were detected in this PR
Security scan by Jit
|
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes issue #235 where GET/DELETE /v1/working-memory/{session_id} could 404 after a successful scoped PUT because user_id/namespace were provided in the PUT body but omitted from GET/DELETE query params. The PR adds an index-based fallback to resolve the correct Redis key by session_id.
Changes:
- Add
_resolve_working_memory_key_via_index()and wire it intoget_working_memory()anddelete_working_memory()as a fallback when the direct key lookup misses. - Return stored
namespace/user_idfrom the persisted JSON document (instead of echoing caller-supplied params). - Extend the MCP
get_working_memorytool to accept optionaluser_id/namespace, and add regression tests for the bug and related scenarios.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
agent_memory_server/working_memory.py |
Adds index-based key resolution fallback for GET/DELETE when scoping params are omitted. |
agent_memory_server/mcp.py |
Adds optional user_id and namespace parameters to the MCP get_working_memory tool. |
tests/test_issue_235.py |
Introduces a dedicated regression test suite for key resolution behavior and API round-trips. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ce omitted (#235) PUT /v1/working-memory/{session_id} stores user_id and namespace from the request body into the Redis key, but GET/DELETE construct the key from query params. When callers omit those params, a different key is produced and the session appears missing (404). Add an index-based fallback: when a direct key lookup returns nothing, query the working memory search index by session_id to resolve the actual Redis key. This preserves multi-tenant isolation (namespace + user_id remain in keys) while making GET/DELETE work without requiring callers to repeat scoping parameters. Changes: - Add _resolve_working_memory_key_via_index() helper in working_memory.py - Use fallback in get_working_memory() and delete_working_memory() - Return stored namespace/user_id from JSON data instead of caller params - Add user_id/namespace params to MCP get_working_memory tool - Add comprehensive tests covering the fix and multi-tenant isolation
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.
Closes #235
Summary
PUT /v1/working-memory/{session_id}acceptsuser_idandnamespacein the request body, embedding them into the Redis key (e.g.working_memory:demo:alice:session-1)GETandDELETEtake those values as query params, which default toNonewhen omitted, producing a different key (working_memory:session-1) — resulting in a 404session_idto resolve the actual Redis keyChanges
working_memory.py: Add_resolve_working_memory_key_via_index()helper; wire fallback intoget_working_memory()anddelete_working_memory(); return storednamespace/user_idfrom the JSON document instead of caller-supplied paramsmcp.py: Add missinguser_idandnamespaceparameters to the MCPget_working_memorytooltests/test_issue_235.py: 9 tests covering key resolution, API round-trips, delete without params, multi-tenant isolation, and non-existent session handlingTest plan
test_get_resolves_via_index_when_params_omitted— PUT with scoping params, GET without → 200test_get_with_partial_params_resolves— GET with namespace only still resolvestest_get_with_correct_params_still_uses_fast_path— direct lookup still works when params matchtest_delete_resolves_via_index_when_params_omitted— DELETE without params removes the correct sessiontest_api_put_body_params_get_without_query_params— full HTTP round-triptest_api_delete_without_query_params— full HTTP DELETE round-triptest_multi_tenant_isolation_preserved— same session_id in different namespaces stays separatetest_nonexistent_session_still_returns_none— no false positives