Skip to content

perf(maintenance): target stale session insight repairs - #1471

Merged
Sinity merged 1 commit into
masterfrom
feature/fix/session-insight-targeted-repair
May 24, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/fix/session-insight-targeted-repair

Conversation

@Sinity

@Sinity Sinity commented May 24, 2026

Copy link
Copy Markdown
Owner

Summary

Use stale session-profile candidate IDs for session-insight repair before escalating to a whole-archive session insight rebuild.

Problem

Live daemon catch-up work has repeatedly shown that full session insight rebuilds are one of the largest remaining IO/RAM risks. The status layer already exposes stale profile candidates, but repair_session_insights ignored that bounded set and called rebuild_session_insights_sync(..., conversation_ids=None) whenever no explicit IDs were supplied.

Solution

  • Import session_profile_repair_candidate_ids_sync into the repair path.
  • When row debt exists and the caller did not supply explicit IDs, rebuild stale profile candidates first.
  • Refresh status after the targeted pass.
  • Preserve correctness by falling back to the broad rebuild if the targeted pass does not restore readiness.
  • Cover the candidate path with a focused repair unit test.

Ref #1447

Verification

  • pytest -q tests/unit/storage/test_repair.py tests/integration/test_health.py::TestMaintenanceSelection::test_session_insight_repair_cleans_duplicate_fts_rows -> 11 passed in 0.18s
  • mypy polylogue/storage/repair.py tests/unit/storage/test_repair.py -> Success: no issues found in 2 source files
  • pre-push devtools verify --quick -> exit_code 0, total_duration_s 37.23

Live daemon work showed repeated large session insight workloads are the main remaining risk after source reads, FTS scans, and append stats recounts were narrowed. The repair surface already has candidate discovery for stale session profiles; use it before falling back to a whole-archive session insight rebuild.\n\nWhen the caller does not provide explicit conversation ids and row debt exists, rebuild the stale profile candidates first. Refresh status afterward and only run the broad rebuild if the targeted pass did not restore readiness, preserving correctness while making the common stale-profile repair bounded.\n\nFocused verification:\n- pytest -q tests/unit/storage/test_repair.py tests/integration/test_health.py::TestMaintenanceSelection::test_session_insight_repair_cleans_duplicate_fts_rows -> 11 passed\n- mypy polylogue/storage/repair.py tests/unit/storage/test_repair.py -> success\n\nRef #1447
@coderabbitai

coderabbitai Bot commented May 24, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@Sinity, we couldn't start this review because you've used your available PR reviews for now.

Your plan currently allows 1 review/hour. Refill in 55 minutes and 13 seconds.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more review capacity refills, 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 trial, open-source, and free plans. In all cases, review capacity refills continuously over time.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 3030780e-9d05-43f3-bff4-1727d83e1d0f

📥 Commits

Reviewing files that changed from the base of the PR and between 010fe6f and 9755575.

📒 Files selected for processing (2)
  • polylogue/storage/repair.py
  • tests/unit/storage/test_repair.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/fix/session-insight-targeted-repair

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 27c40d7 into master May 24, 2026
6 checks passed
@Sinity
Sinity deleted the feature/fix/session-insight-targeted-repair branch May 24, 2026 04:14
Sinity added a commit that referenced this pull request May 24, 2026
Summary

Skip post-write message/action FTS repair when live FTS triggers were already present for the write.

Problem

After #1470 and #1471 were deployed, live validation still showed `polylogued` reading about `2.34 GB` over 10 seconds with IO full avg10 around `20%`, while logs showed hot insight rebuilds were deferred and append writes were small.

The remaining broad path was `commit_archive_write_effects`: it always called `repair_message_fts_index_sync` and `repair_action_fts_index_sync` for changed conversations. On normal live writes the FTS triggers already maintain those rows, so the repair did a redundant delete/reinsert of the whole conversation FTS surface after every append.

Solution

- Record whether message/action FTS triggers were present before write side effects run.
- Always call `ensure_fts_triggers_sync` to restore missing triggers.
- If triggers were already live, trust them and skip the redundant repair.
- If triggers were missing or suspended, keep the existing targeted repair path after trigger restoration.
- Add tests for both paths.

This keeps the hard FTS freshness contract: live-triggered writes stay fresh immediately, and missing/suspended triggers still force repair.

Ref #1447

Verification

- `pytest -q tests/unit/archive/test_write_gateway.py tests/unit/pipeline/test_ingest_append_replay.py` -> `9 passed in 0.20s`
- `mypy polylogue/archive/write_effects.py tests/unit/archive/test_write_gateway.py` -> `Success: no issues found in 2 source files`
- `devtools verify --quick` -> `exit_code 0`, `total_duration_s 39.71`
- pre-push `devtools verify --quick` -> `exit_code 0`, `total_duration_s 34.62`
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