← Back to PRs

#22937: fix: remove legacy unsuffixed QMD collections on upgrade

by sud0n1m-ziggy open 2026-02-21 21:00 View on GitHub →
size: S
## Problem When upgrading from an older OpenClaw version that created default memory collections without an agent ID suffix (`memory-root`, `memory-alt`, `memory-dir`) to a version that uses scoped names (`memory-root-main`, `memory-alt-main`, `memory-dir-main`), the old collections persist in the QMD index. The old collections occupy the same filesystem paths, so the new suffixed collections are created but contain 0 indexed files. This causes `memory_search` to fail with: ``` Collection not found: memory-root-main ``` ...and fall back to the Gemini embedding provider on every search, defeating the purpose of the local QMD index. ## Root Cause `ensureCollections()` checks if the desired collection name (e.g. `memory-root-main`) exists in the index. Since it doesn't, it tries to create it. But the old `memory-root` collection already covers the same path, so the new collection gets created with 0 files. The old collection is never cleaned up because it's not in the desired collection list. ## Fix Added `removeLegacyUnsuffixedCollections()` to `ensureCollections()` that: 1. Checks for known legacy base names (`memory-root`, `memory-alt`, `memory-dir`) 2. If they exist AND the desired scoped name is different, removes them 3. Logs the migration for visibility This runs once on boot — after the legacy collections are removed, subsequent boots find the correctly-named collections and skip. ## Testing - Added test: `removes legacy unsuffixed collections on upgrade` - All 42 existing tests in `qmd-manager.test.ts` pass - All 7 tests in `backend-config.test.ts` pass - Verified fix manually on a real upgrade scenario <!-- greptile_comment --> <h3>Greptile Summary</h3> Adds migration logic to clean up legacy QMD collections created before agent-scoped naming was introduced. When upgrading from older versions, collections like `memory-root` persisted alongside new `memory-root-main` collections, causing the new collections to index 0 files and breaking memory search. The fix removes these legacy collections on boot. - Added `removeLegacyUnsuffixedCollections()` method to detect and remove `memory-root`, `memory-alt`, `memory-dir` if they exist but aren't in the desired collection list - Logs migration actions with `log.info` for visibility - Comprehensive test coverage validates the migration behavior <h3>Confidence Score: 5/5</h3> - This PR is safe to merge with minimal risk - The fix is well-designed and addresses a specific upgrade issue. The implementation is defensive (checks existence before removal, handles errors gracefully), runs only once on boot, and includes comprehensive test coverage. The logic correctly identifies legacy collections by checking if they exist AND aren't in the current desired collection list. - No files require special attention <sub>Last reviewed commit: 9ec83a9</sub> <!-- greptile_other_comments_section --> <sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub> <!-- /greptile_comment -->

Most Similar PRs