Skip to content

fix(daemon): trust ready FTS triggers on live appends - #1469

Merged
Sinity merged 1 commit into
masterfrom
feature/fix/fts-hot-path-and-session-fts-repair
May 24, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/fix/fts-hot-path-and-session-fts-repair

Conversation

@Sinity

@Sinity Sinity commented May 24, 2026

Copy link
Copy Markdown
Owner

Summary

Daemon FTS convergence now trusts an FTS surface only when durable freshness state is ready and the expected live sync triggers are present, avoiding whole-conversation docsize scans on every append to huge active sessions. This also adds targeted session-insight FTS repair so duplicate/stale insight FTS rows can be fixed without rebuilding all session insights.

Problem

After #1468 was deployed, hot insight deferral worked, but live polylogued still read 879,820,800 physical bytes over a 10s append sample while source_payload_read_bytes stayed in the KB range. The remaining broad read path was _fts_repair_needs_for_conversations, which exact-scanned messages/action_events against FTS docsize tables for each changed huge conversation even when FTS was already marked ready and triggers were present.

Solution

  • polylogue/daemon/convergence_stages.py skips exact per-conversation FTS docsize scans for messages_fts and action_events_fts only when the FTS table, docsize table, all expected sync triggers, and fts_freshness_state=ready agree.
  • Missing tables, stale/unknown freshness, missing freshness state, or missing triggers still use the existing exact scan/repair path.
  • polylogue/storage/fts/fts_lifecycle.py exposes rebuild_session_insight_fts_sync for targeted session insight FTS rebuilds.
  • polylogue/storage/repair.py uses the new repair assessment helper to clean FTS-only insight debt without forcing a full session insight rebuild.

Closes #1447

Verification

  • pytest -q tests/unit/daemon/test_convergence_stages.py tests/unit/storage/test_fts_trigger_lifecycle.py tests/integration/test_health.py::TestMaintenanceSelection::test_session_insight_repair_cleans_duplicate_fts_rows -> 26 passed in 0.57s
  • devtools verify-topology -> realized=830 declared=830 blocking=False
  • devtools render-all --check -> pass
  • devtools verify --quick -> exit_code 0, total_duration_s 34.84
  • pre-push devtools verify --quick -> exit_code 0, total_duration_s 34.52

Changelog

Skip: internal daemon convergence and repair behavior only.

Risks and Follow-ups

The live daemon is intentionally still stopped until this lands, updates the Sinnix flake input, and is deployed. The next validation step is another live /proc/$pid/io, cgroup memory, cursor/debt, and ingest-attempt sample against the real archive.

Problem: after #1468, hot insight deferral worked but live polylogued still read 879,820,800 bytes over a 10s append sample while source_payload_read_bytes stayed in the KB range. The remaining broad read came from exact per-conversation FTS docsize scans over huge active Codex sessions.

What changed: daemon FTS convergence now skips exact missing-row scans only when a surface has durable ready freshness state and all live sync triggers are present. Missing tables, stale/unknown freshness, or missing triggers still take the exact scan and repair path. Session-insight FTS repair also gains a targeted rebuild path so duplicate insight FTS rows do not force a full insight rebuild.

Verification: pytest -q tests/unit/daemon/test_convergence_stages.py tests/unit/storage/test_fts_trigger_lifecycle.py tests/integration/test_health.py::TestMaintenanceSelection::test_session_insight_repair_cleans_duplicate_fts_rows; devtools verify-topology; devtools render-all --check; devtools verify --quick.

Ref #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 13 minutes and 11 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: 6b4529f5-18f3-4265-a36d-e0c47c9bc4f3

📥 Commits

Reviewing files that changed from the base of the PR and between 3ff28fd and 7b38d7f.

📒 Files selected for processing (9)
  • docs/plans/topology-target.yaml
  • docs/topology-status.md
  • polylogue/daemon/convergence_stages.py
  • polylogue/storage/fts/fts_lifecycle.py
  • polylogue/storage/insights/session/repair_assessment.py
  • polylogue/storage/repair.py
  • tests/integration/test_health.py
  • tests/unit/daemon/test_convergence_stages.py
  • tests/unit/storage/test_fts_trigger_lifecycle.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/fix/fts-hot-path-and-session-fts-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 1478cc1 into master May 24, 2026
7 checks passed
@Sinity
Sinity deleted the feature/fix/fts-hot-path-and-session-fts-repair branch May 24, 2026 03:49
Sinity added a commit that referenced this pull request May 24, 2026
Summary

Update daemon append writes so conversation stats are maintained from changed tail-message deltas instead of recounting every message in the conversation after each append.

Problem

After #1469 was deployed, live catch-up still produced severe physical reads even though source payload reads were tiny, FTS freshness rows were ready, and hot insight rebuilds were being deferred. The remaining broad read was the append write path: `_append_conversation` always called `_upsert_stats_from_messages`, which scans the full `messages` set for the active conversation after every tiny append.

Live evidence from the deployed daemon:

- catch-up scanned `11886` files and needed `309` files / `508.6 MB`;
- FTS freshness rows were `ready` for the live surfaces;
- `/proc/$pid/io` over 10s still showed `1,440,432,128` read bytes;
- recent attempts recorded tiny `source_payload_read_bytes` while `input_bytes` repeated huge source-file sizes.

Solution

- Add `polylogue/pipeline/services/ingest_batch/_append_stats.py` for append-only stats helpers.
- Reuse existing message signatures to compare content hashes and carry old stat counters.
- Apply deltas only for changed tail messages during append writes.
- Fall back to the full recount only when the `conversation_stats` row is missing, including unchanged append replays that need stats repair.
- Keep non-append writes on the existing full stats path.

Ref #1447

Verification

- `pytest -q tests/unit/pipeline/test_ingest_append_replay.py tests/unit/pipeline/test_ingest_batch.py` -> `29 passed in 0.24s`
- `mypy polylogue/pipeline/services/ingest_batch/_core.py polylogue/pipeline/services/ingest_batch/_append_stats.py tests/unit/pipeline/test_ingest_append_replay.py` -> `Success: no issues found in 3 source files`
- `devtools verify --quick` -> `exit_code 0`, `total_duration_s 38.25`
- pre-push `devtools verify --quick` -> `exit_code 0`, `total_duration_s 36.11`
Sinity added a commit that referenced this pull request Aug 17, 2026
polylogue-gibn1, decisive: instrumented the sole consumer of
summary.fts_repair_session_ids (_commit_sync_ingest_side_effects) and it never
printed across five sessions and sixty messages in the failing
convergence-evidence test. The repair is nested inside `if transaction_started`,
so a route with an externally managed transaction skips FTS repair along with
every other post-write side effect.

Eliminated: repair_message_fts (defaults True everywhere, no daemon override),
the repair queue itself (content_changed appends unconditionally), the invariant
reader, and the triggers. Three independent places each assume another will
populate the index: replay defers the reinsert, ingest-side repair never runs,
and the path-scoped convergence check is a hardcoded `return False`.

Read the #1498 cascade retro as CLAUDE.md requires; its closed list names the
adjacent history (#1462, #1469, #1472, #1500, #1502), several of which narrowed
FTS repair to avoid redundant work. Those PR bodies are the place to start.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01HWcPJJJvuF25CqVwTFgSQC
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.

fix(daemon): checkpoint WAL and bound catch-up memory during ingest

1 participant