Skip to content

fix(cli): keep status responsive under ingest - #1438

Merged
Sinity merged 1 commit into
masterfrom
feature/fix/status-under-ingest
May 23, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/fix/status-under-ingest

Conversation

@Sinity

@Sinity Sinity commented May 23, 2026 •

Copy link
Copy Markdown
Owner

Summary

Keep polylogue status usable while the daemon is ingesting by bounding the daemon probe and making the direct SQLite fallback use cheap readiness counters.

Problem

The FTS trigger-safety fix keeps FTS current, but operator status could still become unavailable under live ingest pressure. If /api/status was busy, the CLI waited too long and then the direct fallback still touched large read-model paths: full message counts and embedding retrieval-band status could scan expensive tables. That made it hard to confirm that FTS was actually ready during catch-up.

Solution

  • Bound the explicit daemon status probe to 3s, then fall back to local read-only SQLite.
  • Use conversation_stats for message totals when present instead of COUNT(*) FROM messages.
  • Keep FTS fallback coverage based on messages_fts_docsize, not the FTS virtual table.
  • Let embedding status payloads skip retrieval-band scans, and use that cheaper mode from direct CLI status.
  • Add tests for the short timeout/fallback path and the stats-backed direct status query shape.

Verification

  • pytest tests/unit/cli/test_status.py tests/unit/storage/test_embedding_stats.py tests/unit/storage/test_vec.py -q -> 53 passed.
  • ruff format --check polylogue/cli/commands/status.py polylogue/storage/embeddings/status_payload.py tests/unit/cli/test_status.py && ruff check polylogue/cli/commands/status.py polylogue/storage/embeddings/status_payload.py tests/unit/cli/test_status.py -> passed.
  • mypy polylogue/cli/commands/status.py polylogue/storage/embeddings/status_payload.py tests/unit/cli/test_status.py -> success.
  • POLYLOGUE_DAEMON_URL=http://127.0.0.1:1 timeout 12 python -m polylogue.cli --plain status against the real archive returned FTS indexed: 100.0%.
  • devtools verify --quick -> passed in 43.39s.

Ref #1437

Summary by CodeRabbit

Release Notes

  • Performance
    • Status command now returns results faster when unable to reach the daemon
    • Optimized database query performance for status report generation

Review Change Stack

Problem: when the daemon API was busy during live ingest, polylogue status could wait on the daemon and then fall back to direct SQLite work that still scanned large read models. That left the operator without a reliable FTS readiness view precisely during catch-up.\n\nWhat changed: bound the explicit daemon status probe, use read-only fallback connections, derive message totals from conversation_stats when present, and skip retrieval-band scans in the direct embedding summary. The fallback still reports archive, FTS, and embedding readiness, but avoids expensive action-event status work.\n\nVerification: pytest tests/unit/cli/test_status.py tests/unit/storage/test_embedding_stats.py tests/unit/storage/test_vec.py -q; ruff format --check + ruff check on touched files; mypy on touched files; real-archive fallback with POLYLOGUE_DAEMON_URL=http://127.0.0.1:1 returned FTS 100.0%.
@coderabbitai

coderabbitai Bot commented May 23, 2026 •

Copy link
Copy Markdown

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

The PR optimizes the status CLI command's fallback path when the daemon is unavailable. It reduces the HTTP timeout from 30 seconds to 3 seconds, introduces fast SQLite counting helpers, switches to readonly connections, adds an include_retrieval_bands parameter to embedding_status_payload, and updates tests to validate the new behavior and enforce efficient query patterns.

Changes

Status Command Optimization

Layer / File(s) Summary
Embedding status payload parameter extension
polylogue/storage/embeddings/status_payload.py, polylogue/cli/commands/status.py
embedding_status_payload now accepts a keyword-only include_retrieval_bands parameter (default True) and forwards it to read_embedding_stats_sync. The status command calls this parameter with False to exclude retrieval bands from the embedding status payload.
SQLite fallback optimization with fast counting and readonly connections
polylogue/cli/commands/status.py
HTTP timeout constant is reduced from 30s to 3s to trigger fallback sooner. New helper functions _table_exists and _fast_message_count efficiently compute message counts by summing conversation_stats when available, with fallback to counting messages. Both JSON and human-readable status fallback paths switch to open_readonly_connection and use the new fast counting logic.
Test coverage for timeout fallback and fast counting behavior
tests/unit/cli/test_status.py
Test imports are updated to include CliRunner and status_command. FakeConn.execute now accepts query parameters, records SQL statements, enforces no direct COUNT(*) against messages or messages_fts, and returns targeted row counts. Tests patch open_readonly_connection instead of open_connection. A new test verifies that when the daemon probe times out, the code falls back to _show_direct_status and exits successfully.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • Sinity/polylogue#1427: Modifies the _FULL_TIMEOUT_S HTTP timeout constant in the same status command fallback path.

Poem

A rabbit hops through timeout lands,
Where SQLite efficiently stands—
No daemon? No worries, we'll count with speed,
Fast helpers and readonly—all that we need! 🐰✨
The embedding bands bow, the queries align,
Status command shines, now optimized and fine.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 43.75% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(cli): keep status responsive under ingest' directly and concisely summarizes the main change: improving CLI status responsiveness during daemon ingestion.
Description check ✅ Passed The pull request description comprehensively covers all required template sections: Summary, Problem, Solution, Verification, and Risks. All sections are well-populated with clear, specific details.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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/fix/status-under-ingest

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 9974bfb into master May 23, 2026
5 of 6 checks passed
@Sinity
Sinity deleted the feature/fix/status-under-ingest branch May 23, 2026 13:06

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bfccd96544

ℹ️ 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".

Comment thread polylogue/cli/commands/status.py Resolved
Comment thread polylogue/cli/commands/status.py Resolved
@Sinity

Sinity commented Oct 1, 2026

Copy link
Copy Markdown
Owner Author

Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.

  • 61.F058 / P2: fixed-already at the checked revision: An in-flight operation failure uses the unavailable renderer, which explicitly says daemon liveness was not observed at polylogue/cli/commands/status.py:918. It no longer renders the old daemon-not-running archive fallback for that failure.
  • 61.F059 / P2: fixed-already at the checked revision: The replacement search-readiness producer uses the FTS derivation partition inspection rather than dividing indexed rows by cached conversation statistics. Its denominator is inspection.required_rows at polylogue/operations/daemon_status.py:824.

Only the rows listed above are dispositioned. Held findings remain open.

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.

1 participant