Skip to content

fix(auth): refresh lite session token team models from team row - #40318

Closed
devin-ai-integration[bot] wants to merge 3 commits into
mainfrom
litellm_cli_session_token_refresh_team_models
Closed

devin-ai-integration[bot] wants to merge 3 commits into
mainfrom
litellm_cli_session_token_refresh_team_models

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • lite login tokens freeze the team's model list at login time
  • Models added to the team never show up until re-login
  • Models removed from the team keep showing up until re-login

How it solves it:

  • Auth already loads the team for every token with a team; session tokens now copy team_models and team_alias from it
  • No extra lookup: reuses that team object. If the team can't be resolved, the minted grants are kept

User Flow

Before: a developer who logged in with lite login cannot see models the admin just added to their team

  1. They run lite login, pick their team, and the token lands in their CLI config
  2. They run lite models list and see gpt-4o-mini
  3. The admin sends POST https://litellm-domain/team/update adding anthropic-haiku-4-5 to the team's models
  4. They run lite models list again and still see only gpt-4o-mini. GET https://litellm-domain/v1/models with the same token returns the same single model
  5. They have to lite logout and lite login again before the new model appears

After: the same token reflects team changes right away

  1. They run lite login, pick their team, and the token lands in their CLI config
  2. They run lite models list and see gpt-4o-mini
  3. The admin sends POST https://litellm-domain/team/update adding anthropic-haiku-4-5 to the team's models
  4. They run lite models list again and now see both anthropic-haiku-4-5 and gpt-4o-mini. GET https://litellm-domain/v1/models returns both
  5. When the admin removes anthropic-haiku-4-5 from the team, the next lite models list no longer shows it

Relevant issues

Reported by a customer (Pylon #8334)

Linear ticket

Resolves LIT-7358

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. 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
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review (Greptile reviews automatically once the PR is opened; only comment @greptileai to 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).

Screenshots / Proof of Fix

Setup: proxy on litellm/proxy/dev_config.yaml (master key sk-1234). Team cli-team created with models: ["gpt-4o-mini"], internal user cli-repro-user added to it. SSO is not available locally, so the session token was minted with the same server-side call the lite login poll endpoint uses (ExperimentalUIJWTToken.get_cli_jwt_auth_token(..., team_id=<team_id>, team_models=["gpt-4o-mini"])), then used from the real CLI via LITELLM_PROXY_API_KEY.

Before (5b2b542)

  1. LITELLM_PROXY_URL=http://localhost:4000 LITELLM_PROXY_API_KEY=<session_token> lite models list
    │ gpt-4o-mini │ model  │ 2023-02-28 18:56 │ openai   │
    
  2. curl -X POST http://localhost:4000/team/update -H "Authorization: Bearer sk-1234" -d '{"team_id":"<team_id>","models":["gpt-4o-mini","anthropic-haiku-4-5"]}' returns "models":["gpt-4o-mini","anthropic-haiku-4-5"]
  3. lite models list again
    │ gpt-4o-mini │ model  │ 2023-02-28 18:56 │ openai   │
    
  4. curl http://localhost:4000/v1/models -H "Authorization: Bearer <session_token>"
    {"data":[{"id":"gpt-4o-mini","object":"model",...}],"object":"list"}
    

After (a443a68)

  1. Same token, team still at ["gpt-4o-mini","anthropic-haiku-4-5"]. lite models list
    │ anthropic-haiku-4-5 │ model  │ 2023-02-28 18:56 │ openai   │
    │ gpt-4o-mini         │ model  │ 2023-02-28 18:56 │ openai   │
    
  2. curl http://localhost:4000/v1/models -H "Authorization: Bearer <session_token>"
    {"data":[{"id":"anthropic-haiku-4-5",...},{"id":"gpt-4o-mini",...}],"object":"list"}
    
  3. curl -X POST http://localhost:4000/team/update -H "Authorization: Bearer sk-1234" -d '{"team_id":"<team_id>","models":["gpt-4o-mini"]}' returns "models":["gpt-4o-mini"]
  4. lite models list again
    │ gpt-4o-mini │ model  │ 2023-02-28 18:56 │ openai   │
    
  5. curl http://localhost:4000/v1/models -H "Authorization: Bearer <session_token>"
    {"data":[{"id":"gpt-4o-mini","object":"model",...}],"object":"list"}
    

Type

🐛 Bug Fix

Caveats (if any)

Low

  • Team model aliases baked into the token are not refreshed here

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

Link to Devin session: https://app.devin.ai/sessions/7e9513eb967049fa920eea64aea16a15
Open in Devin Desktop: https://app.devin.ai/desktop/session/7e9513eb967049fa920eea64aea16a15?variant=devin

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration
devin-ai-integration Bot requested a review from a team September 8, 2026 23:10
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@codspeed

codspeed Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing litellm_cli_session_token_refresh_team_models (a443a68) with litellm_internal_staging (075655c)

Open in CodSpeed

@greptile-apps

greptile-apps Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR refreshes CLI session-token team models and aliases from the current team row during authentication

  • Adds a team-grant refresh helper with fallback to minted grants when lookup fails
  • Adds regression coverage for successful refreshes and lookup failures
  • Introduces a critical-path database fallback and a no-rebinding convention violation

Confidence Score: 4/5

The behavior is covered, but the repository requirements on critical-path database access and variable rebinding must be satisfied before merging

The refresh works for normal CLI requests, but it permits database fallback during authentication and rebinds valid_token contrary to explicit repository guidance

Files Needing Attention: litellm/proxy/auth/user_api_key_auth.py

Important Files Changed

Filename Overview
litellm/proxy/auth/user_api_key_auth.py Refreshes session-token team grants but violates critical-path database-access and variable-rebinding requirements
tests/test_litellm/proxy/auth/test_user_api_key_auth.py Adds focused mocked regression tests for refreshed grants and lookup-failure fallback

Reviews (1): Last reviewed commit: "fix(auth): refresh lite session token te..." | Re-trigger Greptile

Comment thread litellm/proxy/auth/user_api_key_auth.py Resolved
Comment thread litellm/proxy/auth/user_api_key_auth.py Resolved
@codecov

codecov Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

jesus-berri and others added 2 commits September 8, 2026 23:24
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>
@yuneng-berri
yuneng-berri deleted the branch main September 13, 2026 04:51
@yuneng-berri yuneng-berri reopened this Sep 13, 2026
@devin-ai-integration
devin-ai-integration Bot changed the base branch from litellm_internal_staging to main September 23, 2026 14:39
@mateo-berri

Copy link
Copy Markdown
Contributor

#40657 re-reads the team row on each lite login request so team model changes apply. Reopen if it still happens or something is missing

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

❌ Cannot revive Devin session - the session is too old. Please start a new session instead.

View session

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants