Skip to content

test(decisions): audit #47508 - #48777

Merged
mateo-berri merged 3 commits into
BerriAI:mainfrom
tavren27:litellm_audit_47508
Oct 28, 2026
Merged

mateo-berri merged 3 commits into
BerriAI:mainfrom
tavren27:litellm_audit_47508

Conversation

@tavren27

@tavren27 tavren27 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Post-merge audit of #47508, which bills a TypeSafe decisions reply at the requested model's price when the version it answered as has no prices in the cost map, and turns an upstream 200 reply that fails the response schema into a 500 naming the bad field. Every audited behavior holds at the merge commit, and the bugs it fixed still show up at its parent

This adds a timeout-text case to the malformed reply test and a priced returned-version cost case, and points the Databricks decisions cell at its cost-map row, since #48694 priced that model on main. No product code changes

Original

TLDR

Problem this solves:

How it solves it:

User Flow

This PR only adds tests. The flow below is the one #47508 changed

Before (06d56eb): a developer whose TypeSafe deployment answers as a newer version is not billed, and a malformed reply comes back with a guessed status

  1. They send POST https://litellm-domain/v1/systemone with model typesafe/jev-latest and one noul question
  2. TypeSafe answers 200 as jev-1.13.0, a version with no prices in the cost map
  3. The reply carries no x-litellm-response-cost header, so the request is not billed
  4. A 200 reply with no answers field is a 500 naming no field, and an answer reading "Request timed out" is a 408

After (81d8c9a): the request is billed at typesafe/jev-latest's price, and a malformed reply is a 500 that names the field

  1. They send POST https://litellm-domain/v1/systemone with model typesafe/jev-latest and one noul question
  2. TypeSafe answers 200 as jev-1.13.0, a version with no prices in the cost map
  3. x-litellm-response-cost is typesafe/jev-latest's input price times the input tokens, and the spend log row matches
  4. The reply with no answers is a 500 naming answers, the timeout-like answer is a 500 naming answers.defect

Relevant issues

Follow-up audit of #47508

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*, make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • Every automated review on my PR's latest commit has finished, and I have addressed or replied to each of its findings before requesting a maintainer review

Delays in PR merge?

If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).

Screenshots / Proof of Fix

Audit verdict PASS. Base is #47508's parent 06d56eb6d7, head is its merge commit 81d8c9af38, and tip is this branch's a7ba8de4e0, which carries main up to 1176e608b1. Each leg had its own proxy, database, Redis and scripted upstream, with CircleCI's settings, and the head ran twice with the same seeds

Row Contract Base Head Tip
R1 Unpriced returned version bills at requested model, /v1/decisions FAIL PASS x2 PASS
R2 Same on /v1/systemone FAIL PASS x2 PASS
R3 Priced returned version bills at its own price PASS PASS x2 PASS
R4 Reply with no answers is a 500 naming it FAIL PASS x2 PASS
R5 Timeout-like answer text is a 500, never a 408 FAIL PASS x2 PASS
R6 Upstream 401, 429 and 500 keep their status PASS PASS x3 PASS
R7 Unreachable upstream stays a connection error PASS PASS x3 PASS
R8 Each provider's valid reply parses and bills PASS PASS x3 PASS
R9 base_model cross-provider pricing PASS PASS x3 PASS
U1-U3 Decision parsing and pricing rules (unit) n/a PASS PASS

Every case runs uv run --no-sync python tests/integration/run.py <group> <node ids> against the leg's proxy

Before (06d56eb)

An unpriced returned version is billed at the requested model

  1. run.py cost 'tests/integration/cost_calculation/test_cost_tracking.py::test_case_bills_expected_cost[typesafe/jev-latest-decisions]' '...[typesafe/jev-latest-systemone]'
  2. Both fail with x-litellm-response-cost None != expected 1.197e-05

A returned version with its own prices

