Skip to content

Commit fdbc8e2

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 c038b8e commit fdbc8e2

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
@@ -209,6 +209,25 @@ def test_tools_call_dispatches(self, monkeypatch, config, palace_path, seeded_kg
209209

210210

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

0 commit comments

Comments
 (0)