fix(proxy): remove ghost team BYOK models from /models on delete - #29529
fix(proxy): remove ghost team BYOK models from /models on delete#29529aanchal22 wants to merge 1 commit into
Conversation
79f8dad to
726fb9c
Compare
Greptile SummaryFixes ghost team BYOK models persisting in
Confidence Score: 5/5Safe to merge — the change is well-scoped to the delete path, all three concerns raised in the prior review round have been addressed, and the new helpers are covered by focused mock tests. All three previously-flagged issues are resolved: the team-table update now carries include object_permission and litellm_model_table so the cached object retains relational fields; the function returns None (not the initial find_unique row) when nothing was removed; and the test mock for litellm_teamtable.update now returns a proper row. The logic for building names_to_remove, cleaning the alias map, and refreshing the cache is correct across all code paths. No files require special attention.
|
| Filename | Overview |
|---|---|
| litellm/proxy/management_endpoints/model_management_endpoints.py | Adds _resolve_team_public_model_name and _cleanup_team_model_references helpers; rewires delete_model to use them and refresh the team cache with full relational includes after a DB change. |
| tests/test_litellm/proxy/management_endpoints/test_delete_team_byok_cleanup.py | New mock-only unit tests covering empty-alias, populated-alias, no-change, and team-not-found cases for the two new helpers. |
Reviews (3): Last reviewed commit: "fix(proxy): remove ghost team BYOK model..." | Re-trigger Greptile
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
726fb9c to
82fa10f
Compare
|
Please get the score to 5. You can tag the bot to get tit reviewed again |
|
@greptile-apps re-review please |
delete_model passed the internal model_name (model_name_{team_id}_{uuid})
to delete_team_model_alias, which searched alias map values for it.
For BYOK models the alias map is typically empty, so the lookup always
failed and the public name was never removed from team.models; creating
a ghost model visible via /models indefinitely.
Adds _resolve_team_public_model_name to extract the user-visible name
from model_info.team_public_model_name. Adds _cleanup_team_model_references
which always strips the public name from team.models (regardless of alias
map state) and also cleans up any alias entries pointing to the deleted
model's internal name.
On behalf of Adobe Inc.
82fa10f to
3587d46
Compare
|
@greptile-apps re-review |
|
@greptile-apps re-review please |
|
@aanchal22 — could you add a screenshot or short video showing that this change works as expected (e.g. before/after: ghost team BYOK models no longer appearing in /models after delete)? It really helps reviewers verify the fix quickly. Thanks! |
Setup -Before fix (local stack stems from BerriAI:litellm_oss_branch):Create 2 models - After fix (local stack stems from aanchal22:litellm_byok-delete-ghost-models): |
|
Closing this as solved by #29820 |



Relevant issues
Addresses issue - #22594
Related PRs: #29528 (companion create-side fix)
Pre-Submission checklist
make test-unit@greptileaiand received a Confidence Score of at least 4/5 before requesting a maintainer reviewScreenshots / Proof of Fix
Reproduction script creates a team with 2 BYOK models sequentially, then deletes them. Before the fix, both models persist as ghosts in
team.modelsand/modelsindefinitely. After the fix, deleted models are removed immediately.Also tested the alias-overwrite scenario: create model-1, create model-2 (overwrites model-1's alias entry), delete model-1. Before the fix, model-1 persists as a ghost. After the fix, model-1 is cleaned up and model-2 is preserved.
Type
Bug Fix
Changes
delete_modelpassedmodel_params.model_name(the internal name, e.g.model_name_{team_id}_{uuid}) todelete_team_model_alias, which searched alias map values for a match. For BYOK models the alias map is typically empty or was overwritten by a later model create, so the lookup always failed and the public name was never removed fromteam.models.This PR adds two helpers and rewires the delete path:
_resolve_team_public_model_name: extracts the user-visible name frommodel_info.team_public_model_name, falling back tomodel_params.model_namefor non-BYOK models._cleanup_team_model_references: builds anames_to_removeset starting with the public name (unconditionally), then adds any alias keys whose values match the internal name. Strips all matched names fromteam.modelsand cleans up the alias map in the same pass.After the DB cleanup, refreshes the team cache via
_cache_team_objectso/modelsreflects the deletion without waiting for cache TTL. The cache refresh is wrapped in try/except so a Redis failure does not undo the DB delete.delete_team_model_aliasis left in place; other code paths may still reference it.