Skip to content

perf(daemon): use indexed action FTS probe - #1035

Merged
Sinity merged 1 commit into
masterfrom
feature/perf/indexed-action-fts-probe
May 15, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/perf/indexed-action-fts-probe

Conversation

@Sinity

@Sinity Sinity commented May 15, 2026 •

Copy link
Copy Markdown
Owner

Summary

Use the indexed action_events base table to decide whether changed conversations have action rows before repairing action-event FTS during daemon convergence.

Problem

After #1034 removed the full source-file rehash path, the live production daemon still accumulated heavy reads while converging changed files. py-spy showed the remaining busy thread inside _action_fts_has_rows_for_conversations, which queried action_events_fts by conversation_id. On the production archive this behaves like an FTS-table scan during catch-up.

Solution

The repair decision now probes action_events(conversation_id) instead. That table has normal indexes, and the production query plan uses a covering index. The daemon still repairs or inserts the full action FTS rows from the persisted base data; only the existence probe changes.

Verification

  • pytest tests/unit/daemon/test_convergence_stages.py -q --tb=short → 10 passed in 7.93s
  • ruff check polylogue/daemon/convergence_stages.py tests/unit/daemon/test_convergence_stages.py → All checks passed!
  • Push hook quick baseline → exit_code: 0
  • Production query-plan check: EXPLAIN QUERY PLAN SELECT 1 FROM action_events WHERE conversation_id IN (...) LIMIT 1 → SEARCH action_events USING COVERING INDEX idx_action_events_sort

Summary by CodeRabbit

  • Bug Fixes
    • Improved the reliability and accuracy of search index maintenance for action events by enhancing how the system determines when repairs are necessary.

Review Change Stack

Problem: live catch-up convergence checked action_events_fts directly to decide whether to repair or insert action FTS rows. On the production archive that probe sat inside the FTS virtual table during catch-up, keeping the daemon in heavy SQLite reads after the source-file rehash path was fixed.

What changed: probe the indexed action_events base table by conversation_id instead. Repairing from the base table still converges the full action FTS state, but the decision no longer requires scanning the FTS table.

Verification:
- pytest tests/unit/daemon/test_convergence_stages.py -q --tb=short
- ruff check polylogue/daemon/convergence_stages.py tests/unit/daemon/test_convergence_stages.py
- EXPLAIN QUERY PLAN SELECT 1 FROM action_events WHERE conversation_id IN (...) LIMIT 1 -> uses covering index
@coderabbitai

coderabbitai Bot commented May 15, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 3bb0c1c5-848f-4fbb-9254-19bddc8d63c0

📥 Commits

Reviewing files that changed from the base of the PR and between d1fc26b and 2eb7dfd.

📒 Files selected for processing (2)
  • polylogue/daemon/convergence_stages.py
  • tests/unit/daemon/test_convergence_stages.py

📝 Walkthrough

Walkthrough

This PR refactors the FTS action-event repair decision logic in _repair_changed_conversation_fts() to branch on the presence of action_events base table rows rather than checking the FTS index itself. A new helper _action_events_exist_for_conversations() performs this existence check, and tests are updated to validate the probe and integration.

Changes

Action-event FTS repair base table check

Layer / File(s) Summary
Action-event existence probe and FTS repair branching
polylogue/daemon/convergence_stages.py
_repair_changed_conversation_fts() branches on a new _action_events_exist_for_conversations() helper that checks for rows in the action_events base table (not the FTS index) for the target conversation IDs.
Test coverage for base table probe and repair integration
tests/unit/daemon/test_convergence_stages.py
Test imports add sqlite3 and cast. The existing repair test's mock is switched from _action_fts_has_rows_for_conversations to _action_events_exist_for_conversations. A new test validates that the probe queries the base table with correct conversation ID parameters and returns expected truthy results.

🎯 2 (Simple) | ⏱️ ~12 minutes

A rabbit hops with glee,
Base tables now the key,
No FTS confusion here,
Action events crystal clear! 🐰✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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 clearly and specifically describes the main change: switching to use an indexed action_events table probe instead of the FTS table for the daemon's action event repair decision.
Description check ✅ Passed The description includes all major required sections: Summary, Problem (with context about PR #1034 and production profiling), Solution (explaining the indexed table change), Verification (with specific test commands and results), and omits the Changelog section appropriately for a performance improvement.
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/perf/indexed-action-fts-probe

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 62193c7 into master May 15, 2026
4 checks passed
@Sinity
Sinity deleted the feature/perf/indexed-action-fts-probe branch May 15, 2026 01:42
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