Skip to content

fix(daemon): reduce catch-up replay amplification - #1459

Merged
Sinity merged 1 commit into
masterfrom
feature/fix/ingest-write-phase-timings
May 24, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/fix/ingest-write-phase-timings

Conversation

@Sinity

@Sinity Sinity commented May 24, 2026

Copy link
Copy Markdown
Owner

Summary

Reduce daemon catch-up amplification for large Codex sessions by making append-only replay write only changed rows, compacting Codex provider-event payloads, and expanding ingest logs with row/result/RSS attribution fields.

Problem

Live #1447 deployment evidence showed polylogued reaching the 6G memory high mark and severe host IO PSI while processing a single 232MB Codex session. Inspection found a concrete append-only bug: the writer computed changed messages but still upserted every replayed message/block/action/provider-event tuple from the full parsed session. Codex provider events also duplicated raw command output and compaction history already retained in the raw blob and normalized message/action rows.

Solution

  • Chunk large existing-message/provider-event lookups so replay checks do not exceed SQLite variable limits.
  • In append-only mode, write only changed messages, changed blocks/actions, and new provider events; unchanged replayed rows are counted as skipped and left untouched.
  • Preserve append-only content hash progression from the changed tail rather than the whole replayed file hash.
  • Compact Codex compaction, turn-context, and response-item provider-event payloads into source index/type/id/shape metadata instead of storing raw duplicated payloads.
  • Add slow-write and ingest-batch log fields for changed/skipped rows, provider events, serialized result size, max write duration, and observed RSS.

Ref #1447. This does not close #1447: live catch-up still needs to prove whether first-time huge-session ingest requires chunked materialization beyond these amplification fixes.

Verification

  • pytest tests/unit/pipeline/test_ingest_append_replay.py tests/unit/pipeline/test_ingest_batch.py tests/unit/sources/test_parsers_codex.py tests/unit/sources/test_codex_event_stream_contract.py -q → 90 passed in 0.32s
  • ruff check polylogue/sources/parsers/codex.py polylogue/pipeline/services/ingest_batch/_core.py tests/unit/sources/test_parsers_codex.py tests/unit/sources/test_codex_event_stream_contract.py tests/unit/pipeline/test_ingest_batch.py tests/unit/pipeline/test_ingest_append_replay.py → All checks passed!
  • mypy polylogue/sources/parsers/codex.py polylogue/pipeline/services/ingest_batch/_core.py tests/unit/sources/test_parsers_codex.py tests/unit/sources/test_codex_event_stream_contract.py tests/unit/pipeline/test_ingest_batch.py tests/unit/pipeline/test_ingest_append_replay.py → Success: no issues found in 6 source files
  • devtools verify-file-budgets → file-size budgets: clean
  • devtools verify --quick → exit 0, total_duration_s: 37.33
  • pre-push devtools verify --quick → exit 0, total_duration_s: 34.68

Append-only replay now writes only changed message, block, action, and provider-event rows instead of upserting every row from a full replayed session. This avoids turning tiny tails into full-session writes and prevents unchanged content-hash rows from being mutated by replay artifacts.

Codex provider events now store compact provenance metadata for compactions, turn context, and response items rather than duplicating raw command output/history payloads already preserved in the raw blob and normalized message/action rows.

The ingest logs also include changed/skipped row counts, serialized result size, max write duration, and RSS observations so the next live catch-up run can attribute remaining cost without another blind restart.

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 8 minutes and 29 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: 6d4e3594-4a4d-4b9d-b790-9bdf934d7baa

📥 Commits

Reviewing files that changed from the base of the PR and between 3893bd2 and b77223a.

📒 Files selected for processing (5)
  • polylogue/pipeline/services/ingest_batch/_core.py
  • polylogue/sources/parsers/codex.py
  • tests/unit/pipeline/test_ingest_append_replay.py
  • tests/unit/sources/test_codex_event_stream_contract.py
  • tests/unit/sources/test_parsers_codex.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/fix/ingest-write-phase-timings

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 f5688cb into master May 24, 2026
6 checks passed
@Sinity
Sinity deleted the feature/fix/ingest-write-phase-timings branch May 24, 2026 00:17
Sinity added a commit that referenced this pull request May 24, 2026
Summary: Prevent hot JSONL session files from falling back to full ingest when the watcher observes a partial trailing line, and requeue failed live/catch-up paths for the normal retry loop.

Problem: Live deployment of #1459 proved #1447 was not complete: a Codex file triggered `slow_write ... changed_messages=10309 ... elapsed_s=81.76`, drove IO PSI full avg10 to roughly 55%, and left the daemon in D-state. Append planning treated a grown tail without a complete newline as non-appendable, sending an actively written JSONL file into full ingest.

Solution: Add an explicit deferred-append sentinel for incomplete JSONL tails; keep deferred paths out of full ingest and report them as retryable failed paths; requeue failed catch-up/live-drain paths into the existing pending watcher loop; return `LiveBatchMetrics` from `LiveWatcher._ingest_files` so callers can act on retryable failures.

Verification: `pytest tests/unit/sources/test_live_catchup_planning.py tests/unit/sources/test_live_batch_support.py tests/unit/sources/test_live_watcher.py tests/unit/sources/test_live_watcher_locking.py tests/unit/sources/test_live_hot_session_convergence.py -q` -> 83 passed; focused ruff and mypy on touched files passed; `devtools verify-file-budgets` -> clean; `devtools verify --quick` -> exit_code 0, total_duration_s 37.8.

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.

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

1 participant