Repository navigation
perf(daemon): keep live convergence status bounded (#845) - #854
Conversation
Keep daemon status payloads usable when thousands of live cursor rows are failed or excluded by reporting exact counts with a bounded path sample. Heartbeat full-ingest file scanning, blob materialization, and worker-write handoff with the current path and payload-read counts so active convergence does not look stale during long storage phases. Ref #845
Add schema v9 with provider_events.source_message_id and attachment_refs.message_id indexes so deleting messages during conversation replacement does not scan large child tables. The daemon catch-up exposed this on the production archive as repeated provider_events scans during live convergence. Existing v8 archives upgrade in place. Ref #845
Move live-batch helper types and parsing utilities out of the daemon batch executor, split the new focused tests out of oversized unit files, and collapse repeated schema upgrade-tail planning. This keeps the #845 follow-up under the repository file-size budgets without changing the daemon behavior or schema semantics. Ref #845
Regenerate the topology projection after splitting live batch helper code into its own module. Ref #845
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (16)
📝 WalkthroughWalkthroughThis PR caps live cursor file samples in daemon status reporting while preserving exact counts, adds heartbeat emissions during storage operations, introduces schema v9 with message foreign-key indexes to optimize conversation queries, refactors live batch ingestion internals into a new batch_support module, and updates documentation accordingly. ChangesDaemon Status Sampling
Schema v8 → v9 Upgrade with Message Foreign-Key Indexes
Live Batch Ingestion Refactoring
Supporting Documentation
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Possibly related issues
Possibly related PRs
Suggested labels
Poem
✨ Finishing Touches📝 Generate docstrings
🧪 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.
Pull request overview
This PR addresses daemon convergence scalability issues observed on large live archives by (1) bounding daemon status payloads for live cursor failures, (2) adding more granular heartbeats during full-ingest work so “busy vs. stuck” is clearer, and (3) introducing schema v9 FK-supporting indexes to avoid pathological SQLite scans during conversation replacement.
Changes:
- Cap live-cursor failing/excluded file samples in
polylogued statuswhile preserving exact counts (failed/excluded/retry/backoff). - Add full-ingest heartbeats (current path + payload-read counters) and extract shared live-batch helper code into
batch_support.pywith targeted unit tests. - Bump SQLite schema to v9 and add indexes on
provider_events(source_message_id)andattachment_refs(message_id), including an in-place v8→v9 upgrade path and upgrade tests.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
polylogue/daemon/status.py |
Bounds live cursor failure samples in daemon status; adds omitted/sample counts and updates plain output formatting. |
polylogue/sources/live/batch.py |
Uses shared helpers; adds richer heartbeats during full ingest phases (scan/blob copy/worker wait). |
polylogue/sources/live/batch_support.py |
New module factoring out live batch helper logic (fingerprinting, grouping, throttled heartbeat, provider detection). |
polylogue/storage/sqlite/schema_ddl.py |
Bumps SCHEMA_VERSION from 8 to 9. |
polylogue/storage/sqlite/schema_ddl_provider_events.py |
Adds idx_provider_events_source_message to support FK delete/set-null performance. |
polylogue/storage/sqlite/schema_ddl_archive.py |
Adds idx_attachment_refs_message to support FK delete/set-null performance. |
polylogue/storage/sqlite/schema.py |
Allows upgrade action upgrade_v8_to_v9 in sync/async schema ensure paths. |
polylogue/storage/sqlite/schema_bootstrap.py |
Adds v8→v9 upgrade plan + tail upgrade refactor; registers new index extension descriptors. |
tests/unit/daemon/test_daemon_status.py |
Adds test ensuring status caps failing file samples and reports omitted counts. |
tests/unit/sources/test_live_watcher.py |
Updates monkeypatch target after helper extraction to batch_support._path_size. |
tests/unit/sources/test_live_batch_support.py |
New unit test verifying full-ingest heartbeat emits current path + byte counters. |
tests/unit/storage/test_backend.py |
Extends schema snapshot catalog expectations to include the two new indexes. |
tests/unit/storage/test_schema_upgrades.py |
New tests covering v8→v9 index upgrade behavior and upgrade plan contents. |
docs/plans/topology-target.yaml |
Refreshes topology LOC/projections to include new module and updated file sizes. |
docs/topology-status.md |
Updates generated topology status counts. |
CHANGELOG.md |
Notes bounded status samples, ingest heartbeats, and schema v9 FK indexes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
## Summary Replace the daemon startup FTS coverage check's direct `COUNT(*) FROM messages_fts` calls with the existing docsize-backed FTS status helper. This keeps daemon startup bounded enough to report liveness before live convergence work resumes on large archives. ## Problem Production deployment of #854 showed `polylogued` blocked before liveness in `_ensure_fts_startup_readiness`. `py-spy` showed the daemon inside the startup FTS check, and the process had already read multiple GB while `PRAGMA user_version` still showed the archive had not reached the later convergence/schema work. The repo already documents that `COUNT(*)` on FTS5 virtual tables is O(N); daemon startup had reintroduced that pattern. ## Solution `polylogue/daemon/cli.py` now uses `fts_index_status_sync()`, which counts `messages_fts_docsize`, for both the initial gap check and post-rebuild logging. A focused daemon CLI test proves the startup check schedules a rebuild from cheap counts and never issues `COUNT(*) FROM messages_fts`. ## Verification - `ruff format --check polylogue/daemon/cli.py tests/unit/daemon/test_daemon_cli.py` -> `2 files already formatted` - `ruff check polylogue/daemon/cli.py tests/unit/daemon/test_daemon_cli.py` -> `All checks passed!` - `mypy --strict polylogue/daemon/cli.py tests/unit/daemon/test_daemon_cli.py` -> `Success: no issues found in 2 source files` - `pytest tests/unit/daemon/test_daemon_cli.py -q` -> `12 passed in 11.41s` - `devtools verify` -> `verify: all checks passed` - `git push` pre-push quick gate -> `verify: all checks passed` Ref #845.
## Summary Follow-up to the daemon-first #845 work after deploying #847/#850/#851 on the workstation. The live daemon exposed two deployment-scale problems: status payloads became huge with thousands of retryable live cursor failures, and full-ingest attempts could look stale while the worker was actually busy inside storage replacement. The same live run also exposed an unindexed SQLite foreign-key path that made conversation replacement scan millions of provider events. ## Problem During the Sinnix switch, `polylogued status --format json` returned quickly after #851 but emitted thousands of file paths. The active attempt was marked stale in `full_blob_copy`, while `py-spy` showed the daemon was actually in `_process_ingest_batch_sync -> replace_conversation_runtime_state_sync`. The live archive has ~4.0M `provider_events` rows, and `provider_events.source_message_id` referenced `messages(message_id)` without an index, so deleting messages during replacement caused repeated child-table scans and ~91GB of read I/O before I stopped the old service. ## Solution - Bound live cursor file samples in daemon status while preserving exact failed/excluded/retry counts. - Heartbeat full-ingest file scanning, blob materialization, and worker-write handoff with current path and payload-read counters. - Add schema v9 with indexes on `provider_events(source_message_id)` and `attachment_refs(message_id)` so message deletion during replacement has supporting FK indexes; v8 archives upgrade in place. - Split live-batch helper code and the new focused tests out of oversized modules, then refresh topology projections. ## Verification - `ruff check polylogue/sources/live/batch.py polylogue/sources/live/batch_support.py polylogue/storage/sqlite/schema_bootstrap.py tests/unit/sources/test_live_batch_support.py tests/unit/storage/test_schema_upgrades.py tests/unit/sources/test_live_watcher.py tests/unit/storage/test_backend.py` -> all checks passed. - `mypy polylogue/sources/live/batch.py polylogue/sources/live/batch_support.py polylogue/storage/sqlite/schema_bootstrap.py tests/unit/sources/test_live_watcher.py tests/unit/sources/test_live_batch_support.py tests/unit/storage/test_backend.py tests/unit/storage/test_schema_upgrades.py` -> success, no issues. - `pytest tests/unit/sources/test_live_watcher.py tests/unit/sources/test_live_batch_support.py tests/unit/daemon/test_daemon_status.py tests/unit/storage/test_backend.py tests/unit/storage/test_schema_upgrades.py tests/unit/devtools/test_verify_file_budgets.py -q` -> 110 passed. - `devtools verify-file-budgets` -> clean. - `devtools render-all --check` -> OK. - `devtools verify` -> all checks passed. - pre-push quick verification -> all checks passed. Ref #845
Production deployment of #854 showed `polylogued` blocked before liveness inside `_ensure_fts_startup_readiness`. A py-spy trace showed the daemon inside the startup FTS check while `PRAGMA user_version` reported the archive had not yet reached later convergence/schema work; multiple GB had already been read because the check used `COUNT(*) FROM messages_fts`, which is O(N) on FTS5 virtual tables (the repo already documents that pattern). Follow-up to PR #854 after deployment exposed the regression. - `polylogue/daemon/cli.py`: replaces the direct `COUNT(*) FROM messages_fts` calls with the existing `fts_index_status_sync()` helper that counts `messages_fts_docsize` for both the initial gap check and the post-rebuild logging, keeping daemon startup bounded enough to report liveness before live convergence work resumes on large archives. - `tests/unit/daemon/test_daemon_cli.py`: focused test proves the startup check schedules a rebuild from cheap counts and never issues `COUNT(*) FROM messages_fts`. Refs #845
`polylogue status` was reading fields from a pre-#854 `DaemonStatus` shape and partially fabricating values when those fields were missing. After the typed `DaemonStatus` redesign the command was stale and showed misleading data such as a constant uptime or a wrong daemon-running flag. - `polylogue/cli/commands/status.py`: rewritten against the current `DaemonStatus` Pydantic model. Adds `--format json` for machine consumers and a deterministic text format for humans. - `docs/verification-catalog.md`: regenerated after the command-help surface change. Refs #825
Production deployment of #854 showed `polylogued` blocked before liveness inside `_ensure_fts_startup_readiness`. A py-spy trace showed the daemon inside the startup FTS check while `PRAGMA user_version` reported the archive had not yet reached later convergence/schema work; multiple GB had already been read because the check used `COUNT(*) FROM messages_fts`, which is O(N) on FTS5 virtual tables (the repo already documents that pattern). Follow-up to PR #854 after deployment exposed the regression. - `polylogue/daemon/cli.py`: replaces the direct `COUNT(*) FROM messages_fts` calls with the existing `fts_index_status_sync()` helper that counts `messages_fts_docsize` for both the initial gap check and the post-rebuild logging, keeping daemon startup bounded enough to report liveness before live convergence work resumes on large archives. - `tests/unit/daemon/test_daemon_cli.py`: focused test proves the startup check schedules a rebuild from cheap counts and never issues `COUNT(*) FROM messages_fts`. Refs #845
`polylogue status` was reading fields from a pre-#854 `DaemonStatus` shape and partially fabricating values when those fields were missing. After the typed `DaemonStatus` redesign the command was stale and showed misleading data such as a constant uptime or a wrong daemon-running flag. - `polylogue/cli/commands/status.py`: rewritten against the current `DaemonStatus` Pydantic model. Adds `--format json` for machine consumers and a deterministic text format for humans. - `docs/verification-catalog.md`: regenerated after the command-help surface change. Refs #825
Summary
Follow-up to the daemon-first #845 work after deploying #847/#850/#851 on the workstation. The live daemon exposed two deployment-scale problems: status payloads became huge with thousands of retryable live cursor failures, and full-ingest attempts could look stale while the worker was actually busy inside storage replacement. The same live run also exposed an unindexed SQLite foreign-key path that made conversation replacement scan millions of provider events.
Problem
During the Sinnix switch,
polylogued status --format jsonreturned quickly after #851 but emitted thousands of file paths. The active attempt was marked stale infull_blob_copy, whilepy-spyshowed the daemon was actually in_process_ingest_batch_sync -> replace_conversation_runtime_state_sync. The live archive has ~4.0Mprovider_eventsrows, andprovider_events.source_message_idreferencedmessages(message_id)without an index, so deleting messages during replacement caused repeated child-table scans and ~91GB of read I/O before I stopped the old service.Solution
provider_events(source_message_id)andattachment_refs(message_id)so message deletion during replacement has supporting FK indexes; v8 archives upgrade in place.Verification
ruff check polylogue/sources/live/batch.py polylogue/sources/live/batch_support.py polylogue/storage/sqlite/schema_bootstrap.py tests/unit/sources/test_live_batch_support.py tests/unit/storage/test_schema_upgrades.py tests/unit/sources/test_live_watcher.py tests/unit/storage/test_backend.py-> all checks passed.mypy polylogue/sources/live/batch.py polylogue/sources/live/batch_support.py polylogue/storage/sqlite/schema_bootstrap.py tests/unit/sources/test_live_watcher.py tests/unit/sources/test_live_batch_support.py tests/unit/storage/test_backend.py tests/unit/storage/test_schema_upgrades.py-> success, no issues.pytest tests/unit/sources/test_live_watcher.py tests/unit/sources/test_live_batch_support.py tests/unit/daemon/test_daemon_status.py tests/unit/storage/test_backend.py tests/unit/storage/test_schema_upgrades.py tests/unit/devtools/test_verify_file_budgets.py -q-> 110 passed.devtools verify-file-budgets-> clean.devtools render-all --check-> OK.devtools verify-> all checks passed.Ref #845
Summary by CodeRabbit
Release Notes