Fix buffer budget accounting to measure past ready frontier - #1364
Merged
Conversation
The queries' target block (maxQueryBlockNumber) indexed the buffer at `budget + chainPendingBudget - 1`. But `budget` already subtracts totalReadyCount (the ready items in every chain's buffer), and the buffer is then indexed from position 0 — so this chain's ready prefix is charged twice. The target block landed bufferReadyCount items too early, capping the buffer at a fraction of its target (≈50% in the caught-up regime) and stalling fetching even with budget left. Offset the index by bufferReadyCount so budget is measured past the ready frontier. Move bufferReadyCount above getNextQuery to satisfy ordering. Update the FetchState tests that pinned the old under-fetch behavior. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N5UqJXYVuTRrYxwGygeW4S
Contributor
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthrough
FetchState budgeting fix
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix a buffer budget accounting bug where the ready prefix was being subtracted twice, causing the buffer to cap at a fraction of its target size. The budget should measure items past the ready frontier (processable items), not from the start of the buffer.
Changes
bufferReadyCountfunction earlier in FetchState.res to make it available beforegetNextQuery, which now uses it to correctly offset the budget calculationgetNextQueryto addbufferReadyCountwhen indexing into the buffer, ensuring the budget measures items past the ready frontier rather than from the buffer startImplementation Details
The buffer is kept sorted by block number. The ready frontier is the highest block number where all partitions have data (no gaps). Items at or below this frontier are processable immediately.
Previously,
maxQueryBlockNumberwas calculated asbuffer[budget + pending - 1], which treated the budget as an absolute index. This meant ready items (which should always be processable) were consuming budget slots, leaving less room for buffering ahead.Now it's calculated as
buffer[bufferReadyCount + budget + pending - 1], correctly measuring the budget as "how many items past the ready frontier to fetch" rather than "absolute position in buffer". This ensures:https://claude.ai/code/session_01N5UqJXYVuTRrYxwGygeW4S
Summary by CodeRabbit
Bug Fixes
Tests