Skip to content

Commit 3ee71a5

Browse files
author
Wojciech Napierała
committed
Refactor health checks to log warnings and return fallback messages on failures
- Updated Redis and ChromaDB health check functions to log warnings instead of raising exceptions on connectivity failures. - Implemented fallback mechanisms to use in-memory storage when Redis or ChromaDB is unavailable. - Modified tests to assert warnings are generated instead of exceptions being raised during health check failures.
1 parent 7180596 commit 3ee71a5

3 files changed

Lines changed: 22 additions & 6 deletions

File tree

core/health.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,12 @@ def _check_redis(config: AppConfig) -> List[str]:
5050
try:
5151
client.ping()
5252
except Exception as exc: # pragma: no cover - runtime dependent
53-
raise HealthCheckError(f"Redis connectivity check failed: {exc}") from exc
53+
LOGGER.warning(
54+
"Redis connectivity check failed (%s); using in-memory fallback.", exc
55+
)
56+
return [
57+
"redis unavailable; using in-memory working memory fallback.",
58+
]
5459
return []
5560

5661

@@ -69,7 +74,13 @@ def _check_chromadb(config: AppConfig) -> List[str]:
6974
client = cast(Any, chromadb_module).PersistentClient(path=str(persist_dir))
7075
client.list_collections()
7176
except Exception as exc: # pragma: no cover - runtime dependent
72-
raise HealthCheckError(f"ChromaDB availability check failed: {exc}") from exc
77+
LOGGER.warning(
78+
"ChromaDB availability check failed (%s); using in-memory memory store.",
79+
exc,
80+
)
81+
return [
82+
"chromadb unavailable; in-memory persistence activated.",
83+
]
7384
return []
7485

7586

core/memory_manager.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,11 @@ def __init__(self, config: AppConfig) -> None:
385385

386386
self._embedding_fn = self._build_embedding_function(config)
387387
self._supports_vector_query = self._embedding_fn is not None
388+
if not self._supports_vector_query:
389+
self._logger.warning(
390+
"Chroma embedding function unavailable; storing memory in-process."
391+
)
392+
return
388393

389394
try: # pragma: no cover - needs chromadb runtime
390395
self._client = chromadb_module.PersistentClient(

tests/test_health.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import pytest
1414

1515
from config import settings
16-
from core.exceptions import HealthCheckError
1716
from core.health import run_startup_checks
1817

1918

@@ -70,14 +69,15 @@ def test_health_checks_with_stubbed_dependencies(monkeypatch: pytest.MonkeyPatch
7069
assert warnings == []
7170

7271

73-
def test_health_checks_raise_on_redis_failure(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
72+
def test_health_checks_warn_on_redis_failure(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
7473
config = _load_config(tmp_path)
7574
config.memory.chromadb.persist_directory = str(tmp_path / "chroma")
7675

7776
_install_stub_modules(monkeypatch, tmp_path, redis_ping_ok=False)
7877

79-
with pytest.raises(HealthCheckError):
80-
run_startup_checks(config)
78+
warnings = run_startup_checks(config)
79+
assert warnings
80+
assert any("redis unavailable" in warning for warning in warnings)
8181

8282

8383
def test_health_checks_warn_when_standard_embedding_missing(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:

0 commit comments

Comments
 (0)