Steps
  1. run.py cost '...::test_case_bills_expected_cost[typesafe/jev-preview-answered-as-priced-version-systemone]'
  2. Passes, billed at typesafe/jev-latest's price

A reply with no answers field

Steps
  1. run.py providers 'tests/integration/providers/test_decisions_wire.py::test_a_malformed_upstream_success_is_a_server_error_naming_the_field[missing_answers]'
  2. Fails. The 500 reads Input should be a valid dictionary and names no field

An answer whose text reads like a timeout

Steps
  1. run.py providers '...::test_a_malformed_upstream_success_is_a_server_error_naming_the_field[answer_type_timeout_text]'
  2. Fails with assert 408 == 500, the reply being litellm.Timeout with code 408

Unchanged behavior

Steps
  1. run.py providers on the 401, 429 and 500 status cells, both unreachable-upstream cells, and the per-provider cell for every provider
  2. run.py cost on the three test_base_model_cross_provider_spend.py params
  3. All pass

After (81d8c9a)

An unpriced returned version is billed at the requested model

  1. Same command as Before
  2. Both pass on both head runs, with a matching spend row

A returned version with its own prices

Steps
  1. Same command as Before
  2. Passes on both head runs

A reply with no answers field

Steps
  1. Same command as Before
  2. Passes on both head runs. The 500 names answers and the spend row is a failure

An answer whose text reads like a timeout

Steps
  1. Same command as Before
  2. Passes on both head runs. The 500 names answers.defect and the spend row is a failure

Unchanged behavior

Steps
  1. Same commands as Before, on both head runs and on a separate controls rig
  2. All pass

At the tip a7ba8de4e0 every cell passes again. The Databricks per-provider cell failed at c7239bdf02 because #48694 priced that model on main, and now passes at the base, the head twice and the tip

Type

✅ Test

Caveats (if any)

Low

  • OSV Scan is red on main too, so this PR does not cause it

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR
Bugbot summary

[!NOTE]
Low Risk
Only integration test fixtures and assertions change; no runtime gateway or billing logic is modified.

Overview
Test-only follow-up to lock in behaviors from #47508 (decisions billing when the answered-as model differs from the request, and 500 responses that name the invalid field on schema failures). No product code changes.

Integration cost coverage adds a /v1/systemone case where the client asks for typesafe/jev-preview but the upstream answers as priced jev-latest, asserting spend uses typesafe/jev-latest token rates—not the preview alias. The scripted suite cost map gains a typesafe/jev-preview row so that scenario can run.

In provider wire tests, the malformed-upstream test is parametrized: missing answers and an answer whose type is timeout-like text both expect HTTP 500 with the failing field (answers vs answers.defect) in the body and a failed spend row. The Databricks provider fixture now points cost_map_key at its cost-map entry so per-provider billing expectations stay correct after that model was priced on main.

Reviewed by Cursor Bugbot for commit a7ba8de. Bugbot is set up for automated code reviews on this repo. Configure here.

@codecov

codecov Bot commented Oct 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@mateo-berri

Copy link
Copy Markdown
Contributor

@litereview code-review

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@greptile-apps

greptile-apps Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge, with no new actionable issues found

Summary

This test-only PR adds coverage for malformed Decisions replies and returned-model pricing

  • Cost checks cover a TypeSafe reply that names a priced version.
  • Malformed decision replies now include a timeout-like answer case.
  • The Databricks provider test uses its model's catalog price.

mateo-berri accepted scripted proof for the malformed-reply case because real Perplexity cannot be made to send that reply. No new actionable issues were found. Tests were not run during this review

Reviews (2) · Last reviewed commit: "test(decisions): price the Databricks de..." · Reviewed by Greptile

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ 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 a7ba8de. Configure here.

@mateo-berri mateo-berri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@mateo-berri
mateo-berri merged commit 889d8ae into BerriAI:main Oct 28, 2026
93 of 95 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants