fix: unwatch deleted projects to prevent zombie reindex#537
fix: unwatch deleted projects to prevent zombie reindex#537Golevka2001 wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes a “zombie reindex” scenario where deleting a project removes its .db but leaves the project registered with the file-change watcher, causing repeated failed reindex attempts and wasted CPU/I/O.
Changes:
- Add a
cbm_watcher_unwatch()call to the MCPdelete_projecthandler after deleting the project DB. - Guard the unwatch call with
if (srv->watcher).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (srv->watcher) { | ||
| cbm_watcher_unwatch(srv->watcher, name); | ||
| } |
Signed-off-by: Gol3vka <gol3vka@163.com>
|
Mind if I add a pending-free list? Unwatch defers the free there, poll_once drains it under lock before snapshotting—avoids the UAF without refcounting. |
Signed-off-by: Gol3vka <gol3vka@163.com>
Signed-off-by: Gol3vka <gol3vka@163.com>
|
I have formatted the file with |
|
Thanks @Golevka2001 — unwatching deleted projects is the right fix and the deferred-free design is sound. One concern before merge: |
Problem
When
auto_indexis enabled, opening a project directory triggers auto-indexing and registers the project with the file-change watcher. If the user later deletes that project via thedelete_projectMCP tool, the.dbfile is removed but the watcher entry persists.The watcher continues polling the deleted project's git repository every 5–60 seconds. On each poll, it detects HEAD movement or a dirty working tree and invokes the full reindex pipeline — which operates on a database that no longer exists.
Reproduction scenario:
codebase-memory-mcp config set auto_index truedelete_project(project="<name>")cbm_watcher_unwatch()is fully implemented (watcher.c:316–332) but is never called from any production code path — only from tests.