Repository navigation
fix(daemon): bound Drive catch-up writer holds by wall-clock time - #3550
Conversation
Ref polylogue-qlae Problem polylogue-qlae's journal aggregation (2026-07-29 to 2026-07-31) measured maintenance.drive_catchup hold_max=18,623s -- a different daemon actor than the one polylogue-de2a bounded (raw_materialization, PR #3534, merged same day this measurement window predates re-verification of). _periodic_drive_source_catchup wraps its entire Drive acquire+parse pass in one coordinator.run("maintenance.drive_catchup", ...) call with no internal checkpoint, so a large first-run or post-outage backlog holds the process-wide writer for the whole pass, starving every other maintenance actor (heartbeat, wal_checkpoint, fts_merge, watcher prefilter all observed waiting 17,000s+ during these holds). Solution Mirrors de2a's exact technique (repair_raw_materialization's max_pass_seconds) at the equivalent natural checkpoint one layer down: parse_from_raw already batches raw ids by raw_batch_size/blob-byte budget (_iter_raw_id_batches), and each batch boundary is a genuine write/transaction boundary. parse_from_raw and ingest_sources gain an optional max_pass_seconds parameter (None default, byte-for-byte unchanged for existing callers); elapsed time is checked only between batches, guaranteeing at least one batch completes before the budget is enforced. ParseResult gains time_budget_exceeded to signal an early stop. The daemon's _run_drive_source_catchup_once passes a declared _DRIVE_CATCHUP_MAX_PASS_SECONDS = 20.0 (matching de2a's constant), logging when a pass yields early. Raw ids left unattempted stay ordinary parse backlog, recomputed by collect_parse_backlog / collect_validation_backlog on the next tick -- no work is lost. Deliberately NOT bounded here: the acquire stage (network/filesystem walk across configured Drive sources), which runs before the parse stage and isn't chunked at a granularity this checkpoint can safely cover -- noted as residual scope in the PR body. On the general per-actor time-budget mechanism DaemonWriteCoordinator itself could grow (qlae's task item 3): not attempted here. Both de2a and this PR apply the same manual per-actor opt-in pattern at a call-site the actor's own author understands (its natural transaction boundaries); a general enforcement layer in the coordinator would need to either preempt mid-hold (unsafe without releasing the real SQLite write lock, per de2a's own analysis) or externally cancel a non-cooperating actor's task (behavior-changing for any actor not written to expect cancellation mid-write). Recommend a follow-up bead scoped to *auditing every current writer actor* for whether it already has an equivalent natural checkpoint, rather than building a generic mechanism speculatively for a third, not-yet-identified offender. Verification devtools test tests/unit/pipeline/test_parsing_service.py tests/unit/daemon/test_daemon_cli.py -> 140 passed (includes new regression test test_parse_from_raw_max_pass_seconds_bounds_one_call_and_preserves_progress, mirroring de2a's own raw-materialization regression test shape: with max_pass_seconds=1.0 and raw_batch_size=1, exactly 1 of 3 raw ids is processed and time_budget_exceeded is True; a follow-up call without a budget processes the declared remainder, proving no work is lost). devtools test tests/unit/pipeline/test_hermes_raw_identity.py tests/unit/pipeline/test_stage_independence.py tests/unit/storage/test_repair.py -> 67 passed, 11 pre-existing failures unchanged (same "no messages, no positive conversational evidence" parser-refusal drift de2a's PR #3534 already documented as out of scope; repair.py is untouched by this PR). devtools verify --quick -> passes (ruff format/check, mypy --strict, render all --check, layering, schema-versioning, all other quick gates). devtools verify (testmon) not run -- this worktree's testmon cache is unseeded; the devtools test invocations above cover every file this PR touches plus their existing test suites. Co-Authored-By: Claude <[email protected]>
|
Warning Review limit reached
Next review available in: 55 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 (6)
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 |
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]>
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]>
…wall-clock (#3571) ## Summary Adds a declared, enforced wall-clock budget to the daemon's watcher full-ingest path so `watcher.catch_up.chunk` and `watcher.live_ingest.full` can 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_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. Grep confirmed zero `max_pass_seconds` hits in `watcher.py`/`batch.py` before 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`. 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` (not re-armed per group/record, which would let many individually-in-budget units sum to an unbounded total hold): - Between full-ingest progress groups in `ingest_files`'s by-source loop. - Between records inside `_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_exceeded` bucket, kept distinct from both `succeeded` and `failed`: 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. `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 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 ``` 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). 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 on `origin/master` under identical load. 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). ## Acceptance criteria (bead has 1 explicit ask: apply the de2a/qlae bounded-pass pattern to the two remaining unbounded watcher actors) 1. **`watcher.catch_up.chunk` bounded in time** — satisfied: chunks already atomically bound the writer per `_run_coordinated` call, and the internal `ingest_files` call this chunk makes now also checks the shared budget between records/groups. 2. **`watcher.live_ingest.full` bounded in time** — satisfied via the same shared code path. 3. **Per-session atomicity preserved** — satisfied: the checkpoint only ever fires between complete records/groups, never mid-write; verified by the new regression test's second (follow-up) call completing the deferred work intact. 4. **Live re-measurement under a comparable backlog** — not done here, consistent with de2a/qlae's own follow-up notes; requires a deployed daemon under live-scale load. ## Follow-ups - AC4 (live re-measurement) needs a deployed daemon under a comparable backlog; not attempted here. - The single-pathological-file case (one file whose own parse+materialize exceeds the budget) remains genuinely unbounded; a streaming/interruptible parser would be required to close it fully. Ref polylogue-11cg9
Summary
Applies the same bounded-pass technique polylogue-de2a shipped for the daemon's
raw_materializationactor (PR #3534,max_pass_seconds, merged same day this bead's measurement window predates) to a second, still-unbounded writer-holding actor:maintenance.drive_catchup.Problem
polylogue-qlae's journal aggregation (2026-07-29 to 2026-07-31) measured:
maintenance.raw_materializationhold_max=21,433.6s -- the actor de2a's PR fix(daemon): bound raw-materialization writer holds by wall-clock time #3534 bounded viamax_pass_seconds=20.0. That PR merged 2026-08-02, the same day as this measurement window's upper bound; this bead's specific number predates re-verification against the fix and should not be treated as still-live without a fresh live re-measurement (explicitly called out as AC4/follow-up in fix(daemon): bound raw-materialization writer holds by wall-clock time #3534's own PR body).maintenance.drive_catchuphold_max=18,623s -- a different actor, not touched by de2a, confirmed still unbounded by reading_periodic_drive_source_catchup/_run_drive_source_catchup_once(polylogue/daemon/cli.py): the entire Drive acquire+parse pass runs inside onecoordinator.run("maintenance.drive_catchup", ...)call with no internal checkpoint.wal_checkpoint17,642s,fts_merge17,882s,watcher.catch_up.prefilter20,298s).DaemonWriteCoordinator's priority classes (write_coordinator.py:44-56) bound queue order, not the duration of an already-admitted hold -- this is the same structural gap de2a's own analysis already established.Solution
parse_from_rawandingest_sources(polylogue/pipeline/services/parsing_workflow.py) gain an optionalmax_pass_seconds: float | None = Noneparameter, byte-for-byte unchanged for existing callers.ParsingService.parse_from_raw/.ingest_sources(polylogue/pipeline/services/parsing.py) thread it through.parse_from_rawalready batches raw ids byraw_batch_size/ blob-byte budget (_iter_raw_id_batches) -- a genuine write/transaction boundary, structurally identical to raw-materialization's per-component checkpoint. Elapsed time is checked only between batches, and each branch always completes at least one batch before the budget is enforced, so a single slower-than-budget batch still makes forward progress instead of stalling.ParseResultgainstime_budget_exceeded: boolso callers can observe an early stop.polylogue/daemon/cli.py's_run_drive_source_catchup_oncepasses a declared_DRIVE_CATCHUP_MAX_PASS_SECONDS = 20.0(matching de2a's constant) and logs when a pass yields early. Raw ids left unattempted this call stay ordinary parse backlog, recomputed bycollect_parse_backlog/collect_validation_backlogon the next_periodic_drive_source_catchuptick -- no work is lost or corrupted.Deliberately not bounded here: the acquire stage (network/filesystem walk across configured Drive sources), which runs before the parse stage and isn't chunked at a granularity this checkpoint can safely cover. Left as residual scope.
On the general per-actor time-budget mechanism (qlae task item 3)
Not attempted in this PR. Both de2a and this PR apply the same manual, per-actor opt-in pattern at a call site the actor's own author understands (its natural transaction boundaries). A general enforcement mechanism inside
DaemonWriteCoordinatoritself would have to either preempt a hold mid-flight (unsafe -- a mid-hold SQLite transaction cannot safely release the async gate without releasing the real DB-level write lock, per de2a's own prior analysis) or externally cancel a non-cooperating actor's task (behavior-changing for any actor not written to expect cancellation mid-write). I recommend a follow-up bead scoped to auditing every current writer actor for whether it already has an equivalent natural checkpoint it could opt into, rather than building a generic coordinator-level mechanism speculatively ahead of a third, not-yet-identified offender.Verification
-> 140 passed. Includes new regression test
test_parse_from_raw_max_pass_seconds_bounds_one_call_and_preserves_progress, mirroring de2a's own raw-materialization regression test shape: withmax_pass_seconds=1.0andraw_batch_size=1against 3 raw ids, exactly 1 batch is processed andtime_budget_exceededisTrue; a follow-up call without a budget processes the declared remainder (2 batches), proving no work is lost. Verified load-bearing by reverting the production changes only and confirming the new test fails on aTypeError: unexpected keyword argument 'max_pass_seconds'.Also updated 3 pre-existing tests that asserted the exact kwargs of a mocked
parse_from_raw/ingest_sourcescall (now includesmax_pass_seconds=None/the new fake parameter) and one daemon test's fakeingest_sourcessignature.-> 67 passed, 11 pre-existing failures unchanged (same "no messages, no positive conversational evidence" parser-refusal drift already documented as out of scope in de2a's PR #3534;
repair.pyis untouched by this PR).-> passes (ruff format/check, mypy --strict, render all --check, layering, schema-versioning, all other quick gates). Ran again as part of the pre-push hook after the branch rename, also green.
devtools verify(testmon) was not run -- this worktree's testmon cache is unseeded; thedevtools testinvocations above cover every file this PR touches plus their existing test suites.Follow-ups
DaemonWriteCoordinatoractor for an unbounded hold, rather than a generic coordinator-level time-budget mechanism (see reasoning above).Ref polylogue-qlae
Co-Authored-By: Claude [email protected]