Skip to content

fix(daemon): bound watcher full-ingest writer holds by wall-clock time - #3571

Merged
Sinity merged 2 commits into
masterfrom
feature/daemon/bound-live-ingest-writer-holds
Aug 2, 2026
Merged

Sinity merged 2 commits into
masterfrom
feature/daemon/bound-live-ingest-writer-holds

Conversation

@Sinity

@Sinity Sinity commented Aug 2, 2026

Copy link
Copy Markdown
Owner

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

@coderabbitai

coderabbitai Bot commented Aug 2, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

@Sinity, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 19 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 2216abb8-1e6f-4ee7-a573-45ad6bc82c73

📥 Commits

Reviewing files that changed from the base of the PR and between 47a512d and 08654ff.

📒 Files selected for processing (9)
  • .beads/issues.jsonl
  • polylogue/sources/live/batch.py
  • polylogue/sources/live/batch_support.py
  • polylogue/sources/live/metrics.py
  • polylogue/sources/live/watcher.py
  • tests/integration/test_live_read_amplification.py
  • tests/unit/sources/test_live_batch_support.py
  • tests/unit/sources/test_live_watcher.py
  • tests/unit/sources/test_live_watcher_locking.py

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.

Sinity added a commit that referenced this pull request Aug 2, 2026
Sinity added a commit that referenced this pull request Aug 2, 2026
@Sinity
Sinity force-pushed the feature/daemon/bound-live-ingest-writer-holds branch from 3ed40ac to e36e73e Compare August 2, 2026 14:46
Sinity and others added 2 commits August 2, 2026 16:49
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]>
@Sinity
Sinity force-pushed the feature/daemon/bound-live-ingest-writer-holds branch from e36e73e to 08654ff Compare August 2, 2026 14:50
@Sinity
Sinity merged commit 8ec75e5 into master Aug 2, 2026
3 checks passed
@Sinity
Sinity deleted the feature/daemon/bound-live-ingest-writer-holds branch August 2, 2026 14:53
Sinity added a commit that referenced this pull request Aug 2, 2026
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