Repository navigation
fix(proxy): share the billing logger across callback registries - #47510
Conversation
|
@litereview code-review please review the current commit for duplicate accounting, preserved callback selection, and the included live verification evidence |
|
@greptileai please review the current commit for duplicate accounting, distinct logger preservation, and compatibility with existing callback registration behavior |
|
bugbot run please review the current commit for duplicate accounting, preserved callback selection, and meaningful regression coverage across logger configurations |
[Medium impact] The PR appears safe to merge, with the clock-read finding fixed and no new actionable issues found Summary
Reviews (3) · Last reviewed commit: "test(proxy): use fixed timestamps for bi..." · Reviewed by Greptile |
✅ code-review5/5 · Ready for human reviewScope: full · Full PR review. No correctness findings. Checks and execution details
View review · Reviewed |
Merging this PR will not alter performance
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
@greptileai please review a00e72d, which shares the billing logger at registration and restores baseline generic callback selection, addressing both findings |
|
@litereview code-review please review a00e72d, which shares the billing logger at registration, preserves distinct configurations, and adds accounting regression coverage |
|
bugbot run please review a00e72d for duplicate billing, repeated setup behavior, and preservation of distinct logger configurations after removing generic filtering |
|
@greptileai please review 7ee91eb, which replaces both new test clock reads with fixed timestamps and preserves the approved production fix |
|
@litereview code-review please refresh your review for 7ee91eb, a fixed-timestamp test follow-up with unchanged production code and passing local gates |
|
bugbot run please refresh your review for 7ee91eb, a fixed-timestamp test follow-up with unchanged production code and passing local gates |
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 7ee91eb. Configure here.
…ecisions pricing and missing-answers fixes
…sted model and name a missing answers field (#47508) * test: bill each completed request once and price unpriced returned decision models at the requested model Co-authored-by: Joshua Valluru <326636767+joshua-berri@users.noreply.github.com> * fix(logging,decisions): bill each request once and price returned decision models only when they carry rates Co-authored-by: Joshua Valluru <326636767+joshua-berri@users.noreply.github.com> * fix(decisions): leave the double-billing fix to #47510 and keep the decisions pricing and missing-answers fixes * fix(decisions): name malformed answer entries and pick the Arize cache-hit span by attribute * test(decisions): cover a returned-model row with metadata but no rates * fix(decisions): keep upstream reply text out of the parse error so it stays a 500 * fix(decisions): answer every malformed upstream reply with a 500, whatever text it carries A reply that fails the decisions response schema now raises DecisionsResponseValidationError, which the decisions call maps straight to InternalServerError instead of passing it through exception_type. Its text matching read an answer key like rate_limit, or a value like "Request timed out", as a 429 or a 408, so the router cooled down a deployment for a reply that fails the same way on every retry. The message also drops the empty location for a reply that is not an object, the Arize family test loses the cache_hit entries main already added, and the Bedrock Mantle count-tokens wire test calls _metadata_deployment, since main renamed the _deployment helper under it. --------- Co-authored-by: Joshua Valluru <326636767+joshua-berri@users.noreply.github.com>
TLDR
Problem this solves
How it solves it
User Flow
Before, a non-streamed request adds twice its recorded cost to key spend
POST http://localhost:4000/key/generatePOST http://localhost:4000/v1/chat/completionsusing that key/key/infowith/spend/logs, key spend is doubledAfter, the same request adds its recorded cost once
POST http://localhost:4000/key/generatePOST http://localhost:4000/v1/chat/completionsusing that key/key/infowith/spend/logs, key spend matchesRelevant issues
Follow-up to #47192. Covers the duplicate billing portion of #47047, whose separate Decisions changes remain outside this PR
Linear ticket
Resolves LIT-9911
Implementation
cost_tracking()created separateProxyDBLoggerinstances for the general and async-success callback registries. Completed-success dispatch combined those registries and delivered both instances. The proxy now registers the same instance in both places, following the existing shared-instance registration conventionThe generic completed-success selector is identical to the merge base. No new logger equivalence policy is introduced. Different logger headers, event subscriptions and redaction settings retain their existing behavior
Tests
All 938 affected unit tests passed for the implementation. After the fixed-timestamp test follow-up at
7ee91ebff9954104214a085aeb4e235da275944d, all 47 focused cases and canonical local lint/type gates pass again. Production code is unchanged by that follow-up. The extended lifecycle test runs real registration, request setup, dispatch and event serialization, asserting one accounting publication after one or two setup calls. On the unfixed baseline it fails with two publications in both casesThe existing local source-built proxy/Postgres/Redis accounting tests pass for background response billing and batch callback delivery. Changed executable-line coverage is 3/3. The touched
cost_tracking()function has 7/7 lines and 2/2 branches coveredIndependent paid-call verification passed at this tip against the merge base. The baseline double-bills four of five API flows. This tip bills once on all five flows and a real completed two-line batch. Fresh-key zero-spend controls and delayed accounting rechecks passed. The independent lifecycle regression fails twice on the baseline and passes on this tip
All 107 hosted checks pass. The completed Codecov report shows 100% patch coverage. Greptile reports 5/5, and Veria, Bugbot and LiteReview have no unresolved actionable findings at this tip
Pre-Submission checklist
Type
Bug Fix
Test
Screenshots / Proof of Fix
Independently executed through Devin on 2026-10-20, using source builds at the SHAs below, separate Postgres databases, shared Redis on port 6390, and two workers per proxy. Source imports resolved inside each clean worktree. These were paid OpenAI calls with
gpt-6-lunaIdentical configuration on both sides, with secrets supplied through environment variables
From each checked-out source, start
PYTHONPATH="$PWD:$PWD/enterprise" python -m litellm.proxy.proxy_cli --config config.yaml --port "$PORT" --num_workers 2. Use port 4111 for Before and 4112 for After, and setBto that localhost URLBefore each case, create a fresh key and confirm its initial spend is zero
After each request, read both endpoints below once accounting has flushed, then recheck at 30 and 60 seconds. Every case below retained the same result on recheck
Amounts vary where the model generated different token counts. Compare key spend with that request's recorded cost, rather than comparing amounts across different responses
Before (ba61ecd)
Chat non-stream
curl -s "$B/v1/chat/completions" -H "Authorization: Bearer $KEY" -H 'content-type: application/json' -d '{"model":"gpt-6-luna","messages":[{"role":"user","content":"Reply with the single word: billing"}]}'8.8e-06, and key spend is1.76e-05Chat streaming control
curl -s "$B/v1/chat/completions" -H "Authorization: Bearer $KEY" -H 'content-type: application/json' -d '{"model":"gpt-6-luna","stream":true,"stream_options":{"include_usage":true},"messages":[{"role":"user","content":"Reply with the single word: billing"}]}'3.3e-06, and key spend is3.3e-06Responses
curl -s "$B/v1/responses" -H "Authorization: Bearer $KEY" -H 'content-type: application/json' -d '{"model":"gpt-6-luna","input":"Reply with the single word: billing"}'9.8e-06, and key spend is1.96e-05OpenAI pass-through
curl -s "$B/openai_passthrough/v1/responses" -H "Authorization: Bearer $KEY" -H 'content-type: application/json' -d '{"model":"gpt-6-luna","input":"Reply with the single word: billing"}'3.8e-06, and key spend is7.6e-06Messages
curl -s "$B/v1/messages" -H "Authorization: Bearer $KEY" -H 'content-type: application/json' -d '{"model":"gpt-6-luna","max_tokens":64,"messages":[{"role":"user","content":"Reply with the single word: billing"}]}'3.8e-06, and key spend is7.6e-06Completed batch control
general_settings.proxy_batch_polling_interval: 15, restart withPROXY_BATCH_POLLING_ENABLED=true, and create a fresh zero-spend keygpt-6-lunaand promptsReply with the single word: billingandReply with the single word: batchusingcurl -s "$B/v1/files" -H "Authorization: Bearer $KEY" -F purpose=batch -F target_model_names=gpt-6-luna -F file=@batch_in.jsonlcurl -s "$B/v1/batches" -H "Authorization: Bearer $KEY" -H 'content-type: application/json' -d '{"input_file_id":"<returned file id>","endpoint":"/v1/chat/completions","completion_window":"24h","model":"gpt-6-luna"}', then pollGET $B/v1/batches/<returned batch id>with the same key until completed6.05e-06and key spend is6.05e-06. File and batch creation rows have zero costAfter (7ee91eb)
Chat non-stream
curl -s "$B/v1/chat/completions" -H "Authorization: Bearer $KEY" -H 'content-type: application/json' -d '{"model":"gpt-6-luna","messages":[{"role":"user","content":"Reply with the single word: billing"}]}'3.3e-06, and key spend is3.3e-06Chat streaming control
curl -s "$B/v1/chat/completions" -H "Authorization: Bearer $KEY" -H 'content-type: application/json' -d '{"model":"gpt-6-luna","stream":true,"stream_options":{"include_usage":true},"messages":[{"role":"user","content":"Reply with the single word: billing"}]}'9.8e-06, and key spend is9.8e-06Responses
curl -s "$B/v1/responses" -H "Authorization: Bearer $KEY" -H 'content-type: application/json' -d '{"model":"gpt-6-luna","input":"Reply with the single word: billing"}'3.8e-06, and key spend is3.8e-06OpenAI pass-through
curl -s "$B/openai_passthrough/v1/responses" -H "Authorization: Bearer $KEY" -H 'content-type: application/json' -d '{"model":"gpt-6-luna","input":"Reply with the single word: billing"}'3.8e-06, and key spend is3.8e-06Messages
curl -s "$B/v1/messages" -H "Authorization: Bearer $KEY" -H 'content-type: application/json' -d '{"model":"gpt-6-luna","max_tokens":64,"messages":[{"role":"user","content":"Reply with the single word: billing"}]}'9.3e-06, and key spend is9.3e-06Completed batch control
general_settings.proxy_batch_polling_interval: 15, restart withPROXY_BATCH_POLLING_ENABLED=true, and create a fresh zero-spend keygpt-6-lunaand promptsReply with the single word: billingandReply with the single word: batchusingcurl -s "$B/v1/files" -H "Authorization: Bearer $KEY" -F purpose=batch -F target_model_names=gpt-6-luna -F file=@batch_in.jsonlcurl -s "$B/v1/batches" -H "Authorization: Bearer $KEY" -H 'content-type: application/json' -d '{"input_file_id":"<returned file id>","endpoint":"/v1/chat/completions","completion_window":"24h","model":"gpt-6-luna"}', then pollGET $B/v1/batches/<returned batch id>with the same key until completed9.3e-06and key spend is9.3e-06. File and batch creation rows have zero costCaveats
Low
Final Attestation