fix: stop drain after schema contention#519
Conversation
|
Warning Review limit reached
More reviews will be available in 26 minutes and 31 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?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 credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate. 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, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
|
Codex Review: Didn't find any major issues. Another round soon, please! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Summary
Follow-up to #516, which Etan squash-merged while the final review-response commit was still running local pre-push.
This PR carries only that final small fix:
drain_onceafter forced schema bootstrap contention so later queue files are not applied or unlinked while an earlier store file remains queuedburn_drain_onceapplied/skipped events only after the transaction commits, so missing-chunks retry does not double-count rolled-back workVerification
Red/green before the fix:
test_drain_stops_after_forced_schema_bootstrap_writer_in_usefailed becausedrain_onceadvanced to the second queue file after forced schema bootstrap contention.test_burn_drain_missing_chunks_retry_counts_events_oncefailed withapplied_events == 3before counters were moved behind COMMIT.Current local verification:
pytest tests/test_write_queue.py::TestFlushPendingStores::test_drain_stops_after_forced_schema_bootstrap_writer_in_use tests/test_write_queue.py::TestFlushPendingStores::test_burn_drain_missing_chunks_retry_counts_events_once -q-> 2 passedruff check src/brainlayer/drain.py tests/test_write_queue.py-> passedruff format --check src/brainlayer/drain.py tests/test_write_queue.py-> 2 files already formatted3012 passed, 9 skipped, 61 deselected, 1 xfailed, 103 warnings, MCP registration 3 passed, isolated eval/hook routing 40 passed, Bun 1 pass, FTS determinism passed@codex review
@cursor @BugBot re-review
@coderabbitai review
Note
Medium Risk
Changes ordering and metrics in the durable JSONL drain path; mistakes could skip or reorder queued writes, but scope is small and covered by new tests.
Overview
Fixes two queue-drain edge cases in
drain_onceandburn_drain_once.drain_once: When a store file hits a missing-chunkserror and forced schema bootstrap fails (e.g. another writer holds the DB), the loop now setsstop_drainingand exits instead of moving on to the next JSONL file. That keeps FIFO order: later files are not drained or unlinked while an earlier store file is still blocked on schema init.burn_drain_once:applied_eventsandskipped_verified_staleare accumulated only afterCOMMIT, using per-attempt counters. Rolled-back work from a failed first attempt (e.g. missingchunksthen successful retry) no longer inflates reported counts.Regressions cover stopping after contended forced bootstrap (both queue files unchanged, schema helper called once) and burn-drain counting exactly two committed events after a missing-chunks retry.
Reviewed by Cursor Bugbot for commit 245a744. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Fix drain to stop processing queue files after schema contention
WriterInUseError) in the missing-chunks retry path ofdrain_once, processing now stops immediately rather than continuing to later queue files, preserving queue order.burn_drain_once, event counts (applied_events,skipped_verified_stale) are now accumulated into per-attempt local counters and only added to the result after a successfulCOMMIT, preventing double-counting on retries.Macroscope summarized 245a744.