Repository navigation
fix(scim): fail group sync when a member add or user creation fails (LIT-5105) - #37688
Conversation
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Greptile SummaryThe PR makes SCIM group synchronization report user-creation and membership-write failures instead of silently omitting members.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| litellm/proxy/management_endpoints/scim/scim_v2.py | Adds strict SCIM member resolution and membership failure propagation; no follow-up-eligible blocking defect was established. |
| tests/test_litellm/proxy/management_endpoints/scim/test_scim_v2_endpoints.py | Adds focused regression tests and isolates an existing metadata serialization test from unrelated membership persistence. |
Reviews (2): Last reviewed commit: "style(scim): apply ruff format" | Re-trigger Greptile
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
@greptileai please review the current head |
tin-berri
left a comment
There was a problem hiding this comment.
Auth-adjacent (SCIM provisioning) so reviewed the diff directly. The core fix is correct and carefully scoped: patch_team_membership now runs with raise_on_error=True so a genuine add/remove failure fails the whole group sync (so the IdP retries instead of recording false success), while idempotent no-ops (already-in-team, already-removed) are still swallowed internally by patch_team_membership — verified by test_handle_group_membership_changes_already_in_team_is_noop specifically asserting the sync continues to the second member rather than aborting. The concurrent-creation race is handled right too: if user creation fails because another request already created the same user, that's treated as success (id resolves to a real row) rather than a false failure — tested. Bonus fix: duplicate member ids in one request are now deduped before creation instead of double-creating. Honest about test-only proof (no live SCIM sync run, but regression tests verified to fail at merge base and pass at tip — a reasonable substitute given IdP-driven live testing isn't practical here). This is an intentional behavior change (previously-silent partial failures now surface as 5xx) which is exactly the fix, not a regression. CI green.
…ting a placeholder SCIM group members were matched against litellm user ids only. An identity provider that lists people by email or by the OIDC subject therefore matched nothing, and the member fell through to placeholder creation. Since #37688 made a failed member creation fail the group sync rather than drop the member, that fallthrough is no longer quiet: the placeholder is created with user_email set to the member value, the duplicate-email check rejects it, and the whole group push answers 500. So on current staging a group listing anyone by their email fails outright, every other member in the payload included. An unmatched member id is now looked up across sso_user_id and user_email in one query. Searching either field first would hide a value that names one account by its SSO identity and another by its email, and hand the group to whichever was searched first. The two are not compared alike: an email is matched the way new_user matches one before accepting a new account, case-insensitively, because matching more strictly than the layer that would reject the placeholder is what turned an id whose casing differed from the stored email into that same 500. An SSO identity is matched exactly, since OIDC defines sub as case-sensitive and nothing folds its case on the way in. An exact user_id hit is checked the same way rather than trusted outright, since a value can be one account's id and another's SSO identity or email. That is not a corner case: the placeholders this bug provisioned are keyed by the very id the provider keeps pushing, so on a tenant that already has them the placeholder wins the id lookup and the real account can never be matched. Refusing names the problem instead of silently landing on the placeholder again. Those rows still have to be deleted before the real account resolves; making the sync heal itself needs a trustworthy way to tell a placeholder from an account someone created, and created_via lives in caller-writable metadata, so it is left to a follow-up. A value that names more than one account is refused with a 400 naming the id rather than attributed to one of them. Removals resolve too, since the roster holds canonical user ids and a directory removes people by the id it added them with. A removal counts the members one value names: the id as written when the roster holds it verbatim, which is how an earlier release recorded a member it could not match, together with the members it resolves to. Counting only the accounts on the roster keeps someone removable after a second account takes their email, which resolving table-wide would not, and counting both ways of naming a member together stops one value revoking two people when it is one member's canonical id and another's email. A value naming two of the group's own members is undecidable and fails rather than guessing or reporting a removal it did not perform. Resolves LIT-5383
…ting a placeholder (#37686) SCIM group members were matched against litellm user ids only. An identity provider that lists people by email or by the OIDC subject therefore matched nothing, and the member fell through to placeholder creation. Since #37688 made a failed member creation fail the group sync rather than drop the member, that fallthrough is no longer quiet: the placeholder is created with user_email set to the member value, the duplicate-email check rejects it, and the whole group push answers 500. So on current staging a group listing anyone by their email fails outright, every other member in the payload included. An unmatched member id is now looked up across sso_user_id and user_email in one query. Searching either field first would hide a value that names one account by its SSO identity and another by its email, and hand the group to whichever was searched first. The two are not compared alike: an email is matched the way new_user matches one before accepting a new account, case-insensitively, because matching more strictly than the layer that would reject the placeholder is what turned an id whose casing differed from the stored email into that same 500. An SSO identity is matched exactly, since OIDC defines sub as case-sensitive and nothing folds its case on the way in. An exact user_id hit is checked the same way rather than trusted outright, since a value can be one account's id and another's SSO identity or email. That is not a corner case: the placeholders this bug provisioned are keyed by the very id the provider keeps pushing, so on a tenant that already has them the placeholder wins the id lookup and the real account can never be matched. Refusing names the problem instead of silently landing on the placeholder again. Those rows still have to be deleted before the real account resolves; making the sync heal itself needs a trustworthy way to tell a placeholder from an account someone created, and created_via lives in caller-writable metadata, so it is left to a follow-up. A value that names more than one account is refused with a 400 naming the id rather than attributed to one of them. Removals resolve too, since the roster holds canonical user ids and a directory removes people by the id it added them with. A removal counts the members one value names: the id as written when the roster holds it verbatim, which is how an earlier release recorded a member it could not match, together with the members it resolves to. Counting only the accounts on the roster keeps someone removable after a second account takes their email, which resolving table-wide would not, and counting both ways of naming a member together stops one value revoking two people when it is one member's canonical id and another's email. A value naming two of the group's own members is undecidable and fails rather than guessing or reporting a removal it did not perform. Resolves LIT-5383 Co-authored-by: Yassin Kortam <yassin@berri.ai>
TLDR
Problem this solves:
How it solves it:
User Flow
Before: an admin provisions a 50-member group from their identity provider and the IdP reports success, but the team is missing users
After: the same sync either lands every member or surfaces an error the IdP retries
Relevant issues
Linear ticket
Resolves LIT-5105
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)Screenshots / Proof of Fix
Captured against a live proxy on 127.0.0.1:4171 backed by its own Postgres. The proxy ran from a directory outside every checkout so it could not pick up a repo
.env, withPYTHONPATHpointed at the branch worktree, so the two legs really do serve different code. No LLM provider is involved: SCIM provisioning is a management-plane path, so the whole capture is/scim/v2/*plus/team/infoEvery case pushes a 24-member group, comfortably past the size the ticket describes. In cases 2 and 3, 8 of those 24 already have a LiteLLM user row that the pushed member id does not resolve to. Four were onboarded by SSO, so their row is keyed by the identity provider's object id while the group lists them by email, and four arrived through
POST /scim/v2/Usersin lowercase while the group lists them with the casing the directory displays. LiteLLM itself emits group members by email onGET /scim/v2/Groups/{id}, so a directory that reads a group back and re-pushes it sends exactly these valuesThe two legs use disjoint user and team ids (
...before.../...after...) so neither leg can inherit rows the other createdShared setup, run identically inside each leg:
Both legs printed
200 200 200 200then201 201 201 201, andselect count(*) from "LiteLLM_UserTable" where user_id like 'c9p37688-$V-%' or user_id like 'c9p37688.$V.%'returned8Group pushes are built from a
forloop over the member list:Each leg re-printed the identity of the code it was actually serving, so every number below carries proof of which tree produced it:
Before (3a31331)
Case 1: a 24-member group where nobody exists yet
curl -s -w '\nHTTP %{http_code}' -X POST $API/scim/v2/Groups -H "Authorization: Bearer $SCIM_TOKEN" -H 'Content-Type: application/scim+json' -d "$PAYLOAD"curl -s $API/scim/v2/Groups/c9p37688-before-clean -H "Authorization: Bearer $SCIM_TOKEN" | jq '{id, members_on_team: (.members|length)}'curl -s "$API/team/info?team_id=c9p37688-before-clean" -H "Authorization: Bearer $SCIM_TOKEN" | jq '.team_info.members_with_roles | length'Case 2: a 24-member group where 8 members already have a user row under another id
curl -s -w '\nHTTP %{http_code}' -X POST $API/scim/v2/Groups -H "Authorization: Bearer $SCIM_TOKEN" -H 'Content-Type: application/scim+json' -d "$PAYLOAD"The push is reported as a success and the group comes back with 16 of the 24 members that were sent
curl -s $API/scim/v2/Groups/c9p37688-before-mixed -H "Authorization: Bearer $SCIM_TOKEN" | jq '{id, members_on_team: (.members|length)}'curl -s "$API/team/info?team_id=c9p37688-before-mixed" -H "Authorization: Bearer $SCIM_TOKEN" | jq -r '.team_info.members_with_roles[].user_id' | sortAll 8 people who already existed are missing from the team, and nothing in the response says so
grep -c "Failed to create user" proxy-before.logThe proxy knew about all 8 failures and still answered 201
Case 3: the same 24-member set pushed with PUT onto an existing group
Seed the group with one member:
POST $API/scim/v2/GroupsreturnsHTTP 201curl -s -w '\nHTTP %{http_code}' -X PUT $API/scim/v2/Groups/c9p37688-before-put -H "Authorization: Bearer $SCIM_TOKEN" -H 'Content-Type: application/scim+json' -d "$PAYLOAD"curl -s "$API/team/info?team_id=c9p37688-before-put" -H "Authorization: Bearer $SCIM_TOKEN" | jq '.team_info.members_with_roles | length'Same silent loss on the route an identity provider uses for every re-sync
Case 4: the same 24 people, addressed by ids that already resolve
curl -s -w '\nHTTP %{http_code}' -X POST $API/scim/v2/Groups -H "Authorization: Bearer $SCIM_TOKEN" -H 'Content-Type: application/scim+json' -d "$PAYLOAD"curl -s "$API/team/info?team_id=c9p37688-before-ctl" -H "Authorization: Bearer $SCIM_TOKEN" | jq '.team_info.members_with_roles | length'The 8 people dropped in case 2 are real, enrollable users, so the loss there is a loss of people and not a rejected payload
After (74a409b)
Case 1: a 24-member group where nobody exists yet
curl -s -w '\nHTTP %{http_code}' -X POST $API/scim/v2/Groups -H "Authorization: Bearer $SCIM_TOKEN" -H 'Content-Type: application/scim+json' -d "$PAYLOAD"curl -s $API/scim/v2/Groups/c9p37688-after-clean -H "Authorization: Bearer $SCIM_TOKEN" | jq '{id, members_on_team: (.members|length)}'curl -s "$API/team/info?team_id=c9p37688-after-clean" -H "Authorization: Bearer $SCIM_TOKEN" | jq '.team_info.members_with_roles | length'Case 2: a 24-member group where 8 members already have a user row under another id
curl -s -w '\nHTTP %{http_code}' -X POST $API/scim/v2/Groups -H "Authorization: Bearer $SCIM_TOKEN" -H 'Content-Type: application/scim+json' -d "$PAYLOAD"The failure now reaches the caller and names the member it could not provision, so the identity provider retries instead of recording 24 people as synced
curl -s -w '\nHTTP %{http_code}' $API/scim/v2/Groups/c9p37688-after-mixed -H "Authorization: Bearer $SCIM_TOKEN"curl -s "$API/team/info?team_id=c9p37688-after-mixed" -H "Authorization: Bearer $SCIM_TOKEN" | jq '.team_info.members_with_roles | length'No half-populated team is left behind claiming to be the group
Case 3: the same 24-member set pushed with PUT onto an existing group
Seed the group with one member:
POST $API/scim/v2/GroupsreturnsHTTP 201curl -s -w '\nHTTP %{http_code}' -X PUT $API/scim/v2/Groups/c9p37688-after-put -H "Authorization: Bearer $SCIM_TOKEN" -H 'Content-Type: application/scim+json' -d "$PAYLOAD"curl -s "$API/team/info?team_id=c9p37688-after-put" -H "Authorization: Bearer $SCIM_TOKEN" | jq '.team_info.members_with_roles | length'The group keeps the member it already had rather than being rewritten to a roster that silently lost 8 people
Case 4: the same 24 people, addressed by ids that already resolve
curl -s -w '\nHTTP %{http_code}' -X POST $API/scim/v2/Groups -H "Authorization: Bearer $SCIM_TOKEN" -H 'Content-Type: application/scim+json' -d "$PAYLOAD"curl -s "$API/team/info?team_id=c9p37688-after-ctl" -H "Authorization: Bearer $SCIM_TOKEN" | jq '.team_info.members_with_roles | length'A 24-member sync that can land still lands in full, so the strict path costs nothing when the ids resolve
Both legs answered
/health/livelinesswith 200 immediately before and immediately after every case, so no result straddles a restarted proxyType
🐛 Bug Fix
Caveats (if any)
Link to Devin session: https://app.devin.ai/sessions/79e76557aa114b229b47fd35e18bf1f2
Requested by: @yassin-berriai