Repository navigation
fix(batches): handle empty models when logging batch cost - #47155
Conversation
|
@litereview code-review Please review the current commit, including fallback identity, mixed-result accounting, and the attached independent verification evidence |
|
@greptileai Please review this batch logging fix and regression coverage, including all-failed output, mixed results, and fallback identity |
|
cursor review Please review this batch logging fix, especially fallback identity, mixed-result accounting, and the regression cases |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit fa2effb. Configure here.
✅ code-review5/5 · Ready for human reviewScope: full · Full PR review. No correctness findings. Checks and execution details
View review · Reviewed |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
) Backport of BerriAI#47155 to stable/1.103.x. Cherry-picked from 4143e08 (main).
) Backport of BerriAI#47155 to stable/1.106.x. Cherry-picked from 4143e08 (main).
) Backport of BerriAI#47155 to stable/1.105.x. Cherry-picked from 4143e08 (main).
) Co-authored-by: Joshua Valluru <326636767+joshua-berri@users.noreply.github.com> (cherry picked from commit 4143e08)
TLDR
Problem this solves:
How it solves it:
User Flow
Before, an all-failed batch can repeatedly produce an error during cost reconciliation
list index out of rangeAfter, the same batch finishes cost reconciliation with a fallback identity
Relevant issues
Addresses the empty-model case in #45065
Linear ticket
Resolves LIT-9498
Pre-Submission checklist
Verification
The parameterized regression runs the cost poller twice with all-failed, mixed, and successful output. It checks the logged identity, exact cost and tokens, success/failure counts, processed state, and one accounting callback
Both empty-model cases fail on the baseline with
IndexError. All five cases pass on the candidate, and the two affected test files pass all 305 testsLocal changed executable-line coverage is 1/1. The touched function has 12/18 branches covered, with the six existing uncovered branches outside this fallback. All three identity choices are exercised
Independent Devin MCP execution at
fa2effb94d1f98bc4643eca5406df72894989ae3confirmed the same five cases using the real Router, logging pipeline, HTTP downloads and PostgreSQL. No LiteLLM function was patched. All 305 tests passed independently, and 16 existing failure/retry tests passed on both source buildsLocal canonical lint, test-quality, type-discipline, OpenAPI, import checks and type-count comparison passed. All four required CI checks passed, including the affected 395-test shard. Its uploaded coverage artifact covers the changed executable line (1/1). Codecov finished processing both fresh uploads and reports 100% changed-line coverage (1/1). Repository coverage is 87.77%
Bugbot and Veria found no issues on
fa2effb94d1f98bc4643eca5406df72894989ae3. LiteReview gave 5/5, ran all 128 worker tests, and confirmed both regressions fail when the fix is reverted. Greptile was requested but has not returned a review, so full readiness remains pendingScreenshots / Proof of Fix
This is a controlled replay of the reported file-download boundary, using a real HTTP fixture server and scratch PostgreSQL databases. The provider responses are synthetic. It does not demonstrate live provider batch creation, proxy HTTP routes, or insertion into
LiteLLM_SpendLogsThe replay uses source builds and asserts imported paths. The complete executed harness and setup are included below, with no credentials
Executed replay harness and setup
Setup steps before running (not part of run.sh):
git worktree add --detach <H>/base b5037f28andgit worktree add --detach <H>/head fa2effb9createdb v9498_baseandcreatedb v9498_headDATABASE_URL=<db> .venv/bin/prisma db push --schema .venv/lib/python3.12/site-packages/prisma/schema.prisma --skip-generate. TheLiteLLM_ManagedObjectTablemodel there is identical to the one in both worktrees.harness/run.sh
harness/fake_openai.py
harness/run_cases.py
Before (b5037f2)
All-failed output
harness/run.sh base 18491using the shared setup belowopenai/and the empty deployment model, observe zero accounting events, an unprocessed row, andlist index out of rangeon both pollsMixed and successful output
After (fa2effb)
All-failed output
harness/run.sh head 18492using the shared setup belowopenai/and the deployment ID respectively; each downloads once, with no repeat accountingMixed and successful output
Measured before and after results
(b5037f2)
{"source":{"litellm":"/home/ubuntu/wt9498/base/litellm/__init__.py","check_batch_cost":"/home/ubuntu/wt9498/base/enterprise/litellm_enterprise/proxy/common_utils/check_batch_cost.py","worktree_head":"b5037f28d172f6f6375ba3d08dcdf2c10deb8d2d","check_batch_cost_dirty":""},"registered_deployments":["dep-A_allfailed_openai_slash","dep-B_allfailed_empty_model","dep-C_mixed_openai_slash","dep-D_mixed_named","dep-E_allsuccess_control"],"aretrieve_batch_events_per_poll":[3,0],"cases":{"A_allfailed_openai_slash":{"deployment_model":"openai/","successes":0,"failures":2,"events":0,"logged_model":null,"model_id":null,"model_group":null,"response_cost":null,"expected_cost":0.0,"prompt_tokens":null,"completion_tokens":null,"batch_successful_requests":null,"batch_failed_requests":null,"batch_models":null,"db_batch_processed":false,"db_status":"validating","provider_retrieve_hits":2,"provider_content_downloads":2,"poller_logs":["ERROR CheckBatchCost: failed to track cost for batch batch_A_allfailed_openai_slash (job e12b56af-5b63-4b37-a648-d90221e9ea3a); leaving it unprocessed so the next poll retries: list index out of range","ERROR CheckBatchCost: failed to track cost for batch batch_A_allfailed_openai_slash (job e12b56af-5b63-4b37-a648-d90221e9ea3a); leaving it unprocessed so the next poll retries: list index out of range"]},"B_allfailed_empty_model":{"deployment_model":"","successes":0,"failures":2,"events":0,"logged_model":null,"model_id":null,"model_group":null,"response_cost":null,"expected_cost":0.0,"prompt_tokens":null,"completion_tokens":null,"batch_successful_requests":null,"batch_failed_requests":null,"batch_models":null,"db_batch_processed":false,"db_status":"validating","provider_retrieve_hits":2,"provider_content_downloads":2,"poller_logs":["ERROR CheckBatchCost: failed to track cost for batch batch_B_allfailed_empty_model (job 7b41f7a6-ae42-490f-a98b-e2b23ae8a7ca); leaving it unprocessed so the next poll retries: list index out of range","ERROR CheckBatchCost: failed to track cost for batch batch_B_allfailed_empty_model (job 7b41f7a6-ae42-490f-a98b-e2b23ae8a7ca); leaving it unprocessed so the next poll retries: list index out of range"]},"C_mixed_openai_slash":{"deployment_model":"openai/","successes":2,"failures":1,"events":1,"logged_model":"gpt-4o-mini","model_id":"dep-C_mixed_openai_slash","model_group":"grp-C_mixed_openai_slash","response_cost":2.7e-05,"expected_cost":2.7e-05,"prompt_tokens":200,"completion_tokens":40,"batch_successful_requests":2,"batch_failed_requests":1,"batch_models":["gpt-4o-mini","gpt-4o-mini"],"db_batch_processed":true,"db_status":"complete","provider_retrieve_hits":1,"provider_content_downloads":1,"poller_logs":[]},"D_mixed_named":{"deployment_model":"openai/gpt-4o-mini","successes":2,"failures":1,"events":1,"logged_model":"gpt-4o-mini","model_id":"dep-D_mixed_named","model_group":"grp-D_mixed_named","response_cost":2.7e-05,"expected_cost":2.7e-05,"prompt_tokens":200,"completion_tokens":40,"batch_successful_requests":2,"batch_failed_requests":1,"batch_models":["gpt-4o-mini"],"db_batch_processed":true,"db_status":"complete","provider_retrieve_hits":1,"provider_content_downloads":1,"poller_logs":[]},"E_allsuccess_control":{"deployment_model":"openai/gpt-4o-mini","successes":2,"failures":0,"events":1,"logged_model":"gpt-4o-mini","model_id":"dep-E_allsuccess_control","model_group":"grp-E_allsuccess_control","response_cost":2.7e-05,"expected_cost":2.7e-05,"prompt_tokens":200,"completion_tokens":40,"batch_successful_requests":2,"batch_failed_requests":0,"batch_models":["gpt-4o-mini"],"db_batch_processed":true,"db_status":"complete","provider_retrieve_hits":1,"provider_content_downloads":1,"poller_logs":[]}}}head/result.json (fa2effb)
{"source":{"litellm":"/home/ubuntu/wt9498/head/litellm/__init__.py","check_batch_cost":"/home/ubuntu/wt9498/head/enterprise/litellm_enterprise/proxy/common_utils/check_batch_cost.py","worktree_head":"fa2effb94d1f98bc4643eca5406df72894989ae3","check_batch_cost_dirty":""},"registered_deployments":["dep-A_allfailed_openai_slash","dep-B_allfailed_empty_model","dep-C_mixed_openai_slash","dep-D_mixed_named","dep-E_allsuccess_control"],"aretrieve_batch_events_per_poll":[5,0],"cases":{"A_allfailed_openai_slash":{"deployment_model":"openai/","successes":0,"failures":2,"events":1,"logged_model":"openai/","model_id":"dep-A_allfailed_openai_slash","model_group":"grp-A_allfailed_openai_slash","response_cost":0.0,"expected_cost":0.0,"prompt_tokens":0,"completion_tokens":0,"batch_successful_requests":0,"batch_failed_requests":2,"batch_models":[],"db_batch_processed":true,"db_status":"complete","provider_retrieve_hits":1,"provider_content_downloads":1,"poller_logs":[]},"B_allfailed_empty_model":{"deployment_model":"","successes":0,"failures":2,"events":1,"logged_model":"dep-B_allfailed_empty_model","model_id":"dep-B_allfailed_empty_model","model_group":"grp-B_allfailed_empty_model","response_cost":0.0,"expected_cost":0.0,"prompt_tokens":0,"completion_tokens":0,"batch_successful_requests":0,"batch_failed_requests":2,"batch_models":[],"db_batch_processed":true,"db_status":"complete","provider_retrieve_hits":1,"provider_content_downloads":1,"poller_logs":[]},"C_mixed_openai_slash":{"deployment_model":"openai/","successes":2,"failures":1,"events":1,"logged_model":"gpt-4o-mini","model_id":"dep-C_mixed_openai_slash","model_group":"grp-C_mixed_openai_slash","response_cost":2.7e-05,"expected_cost":2.7e-05,"prompt_tokens":200,"completion_tokens":40,"batch_successful_requests":2,"batch_failed_requests":1,"batch_models":["gpt-4o-mini","gpt-4o-mini"],"db_batch_processed":true,"db_status":"complete","provider_retrieve_hits":1,"provider_content_downloads":1,"poller_logs":[]},"D_mixed_named":{"deployment_model":"openai/gpt-4o-mini","successes":2,"failures":1,"events":1,"logged_model":"gpt-4o-mini","model_id":"dep-D_mixed_named","model_group":"grp-D_mixed_named","response_cost":2.7e-05,"expected_cost":2.7e-05,"prompt_tokens":200,"completion_tokens":40,"batch_successful_requests":2,"batch_failed_requests":1,"batch_models":["gpt-4o-mini"],"db_batch_processed":true,"db_status":"complete","provider_retrieve_hits":1,"provider_content_downloads":1,"poller_logs":[]},"E_allsuccess_control":{"deployment_model":"openai/gpt-4o-mini","successes":2,"failures":0,"events":1,"logged_model":"gpt-4o-mini","model_id":"dep-E_allsuccess_control","model_group":"grp-E_allsuccess_control","response_cost":2.7e-05,"expected_cost":2.7e-05,"prompt_tokens":200,"completion_tokens":40,"batch_successful_requests":2,"batch_failed_requests":0,"batch_models":["gpt-4o-mini"],"db_batch_processed":true,"db_status":"complete","provider_retrieve_hits":1,"provider_content_downloads":1,"poller_logs":[]}}}Caveats
Low
Type
Bug Fix
Final Attestation