Repository navigation
fix(batch): shuffle record drain page per replica to stop admission contention - #24500
Conversation
…ontention Every backend-integration replica selects the same oldest record_pending page and its workers start on the same rows, so admissions collide and fail with FirestoreContentionExhausted (734 retries in 4 min, 0 drain progress, 12:10Z). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
1 issue found across 1 file
Confidence score: 3/5
live.pycan maketest_drain_bounds_concurrency_and_passes_slow_partialhang when row'0'is shuffled outside the first four rows. Make the test’s row order deterministic or ensure the partial coordinator is included early.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="backend/utils/batch_pipeline/live.py">
<violation number="1" location="backend/utils/batch_pipeline/live.py:435">
P2: `random.shuffle` makes `test_drain_bounds_concurrency_and_passes_slow_partial` nondeterministic. That test needs the partial coordinator (row `'0'`) to be pulled among the first 4 rows; otherwise it deadlocks and hangs in `await task`. Patch the shuffle to a no-op in that test, or inject the order, and keep the randomness out of the deterministic concurrency test.</violation>
</file>
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
| segments = await run_blocking(db_executor, store.due, 'record_pending', time.time(), batch_size) | ||
| # Every replica selects the same oldest page; a per-replica order keeps | ||
| # replicas from admitting the same rows at once and exhausting contention. | ||
| random.shuffle(segments) |
There was a problem hiding this comment.
P2: random.shuffle makes test_drain_bounds_concurrency_and_passes_slow_partial nondeterministic. That test needs the partial coordinator (row '0') to be pulled among the first 4 rows; otherwise it deadlocks and hangs in await task. Patch the shuffle to a no-op in that test, or inject the order, and keep the randomness out of the deterministic concurrency test.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At backend/utils/batch_pipeline/live.py, line 435:
<comment>`random.shuffle` makes `test_drain_bounds_concurrency_and_passes_slow_partial` nondeterministic. That test needs the partial coordinator (row `'0'`) to be pulled among the first 4 rows; otherwise it deadlocks and hangs in `await task`. Patch the shuffle to a no-op in that test, or inject the order, and keep the randomness out of the deterministic concurrency test.</comment>
<file context>
@@ -429,6 +430,9 @@ async def worker():
segments = await run_blocking(db_executor, store.due, 'record_pending', time.time(), batch_size)
+ # Every replica selects the same oldest page; a per-replica order keeps
+ # replicas from admitting the same rows at once and exhausting contention.
+ random.shuffle(segments)
remaining = iter(segments)
# Join every worker even on failure; a retry must not overlap unfinished
</file context>
Every admission rewrites the owner's scheduler row (owners/<key>), so local drain workers admitting the same owner's rows exhaust each other's contention retries. After #24500, FirestoreContentionExhausted was still about 100 a minute and the backlog fell only about 17 rows a minute (13:00Z). Skip a row whose owner is already being admitted on this replica; it stays due for the next pass. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…4506) Every admission rewrites the owner's scheduler row (owners/<key>), so local drain workers admitting the same owner's rows exhaust each other's contention retries. After #24500, FirestoreContentionExhausted was still about 100 a minute and the backlog fell only about 17 rows a minute (13:00Z). Skip a row whose owner is already being admitted on this replica; it stays due for the next pass. Co-authored-by: Claude Opus 5.5 <[email protected]>
Requested by David
Outage fix, follow-up to #24494. Every backend-integration replica selects the same oldest
record_pendingpage, and its workers all start on the same rows. Admissions collide and fail with FirestoreContentionExhausted: 734 retries in 4 minutes at 12:10Z, and the backlog did not shrink (about 5,070 rows).This shuffles each pass's page per replica, so replicas work on different rows. A row a replica reaches after another replica admitted it is skipped by the existing
state != record_pendingcheck.David asked to ship this without waiting for CI (break glass, 12:17Z).
🤖 Generated with Claude Code