fix(core): validate batch_size in _batch and _abatch to prevent infinite loop - #36663
Merged
ccurme (ccurme) merged 1 commit intoApr 26, 2026
Merged
Conversation
…ite loop Add ValueError for non-positive batch_size in both _batch and _abatch utility functions. Previously, batch_size=0 caused _batch to loop forever and _abatch to yield endless empty lists. Fixes langchain-ai#36647 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sharvil Saxena (sharziki)
requested a review
from Eugene Yurtsev (eyurtsev)
as a code owner
April 11, 2026 03:08
This comment has been minimized.
This comment has been minimized.
Eugene Yurtsev (eyurtsev)
approved these changes
Apr 14, 2026
Eugene Yurtsev (eyurtsev)
enabled auto-merge (squash)
April 14, 2026 15:01
Merging this PR will not alter performance
Comparing Footnotes
|
|
|
||
| def _batch(size: int, iterable: Iterable[T]) -> Iterator[list[T]]: | ||
| """Utility batching function.""" | ||
| if size <= 0: |
There was a problem hiding this comment.
The fix is correct and well-scoped. A size=0 case would have caused _batch to loop forever since islice(it, 0) always yields nothing — the while loop never breaks. Good catch and clean fix.
ccurme (ccurme)
disabled auto-merge
April 26, 2026 19:13
ccurme (ccurme)
merged commit Apr 26, 2026
78546e9
into
langchain-ai:master
105 of 183 checks passed
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
ValueErrorfor non-positivebatch_sizein_batchand_abatchutility functionsbatch_size=0caused_batchto loop forever and_abatchto yield endless empty listsFixes #36647
Test plan
test_batch_validationandtest_abatch_validationcovering0and negative sizestest_abatchstill passesAI assistance (Claude Code) was used. All changes reviewed and validated by the submitting human.
🤖 Generated with Claude Code