fix(budgets): make LiteLLM spend reporting resilient - #242
Draft
ak684 wants to merge 8 commits into
Draft
Conversation
|
|
ak684
force-pushed
the
alona/ohe-budget-resilient-snapshots
branch
from
August 25, 2026 17:41
6f6e066 to
b92e861
Compare
Use LiteLLM cumulative team and membership spend minus stored cycle baselines for budget UI and alert calculations. Keep per-member baselines for all LiteLLM members so direct SDK/API usage is visible in reporting and threshold checks.\n\nCo-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: openhands <openhands@all-hands.dev>
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Context
This is an alternative follow-up to #207. It includes the useful #207 changes on top of current
main. LiteLLM counters drive budget reporting and sync writes are verified, but this PR hardens the boundary before those counters can affect durable OpenHands cycle state.The intended authority split is:
If this direction makes sense, this PR can supersede #207.
What changes
$0.LiteLlmManageradapter so upstream contract drift cannot be normalized to zero before service validation sees it.live,stale, orunavailable, including the observation timestamp. Unknown spend remainsnullthrough the API and UI.Required before declaring the budget work 100% shipped
user_cycle_start_spendmap has no baseline for an existing member. Migration 149 introduced this map with an empty default. The current compatibility behavior initializes a missing baseline to the member's current cumulative spend, which gives that member a full allowance from deployment time. The alternatives are a conservative no-additional-allowance policy until the next cycle or a historical backfill from a trustworthy per-user spend source. This cannot be inferred safely from the current schema alone.The first two items are policy-dependent code work. They do not require a change to the LiteLLM repository, but they require an explicit allowance decision because the historical per-user counter needed to distinguish prior-cycle spend from current-cycle spend may no longer exist. The third and fourth items are release validation and operations work rather than missing implementation in this PR.
Known boundary, not a ship blocker
This solution does not require an upstream LiteLLM change. A future endpoint exposing the same counter used synchronously by enforcement could reduce observation lag, but the dashboard still could not atomically predict whether a later inference request will be admitted. The UI therefore presents the observation time and treats LiteLLM as the final request-admission authority.
Validation
PYTHONPATH=enterprise poetry run --project=enterprise pytest enterprise/tests/unit/test_org_budget_service.py enterprise/tests/unit/test_org_budget_maintenance_processor.py enterprise/tests/unit/test_lite_llm_manager.py enterprise/tests/unit/test_migration_graph.py -qpassed locally.npm run lint:fixpassed with five existing warnings.npm run buildpassed.npm run typecheckpassed.npm run test -- --run __tests__/components/features/budgets/budgets.test.tsxpassed.The new failure-path coverage includes transient read retry, malformed payloads, last-known-good fallback, no-cache unavailability, rollback on enable without fresh data, rollover preservation during an outage, readback mismatch, and membership drift.
Enterprise server image for this PR: