Add palace compatibility guardrails - #217
Conversation
PR Review: Add palace compatibility guardrailsExecutive Summary
Affected Areas: Business Impact: Users on Chroma >= 1 cannot create new palaces. Existing users upgrading to Chroma >= 1 with pre-metadata palaces have no migration path. MCP server and conversation mining bypass the guardrails entirely. Flow Changes: Every read path (search, wake-up, status, compress) and the write path (mine) now gate on Ratings
PR Health
High Priority Issues🐛 #1: Fresh palace creation impossible under Chroma >= 1Location:
def get_collection(palace_path: str):
os.makedirs(palace_path, exist_ok=True)
- ensure_palace_safe(palace_path)
client = chromadb.PersistentClient(path=palace_path)
try:
collection = client.get_collection("mempalace_drawers")
except Exception:
collection = client.create_collection("mempalace_drawers")
write_palace_metadata(palace_path)
+ ensure_palace_safe(palace_path)
return collectionAlternatively, make the guard bootstrap-aware — distinguish a truly fresh palace (no def ensure_palace_safe(palace_path: str) -> None:
current_major = chromadb_major()
meta = read_palace_metadata(palace_path)
if meta is None:
- if current_major is not None and current_major >= 1:
+ has_existing_data = (Path(palace_path) / "chroma.sqlite3").exists()
+ if has_existing_data and current_major is not None and current_major >= 1:
raise RuntimeError(...)
return🐛 #2: Incomplete guardrail coverage — 3 unguarded ChromaDB entry pointsLocation: These modules all create
The MCP server is particularly significant — it serves 14 tools to AI assistants and is a primary access path. Any palace operation via MCP bypasses the new guardrails completely. # mcp_server.py — _get_collection
+from .compat import ensure_palace_safe
+
def _get_collection(create=False):
global _client_cache, _collection_cache
try:
if _client_cache is None:
+ ensure_palace_safe(_config.palace_path)
_client_cache = chromadb.PersistentClient(path=_config.palace_path)Medium Priority Issues🏗️ #3: Scattered enforcement — should be centralized in
|
| CLI entry | Also checked in |
|---|---|
cmd_search → ensure_palace_safe |
searcher.search() → ensure_palace_safe |
cmd_status → ensure_palace_safe |
miner.status() → ensure_palace_safe |
cmd_wakeup → ensure_palace_safe |
MemoryStack.wake_up() → 2-3 layer methods each call ensure_palace_safe |
Each call reads mempalace_meta.json from disk. For wake_up, the file is read 4+ times in a single operation. This is not a performance-critical path today, but centralizing in palace_db.py (issue #3) would eliminate the redundancy by design.
Low Priority Issues
🎨 #5: Broad RuntimeError catch in main() swallows unrelated errors
Location: mempalace/cli.py:main() | Confidence:
The new top-level catch intercepts all RuntimeError exceptions, not just compatibility ones. Any unrelated RuntimeError from any command will print a clean one-liner and exit — losing the stack trace needed for debugging.
- except RuntimeError as e:
+ except PalaceCompatError as e:
print(f"\n Error: {e}")
sys.exit(1)Define class PalaceCompatError(RuntimeError) in compat.py and raise that instead.
🎨 #6: No migration path for existing pre-metadata palaces
Location: mempalace/compat.py:ensure_palace_safe() | Confidence:
Users who upgrade to Chroma >= 1 with an existing palace (created before this PR) will hit: "Refusing to open palace without compatibility metadata under Chroma 1.x." The error tells them to "rebuild the palace" but provides no command to do so without losing data. A mempalace stamp or mempalace migrate command that writes mempalace_meta.json to an existing palace would provide a clean upgrade path.
🧪 #7: No test coverage for compat.py
Location: mempalace/compat.py | Confidence: ✅ HIGH
The new module has 4 public functions and multiple branching paths (Chroma version parsing, metadata read/write, the bootstrap guard logic). None are tested. Key cases:
chromadb_major()with valid, invalid, and missing__version__ensure_palace_safe()with: no metadata + Chroma < 1, no metadata + Chroma >= 1, matching major, mismatched majorread_palace_metadata()with corrupt JSON, permission errorswrite_palace_metadata()creating parent dirs
Flow Impact Analysis
BEFORE (no guardrails):
CLI/MCP → PersistentClient → ChromaDB (direct, any version)
AFTER (this PR):
CLI commands:
cmd_search ──→ ensure_palace_safe ──→ searcher.search ──→ ensure_palace_safe ──→ PersistentClient
cmd_mine ──→ get_collection ──→ ensure_palace_safe ──→ PersistentClient ──→ write_metadata
cmd_wakeup ──→ ensure_palace_safe ──→ MemoryStack ──→ ensure_palace_safe (×N layers) ──→ PersistentClient
UNGUARDED paths (bypass):
convo_miner.mine_convos ──→ PersistentClient (NO CHECK)
mcp_server._get_collection ──→ PersistentClient (NO CHECK)
palace_graph.build_graph ──→ PersistentClient (NO CHECK)
Created by Octocode MCP https://octocode.ai
web3guru888
left a comment
There was a problem hiding this comment.
👀 Review of #217 — Add palace compatibility guardrails
Scope: +104/−3 · 5 file(s) · touches core
mempalace/cli.py(modified: +11/−1)mempalace/compat.py(added: +75/−0)mempalace/layers.py(modified: +6/−0)mempalace/miner.py(modified: +8/−2)⚠️ mempalace/searcher.py(modified: +4/−0)
Technical Analysis
- 🪟 Windows compatibility — verify path handling works cross-platform
Issues
⚠️ Touchesmempalace/searcher.py— Core search — affects all retrieval paths
Suggestions
- 💡 No tests included — consider adding coverage for the new code paths
🟡 Needs attention — touches guarded files and has items to address.
🏛️ Reviewed by MemPalace-AGI · Autonomous research system with perfect memory · Showcase: Truth Palace of Atlantis
|
Addressed the review concerns and pushed an update. What changed:
Verification:
Latest commit: |
|
Hi, thanks for the contribution. This PR has merge conflicts with Could you rebase onto If this change is no longer relevant, feel free to close the PR. (This message is part of a periodic backlog pass, sent to all open PRs that match this state.) |
7c78b6b to
4f12c6b
Compare
Summary
This PR adds basic compatibility guardrails around local palace access so MemPalace fails cleanly when the local Chroma environment is incompatible with the palace metadata.
What changed
mempalace/compat.pymempalace_meta.jsoninto the palace with:searchwake-upstatuscompressminer.pyRuntimeErrorfailures incli.pyinto clean CLI error messagesWhy
I hit a local case where MemPalace had indexed successfully, but later access crashed because the effective Chroma environment had changed. This PR does not try to solve every Chroma-side issue, but it does make one bad failure mode much safer:
Behavior
Before:
After:
Notes
This is intentionally conservative.
It is better to stop with a clear message and ask for a rebuild than to touch a palace with a known-incompatible local environment.