From b61134b747815da1438741f6aa493228743e910a Mon Sep 17 00:00:00 2001 From: Yiorgis Gozadinos Date: Thu, 25 Jun 2026 13:00:29 +0300 Subject: [PATCH] Log FTS index build failures at WARNING --- CHANGELOG.md | 4 +++ .../haiku/rag/store/repositories/chunk.py | 3 +- tests/test_chunk.py | 31 +++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ce56292..87b76ad4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Changelog ## [Unreleased] +### Fixed + +- A failed FTS index build is logged at `WARNING` instead of `DEBUG`, so silent full-text search degradation is visible. + ### Changed - A bare `${VAR}` in YAML config now raises `MissingEnvVarError` when the variable is set but empty, matching the unset case. Use `${VAR:-default}` to allow an empty/absent value. diff --git a/haiku_rag_slim/haiku/rag/store/repositories/chunk.py b/haiku_rag_slim/haiku/rag/store/repositories/chunk.py index 09a0f40a..ad319121 100644 --- a/haiku_rag_slim/haiku/rag/store/repositories/chunk.py +++ b/haiku_rag_slim/haiku/rag/store/repositories/chunk.py @@ -33,8 +33,7 @@ class ChunkRepository: replace=True, ) except Exception as e: - # Log the error but don't fail - FTS might already exist - logger.debug(f"FTS index creation skipped: {e}") + logger.warning(f"FTS index build failed; full-text search degraded: {e}") def _contextualize_content(self, chunk: Chunk) -> str: """Generate contextualized content for FTS by prepending headings.""" diff --git a/tests/test_chunk.py b/tests/test_chunk.py index 2dcc7299..c3efccc0 100644 --- a/tests/test_chunk.py +++ b/tests/test_chunk.py @@ -510,3 +510,34 @@ async def test_chunk_content_fts_without_headings(temp_db_path): # Both should be the same when no headings assert record["content"] == "Plain content without headings." assert record["content_fts"] == "Plain content without headings." + + +async def test_ensure_fts_index_warns_on_failure(temp_db_path): + """A failed FTS index build is surfaced at WARNING, not swallowed silently.""" + import logging + + from haiku.rag.store.repositories import chunk as chunk_module + + async with HaikuRAG(db_path=temp_db_path, config=Config, create=True) as client: + repo = client.chunk_repository + + async def _boom(*_args, **_kwargs): + raise RuntimeError("index build failed") + + repo.store.chunks_table.create_index = _boom + + records: list[logging.LogRecord] = [] + + class _Capture(logging.Handler): + def emit(self, record: logging.LogRecord) -> None: + records.append(record) + + handler = _Capture(level=logging.WARNING) + chunk_module.logger.addHandler(handler) + try: + await repo._ensure_fts_index() + finally: + chunk_module.logger.removeHandler(handler) + + assert [r for r in records if r.levelno == logging.WARNING] + assert any("index build failed" in r.getMessage() for r in records)