Repository navigation
fix(sso): keep CLI SSO and Claude Code gateway team lists in the user record's order - #49033
Conversation
…am on the user record
[Medium impact] The PR appears safe to merge, with the previous numbered finding addressed and no new blocking issues SummaryThe PR keeps CLI SSO and gateway team lists in the user record's order. User creation, SSO group sync, SCIM, and JWT sync append new teams in the order sent The latest change adds types and In the earlier SCIM thread, mateo-berri explained that ignoring group changes after a replace preserves existing behavior and avoids blocking deactivation when a later add names a missing team. Greptile conceded that this was not a regression
Reviews (9) · Last reviewed commit: "test(sso): type the CLI team detail row ..." · Reviewed by Greptile |
Merging this PR will not alter performance1 warning
Comparing |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…SSO groups once SCIM PATCH and JWT team sync saved a user's teams from a set, so the first team on the record, the one a Claude Code gateway sign-in binds, could change on any sync. Both now keep the record's order and append new teams in the order the IdP sent them. SSO group sync now drops claim groups that are not LiteLLM teams with one lookup before adding the missing teams one at a time, so a claim full of non-team groups no longer costs one failed add per group on every sign-in.
… replace team order
…gain Applying group adds and removes after a replace made a PATCH that deactivates a user and adds a team that does not exist answer 404 and leave the user active, where it answered 200 before. Keep the record's team order, but ignore group ops after the last replace as the base did.
|
bugbot run |
There was a problem hiding this comment.
✅ 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 af22af0. Configure here.
For a developer on several teams, the proxy listed their teams in Postgres's row order, which moves on every team write. So
lite login'sskip, the--pkcepreselect, and the gateway's team dropdown (#49001) changed between sign-insThis PR keeps the user record's order, and user create, group sync, SCIM, and JWT sync add new teams in the order sent
Original
TLDR
Problem this solves:
How it solves it:
User Flow
Before: a developer on two teams gets a different default team from one sign-in to the next
"teams": ["team-alpha", "team-zeta"]/loginin Claude Code, and the browser's "Complete CLI Login" page lists team-zeta first in its team dropdownskipinlite loginand Approve on its--pkcepage sign dev1 in on team-zetaAfter: the same developer sees their teams in their user record's order, and every default is the first one
"teams": ["team-alpha", "team-zeta"]/loginin Claude Code, and the browser's "Complete CLI Login" page lists team-alpha first in its team dropdownskipinlite loginand Approve on its--pkcepage sign dev1 in on team-alphaDecisions
/user/infoshows that order and the gateway docs promise the developer's first team as the default. Sorting by alias then id (fix: order CLI SSO team choices by alias then id for a stable consent default #37666) is stable but ignores the record, so a developer whose record lists zeta first would still land on alpha. AnORDER BY array_positionin SQL needs raw SQL, and reordering at each of the four readers of the list is four places to forgetPOST /user/newtook a median 2.049 s on this PR and 2.679 s before, and SCIM create took 2.523 s and 3.740 s. Only this PR kept the order sent/user/newtest that already patches itprimary) and an IdP's group order is not a default the admin chose.Relevant issues
Fixes #37642 with the user record's order as the stable order (see Decisions)
Affected release
lite loginregressed in v1.98.0 (#36826), and the gateway has done this since v1.103.0Linear ticket
Resolves LIT-9412
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
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 moreDelays 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
Last updated: af22af0 (test types only). QA ran on f11cf98 for A to C, 2ceceae for D to G, 69604c9 for H, 50c4368 for I, and 7c616ad for J. Later commits change group sync's lookup, user create, and SCIM writes. Proof remains valid because A to C add teams with
/team/member_addand sign in with no IdP groups, D to G send no SCIM POST with an email, a successful SCIM write saves the same ordered teams, and J re-ran G's PATCH, the one replace step. Verification: unit tests pass, and D to J prove them liveBoth legs used Claude Code 2.1.312's TUI,
lite login, Keycloak, and curl, on 2 uvicorn workers with Redis and Postgres and real Anthropic spendlite login--pkcepageCase A
After a write to team-alpha's row, dev1's record still lists team-alpha first. Sign-in 2 takes the dropdown's first entry
Setup requests, the same on both legs
Every step is in the before and after gists
Before (71babd9)
Spend logs
After (f11cf98)
Spend logs
Case B
Before (71babd9)
The
lite loginlist put team-zeta first, andskipbound and billed team-zetaEvery step
After (f11cf98)
The
lite loginlist followed dev1's record, andskipbound and billed team-alphaEvery step
Case C
Before (71babd9)
The consent page preselected team-zeta, and Approve with the dropdown untouched bound team-zeta
Every step
After (f11cf98)
The consent page preselected team-alpha, dev1's first team, and Approve bound team-alpha
Every step
Case D
Before (71babd9)
Both users got the same
team_orderclaim, yet group sync saved two different orders, and after the team-zeta write orderdev1's dropdown listed team-mu first and billed itEvery step
After (2ceceae)
Group sync saved both records in claim order without grp-vpn, and after the team-zeta write both dropdowns listed team-zeta first and billed it
Every step
Case E
Before (71babd9)
The PATCH put team-kappa first on dev1's record.
skipinlite loginbilled team-zeta, and after that request the next sign-in's dropdown listed team-zeta last and billed team-kappaEvery step
After (2ceceae)
The PATCH kept team-alpha first and added the new teams in the order sent, and
lite loginand the Claude Code dropdown both followed that order and billed team-alphaEvery step
Case E-PUT
Before (71babd9)
A PUT that only reordered the same three teams rewrote the record to the PUT's order, and the dropdown then listed team-alpha first, matching neither order, and billed it
Every step
After (2ceceae)
A PUT that only reordered the same three teams left the record at team-alpha, team-zeta, team-mu, and the dropdown listed that order and billed team-alpha
Every step
Case F
Before (71babd9)
Boots 1 to 4 saved team-alpha, team-zeta, team-mu by chance, but boot 5 saved team-mu before team-zeta from the same claim, and its dropdown listed team-mu first and billed it
Every step
After (2ceceae)
On boots 3 and 3b the JWT request kept team-alpha first, added team-zeta and team-mu in claim order, and dropped team-kappa, and the dropdown billed team-alpha
Every step
Case G
Before (71babd9)
Every user created on five teams saved them out of the order sent. Case J re-ran the PATCH step
Every step
After (2ceceae)
All 13 users saved their five teams in the order sent. Case J re-ran the PATCH step
Every step
Case H
Before (71babd9)
A SCIM POST for orderdev1's email kept its id but rewrote the record to the POST's order, although team-zeta and team-kappa were there first
The dropdown follows Postgres's row order here, as in case A, so its first entry matches the fixed order by chance
Every step
After (69604c9)
The same POST kept team-zeta and team-kappa in their place, dropped team-alpha, and added team-mu and team-beta after them in the order sent, and the dropdown listed the record's order
Every step
Case I
Before (71babd9)
The PATCH answered 404 for team-nu and left the seven teams it joined in a random order. The retry after team-nu was created reordered the whole record and moved team-zeta last
The dropdown follows Postgres's row order here, as in case A, so it matches neither the record nor the PATCH
Every step
After (50c4368)
The same PATCH answered 404 for team-nu and left the seven teams it joined in the order sent. The retry kept that order and appended team-nu, and the dropdown listed the record's order
Every step
Case J
Before (71babd9)
scimdev1's PATCH kept the replace's three teams in a random order and dropped the add and the remove. scimdev2's PATCH answered 200, and scimdev2 ended inactive on team-alpha
Every step
After (7c616ad)
scimdev1's PATCH kept the replace's three teams in record order and dropped the add and the remove. scimdev2's PATCH answered 200, and scimdev2 ended inactive on team-alpha
Every step
Surprises
lite whoamiprints no Team ID (leaves it alone)/key/info(leaves it alone)Type
🐛 Bug Fix
Caveats (if any)
Medium
Low
5 more low caveats
lite login --pkcestill preselects the first team, where [Bug]: native CLI login consent page lists teams in database order and preselects the first one #37642 also suggested a forced choicefind_existing_team_idsreads the module's globalprisma_client, like its siblingFinal Attestation
/live-pr-risk backward incompatible changes
Default team. Every reader of a user's first team now follows the user record instead of Postgres row order. The Expected section of LIT-9412, which Shivam filed, asks for this
SSO group sync. It adds new teams in claim order, and it skips a claim group with no LiteLLM team instead of trying to add it. The Suggested fix in LIT-9412 asks for the claim order, and the skip has no separate sign-off
SCIM PATCH, PUT and known-email POST, user create, and JWT team sync. These keep the record's order and add new teams in the order sent. LIT-9412 does not name these paths, and this PR adds them so one order holds everywhere, with no separate sign-off
SCIM PUT with a repeated team. It now stores one copy, so the single-team JWT fallback applies to that user. This has no separate sign-off
Bugbot summary