diff --git a/reme/components/file_store/local_file_store.py b/reme/components/file_store/local_file_store.py index 5e738d4f..3bb797f8 100644 --- a/reme/components/file_store/local_file_store.py +++ b/reme/components/file_store/local_file_store.py @@ -272,12 +272,6 @@ class LocalFileStore(BaseFileStore): f"elapsed={time.monotonic() - started_at:.3f}s", ) return - if not self.file_chunks: - self.logger.info( - f"{self.name}: embedding backfill skipped: reason=no_chunks, " - f"elapsed={time.monotonic() - started_at:.3f}s", - ) - return if self._embedding_backfill_task is not None and not self._embedding_backfill_task.done(): pending_verified = skip_health_check or bool( self._embedding_backfill_pending and self._embedding_backfill_pending[0], @@ -292,6 +286,12 @@ class LocalFileStore(BaseFileStore): f"elapsed={time.monotonic() - started_at:.3f}s", ) return + if not self.file_chunks: + self.logger.info( + f"{self.name}: embedding backfill skipped: reason=no_chunks, " + f"elapsed={time.monotonic() - started_at:.3f}s", + ) + return self._embedding_backfill_task = asyncio.create_task( self._run_embedding_backfill(skip_health_check=skip_health_check, rebuild=rebuild), name=f"embedding-backfill:{self.name}", diff --git a/tests/unit/test_file_store_consistency.py b/tests/unit/test_file_store_consistency.py index 0f09cd47..6c49b4ab 100644 --- a/tests/unit/test_file_store_consistency.py +++ b/tests/unit/test_file_store_consistency.py @@ -724,6 +724,34 @@ def test_verified_resume_supersedes_inflight_startup_health_check(): run(go()) +def test_verified_resume_without_chunks_supersedes_inflight_health_check(): + """A newer verified state survives a stale probe even after chunks are cleared.""" + + async def go(): + with tempfile.TemporaryDirectory() as tmp, temp_chdir(tmp): + store = _new_local_store("t_embedding_empty_verified_resume_race") + await store.start() + await set_chunks_with_graph(store, {"a": chunk("a", "a.md", "alpha text")}) + fake = CancellationResistantHealthStore() + store.embedding_store = fake + store._start_embedding_backfill() + startup_task = store._embedding_backfill_task + await fake.health_started.wait() + + await store.clear() + assert await store.resume_embedding(verified=True) is True + assert store._embedding_backfill_pending == (True, False) + fake.release_health.set() + + await startup_task + assert fake.is_healthy is True + assert not fake.node_embedding_calls + assert store._embedding_backfill_task is None + await store.close() + + run(go()) + + @pytest.mark.parametrize("store_factory", [_new_local_store, _new_faiss_store, _new_zvec_store]) def test_verified_rebuild_discards_same_dimension_vectors_before_backfill(store_factory): """A changed vector space never searches compatible-shaped stale vectors."""