Skip to content

fix(daemon): bound live catch-up ingest batches - #1452

Merged
Sinity merged 1 commit into
masterfrom
feature/fix/catchup-batch-bounds
May 23, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/fix/catchup-batch-bounds

Conversation

@Sinity

@Sinity Sinity commented May 23, 2026

Copy link
Copy Markdown
Owner

Summary

Bound daemon catch-up ingestion into serial chunks by file count and source bytes. The daemon still scans and converges the full source set; it just no longer sends every changed startup file into one huge parse/write batch.

Problem

Live validation after deploying #1451 showed the next resource failure clearly: startup catch-up planned 310 changed files / 460.8 MB and ingested them as one unit. That single batch pushed the daemon back to the systemd 6 GiB high line, accumulated swap, drove high IO PSI, and produced a 172s slow write for a large Codex session.

Solution

Catch-up now chunks needed paths with bounded defaults: 50 files or 64 MiB of source bytes per batch. Chunks are ingested serially and preserve full convergence scope. The first chunk preserves the whole catch-up queued/skipped context; later chunks report their own bounded sizes.

Verification

  • pytest tests/unit/sources/test_live_watcher.py::test_catch_up_uses_bulk_cursor_records tests/unit/sources/test_live_watcher.py::test_catch_up_processes_pre_existing_files tests/unit/sources/test_live_catchup_planning.py -q → 4 passed in 0.26s
  • ruff format --check polylogue/sources/live/watcher.py tests/unit/sources/test_live_watcher.py tests/unit/sources/test_live_catchup_planning.py → 3 files already formatted
  • ruff check polylogue/sources/live/watcher.py tests/unit/sources/test_live_watcher.py tests/unit/sources/test_live_catchup_planning.py → All checks passed
  • mypy polylogue/sources/live/watcher.py tests/unit/sources/test_live_catchup_planning.py → Success: no issues found in 2 source files
  • devtools verify --quick → exit_code 0, total_duration_s 34.47
  • pre-push devtools verify --quick → exit_code 0, total_duration_s 34.27

Ref #1447

Catch-up still scans and converges the full source set, but it no longer sends every changed file into one parse/write batch. The live archive showed 310 changed files and 460 MB being ingested as a single unit, driving high RSS, cgroup file cache, WAL churn, and IO PSI.

Chunk catch-up work by file count and source bytes while preserving scope. Each chunk is ingested serially, so all files still converge but large startup catch-up releases parser/write state between bounded batches.

Ref #1447
@coderabbitai

coderabbitai Bot commented May 23, 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 18 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: 9b94e999-b766-46c0-a1b5-77f3b9878030

📥 Commits

Reviewing files that changed from the base of the PR and between 9136558 and 7ca80d8.

📒 Files selected for processing (2)
  • polylogue/sources/live/watcher.py
  • tests/unit/sources/test_live_catchup_planning.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/fix/catchup-batch-bounds

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 9632fde into master May 23, 2026
6 checks passed
@Sinity
Sinity deleted the feature/fix/catchup-batch-bounds branch May 23, 2026 20:35
Sinity added a commit that referenced this pull request May 23, 2026
## Summary

Reduce the remaining live catch-up write amplification for huge single-session files. Live append/full-ingest paths now avoid redundant message FTS repair when active triggers already maintained FTS rows, while large full-ingest batches deliberately suspend triggers inside the ingest transaction and repair the changed conversations once before commit.

## Problem

After #1452 bounded catch-up into file chunks, live validation still showed a single 221 MB Codex session with 31,417 messages spending 314 seconds in `slow_write`, driving severe host IO pressure. The batch was bounded, but the single-conversation write path was still monolithic and FTS-heavy.

The code also had a latent suspended-trigger transaction bug: `_process_ingest_batch_sync` dropped FTS triggers before `BEGIN IMMEDIATE`, so a suspended bulk path could fail with `sqlite3.OperationalError: cannot start a transaction within a transaction`.

## Solution

- Add a `repair_message_fts` switch to the canonical archive write effects path, matching the existing `repair_action_fts` control.
- Keep conservative defaults for ordinary archive writes.
- Make live append ingest opt out of redundant message/action FTS repair because FTS triggers are active for those row writes.
- Make live full ingest suspend FTS triggers for raw records at or above 32 MiB, then force message/action FTS repair once before commit.
- Move sync trigger suspension inside `BEGIN IMMEDIATE` and add `mark_stale=False` for transaction-scoped suspension so an already-ready freshness ledger is not falsely degraded by a transaction that repairs before commit.

Synthetic local probe on a temporary archive with a 12k-message conversation:

- active triggers + post-write message repair: `0.292s`
- suspended triggers + one message repair: `0.143s`

This does not claim the production 31k-message case is solved completely; it removes a known FTS write-amplification layer and fixes the transaction bug. The next live daemon run should verify residual parse/write/insight cost against the real 221 MB session.

## Verification

- `pytest tests/unit/archive/test_write_gateway.py tests/unit/sources/test_live_batch_support.py tests/unit/pipeline/test_ingest_batch.py tests/unit/storage/test_fts_trigger_lifecycle.py tests/unit/storage/test_fts_bloat_invariants.py -q` → `51 passed in 1.16s`
- `python -m mypy polylogue/archive/write_effects.py polylogue/pipeline/services/ingest_batch/_core.py polylogue/sources/live/batch.py polylogue/sources/live/append_ingest.py polylogue/storage/fts/fts_lifecycle.py tests/unit/archive/test_write_gateway.py tests/unit/sources/test_live_batch_support.py` → `Success: no issues found in 7 source files`
- `devtools verify --quick` → PASS, `exit_code: 0`, `total_duration_s: 34.63`
- pre-push `devtools verify --quick` → PASS, `exit_code: 0`, `total_duration_s: 35.15`

`devtools verify` reached pytest-testmon and was stopped after `785.8s` because the affected selector expanded to effectively the full serial suite (`9297` JUnit testcases recorded, `failures=0`, `skipped=2`) and was still running at 99%. That behavior is the existing verification-efficiency problem being tracked separately; I did not restart another broad pytest loop for this small branch.

Ref #1447.
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