Repository navigation
fix(daemon): bound watcher full-ingest writer holds by wall-clock time - #3571
Conversation
|
Warning Review limit reached
Next review available in: 19 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (9)
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. Comment |
Ref polylogue-11cg9 Co-Authored-By: Claude <[email protected]>
Ref polylogue-11cg9 Co-Authored-By: Claude <[email protected]>
3ed40ac to
e36e73e
Compare
Problem Ref polylogue-11cg9. de2a (PR #3534) and qlae (PR #3550) bounded maintenance.raw_materialization and maintenance.drive_catchup writer holds to a declared max_pass_seconds checkpoint, but watcher.catch_up.chunk and watcher.live_ingest.full had only size bounds (4 files/16MiB per catch-up chunk; up to 64 files/64MiB per full-ingest progress group) and no time bound. The original de2a incident (an in-size-bounds ~7MB chunk that held the sole archive writer for 860s) is exactly the case a time budget would catch, and it starves every other writer-lock actor for however long parsing/materializing takes. Solution Both actors bottom out in LiveBatchProcessor.ingest_files -> _ingest_full_paths -> _ingest_full_paths_sync -> _ingest_full_records_archive, regardless of which outer wrapper (watcher.catch_up.chunk or a plain watch-flush) invokes them. A max_pass_seconds parameter is threaded through this whole chain, checked against one shared time.monotonic() reference established once at the top of ingest_files: - Between full-ingest progress groups in ingest_files's by-source loop. - Between records inside _ingest_full_records_archive's per-record loop (the important case: a progress group can already bundle up to 64 small files into one writer hold). A single logical session write cannot be split mid-transaction, so the budget is only ever checked between complete units, never inside one; the first unit of every pass always completes regardless of budget (forward progress guarantee). Records/groups skipped by the budget are excluded from both succeeded and failed (a new _ArchiveFullWriteResult.skipped_raw_ids / _FullIngestResult.time_budget_exceeded bucket) so no cursor is recorded and no failure backoff applies -- they remain ordinary backlog for the next catch-up scan or watch tick. LiveWatcher passes a declared _LIVE_INGEST_MAX_PASS_SECONDS = 20.0 (matching de2a/qlae's constant), observable via LiveBatchMetrics.time_budget_exceeded and a new log line. Residual gap (documented, not fixed here): a single file whose own parse+materialize exceeds the budget still cannot be interrupted -- bounding that would need a streaming/interruptible parser, out of scope for this pass (matches the bead's own framing and qlae's precedent of leaving Drive's acquire stage unbounded for the same reason). Verification devtools test tests/unit/sources/test_live_watcher.py tests/unit/sources/test_live_batch_support.py tests/unit/sources/test_live_batch_observability.py tests/unit/sources/test_live_watcher_catchup_order.py tests/unit/sources/test_live_watcher_locking.py tests/unit/sources/test_live_watcher_parse_stage_equivalence.py tests/unit/sources/test_live_cursor_locking.py tests/unit/daemon/test_schema_preflight.py tests/unit/pipeline/test_parsing_service.py tests/unit/storage/test_repair.py -> 294 passed, 4 pre-existing failures unchanged (confirmed identical on origin/master by stashing this branch's changes and re-running 3x; same "did not prove one session and cursor identity" / "raw revision did not replay to exactly one session" fixture drift, unrelated to this change). New regression test test_ingest_files_max_pass_seconds_bounds_one_pass_and_preserves_progress reproduces the shape of the de2a incident: three small same-progress-group codex sessions with a deterministic fake monotonic clock and max_pass_seconds=1.0 -- exactly one is written this pass, the other two are left as ordinary un-recorded backlog (not succeeded, not failed), and a follow-up call without a budget finishes them with nothing lost. Verified load-bearing by reverting the production changes only and confirming it fails with TypeError: unexpected keyword argument 'max_pass_seconds'. devtools verify --quick -> passes (ruff format/check, mypy --strict, render all --check, layering, schema-versioning, all other quick gates). Ref polylogue-11cg9 Co-Authored-By: Claude <[email protected]>
Ref polylogue-11cg9 Co-Authored-By: Claude <[email protected]>
e36e73e to
08654ff
Compare
Summary
Adds a declared, enforced wall-clock budget to the daemon's watcher full-ingest path so
watcher.catch_up.chunkandwatcher.live_ingest.fullcan no longer hold the process-wide writer coordinator indefinitely, closing the last residual gap in the de2a/qlae starvation-fix series.Problem
Ref polylogue-11cg9. de2a (PR #3534) and qlae (PR #3550) bounded
maintenance.raw_materializationandmaintenance.drive_catchupwriter holds to a declaredmax_pass_secondscheckpoint, butwatcher.catch_up.chunkandwatcher.live_ingest.fullhad only size bounds (4 files/16MiB per catch-up chunk; up to 64 files/64MiB per full-ingest progress group) and no time bound. Grep confirmed zeromax_pass_secondshits inwatcher.py/batch.pybefore this change. The original de2a incident (an in-size-bounds ~7MB chunk that held the sole archive writer for 860s) is exactly the case a time budget would have caught, and while that hold runs, every other writer-lock actor is starved.This bead's own framing flagged the harder constraint: a single logical session write cannot be split mid-transaction, so a simple checkpoint loop (like raw-materialization's) isn't directly applicable — the right unit to bound is the record/group boundary, not mid-record.
Solution
Both named actors bottom out in the same call chain regardless of which outer wrapper invokes them:
LiveBatchProcessor.ingest_files->_ingest_full_paths->_ingest_full_paths_sync->_ingest_full_records_archive. Amax_pass_secondsparameter is threaded through this whole chain, checked against one sharedtime.monotonic()reference established once at the top ofingest_files(not re-armed per group/record, which would let many individually-in-budget units sum to an unbounded total hold):ingest_files's by-source loop._ingest_full_records_archive's per-record loop — the case that matters most, since one progress group can already bundle up to 64 small files into a single writer hold.The first unit of every pass always completes regardless of budget (forward-progress guarantee, same shape as de2a/qlae). Records/groups skipped by the budget go into a new
_ArchiveFullWriteResult.skipped_raw_ids/_FullIngestResult.time_budget_exceededbucket, kept distinct from bothsucceededandfailed: no cursor is recorded (so no work is silently marked done) and no failure backoff applies (so retry isn't penalized) — they remain ordinary backlog for the next catch-up scan or watch tick.LiveWatcherpasses a declared_LIVE_INGEST_MAX_PASS_SECONDS = 20.0(matching de2a/qlae's constant), observable viaLiveBatchMetrics.time_budget_exceededand a new log line when a pass yields early.Deliberately not bounded here (documented residual gap, matching qlae's precedent for Drive's acquire stage): a single file whose own parse+materialize step exceeds the budget still cannot be interrupted mid-record — bounding that would need a streaming/interruptible parser, out of scope for this pass. This PR fixes the "many files back-to-back" unbounded case completely and tightens the "one pathological file" case to at most one file over budget per pass, down from unbounded.
Verification
-> 294 passed, 4 pre-existing failures unchanged (confirmed identical on
origin/masterby stashing this branch's changes and re-running 3x; same "did not prove one session and cursor identity" / "raw revision did not replay to exactly one session" fixture drift, unrelated to this change). One additional test (test_end_to_end_hidden_root_file_creation_triggers_ingest, a real-filesystem-watch timing test) flaked once under heavy concurrent load from an unrelated background suite run and passed cleanly on every other run (4/4 in isolation, 2/2 in the full batch afterward) — confirmed pre-existing timing fragility, not a regression, by reproducing the same flake shape onorigin/masterunder identical load.New regression test
test_ingest_files_max_pass_seconds_bounds_one_pass_and_preserves_progressreproduces the shape of the de2a incident: three small same-progress-group codex sessions with a deterministic fake monotonic clock andmax_pass_seconds=1.0— exactly one is written this pass, the other two are left as ordinary un-recorded backlog (not succeeded, not failed), and a follow-up call without a budget finishes them with nothing lost. Verified load-bearing by reverting the production changes only and confirming it fails withTypeError: unexpected keyword argument 'max_pass_seconds'.-> passes (ruff format/check, mypy --strict, render all --check, layering, schema-versioning, all other quick gates).
Acceptance criteria (bead has 1 explicit ask: apply the de2a/qlae bounded-pass pattern to the two remaining unbounded watcher actors)
watcher.catch_up.chunkbounded in time — satisfied: chunks already atomically bound the writer per_run_coordinatedcall, and the internalingest_filescall this chunk makes now also checks the shared budget between records/groups.watcher.live_ingest.fullbounded in time — satisfied via the same shared code path.Follow-ups
Ref polylogue-11cg9