Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

perf(ci): cache the Rust build the unit shards compile from scratch (#37795)

yuneng-jiangafec9b8ab901
diff --git a/.github/actions/cache-cargo-build/action.yml b/.github/actions/cache-cargo-build/action.yml
new file mode 100644
index 00000000000..36c6c790b84
--- /dev/null
+++ b/.github/actions/cache-cargo-build/action.yml
@@ -0,0 +1,31 @@
+name: "Cache the Rust build"
+description: >-
+ Cache the Cargo registry and target directory the root package's build needs,
+ so only the first job on a given Cargo.lock compiles the bridge from scratch.
+
+ litellm builds through maturin, which compiles litellm-rust/crates/python-bridge
+ in release mode before it can produce a wheel. `uv sync` therefore pays a full
+ build in every job that installs the workspace: measured at 2m40s per unit shard
+ on 2026-08-21, more than the whole unit tier spends running tests. Nothing caught
+ it, because the uv cache holds wheels uv downloads rather than wheels it builds,
+ and a path dependency whose source moves every commit could never hit that cache
+ anyway. Cargo rebuilds only what changed when its target directory survives, so a
+ warm job pays for the bridge crate alone.
+
+ The key namespace is separate from test-rust.yml's. Both cache the same directory,
+ but that workflow fills it with debug and clippy artifacts, which a release build
+ cannot reuse, and a shared key would let whichever ran first deny the other a save.
+
+runs:
+ using: composite
+ steps:
+ - name: Restore the Cargo registry and target directory
+ uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
+ with:
+ path: |
+ ~/.cargo/registry
+ ~/.cargo/git
+ litellm-rust/target
+ key: ${{ runner.os }}-cargo-release-${{ hashFiles('litellm-rust/Cargo.lock') }}
+ restore-keys: |
+ ${{ runner.os }}-cargo-release-
diff --git a/.github/workflows/_test-unit-base.yml b/.github/workflows/_test-unit-base.yml
index 54f50524a39..b7d185bd0b9 100644
--- a/.github/workflows/_test-unit-base.yml
+++ b/.github/workflows/_test-unit-base.yml
@@ -27,7 +27,7 @@ on:
default: 20
job-timeout-minutes:
description: >-
- Backstop for the whole job. Keep it >= `timeout-minutes` plus 35: 30 for
+ Backstop for the whole job. Keep it >= `timeout-minutes` plus 40: 35 for
the per-step ceilings on the setup steps below, and 5 for the runner
overhead the job clock charges but no step owns (job init, step
transitions, post-job cleanup). That headroom is what makes the test
@@ -36,7 +36,7 @@ on:
arithmetic, so the sum is passed in rather than computed.
required: false
type: number
- default: 55
+ default: 60
max-failures:
description: "Stop after this many failures"
required: false
@@ -103,6 +103,11 @@ jobs:
restore-keys: |
${{ runner.os }}-uv-
+ - name: Cache the Rust build
+ if: steps.changes.outputs.decision != 'skip'
+ timeout-minutes: 5
+ uses: ./.github/actions/cache-cargo-build
+
- name: Install dependencies
if: steps.changes.outputs.decision != 'skip'
timeout-minutes: 8
diff --git a/.github/workflows/check-ui-api-types.yml b/.github/workflows/check-ui-api-types.yml
index dbd663a2efa..285676a0ddd 100644
--- a/.github/workflows/check-ui-api-types.yml
+++ b/.github/workflows/check-ui-api-types.yml
@@ -67,6 +67,10 @@ jobs:
restore-keys: |
${{ runner.os }}-uv-
+ - name: Cache the Rust build
+ if: steps.changes.outputs.relevant == 'true'
+ uses: ./.github/actions/cache-cargo-build
+
- name: Install backend dependencies
if: steps.changes.outputs.relevant == 'true'
run: .github/scripts/uv_sync_with_retries.sh --frozen --group ci --group proxy-dev --extra google --extra proxy --extra semantic-router
diff --git a/.github/workflows/mutation-test.yml b/.github/workflows/mutation-test.yml
index 68317d5dd12..602c26a3e98 100644
--- a/.github/workflows/mutation-test.yml
+++ b/.github/workflows/mutation-test.yml
@@ -53,6 +53,9 @@ jobs:
restore-keys: |
${{ runner.os }}-uv-
+ - name: Cache the Rust build
+ uses: ./.github/actions/cache-cargo-build
+
- name: Install dependencies
run: |
.github/scripts/uv_sync_with_retries.sh --frozen --group ci --group proxy-dev --extra google --extra proxy --extra semantic-router --extra saml
diff --git a/.github/workflows/publish-basedpyright-base-counts.yml b/.github/workflows/publish-basedpyright-base-counts.yml
index 71e196d8361..cd443a8e9db 100644
--- a/.github/workflows/publish-basedpyright-base-counts.yml
+++ b/.github/workflows/publish-basedpyright-base-counts.yml
@@ -43,6 +43,9 @@ jobs:
with:
version: "0.10.9"
+ - name: Cache the Rust build
+ uses: ./.github/actions/cache-cargo-build
+
- name: Cache Prisma binaries
uses: ./.github/actions/cache-prisma-binaries
diff --git a/.github/workflows/test-code-quality.yml b/.github/workflows/test-code-quality.yml
index 8f62837d29a..2a832d1956e 100644
--- a/.github/workflows/test-code-quality.yml
+++ b/.github/workflows/test-code-quality.yml
@@ -56,6 +56,9 @@ jobs:
restore-keys: |
${{ runner.os }}-uv-
+ - name: Cache the Rust build
+ uses: ./.github/actions/cache-cargo-build
+
- name: Install dependencies
run: uv sync --frozen --all-groups --all-extras
diff --git a/.github/workflows/test-linting.yml b/.github/workflows/test-linting.yml
index e031ba46773..ccb58f5cc9c 100644
--- a/.github/workflows/test-linting.yml
+++ b/.github/workflows/test-linting.yml
@@ -78,6 +78,10 @@ jobs:
run: |
uv lock --check || (echo "❌ uv.lock is out of sync with pyproject.toml. Run 'uv lock' locally and commit the result." && exit 1)
+ - name: Cache the Rust build
+ if: steps.changes.outputs.decision != 'skip'
+ uses: ./.github/actions/cache-cargo-build
+
- name: Install dependencies
if: steps.changes.outputs.decision != 'skip'
run: |
diff --git a/.github/workflows/test-mcp.yml b/.github/workflows/test-mcp.yml
index 95187ef2835..6ea814dc2de 100644
--- a/.github/workflows/test-mcp.yml
+++ b/.github/workflows/test-mcp.yml
@@ -47,6 +47,10 @@ jobs:
with:
version: "0.10.9"
+ - name: Cache the Rust build
+ if: steps.changes.outputs.decision != 'skip'
+ uses: ./.github/actions/cache-cargo-build
+
- name: Install dependencies
if: steps.changes.outputs.decision != 'skip'
run: |
diff --git a/.github/workflows/test-terraform-provider.yml b/.github/workflows/test-terraform-provider.yml
index 7ea22825f4f..e46432e0e31 100644
--- a/.github/workflows/test-terraform-provider.yml
+++ b/.github/workflows/test-terraform-provider.yml
@@ -88,6 +88,9 @@ jobs:
restore-keys: |
${{ runner.os }}-uv-
+ - name: Cache the Rust build
+ uses: ./.github/actions/cache-cargo-build
+
- name: Install dependencies
run: |
.github/scripts/uv_sync_with_retries.sh --frozen --group ci --group proxy-dev --extra google --extra proxy --extra semantic-router
diff --git a/.github/workflows/test-unit-documentation.yml b/.github/workflows/test-unit-documentation.yml
index cb8035aafa1..90b6b28374e 100644
--- a/.github/workflows/test-unit-documentation.yml
+++ b/.github/workflows/test-unit-documentation.yml
@@ -67,6 +67,10 @@ jobs:
restore-keys: |
${{ runner.os }}-uv-
+ - name: Cache the Rust build
+ if: steps.changes.outputs.decision != 'skip'
+ uses: ./.github/actions/cache-cargo-build
+
- name: Install dependencies
if: steps.changes.outputs.decision != 'skip'
run: |
diff --git a/.github/workflows/test-unit.yml b/.github/workflows/test-unit.yml
index 3d6fffe7304..71eb0958bec 100644
--- a/.github/workflows/test-unit.yml
+++ b/.github/workflows/test-unit.yml
@@ -55,7 +55,7 @@ jobs:
workers: 2
reruns: 1
timeout-minutes: 20
- job-timeout-minutes: 55
+ job-timeout-minutes: 60
- shard: enterprise-routing
artifact-name: enterprise-routing
@@ -67,7 +67,7 @@ jobs:
workers: 2
reruns: 2
timeout-minutes: 20
- job-timeout-minutes: 55
+ job-timeout-minutes: 60
- shard: integrations
artifact-name: integrations
@@ -75,7 +75,7 @@ jobs:
workers: 2
reruns: 3
timeout-minutes: 20
- job-timeout-minutes: 55
+ job-timeout-minutes: 60
- shard: Vertex AI
artifact-name: llm-vertex-ai
@@ -83,7 +83,7 @@ jobs:
workers: 1
reruns: 2
timeout-minutes: 20
- job-timeout-minutes: 55
+ job-timeout-minutes: 60
- shard: All Other Providers
artifact-name: llm-other-providers
@@ -91,7 +91,7 @@ jobs:
workers: 2
reruns: 2
timeout-minutes: 20
- job-timeout-minutes: 55
+ job-timeout-minutes: 60
- shard: misc
artifact-name: misc
@@ -122,7 +122,7 @@ jobs:
workers: 2
reruns: 2
timeout-minutes: 20
- job-timeout-minutes: 55
+ job-timeout-minutes: 60
- shard: proxy-auth
artifact-name: proxy-auth
@@ -134,7 +134,7 @@ jobs:
workers: 2
reruns: 2
timeout-minutes: 20
- job-timeout-minutes: 55
+ job-timeout-minutes: 60
- shard: proxy-endpoints
artifact-name: proxy-endpoints
@@ -171,7 +171,7 @@ jobs:
workers: 2
reruns: 2
timeout-minutes: 20
- job-timeout-minutes: 55
+ job-timeout-minutes: 60
- shard: proxy-server
artifact-name: proxy-server
@@ -179,7 +179,7 @@ jobs:
workers: 4
reruns: 2
timeout-minutes: 60
- job-timeout-minutes: 95
+ job-timeout-minutes: 100
- shard: proxy-infra
artifact-name: proxy-infra
@@ -198,7 +198,7 @@ jobs:
workers: 2
reruns: 2
timeout-minutes: 20
- job-timeout-minutes: 55
+ job-timeout-minutes: 60
- shard: responses-caching-types
artifact-name: responses-caching-types
@@ -209,7 +209,7 @@ jobs:
workers: 2
reruns: 2
timeout-minutes: 20
- job-timeout-minutes: 55
+ job-timeout-minutes: 60
uses: ./.github/workflows/_test-unit-base.yml
with:
test-path: ${{ matrix.test-path }}
diff --git a/.github/workflows/weekly_load_anomaly.yml b/.github/workflows/weekly_load_anomaly.yml
index 2dffc889d0e..3e1fca89645 100644
--- a/.github/workflows/weekly_load_anomaly.yml
+++ b/.github/workflows/weekly_load_anomaly.yml
@@ -47,6 +47,9 @@ jobs:
with:
version: "0.10.9"
+ - name: Cache the Rust build
+ uses: ./.github/actions/cache-cargo-build
+
- name: Install dependencies
run: |
.github/scripts/uv_sync_with_retries.sh --frozen --group ci --group proxy-dev --extra proxy