Repository navigation
feat(daemon): add tiered health checks, config-driven notifications, maintenance docs - #920
Conversation
…maintenance docs
Add four new health checks across all three tiers:
- FAST: source availability (watch root existence and readability)
- MEDIUM: insight freshness (session profile gap detection), repeated
stage failures (recent ingest attempt failure rate)
- EXPENSIVE: blob integrity (bounded BlobStore content verification),
embedding coverage (coverage + failure count when enabled)
Make notification backend selection config-driven via
PolylogueConfig.notification_backend ("log" only for now, with
_resolve_backend() ready for future backends). Add health check
interval and tier config keys with env var overrides.
Document daemon-owned vs operator-owned maintenance task split in
docs/daemon.md, including Litestream/restic integration guidance.
Ref #830
Co-Authored-By: Claude Opus 4.7 <[email protected]>
|
Warning Rate limit exceeded
To continue reviewing without waiting, purchase usage credits in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (6)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ddd8d5d79c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| "SELECT COUNT(*) FROM (" | ||
| "SELECT 1 FROM live_ingest_attempt " | ||
| "WHERE status = 'failed' " | ||
| "ORDER BY started_at DESC LIMIT 20" | ||
| ")" |
There was a problem hiding this comment.
Count failures within the same recent-attempt window
failed_recent is computed from the latest 20 failed rows overall, not from the latest 20 attempts overall, so old failures can trigger warnings/errors even when the most recent attempts are healthy. This makes the repeated_stage_failures health check report incorrect failure rates (and can even produce impossible ratios) because it compares two different populations.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Pull request overview
This PR completes remaining #830 scope by expanding the daemon’s tiered health checks, making notification delivery backend configurable via runtime config, wiring periodic health-check scheduling to config, and documenting daemon vs. operator maintenance responsibilities.
Changes:
- Add new FAST/MEDIUM/EXPENSIVE health checks (source availability, insight freshness, repeated stage failures, blob integrity, embedding coverage).
- Add config-driven notification backend selection and new health/notification config keys (TOML + env overrides).
- Update daemon periodic health loop to use configured tiers/interval and document operational maintenance guidance.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/storage/test_backend.py | Removes stray merge-artifact lines in a storage test (but leaves a problematic duplicate block). |
| polylogue/daemon/notifications.py | Adds backend factory resolution and config-based default backend selection. |
| polylogue/daemon/health.py | Implements additional tiered health checks and wires them into tier runners. |
| polylogue/daemon/cli.py | Makes periodic health-check tiers/interval and notification routing config-driven. |
| polylogue/config.py | Adds new config keys, TOML parsing, env overrides, and TOML rendering for notifications/health. |
| docs/daemon.md | Documents health tiers, notification backend config, and daemon-owned vs operator-owned maintenance tasks. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # FTS should have both messages (the original m1 via repair, | ||
| # and m2 via active trigger after restore) | ||
| ||||||| parent of e895ccf5 (refactor(storage): remove 4 unused session profile FTS tables and 12 triggers (#817)) | ||
| """FTS triggers must be active even after an exception during ingest (#817).""" | ||
| import sqlite3 | ||
|
|
||
| from polylogue.storage.sqlite.schema_ddl_actions import ACTION_EVENT_DDL |
| elif missing and not unreadable: | ||
| severity = HealthSeverity.WARNING | ||
| message = f"{available}/{len(sources)} source(s) available, missing: {', '.join(missing)}" | ||
| elif unreadable: | ||
| severity = HealthSeverity.ERROR | ||
| message = f"{available}/{len(sources)} source(s) available, unreadable: {', '.join(unreadable)}" | ||
| else: | ||
| severity = HealthSeverity.WARNING | ||
| message = f"{available}/{len(sources)} source(s) available" |
| consecutive_failures=_record_failure("repeated_stage_failures", False), | ||
| ) | ||
| try: | ||
| conn = sqlite3.connect(str(dbf)) |
| "SELECT 1 FROM live_ingest_attempt " | ||
| "WHERE status = 'failed' " | ||
| "ORDER BY started_at DESC LIMIT 20" | ||
| ")" |
| if not tiers: | ||
| tiers = {HealthTier.FAST, HealthTier.MEDIUM} | ||
|
|
||
| await asyncio.sleep(interval) |
First production-grade hardening slice for #830 on top of the existing daemon/status substrate. Three new modules and modifications to status and CLI; PR #920 / #903 land the remaining checks and config wiring on top of this. - `polylogue/daemon/health.py`: `HealthTier` enum (FAST / MEDIUM / EXPENSIVE), `HealthAlert` typed model with severity and consecutive-failure tracking, `DaemonHealth` aggregation, and `check_health()` runner. Fast checks cover liveness/disk/WAL; medium covers FTS readiness, raw failure counts, and stale ingest attempts; expensive runs PRAGMA integrity_check. - `polylogue/daemon/backup.py`: `backup_archive()` using `VACUUM INTO` with a file-copy fallback; `--check` dry-run; optional blob-store backup via `--include-blobs`. - `polylogue/daemon/notifications.py`: `NotificationBackend` protocol with `LogNotificationBackend` routing alerts through the structured logger by severity. - `polylogue/daemon/status.py`: `DaemonStatus` gains `health: DaemonHealth`, populated by `build_daemon_status()` and exposed in the JSON payload and text formatter. - `polylogue/daemon/cli.py`: `polylogued health` subcommand with tier selection (`--tier`, `--expensive`), JSON output, and deterministic exit codes (1 on error/critical). - `polylogue/cli/commands/backup.py` + registration: `polylogue backup` with `--output-dir`, `--check`, `--include-blobs`. Closes #830 on the substrate axis; remaining health-check additions land in PR #920. Refs #830
Completes #830 on top of the health/backup substrate from PRs #898 / #903: four new health checks across the FAST/MEDIUM/ EXPENSIVE tiers, config-driven notification backend selection, and operator vs. daemon maintenance documentation. - `polylogue/daemon/health.py`: - FAST: `_check_source_availability_fast()` verifies each watch root from `default_sources()` exists and is readable. - MEDIUM: `_check_insight_freshness_medium()` flags >10% gap between session-profile coverage and total conversations. - MEDIUM: `_check_repeated_stage_failures_medium()` reads `live_ingest_attempt` for recent failure rates and samples the latest error. - EXPENSIVE: `_check_blob_integrity_expensive()` runs a bounded `BlobStore.verify_all(max_failures=5)` content check. - EXPENSIVE: `_check_embedding_coverage_expensive()` reports coverage and failure count when embeddings are enabled. - `polylogue/daemon/notifications.py` + `config.py`: backend factory `_resolve_backend(backend_name)` (currently log-only), resolved from `PolylogueConfig` so tier set, interval, and backend can be set via TOML or the matching env vars. - `polylogue/daemon/cli.py`: `_periodic_health_check()` reads config to pick the tier set and backend. - `docs/daemon.md`: separates daemon-owned and operator-owned maintenance tasks. Refs #830
First production-grade hardening slice for #830 on top of the existing daemon/status substrate. Three new modules and modifications to status and CLI; PR #920 / #903 land the remaining checks and config wiring on top of this. - `polylogue/daemon/health.py`: `HealthTier` enum (FAST / MEDIUM / EXPENSIVE), `HealthAlert` typed model with severity and consecutive-failure tracking, `DaemonHealth` aggregation, and `check_health()` runner. Fast checks cover liveness/disk/WAL; medium covers FTS readiness, raw failure counts, and stale ingest attempts; expensive runs PRAGMA integrity_check. - `polylogue/daemon/backup.py`: `backup_archive()` using `VACUUM INTO` with a file-copy fallback; `--check` dry-run; optional blob-store backup via `--include-blobs`. - `polylogue/daemon/notifications.py`: `NotificationBackend` protocol with `LogNotificationBackend` routing alerts through the structured logger by severity. - `polylogue/daemon/status.py`: `DaemonStatus` gains `health: DaemonHealth`, populated by `build_daemon_status()` and exposed in the JSON payload and text formatter. - `polylogue/daemon/cli.py`: `polylogued health` subcommand with tier selection (`--tier`, `--expensive`), JSON output, and deterministic exit codes (1 on error/critical). - `polylogue/cli/commands/backup.py` + registration: `polylogue backup` with `--output-dir`, `--check`, `--include-blobs`. Closes #830 on the substrate axis; remaining health-check additions land in PR #920. Refs #830
Completes #830 on top of the health/backup substrate from PRs #898 / #903: four new health checks across the FAST/MEDIUM/ EXPENSIVE tiers, config-driven notification backend selection, and operator vs. daemon maintenance documentation. - `polylogue/daemon/health.py`: - FAST: `_check_source_availability_fast()` verifies each watch root from `default_sources()` exists and is readable. - MEDIUM: `_check_insight_freshness_medium()` flags >10% gap between session-profile coverage and total conversations. - MEDIUM: `_check_repeated_stage_failures_medium()` reads `live_ingest_attempt` for recent failure rates and samples the latest error. - EXPENSIVE: `_check_blob_integrity_expensive()` runs a bounded `BlobStore.verify_all(max_failures=5)` content check. - EXPENSIVE: `_check_embedding_coverage_expensive()` reports coverage and failure count when embeddings are enabled. - `polylogue/daemon/notifications.py` + `config.py`: backend factory `_resolve_backend(backend_name)` (currently log-only), resolved from `PolylogueConfig` so tier set, interval, and backend can be set via TOML or the matching env vars. - `polylogue/daemon/cli.py`: `_periodic_health_check()` reads config to pick the tier set and backend. - `docs/daemon.md`: separates daemon-owned and operator-owned maintenance tasks. Refs #830
|
Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.
Only the rows listed above are dispositioned. Held findings remain open. |
Summary
Completes the remaining work in #830: four new health checks across all three tiers, config-driven notification backend selection, and daemon vs. operator maintenance documentation.
Problem
issue #830 specified tiered health, backup, alerts, and maintenance. PRs #898 and #903 landed the health infrastructure (typed
DaemonHealth, fast/medium/expensive tiers, WAL checkpointing, pidfile locking). Four health checks, config-driven notifications, and maintenance docs remained.Solution
New health checks (health.py)
_check_source_availability_fast()— verifies each watch root fromdefault_sources()exists and is readable_check_insight_freshness_medium()— session profile coverage vs. total conversations; warns at >10% gap_check_repeated_stage_failures_medium()— recent ingest attempt failure rate fromlive_ingest_attempttable; samples latest error for context_check_blob_integrity_expensive()— boundedBlobStore.verify_all(max_failures=5)content verification_check_embedding_coverage_expensive()— coverage percentage + failure count when embedding is enabled; OK when disabledConfig-driven notifications (notifications.py + config.py)
_resolve_backend(backend_name)factory — currently supports"log"only, ready for future backendssend_notifications()now resolves backend from config when none is explicitly passedPolylogueConfiggainsnotification_backend,health_check_interval_s,health_check_tiersproperties with env var overrides (POLYLOGUE_NOTIFICATION_BACKEND,POLYLOGUE_HEALTH_CHECK_INTERVAL_S,POLYLOGUE_HEALTH_CHECK_TIERS)[notifications]and[health]are parsed and renderedDaemon wiring (cli.py)
_periodic_health_check()now loadsPolylogueConfigto determine health check interval and tier set. Notifications go through the configured backend.Maintenance docs (docs/daemon.md)
Added clear split between daemon-owned tasks (WAL checkpoint, heartbeat, FTS convergence, health checks) and operator-owned tasks (database backup, blob store backup, vacuum, Litestream replication). Includes Litestream and restic integration guidance.
What was done
_check_source_availability_fast()— wired into fast checks_check_insight_freshness_medium()— wired into medium checks_check_repeated_stage_failures_medium()— wired into medium checks_check_blob_integrity_expensive()— wired into expensive checks_check_embedding_coverage_expensive()— wired into expensive checks_resolve_backend()PolylogueConfigproperties for notification/health config_periodic_health_check()uses config for tiers and intervalWhat's the gap
"log"(email, Slack, webhook) are not implemented — the_resolve_backend()factory is structured to accept themVerification
Ref #830
Co-Authored-By: Claude Opus 4.7 [email protected]