fix(repair): harden recovery flows and serialize writers - #1407
Open
mjc wants to merge 6 commits into
Open
Conversation
3 tasks
mjc
force-pushed
the
fix/repair-performance
branch
from
May 7, 2026 16:54
d79acba to
fc276a8
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens MemPalace’s Chroma repair/recovery paths by staging rebuilds into temporary collections (with rename swap + inventory validation), honoring configured collection names, and introducing a shared per-palace write lock to serialize repair/mine/MCP writes and prevent rebuild/write races.
Changes:
- Repair/recovery: stage into uniquely-named temp collections, swap by rename, reuse stored embeddings when available, and validate inventories/counts (plus new repair-status artifact detection + cleanup).
- Concurrency: add
palace_write_lockand integrate it across miners, repair, MCP tools, and backend write wrappers. - Migration & tests: adjust
migrate()behavior (no-op on healthy palaces; dry-run avoids probe writes), plus extensive regression/behavioral test coverage.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| mempalace/repair.py | Implements staging+swap rebuild flows, SQLite extraction/vector reuse, inventory validation, repair-status artifacts/cleanup, and repair write-locking. |
| mempalace/palace.py | Introduces palace_write_lock (blocking/non-blocking) and maps mine_palace_lock onto it for shared serialization. |
| mempalace/backends/chroma.py | Adds ChromaCollection.modify() wrapper and adjusts quarantine preflight gating semantics. |
| mempalace/mcp_server.py | Uses configured collection name safely and serializes MCP write tools behind the palace write lock. |
| mempalace/cli.py | Adds from-SQLite confirmation helper, repair-status CLI flags, and forwards new repair options. |
| mempalace/migrate.py | Skips write/delete probe in dry-run; avoids prompting on healthy palaces; filters synthetic probe drawers in SQLite fallback. |
| tests/test_repair.py | Adds extensive coverage for new repair/recovery behaviors (temp swap, locking, vectors reuse, inventory validation, artifacts, archive restore). |
| tests/test_palace_locks.py | Covers conflict/compat between mine lock and shared writer lock, plus blocking + Windows behavior. |
| tests/test_mcp_server.py | Verifies MCP tools wait/serialize correctly behind palace write lock. |
| tests/test_cli.py | Adds coverage for new CLI confirmation + repair-status + repair error/lock-handling paths. |
| tests/test_migrate.py | Updates/extends migration behavior tests (healthy no-op, dry-run semantics, probe drawer filtering). |
| tests/test_backends.py | Adds coverage for modify() delegation + lock acquisition; updates quarantine gating tests. |
| tests/test_searcher.py | Adds regression coverage for candidate_strategy API stability and minor assertion formatting. |
Comments suppressed due to low confidence (1)
mempalace/repair.py:52
REPAIR_TEMP_COLLECTIONappears unused and is now misleading since temp collections are generated via_unique_temp_collection_name(...)rather than a fixed...__repair_tmpname. Consider removing this constant or updating it to reflect the new naming scheme to avoid future callers relying on the old value.
COLLECTION_NAME = "mempalace_drawers"
REPAIR_TEMP_COLLECTION = f"{COLLECTION_NAME}__repair_tmp"
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
mjc
force-pushed
the
fix/repair-performance
branch
2 times, most recently
from
May 7, 2026 17:22
df5a4e9 to
b182a4d
Compare
Contributor
Author
|
I'm still experiencing occasional corruption but this cut it down a lot. unsure if its worth taking yet though. |
mjc
force-pushed
the
fix/repair-performance
branch
from
May 15, 2026 03:31
65f9e54 to
b182a4d
Compare
mjc
force-pushed
the
fix/repair-performance
branch
from
May 15, 2026 21:40
b182a4d to
a54a02f
Compare
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.
What does this PR do?
This PR hardens MemPalace repair and recovery for damaged Chroma palaces and reduces rebuild time on the common recovery path.
Rebased on 2026-05-15 onto
upstream/developatbb31396. Since the original PR, upstream has already landed overlapping repair hardening for rebuild progress/ETA and empty-metadata sanitization. This PR now focuses on the remaining repair-performance and writer-safety pieces that are still unique to this branch.Current delta after rebase
mempalace_drawers.repair,mine, repair cleanup, MCP write tools, and direct backend mutators do not race rebuild/swap paths. MemPalace-managed writes against the same palace no longer write the HNSW index concurrently.User-visible outcomes
Verification
After the rebase:
Result:
272 passed; targeted ruff check clean.Broader test plan
uv run pytest tests/test_backends.py tests/test_searcher.py tests/test_repair.py tests/test_migrate.py tests/test_cli.py tests/test_mcp_server.py tests/test_miner.py -qmempalace repairagainst a palace with a non-default configured collection namemempalace migrateagainst a healthy readable palace and confirm it exits successfully without prompting for destructive confirmationChecklist