Skip to content

fix(daemon): keep status probes bounded - #851

Merged
Sinity merged 1 commit into
masterfrom
feature/fix/daemon-status-responsive
May 6, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/fix/daemon-status-responsive

Conversation

@Sinity

@Sinity Sinity commented May 6, 2026

Copy link
Copy Markdown
Owner

Summary

Keeps polylogued status responsive while the daemon is converging a large archive.

Problem

During the Sinnix deployment of #847/#850, the daemon was healthy and had live attempt state in SQLite, but polylogued status --format json exceeded a 30s timeout while convergence was starting. The status path was doing work that scales with archive size or takes deep archive locks: recursive blob-size walking, deep readiness imports, async insight status, and duplicate status probes.

Solution

Make the local daemon status path bounded: blob size is reported as unmeasured 0, FTS readiness and insight freshness use small read-only SQLite probes, and JSON rendering reuses the typed DaemonStatus probe results instead of recomputing them. The live busy-daemon probe that timed out before returned in 1.7s with this branch.

Ref #845

Verification

  • ruff format --check polylogue/daemon/status.py tests/unit/daemon/test_daemon_status.py
  • ruff check polylogue/daemon/status.py tests/unit/daemon/test_daemon_status.py
  • mypy --strict polylogue/daemon/status.py tests/unit/daemon/test_daemon_status.py
  • pytest tests/unit/daemon/test_daemon_status.py -q → 8 passed in 10.84s
  • .venv/bin/polylogued status --format json against the live busy daemon → returned in 1.731s
  • devtools verify → verify: all checks passed
  • pre-push devtools verify --quick → verify: all checks passed

Problem: during production daemon convergence, polylogued status could exceed 30 seconds even though the daemon was healthy and the live attempt state was available in SQLite. Status was doing archive-size/deep-readiness work that does not belong on the critical status path.\n\nWhat changed: keep blob size as an unmeasured zero on the local status path, replace deep readiness/API probes with bounded read-only SQLite checks, and reuse the typed status probe results when rendering JSON instead of repeating them. Tests pin the single-probe behavior and lightweight readiness/freshness SQL.\n\nVerification: ruff format --check polylogue/daemon/status.py tests/unit/daemon/test_daemon_status.py; ruff check polylogue/daemon/status.py tests/unit/daemon/test_daemon_status.py; mypy --strict polylogue/daemon/status.py tests/unit/daemon/test_daemon_status.py; pytest tests/unit/daemon/test_daemon_status.py -q; .venv/bin/polylogued status --format json against the live busy daemon returned in 1.7s; devtools verify.
Copilot AI review requested due to automatic review settings May 6, 2026 21:02
@coderabbitai

coderabbitai Bot commented May 6, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@Sinity has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 38 minutes and 1 second before requesting another review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 2b4a2487-b439-47ad-802f-33d2b5af4e0b

📥 Commits

Reviewing files that changed from the base of the PR and between eef06cb and a43deb2.

📒 Files selected for processing (2)
  • polylogue/daemon/status.py
  • tests/unit/daemon/test_daemon_status.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/fix/daemon-status-responsive

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 419c359 into master May 6, 2026
4 checks passed
@Sinity
Sinity deleted the feature/fix/daemon-status-responsive branch May 6, 2026 21:02

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR keeps polylogued status responsive during large/locking daemon convergence by ensuring status probes are bounded and by reusing the already-computed DaemonStatus results when rendering JSON output.

Changes:

  • Make blob store size reporting constant-time by returning an unmeasured 0 (avoids recursive filesystem walks).
  • Replace “deep” readiness/insight status work with lightweight read-only SQLite probes (table presence + small counts).
  • Update daemon_status_payload() to reuse DaemonStatus fields instead of recomputing status sub-probes, and add unit tests covering the new bounded behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
polylogue/daemon/status.py Replaces expensive status probes with bounded SQLite/table checks; JSON payload now reuses the typed DaemonStatus results.
tests/unit/daemon/test_daemon_status.py Adds tests asserting bounded probe behavior and that JSON payload rendering doesn’t duplicate probe work.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sinity added a commit that referenced this pull request May 6, 2026
## 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
Sinity added a commit that referenced this pull request May 7, 2026
## Summary

Keeps `polylogued status` responsive while the daemon is converging a large archive.

## Problem

During the Sinnix deployment of #847/#850, the daemon was healthy and had live attempt state in SQLite, but `polylogued status --format json` exceeded a 30s timeout while convergence was starting. The status path was doing work that scales with archive size or takes deep archive locks: recursive blob-size walking, deep readiness imports, async insight status, and duplicate status probes.

## Solution

Make the local daemon status path bounded: blob size is reported as unmeasured `0`, FTS readiness and insight freshness use small read-only SQLite probes, and JSON rendering reuses the typed `DaemonStatus` probe results instead of recomputing them. The live busy-daemon probe that timed out before returned in 1.7s with this branch.

Ref #845

## Verification

- `ruff format --check polylogue/daemon/status.py tests/unit/daemon/test_daemon_status.py`
- `ruff check polylogue/daemon/status.py tests/unit/daemon/test_daemon_status.py`
- `mypy --strict polylogue/daemon/status.py tests/unit/daemon/test_daemon_status.py`
- `pytest tests/unit/daemon/test_daemon_status.py -q` → `8 passed in 10.84s`
- `.venv/bin/polylogued status --format json` against the live busy daemon → returned in `1.731s`
- `devtools verify` → `verify: all checks passed`
- pre-push `devtools verify --quick` → `verify: all checks passed`
Sinity added a commit that referenced this pull request May 7, 2026
## 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
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.

2 participants