Skip to content

fix(lens): refund failed model requests without a response - #44430

Closed
moe-berri wants to merge 1 commit into
mainfrom
litellm_lens_budget_failure_fix
Closed

moe-berri wants to merge 1 commit into
mainfrom
litellm_lens_budget_failure_fix

Conversation

@moe-berri

@moe-berri moe-berri commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Superseded by merged #44431, which fixes the same budget-settlement bug. The extra regression assertion remains in #44428

TLDR

Problem this solves:

  • Failed analysis requests crash while releasing reserved budget

How it solves it:

  • Refund failed requests without reading a nonexistent response
  • Record completion details only after a model responds

User Flow

Before: an analysis provider error becomes an internal error and leaves reserved spend behind

  1. Run a Lens investigation using a provider that returns an error
  2. The worker receives HTTP 500 with an undefined-response error
  3. The investigation retains the request's estimated spend

After: the provider error is preserved and reserved spend is released

  1. Run a Lens investigation using a provider that returns an error
  2. The worker receives the provider's original error status
  3. The investigation releases the estimated spend without recording a completion

Validation

Reproduced the regression on fe683ea139 against a fresh PostgreSQL database: a rate-limited request returned HTTP 500 instead of 429. The fixed database lifecycle suite passes all eight cases, including three repeated provider failures with zero retained budget and no fabricated model-completion steps

The full Lens suite passes 200 tests. make check passes on this branch and with the fix in the coordinated-release branch. Current-tip hosted checks pass, including Codecov coverage of every modified executable line. The eight PostgreSQL lifecycle cases also passed again against a fresh disposable database

Screenshots / Proof of Fix

Both runs used the same local proxy at http://127.0.0.1:4426, real PostgreSQL, and a real paid provider. Register an analysis model with explicit pricing and a limited worker key, create an investigation, and claim it. The IDs below are the values returned by those API calls. The success request body is {"purpose":"extract","prompt":"Return JSON only: {\"observations\":[]}"}. Then replace only that test deployment's provider credential with an invalid value and send the same request again

Before (fe683ea)

  1. Send POST http://127.0.0.1:4426/lens/worker/<lens-id>/<job-id>/model with the worker token and request above: HTTP 200, actual cost $0.000274
  2. Repeat after invalidating the test provider credential: HTTP 500, cannot access free variable 'response'
  3. Read GET http://127.0.0.1:4426/lens/<lens-id>: spend increases to $0.041398 despite the failed request

After (91644ec)

  1. Send POST http://127.0.0.1:4426/lens/worker/<lens-id>/<job-id>/model with the worker token and request above: HTTP 200, actual cost $0.000274
  2. Repeat after invalidating the test provider credential: HTTP 401; two immediate retries return the router's HTTP 429 cooldown response
  3. Read GET http://127.0.0.1:4426/lens/<lens-id> after each failure: spend stays $0.000274 and the one successful model step is preserved

Companion changes

Found during end-to-end release validation for #44428. This focused fix can merge independently; the release branch also contains it for combined validation

Pre-Submission checklist

  • Meaningful regression tests pass locally
  • Current-tip hosted tests and coverage pass
  • The fix only changes failed-request budget settlement
  • Greptile, Veria, and Bugbot reviews are available and acceptable

Caveats

Low

  • Required automated reviews have not appeared; keeping this draft

Type

Bug fix

@codspeed

codspeed Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing litellm_lens_budget_failure_fix (91644ec) with main (fe683ea)

Open in CodSpeed

@codecov

codecov Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@moe-berri

Copy link
Copy Markdown
Contributor Author

@greptileai @veria-ai Please review the current tip for release regressions, incompatible worker versions, unsafe upgrades, and missed failure paths

@moe-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

Please review the current tip for release regressions, incompatible worker versions, unsafe upgrades, and missed failure paths

@moe-berri moe-berri closed this Oct 3, 2026
@greptile-apps

greptile-apps Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium risk] Changes how failed model requests record their lifecycle.

The PR appears safe to merge; no issue caused by the changed code was established.

Summary

The PR refunds Lens budget reservations when a model request fails without a response and records a model step only after a response exists.

  • Adds a regression assertion that repeated provider failures leave no model-completion steps.

Reviews (1) · Last reviewed commit: "fix(lens): refund failed model requests ..."

@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 91644ec. Configure here.

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.

1 participant