Skip to content

Commit 17d3adc

Browse files
committed
fix: return empty status instead of error on cold-start palace (#830)
tool_status() called _get_collection() with the default create=False, which throws when the ChromaDB collection does not exist yet (valid palace, zero drawers). The exception was swallowed and status returned "No palace found" even though init had completed successfully. Switching to create=True bootstraps an empty collection on first status call, matching what the write path already does. Fix suggested by @hkevinchu in the issue.
1 parent 5a2f7db commit 17d3adc

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

mempalace/mcp_server.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,11 @@ def _sanitize_optional_name(value: str = None, field_name: str = "name") -> str:
267267

268268

269269
def tool_status():
270-
col = _get_collection()
270+
# Use create=True only when a palace DB already exists on disk -- this
271+
# bootstraps the ChromaDB collection on a valid-but-empty palace without
272+
# accidentally creating a palace in a non-existent directory (#830).
273+
db_exists = os.path.isfile(os.path.join(_config.palace_path, "chroma.sqlite3"))
274+
col = _get_collection(create=db_exists)
271275
if not col:
272276
return _no_palace()
273277
count = col.count()

tests/test_mcp_server.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,25 @@ def test_tools_call_dispatches(self, monkeypatch, config, palace_path, seeded_kg
212212

213213

214214
class TestReadTools:
215+
def test_status_cold_start_no_collection(self, monkeypatch, config, palace_path, kg):
216+
"""Status on a valid palace with no ChromaDB collection yet (#830).
217+
218+
After `mempalace init`, chroma.sqlite3 exists but the mempalace_drawers
219+
collection has not been created (no mine or add_drawer yet). Status
220+
should return total_drawers: 0, not 'No palace found'.
221+
"""
222+
import chromadb
223+
224+
_patch_mcp_server(monkeypatch, config, kg)
225+
# Create the DB file (init does this) but NOT the collection
226+
client = chromadb.PersistentClient(path=palace_path)
227+
del client
228+
from mempalace.mcp_server import tool_status
229+
230+
result = tool_status()
231+
assert "error" not in result, f"cold-start should not error: {result}"
232+
assert result["total_drawers"] == 0
233+
215234
def test_status_empty_palace(self, monkeypatch, config, palace_path, kg):
216235
_patch_mcp_server(monkeypatch, config, kg)
217236
_client, _col = _get_collection(palace_path, create=True)

0 commit comments

Comments
 (0)