Skip to content

test(daemon): per-tier health check failure and recovery (#1146) - #1151

Merged
Sinity merged 1 commit into
masterfrom
feature/test/daemon-health-tier-coverage
May 17, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/test/daemon-health-tier-coverage

Conversation

@Sinity

@Sinity Sinity commented May 17, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adds tests/unit/daemon/test_health_check_paths.py covering each of the
13 registered health checks in polylogue/daemon/health.py with an OK
path and a representative degraded path. Three checks (one per tier)
also pin the recovery transition with consecutive_failures reset.

Problem

#999 (resurrected from #830) shipped tiered health checks (FAST /
MEDIUM / EXPENSIVE) across ~10 individual checks, but the existing
suite only covered the aggregation surface (test_health_contracts.py)
plus a handful of HTTP envelope tests. Individual checks could silently
report HealthSeverity.OK for every input and the aggregation tests
would still pass. #1146 — first Scope item on #999 — calls for per-tier
failure-and-recovery evidence so regressions in tier severity,
escalation counters (consecutive_failures via _record_failure),
and recovery transitions become visible before they hit production.

Solution

  • tests/unit/daemon/test_health_check_paths.py exercises all 13
    registered checks:
    • FAST: daemon_liveness (with recovery), disk_space, wal_size,
      source_availability, schema_version.
    • MEDIUM: fts_readiness, raw_failures (with recovery),
      stale_ingest_attempts, insight_freshness,
      repeated_stage_failures.
    • EXPENSIVE: db_integrity (with recovery), blob_integrity,
      embedding_coverage.
  • Recovery checks (daemon_liveness, raw_failures, db_integrity)
    force the degraded path, confirm consecutive_failures increments,
    then force the OK path and confirm the counter resets to zero —
    exercising the three distinct _record_failure invocation patterns
    used across health.py.
  • An autouse fixture (_reset_failure_counts) clears the module-level
    _failure_counts map so escalation counts never leak between tests.
  • Every test records a daemon.health.<check_name> evidence artifact
    via record_contract_evidence (tests/infra/contract_evidence.py,
    test(contracts): emit pytest evidence artifacts for surface contracts #1060) with bounded fields: severity_before, severity_after,
    consecutive_failures, tier.
  • EXPENSIVE-tier tests carry @pytest.mark.slow so the default
    devtools verify pytest selection stays fast.
  • Synthetic-only: status helpers (_raw_failure_info,
    _live_ingest_attempt_summary_info, _insight_freshness_info,
    _embedding_readiness_info, _check_daemon_liveness) and
    BlobStore.verify_all are monkey-patched; DB-backed checks (FTS gap,
    schema version, repeated stage failures, integrity recovery) write
    small SQLite files under workspace_env's tmp archive root. No
    private archive paths or real user data are referenced.
  • No changes to production code — the existing checks already expose
    the seams needed for synthetic coverage.

Verification

nix develop -c pytest tests/unit/daemon/test_health_check_paths.py
# 23 passed in 9.92s

nix develop -c pytest tests/unit/daemon/ -q
# 407 passed in 15.78s

nix develop -c mypy tests/unit/daemon/test_health_check_paths.py
# Success: no issues found in 1 source file

nix develop -c devtools verify --quick
# exit_code: 0, total_duration_s: 22.0

Closes #1146. Ref #999.

Summary by CodeRabbit

  • Tests
    • Added comprehensive unit tests for health-check functionality, validating success paths, degradation scenarios, and recovery transitions across all configured system tiers.

Review Change Stack

Adds tests/unit/daemon/test_health_check_paths.py covering all 13
registered checks in polylogue/daemon/health.py: OK path on a healthy
synthetic fixture plus at least one representative degraded path per
check. Three checks (one per tier) also pin the recovery transition with
consecutive_failures reset: daemon_liveness (FAST), raw_failures
(MEDIUM), db_integrity (EXPENSIVE).

Every test records daemon.health.<check_name> evidence via
record_contract_evidence with severity_before, severity_after, and
consecutive_failures. EXPENSIVE-tier tests are marked @pytest.mark.slow
so default devtools verify selection stays fast.

Synthetic-only: monkeypatches polylogue.daemon.status helpers and stubs
PRAGMA integrity_check + BlobStore.verify_all; DB-backed checks (FTS,
schema_version, repeated_stage_failures) use minimal in-tmp SQLite
files. No private archive paths or real user data.

Closes #1146. Ref #999.

Co-Authored-By: Claude <[email protected]>
@coderabbitai

coderabbitai Bot commented May 17, 2026 •

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: c5567fe2-386f-4d93-a637-d265b4cb28b8

📥 Commits

Reviewing files that changed from the base of the PR and between 2ab5201 and dc8458a.

📒 Files selected for processing (1)
  • tests/unit/daemon/test_health_check_paths.py

📝 Walkthrough

Walkthrough

This PR adds a comprehensive unit test module that validates health-check behavior across all FAST, MEDIUM, and EXPENSIVE tiers in polylogue/daemon/health.py. Tests cover OK paths, degradation transitions, recovery cycles, and failure-counter reset via contract evidence recording.

Changes

Daemon health check comprehensive path coverage

Layer / File(s) Summary
Test infrastructure, fixtures, and helpers
tests/unit/daemon/test_health_check_paths.py (lines 1–128)
Module docstring, imports, autouse fixture that resets _failure_counts per test, _record() helper to capture daemon.health.<check_name> evidence with severity transitions and consecutive-failure counters, and setup helpers (_init_messages_db(), _FakeSource) for simulating readiness gaps and filesystem availability.
FAST tier health checks (5 checks)
tests/unit/daemon/test_health_check_paths.py (lines 129–349)
Five FAST-tier tests: daemon_liveness (toggle liveness, verify recovery), disk_space (OK and critical-low via os.statvfs monkeypatch), wal_size (OK with no WAL, error with oversized file), source_availability (OK and WARNING when default source root exists/missing), schema_version (OK on fresh install, CRITICAL on incompatible schema). Each validates severity, message content, failure-counter progression, and records evidence.
MEDIUM tier health checks (5 checks)
tests/unit/daemon/test_health_check_paths.py (lines 350–592)
Five MEDIUM-tier tests: fts_readiness (OK and ERROR via controlled row counts), raw_failures (degraded-to-recovery via patched status helper), stale_ingest_attempts (OK and WARNING via patched attempt summary), insight_freshness (OK and ERROR via patched profile-readiness info), repeated_stage_failures (OK and ERROR via live_ingest_attempt rows). Each validates severity, consecutive-failures reset on recovery, and records evidence.
EXPENSIVE tier health checks (3 checks, marked slow)
tests/unit/daemon/test_health_check_paths.py (lines 593–757)
Three slow EXPENSIVE-tier tests: db_integrity (patched sqlite3.connect, verify recovery), blob_integrity (patched get_blob_store with controlled verify results), embedding_coverage (patched config and readiness info). Each validates severity transitions, failure-counter reset, and records evidence including pre-recovery failure counts.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~30 minutes

Possibly related issues

  • #1146: test(daemon): per-tier health check failure and recovery coverage — This PR directly implements the comprehensive per-tier test coverage scope and acceptance criteria described in the issue, addressing all registered health checks with OK-path, degradation-path, and recovery-transition tests plus contract evidence recording.

Poem

🐰 Per-tier the checks now dance and play,
Each path from failure back to OK—
With mocks and patches, health shines bright,
The daemon's heartbeat tested right! 💚

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/test/daemon-health-tier-coverage

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Sinity
Sinity merged commit c599586 into master May 17, 2026
2 of 3 checks passed
@Sinity
Sinity deleted the feature/test/daemon-health-tier-coverage branch May 17, 2026 04:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test(daemon): per-tier health check failure and recovery coverage

1 participant