Repository navigation
fix(proxy): drop cost-map metadata echoed back on model save - #41944
Conversation
Filter unchanged cost-map fields from model-info save echoes while preserving edited overrides. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
Merging this PR will not alter performance
Comparing |
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…he cost-map value Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
… lookup Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
tin-berri
left a comment
There was a problem hiding this comment.
Approving. Filters out model_info fields the Admin UI echoes back unchanged from /model/info, so a plain save no longer persists cost-map display values as operator overrides. Using the presence of the cost-map key as the echo signal, plus per-field equality against the resolved entry, means an edited value still counts as a real override. base_model and encrypted-model lookup paths are covered in tests.
…_map_metadata_echo
…n after router registration Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
… the bundled backup Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…apping[str, object] Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…f patching the class Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…_map_metadata_echo Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> # Conflicts: # litellm/proxy/management_endpoints/model_management_endpoints.py
|
@greptileai merged main into head 099a8f6 (import-order conflict only); verdict for 0141ea4 remains an ancestor. |
|
The main merge only resolves an import-order conflict. The reviewed PR changes remain an ancestor, so the previous 5/5 confidence score and no-actionable-findings verdict still stand. |
…under BLE001 budget Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
@greptileai new head f8c28e2: swapped the blind except for contextlib.suppress after main used up the BLE001 budget. |
TLDR
Problem this solves:
How it solves it:
/model/infoderived them from (looked up bybase_model, else the deployment's decryptedlitellm_params.model)keyas last loaded (remote map or bundled backup, snapshotted before anyregister_modelor router registration toucheslitellm.model_cost), so a reset reads as an echo even after the router registered a deployment's override under the shared modelUser Flow
Before: an operator changes one field on a deployment in the Admin UI and every cost-map field the form showed is stored as an override
model_infokey,litellm_provider,max_input_tokens,supported_openai_params,supports_*and so onAfter: the same save stores only what the operator set, so cost map updates keep flowing
Relevant issues
None
Affected release
None (unreleased)
Linear ticket
Resolves LIT-5534
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/test_litellm/<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@greptileaito re-request a review after pushing changes)Delays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Taxonomy audit
Run against the current diff (production and test files) using the rules restated in the automation brief plus the H lints; the knowledge note itself was not reachable from this session
==against each resolved entry, so0,False,[]and""compare as values and are never treated as missingmodel_dumpproduces a fresh dict, the filter builds a new mapping, the loaded catalog snapshot is validated through aTypeAdapterinto nestedMappingProxyType, so neither the caller'supdated_patchnorlitellm.model_costis mutatedloaded_model_cost_mapis re-snapshotted by every cost-map load (startup and the periodic remote refetch, a single attribute rebind so readers see either the old or the new snapshot), the live entry is still read fresh on every save, so nothing stale is servedmonkeypatchrestores the one patched lookupadd_new_modelis excluded on purpose, the Add Model form never sends the cost-mapkeyso the echo cannot occur thereget_model_infolookup failure, an undecryptable stored model, or akeymissing from the loaded catalog returns an empty entry, which filters nothing, so a lookup problem can only keep the old behaviour, never drop a valueX | Nonestyle, typedMappingparams, the catalog is validated through a PydanticTypeAdapterrather than typedAny, line length under 120Screenshots / Proof of Fix
Shared setup: Postgres plus the proxy started with
PYTHONPATH=<checkout>on~/repro/config.yaml, the Before tree is a worktree at the merge base on port 4011, the After tree is the PR tip on port 4010H='Authorization: Bearer <that key>'. Both arms run the same script (~/repro/arm.sh <port> <id> <tree>) with byte-identical payloads; the served tree is identified bygrep -c _loaded_catalog_entry litellm/proxy/management_endpoints/model_management_endpoints.pyin the tree the proxy imports (MARKER_loaded_catalog_entry ABSENTfor Before,PRESENTfor After).rowispsql "$DATABASE_URL" -Atc "select model_info from \"LiteLLM_ProxyModelTable\" where model_id='$ID'"with the created_/updated_ bookkeeping fields stripped for readability. Thedb-minirows were deleted before each armBefore (6ef7b86)
add the deployment the way the Add Model form does (model_info = mode only)
curl -s localhost:4011/model/new -H "$H" -H 'Content-Type: application/json' -d '{"model_name":"db-mini","litellm_params":{"model":"openai/gpt-4.1-mini","api_key":"os.environ/OPENAI_API_KEY"},"model_info":{"id":"dep-before-6ef7b8","mode":"chat"}}' -o /dev/null -w "HTTP %{http_code}\n"/model/info echoes cost-map metadata into model_info (what the UI edit form seeds)
INFO=$(curl -s "localhost:4011/model/info?litellm_model_id=dep-before-6ef7b8" -H "$H" | python3 -c 'import json,sys; print(json.dumps(json.load(sys.stdin)["data"][0]["model_info"]))')save the untouched echo with access_groups added
P=$(echo "$INFO" | python3 -c 'import json,sys; d=json.load(sys.stdin); d["access_groups"]=["prod"]; print(json.dumps({"model_info":d}))'); curl -s -X PATCH localhost:4011/model/dep-before-6ef7b8/update -H "$H" -H 'Content-Type: application/json' -d "$P" -o /dev/null -w "HTTP %{http_code}\n"; rowedit max_input_tokens to 2048 in the echoed blob
P=$(echo "$INFO" | python3 -c 'import json,sys; d=json.load(sys.stdin); d["access_groups"]=["prod"]; d["max_input_tokens"]=2048; print(json.dumps({"model_info":d}))'); curl -s -X PATCH localhost:4011/model/dep-before-6ef7b8/update -H "$H" -H 'Content-Type: application/json' -d "$P" -o /dev/null -w "HTTP %{http_code}\n"; rowreload the form and type the catalog value back
INFO2=$(curl -s "localhost:4011/model/info?litellm_model_id=dep-before-6ef7b8" -H "$H" | ...same extraction...); P=$(echo "$INFO2" | python3 -c "import json,sys; d=json.load(sys.stdin); d['max_input_tokens']=1047576; print(json.dumps({'model_info':d}))"); curl -s -X PATCH localhost:4011/model/dep-before-6ef7b8/update -H "$H" -H 'Content-Type: application/json' -d "$P" -o /dev/null -w "reset to 1047576 -> HTTP %{http_code}\n"; rowthe deployment still serves a real request
curl -s localhost:4011/v1/chat/completions -H "$H" -H 'Content-Type: application/json' -d '{"model":"db-mini","messages":[{"role":"user","content":"Say ok"}],"max_tokens":5}'After (0141ea4; head f8c28e2 adds only a main merge and an equivalent
contextlib.suppressswap for the BLE001 budget)add the deployment the way the Add Model form does (model_info = mode only)
curl -s localhost:4010/model/new -H "$H" -H 'Content-Type: application/json' -d '{"model_name":"db-mini","litellm_params":{"model":"openai/gpt-4.1-mini","api_key":"os.environ/OPENAI_API_KEY"},"model_info":{"id":"dep-after-v4","mode":"chat"}}' -o /dev/null -w "HTTP %{http_code}\n"/model/info echoes cost-map metadata into model_info (what the UI edit form seeds)
INFO=$(curl -s "localhost:4010/model/info?litellm_model_id=dep-after-v4" -H "$H" | python3 -c 'import json,sys; print(json.dumps(json.load(sys.stdin)["data"][0]["model_info"]))')save the untouched echo with access_groups added
P=$(echo "$INFO" | python3 -c 'import json,sys; d=json.load(sys.stdin); d["access_groups"]=["prod"]; print(json.dumps({"model_info":d}))'); curl -s -X PATCH localhost:4010/model/dep-after-v4/update -H "$H" -H 'Content-Type: application/json' -d "$P" -o /dev/null -w "HTTP %{http_code}\n"; rowedit max_input_tokens to 2048 in the echoed blob
P=$(echo "$INFO" | python3 -c 'import json,sys; d=json.load(sys.stdin); d["access_groups"]=["prod"]; d["max_input_tokens"]=2048; print(json.dumps({"model_info":d}))'); curl -s -X PATCH localhost:4010/model/dep-after-v4/update -H "$H" -H 'Content-Type: application/json' -d "$P" -o /dev/null -w "HTTP %{http_code}\n"; rowreload the form and type the catalog value back
INFO2=$(curl -s "localhost:4010/model/info?litellm_model_id=dep-after-v4" -H "$H" | ...same extraction...); P=$(echo "$INFO2" | python3 -c "import json,sys; d=json.load(sys.stdin); d['max_input_tokens']=1047576; print(json.dumps({'model_info':d}))"); curl -s -X PATCH localhost:4010/model/dep-after-v4/update -H "$H" -H 'Content-Type: application/json' -d "$P" -o /dev/null -w "reset to 1047576 -> HTTP %{http_code}\n"; rowopenai/gpt-4.1-miniin this process):the deployment still serves a real request
curl -s localhost:4010/v1/chat/completions -H "$H" -H 'Content-Type: application/json' -d '{"model":"db-mini","messages":[{"role":"user","content":"Say ok"}],"max_tokens":5}'Regression tests, run with
LITELLM_LOCAL_MODEL_COST_MAP=True uv run --no-sync pytest tests/test_litellm/proxy/management_endpoints/test_model_management_endpoints.py -q: 272 passed. Mutation checks: removing thek not in echoed_fieldsfilter fails the echo tests, removing the cost-map key gate fails the no-key test, removing the equality check fails the edited-value test, removing the reset loop fails the reset test, looking the entry up bykeyinstead of the deployment model fails 3 tests, skipping decryption fails the encrypted-model test, dropping the loaded catalog argument failstest_reset_is_recognised_after_the_router_registered_the_overrideandtest_reset_to_a_remote_catalog_value_that_differs_from_the_bundled_one, replacing the snapshot call withpassfailstest_loaded_catalog_snapshot_follows_the_fetched_map_and_ignores_later_registrationsintests/test_litellm/litellm_core_utils/test_get_model_cost_map.py(34 passed).make checkpassesType
🐛 Bug Fix
Caveats (if any)
Low
keyabsent from it falls back to the live entry alone, which is the previous behaviourkey, so no echo happens there/model/{id}/update(both the admin and the team-model paths shareupdate_db_model). The legacy/model/updatenever writes incomingmodel_info, so it has nothing to filterlitellm.get_model_infofor the duration of the test, since the live lookup is a module function rather than an injected dependency; the loaded catalog is injected intoupdate_db_modelas a callable insteadFinal Attestation
Link to Devin session: https://app.devin.ai/sessions/a4ca2e0396d94fe9a24d7805d503de96
Open in Devin Desktop: https://app.devin.ai/desktop/session/a4ca2e0396d94fe9a24d7805d503de96?variant=devin