Skip to content

fix: make writer-batching test deterministic under host load - #289

Merged
ryuzdev merged 1 commit into
mainfrom
fix/flake-240
Nov 25, 2026
Merged

ryuzdev merged 1 commit into
mainfrom
fix/flake-240

Conversation

@ryuzdev

@ryuzdev ryuzdev commented Nov 25, 2026

Copy link
Copy Markdown
Member

Root cause

batch_loop (crates/cello/local_store.rs) drains with a blocking recv
followed by try_recv: each commit holds exactly what had arrived when
the writer woke, with no clock or gate coordinating the two sides. A
barrier-synchronized burst of 64 async PUTs usually arrives clustered
(1-4 batches), but when host load starves the PUT tasks mid-burst while
the unstopped writer keeps committing, one burst splits into more than
16 commits. The batch count is scheduler luck, so the test is flaky.

Fix (test-only, no production change)

The test now queues all 64 writes synchronously while a
BEGIN IMMEDIATE transaction on a second connection holds the database
write lock. The writer parks in its own BEGIN IMMEDIATE (30s busy
timeout) and cannot commit until the test COMMITs the holder after the
64th send, so at most one partial head plus the rest commit: 1-2 batches
by construction, against the unchanged 1..=16 bound (8x margin).
Concurrent PUT fan-in stays covered by
concurrent_conditional_puts_stay_correct. Splitting under load was
never a correctness bug (every row still lands), so per the 0.3.1 slice
rules this test-only fix adds no changelog entry.

Fail-before / after evidence

  • Natural repro is rare (matches the issue's single sighting): 30
    targeted runs plus 55 loaded full-suite runs (taskset 0-3/0-1, 28 CPU
    hogs pinned and unpinned) showed 0 failures either way.
  • Mechanism, deterministic: a throwaway variant staggering the 64
    arrivals 1ms apart with no lock held committed 62-64 batches and
    failed the bound 3/3; it isolates arrival timing as the variable the
    fix controls (deleted before commit).
  • After: the rewritten test passes 30/30 beside 28 CPU hogs, with
    batches exactly 1-2 (17x one batch, 13x two). The 25 harsh full-suite
    runs above also each ran the rewritten test green.
  • Full checks green: fmt, clippy (-D warnings), full
    cargo test -p cello, workerdiff gate (297 cases agree),
    check-docs.

Closes #240

@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 6 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2ac8aca2-6779-4f50-a0d3-3f5645c9c462
Commits

Reviewing files that changed from the base of the PR and between 4643ddf and 5ff995d.

Files selected for processing: 1

  • crates/cello/local_store.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

- Queue the 64-write burst synchronously while a BEGIN IMMEDIATE
  holder blocks the writer, so every row is queued before the
  first commit and the burst lands in 1-2 batches by construction.
- The old barrier-synchronized async burst let host load starve
  producers mid-burst, splitting it past the 16-batch bound (#240).
- Test-only: production batching is untouched, so no changelog.
@ryuzdev
ryuzdev merged commit 338c41c into main Nov 25, 2026
7 checks passed
@ryuzdev ryuzdev mentioned this pull request Nov 25, 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.

test flake: local_store writer_batches_one_burst_into_few_commits exceeds 16 batches under host load

1 participant