Skip to content

fix(mcp): purge stale closets on drawer update and delete - #2355

Open
AmirF194 wants to merge 1 commit into
MemPalace:developfrom
AmirF194:fix/2325-drawer-mutation-closet-purge
Open

fix(mcp): purge stale closets on drawer update and delete#2355
AmirF194 wants to merge 1 commit into
MemPalace:developfrom
AmirF194:fix/2325-drawer-mutation-closet-purge

Conversation

@AmirF194

Copy link
Copy Markdown

What does this PR do?

Closets (the AAAK search-index layer) are mined once from a source file's raw content and only ever rebuilt by re-mining that file. Neither tool_update_drawer nor tool_delete_drawer touches them, so a drawer corrected or deleted in place leaves its closet quoting the old text indefinitely. search_memories boosts ranking by source_file and previews the closet document verbatim, so a stale closet can outrank the corrected drawer, worst case a retracted instruction stays the top search result.

Both tools now purge the matching source's closets through _purge_source_closets, the helper delete_by_source already uses for this exact reason (#1722), rather than rebuild them: closets are LLM-derived from file content, and neither tool has the source file or the budget to regenerate them inline. delete_drawer purges unconditionally; update_drawer purges only when content changes, since a wing/room move alone leaves the quoted text correct.

This implements the issue's first, cheapest direction: invalidate on mutation. Rebuilding stale closets from the stored drawers (the issue's second direction) is a separate, larger change and is not attempted here.

How to test

  • New regression tests reproduce the bug directly: closet purge on delete, purge on a content update, and no purge on a wing/room-only move. All three fail on develop (KeyError: 'closets_deleted') and pass on this branch.
  • python -m pytest tests/ -v on Python 3.9 and 3.13 in clean containers: 373 passed, 3 pre-existing failures unrelated to this change (root-owned chmod 0o000 tests no-op under a root test runner; the same 3 fail on unmodified develop).
  • Not verified: the rebuild verb the issue's second direction asks for. This PR stops closets from going stale; it does not regenerate one once purged.

Checklist

  • Tests pass (python -m pytest tests/ -v)
  • No hardcoded paths
  • Linter passes (ruff check .)

Fixes #2325

@igorls

igorls commented Aug 24, 2026

Copy link
Copy Markdown
Member

Thanks for working on this fix! The logic for invalidating stale closets on drawer update/delete looks great and directly addresses #2325.

Could you please rebase your branch against the latest develop to resolve merge conflicts? Once rebased and CI is green, we can get this merged.

@igorls igorls added bug Something isn't working area/mcp MCP server and tools area/kg Knowledge graph needs-rebase PR has merge conflicts with develop and needs rebase labels Aug 24, 2026
Closets are mined once from a source file's content and only rebuilt by
re-mining that file. tool_update_drawer and tool_delete_drawer never
touched them, so a corrected or deleted drawer left a closet quoting the
old text indefinitely, and search boosts ranking by source_file, so a
stale closet could outrank the corrected drawer.

Purge the matching source's closets through _purge_source_closets, the
helper delete_by_source already uses for this reason. update_drawer
purges only when content changes; a wing/room move alone leaves the
quoted text correct.

Fixes MemPalace#2325
@AmirF194
AmirF194 force-pushed the fix/2325-drawer-mutation-closet-purge branch from 79e9658 to f92095e Compare August 24, 2026 23:15
@AmirF194

Copy link
Copy Markdown
Author

Rebased onto the latest develop, force-pushed. CI is running now; will follow up if anything comes back red.

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

Labels

area/kg Knowledge graph area/mcp MCP server and tools bug Something isn't working needs-rebase PR has merge conflicts with develop and needs rebase

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Correcting or deleting a drawer never invalidates its closets, and no verb can rebuild them

2 participants