Repository navigation
fix(azure_sentinel): split batches under the 1MB ingestion cap #39880
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
yucheng-berri
merged 10 commits into
litellm_internal_staging
from
litellm_lit5899_azure_sentinel_batch_split
Sep 6, 2026
Merged
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
934a0d1
fix(azure_sentinel): split batches under the 1MB ingestion cap and ke…
yucheng-berri ef94b7d
fix(azure_sentinel): retry undelivered records on the flush timer only
yucheng-berri 396f0ee
fix(azure_sentinel): decide threshold sends under the flush lock
yucheng-berri 91566d2
test(azure_sentinel): cover successful threshold waiters
yucheng-berri add9ef4
fix(azure_sentinel): preserve cancelled batches for retry
yucheng-berri 577ff5c
fix(azure_sentinel): requeue only the undelivered part of a cancelled…
yucheng-berri 0b0e470
fix(azure_sentinel): drop batches a permanent rejection will never ac…
yucheng-berri 16e2e80
chore(logging): document mutable queue ownership
yucheng-berri 154ad28
fix(datadog): preserve non-413 retry behavior
yucheng-berri 4b78699
fix(batch_utils): requeue by default and let Sentinel opt into dropping
yucheng-berri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| from collections.abc import Awaitable, Callable, Sequence | ||
| from typing import Final, TypeVar | ||
|
|
||
| import httpx | ||
|
|
||
| from litellm._logging import verbose_logger | ||
| from litellm.llms.custom_httpx.http_handler import MaskedHTTPStatusError | ||
|
|
||
| _BatchItem = TypeVar("_BatchItem") | ||
|
|
||
|
|
||
| async def send_batch_with_413_split( | ||
| batch: Sequence[_BatchItem], | ||
| send_batch: Callable[[Sequence[_BatchItem]], Awaitable[httpx.Response]], | ||
| exceeds_limits: Callable[[Sequence[_BatchItem]], bool], | ||
| success_status_codes: frozenset[int], | ||
| integration_name: str, | ||
| drop_error_message: str, | ||
| ) -> tuple[_BatchItem, ...]: | ||
| async def _halve() -> tuple[_BatchItem, ...]: | ||
| midpoint: Final = len(batch) // 2 | ||
| left_undelivered: Final = await send_batch_with_413_split( | ||
| batch=batch[:midpoint], | ||
| send_batch=send_batch, | ||
| exceeds_limits=exceeds_limits, | ||
| success_status_codes=success_status_codes, | ||
| integration_name=integration_name, | ||
| drop_error_message=drop_error_message, | ||
| ) | ||
| if left_undelivered: | ||
| return left_undelivered + tuple(batch[midpoint:]) | ||
| return await send_batch_with_413_split( | ||
| batch=batch[midpoint:], | ||
| send_batch=send_batch, | ||
| exceeds_limits=exceeds_limits, | ||
| success_status_codes=success_status_codes, | ||
| integration_name=integration_name, | ||
| drop_error_message=drop_error_message, | ||
| ) | ||
|
|
||
| async def _handle_413() -> tuple[_BatchItem, ...]: | ||
| if len(batch) == 1: | ||
| verbose_logger.error(drop_error_message) | ||
| return () | ||
| return await _halve() | ||
|
|
||
| if not batch: | ||
| return () | ||
|
|
||
| try: | ||
| oversized: Final = exceeds_limits(batch) | ||
| except (TypeError, ValueError) as e: | ||
| if len(batch) > 1: | ||
| return await _halve() | ||
| verbose_logger.exception("%s dropped a record that cannot be serialized - %s", integration_name, e) | ||
| return () | ||
| if oversized and len(batch) > 1: | ||
| return await _halve() | ||
|
|
||
| try: | ||
| response: Final = await send_batch(batch) | ||
| except MaskedHTTPStatusError as e: | ||
| if e.status_code == 413: | ||
| return await _handle_413() | ||
| verbose_logger.exception("%s Error sending batch API - %s", integration_name, e) | ||
| return tuple(batch) | ||
| except Exception as e: | ||
| verbose_logger.exception("%s Error sending batch API - %s", integration_name, e) | ||
| return tuple(batch) | ||
|
|
||
| if response.status_code == 413: | ||
| return await _handle_413() | ||
| if response.status_code not in success_status_codes: | ||
| verbose_logger.error( | ||
| "%s API error: status_code=%s, response=%s", | ||
| integration_name, | ||
| response.status_code, | ||
| response.text, | ||
| ) | ||
| return tuple(batch) | ||
|
|
||
| verbose_logger.debug("%s delivered %s records, status_code=%s", integration_name, len(batch), response.status_code) | ||
| return () |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.