From 3e5e296cba877470508ddba99d3054a0b1796371 Mon Sep 17 00:00:00 2001 From: danielhertz1999-bit Date: Sat, 27 Jun 2026 04:58:32 -0400 Subject: [PATCH] fix: boot integrity check uses HNSW element count, not label_map size _repopulate_label_map_from_sqlite() runs immediately before _initialize_hnsw_index(), so len(_label_map) always equals sqlite_count and the integrity check never fired. The HNSW file could have fewer elements (e.g. 1 vs 2 in SQLite) causing knn_query(k=2) on a 1-element index to raise RuntimeError, breaking every insert via the pattern separation gate. Fix: compare self._hnsw.get_current_count() (actual file elements) to sqlite_count instead of len(_label_map). Co-Authored-By: Claude Sonnet 4.6 --- src/iai_mcp/hippo/_db.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/iai_mcp/hippo/_db.py b/src/iai_mcp/hippo/_db.py index 6df8d4e..98b34fc 100644 --- a/src/iai_mcp/hippo/_db.py +++ b/src/iai_mcp/hippo/_db.py @@ -474,11 +474,11 @@ def _initialize_hnsw_index(self) -> None: self._allocate_standby_index(cap) return - active_label_count = len(self._label_map) - if active_label_count != sqlite_count: + hnsw_count = self._hnsw.get_current_count() + if hnsw_count != sqlite_count: _log.info( - "Boot integrity check: active labels=%d != sqlite count=%d — rebuilding", - active_label_count, + "Boot integrity check: hnsw count=%d != sqlite count=%d — rebuilding", + hnsw_count, sqlite_count, ) self._rebuild_index_from_sqlite()