From 54a386d925f82579bcc648d99be3c72f53d1c5ff Mon Sep 17 00:00:00 2001 From: Mikhail Valentsev Date: Wed, 15 Apr 2026 12:26:35 +0500 Subject: [PATCH] fix: return empty status instead of error on cold-start palace (#830) (#831) 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. --- mempalace/mcp_server.py | 6 +++++- tests/test_mcp_server.py | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/mempalace/mcp_server.py b/mempalace/mcp_server.py index f0edfbb..4f10f96 100644 --- a/mempalace/mcp_server.py +++ b/mempalace/mcp_server.py @@ -269,7 +269,11 @@ def _sanitize_optional_name(value: str = None, field_name: str = "name") -> str: def tool_status(): - col = _get_collection() + # Use create=True only when a palace DB already exists on disk -- this + # bootstraps the ChromaDB collection on a valid-but-empty palace without + # accidentally creating a palace in a non-existent directory (#830). + db_exists = os.path.isfile(os.path.join(_config.palace_path, "chroma.sqlite3")) + col = _get_collection(create=db_exists) if not col: return _no_palace() count = col.count() diff --git a/tests/test_mcp_server.py b/tests/test_mcp_server.py index 9584f36..09073f5 100644 --- a/tests/test_mcp_server.py +++ b/tests/test_mcp_server.py @@ -212,6 +212,25 @@ class TestHandleRequest: class TestReadTools: + def test_status_cold_start_no_collection(self, monkeypatch, config, palace_path, kg): + """Status on a valid palace with no ChromaDB collection yet (#830). + + After `mempalace init`, chroma.sqlite3 exists but the mempalace_drawers + collection has not been created (no mine or add_drawer yet). Status + should return total_drawers: 0, not 'No palace found'. + """ + import chromadb + + _patch_mcp_server(monkeypatch, config, kg) + # Create the DB file (init does this) but NOT the collection + client = chromadb.PersistentClient(path=palace_path) + del client + from mempalace.mcp_server import tool_status + + result = tool_status() + assert "error" not in result, f"cold-start should not error: {result}" + assert result["total_drawers"] == 0 + def test_status_empty_palace(self, monkeypatch, config, palace_path, kg): _patch_mcp_server(monkeypatch, config, kg) _client, _col = _get_collection(palace_path, create=True)