Skip to content

fix(core): validate batch_size in _batch and _abatch to prevent infinite loop - #36663

Merged
ccurme (ccurme) merged 1 commit into
langchain-ai:masterfrom
sharziki:fix/36647-batch-size-validation
Apr 26, 2026
Merged

fix(core): validate batch_size in _batch and _abatch to prevent infinite loop#36663
ccurme (ccurme) merged 1 commit into
langchain-ai:masterfrom
sharziki:fix/36647-batch-size-validation

Conversation

@sharziki

Copy link
Copy Markdown
Contributor

Summary

  • Add ValueError for non-positive batch_size in _batch and _abatch utility functions
  • Previously, batch_size=0 caused _batch to loop forever and _abatch to yield endless empty lists

Fixes #36647

Test plan

  • Added test_batch_validation and test_abatch_validation covering 0 and negative sizes
  • Existing test_abatch still passes

AI assistance (Claude Code) was used. All changes reviewed and validated by the submitting human.

🤖 Generated with Claude Code

…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>
@github-actions github-actions Bot added core `langchain-core` package issues & PRs fix For PRs that implement a fix size: XS < 50 LOC labels Apr 11, 2026
@github-actions

This comment has been minimized.

@eyurtsev
Eugene Yurtsev (eyurtsev) enabled auto-merge (squash) April 14, 2026 15:01
@codspeed-hq

codspeed-hq Bot commented Apr 14, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 13 untouched benchmarks
⏩ 2 skipped benchmarks1


Comparing sharziki:fix/36647-batch-size-validation (f6588d3) with master (8182d63)

Open in CodSpeed

Footnotes

  1. 2 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.


def _batch(size: int, iterable: Iterable[T]) -> Iterator[list[T]]:
"""Utility batching function."""
if size <= 0:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bypass-issue-check core `langchain-core` package issues & PRs external fix For PRs that implement a fix new-contributor size: XS < 50 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(core): _batch and _abatch lack batch_size validation causing infinite loop

4 participants