Skip to content

test(auth): hold the JWT mapping insert the Rust repository now sends - #53144

Merged
yuneng-berri merged 2 commits into
mainfrom
litellm_/integ-flaking-11ebf8
Nov 20, 2026
Merged

yuneng-berri merged 2 commits into
mainfrom
litellm_/integ-flaking-11ebf8

Conversation

@yuneng-berri

Copy link
Copy Markdown
Contributor

Handwritten 1-3 sentence description

[insert handwritten description here]

Details

TLDR

Problem this solves:

How it solves it:

  • Match the insert text the Rust JWT mapping repository sends

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/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 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
  • Every automated review on my PR's latest commit has finished, and I have addressed or replied to each of its findings before requesting a maintainer review

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

E2E exception at a4782b8. The diff is one bytes literal in an integration test and touches no product code, so the focused integration run below fully proves it. The runs were made at 9ad81f4, and the tip only adds a merge of main that changes nothing under auth, the JWT repositories or the integration support code.

The test pauses the first JWT call's mapping insert at a Postgres relay, sends a second call, then releases the first. Before #52756 the insert came from Prisma as INSERT INTO "public"."LiteLLM_JWTKeyMapping". Now it comes from litellm/rust/crates/repositories/src/jwt_key_mapping/queries/insert_mapping.sql as INSERT INTO "LiteLLM_JWTKeyMapping", so the relay never saw it and both cases failed with "the first call never reached its mapping insert". The first scheduled run after #52756 merged (44771273647) failed both cases that way, and the run before it passed.

Each run used a throwaway Postgres and Redis, the worktree's own venv and Rust _native build, and this command under env -i with PATH, HOME, PYTHONPATH, INTEGRATION_PYTHON, DATABASE_URL, REDIS_HOST, REDIS_PORT, LITELLM_MASTER_KEY, LITELLM_SALT_KEY, LITELLM_LICENSE, LITELLM_MODE=PRODUCTION, STORE_MODEL_IN_DB=True, LITELLM_LOCAL_MODEL_COST_MAP=True and empty INTEGRATION_PROXY_DATABASE_URL, INTEGRATION_PROXY_READ_REPLICA_URL, INTEGRATION_ROUTING, INTEGRATION_PEER_URL.

python tests/integration/run.py management --workers 2 --results <dir> \
  tests/integration/authorization/test_jwt_auto_register_map_existing_key.py::test_concurrent_first_jwt_calls_both_succeed_on_one_surviving_mapped_key

With the old trigger restored, both cases fail the same way CI does.

[gw1] [ 50%] FAILED ...::test_concurrent_first_jwt_calls_both_succeed_on_one_surviving_mapped_key[link_only]
[gw0] [100%] FAILED ...::test_concurrent_first_jwt_calls_both_succeed_on_one_surviving_mapped_key[auto_register]
E   AssertionError: the first call never reached its mapping insert
E   AssertionError: the first call never reached its mapping insert
======================== 2 failed in 102.73s (0:01:42) =========================

With the fix, both cases pass, and three more runs in a row passed too.

[gw1] [ 50%] PASSED ...::test_concurrent_first_jwt_calls_both_succeed_on_one_surviving_mapped_key[link_only]
[gw0] [100%] PASSED ...::test_concurrent_first_jwt_calls_both_succeed_on_one_surviving_mapped_key[auto_register]
============================== 2 passed in 44.84s ==============================
run 1 exit=0 ============================== 2 passed in 42.77s ==============================
run 2 exit=0 ============================== 2 passed in 42.34s ==============================
run 3 exit=0 ============================== 2 passed in 43.26s ==============================

To check the test exercises the race again, I mutated the losing call in litellm/proxy/auth/host/steps/jwt_auto_register.py to keep its own key instead of the winner's (return inserted.token, True to return token_hash, True). The auto_register case goes red because the held call is served with the orphan key that was just deleted. The link_only case stays green under this mutant since both calls already share one existing key.

[gw0] [ 50%] PASSED ...[link_only]
[gw1] [100%] FAILED ...[auto_register]
E   AssertionError: {"error":{"message":"Authentication Error, Invalid API key provided.","type":"token_not_found_in_db","param":"key","code":"401"}}
E   assert 401 == 200
========================= 1 failed, 1 passed in 43.00s =========================

Type

✅ Test

Caveats (if any)

Low

  • Integration stays red from the unrelated test_budget_updates.py failure

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

The concurrent first-call test paused the mapping insert by matching Prisma's
INSERT INTO "public"."LiteLLM_JWTKeyMapping". Since #52756 the insert goes
through the Rust repository as INSERT INTO "LiteLLM_JWTKeyMapping", so the relay
never held it and both parametrizations failed on every integration run.
@veria-ai

veria-ai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

PR overview

No security issues were found in this pull request.

Reviews

@yuneng-berri
yuneng-berri merged commit b487bfc into main Nov 20, 2026
39 checks passed
@yuneng-berri
yuneng-berri deleted the litellm_/integ-flaking-11ebf8 branch November 20, 2026 18:43
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.

2 participants