diff --git a/.github/actions/rust-bridge/action.yml b/.github/actions/rust-bridge/action.yml index 99002d4f287..d1a5ef0a752 100644 --- a/.github/actions/rust-bridge/action.yml +++ b/.github/actions/rust-bridge/action.yml @@ -1,19 +1,45 @@ name: Set up the Rust bridge -description: Select the shared Rust bridge artifact or the Cargo cache -inputs: - artifact: - description: Rust bridge artifact name - required: false - default: "" +description: >- + Fill rust-bridge-dist with the editable Rust bridge wheel and native module, and + install them with .github/scripts/uv_sync_with_rust_bridge.sh. + + Restore the build for the current Rust sources, so most commits, which leave Rust + untouched, skip Cargo entirely. Only main saves it. A miss builds on cache-cargo-build, so + Cargo rebuilds only what changed. Requires Python and uv on the PATH. runs: using: composite steps: - - name: Restore the Cargo build cache - if: inputs.artifact == '' - uses: ./.github/actions/cache-cargo-build - - name: Download the Rust bridge artifact - if: inputs.artifact != '' - uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e + - name: Restore the Rust bridge build + id: restore + uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 with: - name: ${{ inputs.artifact }} path: rust-bridge-dist + key: ${{ runner.os }}-rust-bridge-editable-${{ hashFiles('litellm-rust/Cargo.lock', 'litellm-rust/Cargo.toml', 'litellm-rust/crates/**', 'pyproject.toml', 'rust-toolchain.toml', '.cargo/config.toml') }} + + - name: Restore the Cargo build cache + if: steps.restore.outputs.cache-hit != 'true' + uses: ./.github/actions/cache-cargo-build + + - name: Build the Rust bridge + if: steps.restore.outputs.cache-hit != 'true' + shell: bash + env: + RUNNER_OS_NAME: ${{ runner.os }} + run: | + rm -rf rust-bridge-dist + mkdir -p rust-bridge-dist/litellm/rust_bridge + uv run --no-project --with maturin==1.15.0 python -c 'import maturin; maturin.build_editable("rust-bridge-dist")' + for native in litellm/rust_bridge/_native.abi3.so litellm/rust_bridge/_native.pyd; do + [ -f "$native" ] || continue + if [ "$RUNNER_OS_NAME" = "Linux" ]; then + strip --strip-debug "$native" + fi + cp "$native" rust-bridge-dist/litellm/rust_bridge/ + done + + - name: Save the Rust bridge build + if: steps.restore.outputs.cache-hit != 'true' && github.ref == 'refs/heads/main' + uses: actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 + with: + path: rust-bridge-dist + key: ${{ steps.restore.outputs.cache-primary-key }} diff --git a/.github/scripts/uv_sync_with_rust_bridge.sh b/.github/scripts/uv_sync_with_rust_bridge.sh new file mode 100755 index 00000000000..b2c22ec5a74 --- /dev/null +++ b/.github/scripts/uv_sync_with_rust_bridge.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +# Sync the environment without building litellm, then install the editable Rust +# bridge that .github/actions/rust-bridge put in rust-bridge-dist. +set -euo pipefail + +if [[ "$#" -eq 0 ]]; then + echo "usage: $0 " >&2 + exit 2 +fi + +uv sync "$@" --no-install-project +venv_python=.venv/bin/python +[[ -x "${venv_python}" ]] || venv_python=.venv/Scripts/python.exe +uv pip install --no-deps --python "${venv_python}" rust-bridge-dist/*.whl +cp rust-bridge-dist/litellm/rust_bridge/_native.* litellm/rust_bridge/ +uv run --no-sync python -c "import importlib.metadata, litellm.rust_bridge._native; print(importlib.metadata.version('litellm'))" diff --git a/.github/workflows/e2e_record_replay.yml b/.github/workflows/e2e_record_replay.yml index 4ae0f68e3f3..f09cb0b687c 100644 --- a/.github/workflows/e2e_record_replay.yml +++ b/.github/workflows/e2e_record_replay.yml @@ -61,12 +61,12 @@ jobs: with: version: "0.10.9" - - name: Cache the Rust build - uses: ./.github/actions/cache-cargo-build + - name: Set up the Rust bridge + uses: ./.github/actions/rust-bridge - name: Install dependencies run: | - uv sync --frozen --group ci --group proxy-dev --extra proxy + .github/scripts/uv_sync_with_rust_bridge.sh --frozen --group ci --group proxy-dev --extra proxy - name: Cache Prisma binaries uses: ./.github/actions/cache-prisma-binaries @@ -159,12 +159,12 @@ jobs: with: version: "0.10.9" - - name: Cache the Rust build - uses: ./.github/actions/cache-cargo-build + - name: Set up the Rust bridge + uses: ./.github/actions/rust-bridge - name: Install dependencies run: | - uv sync --frozen --group ci --group proxy-dev --extra proxy + .github/scripts/uv_sync_with_rust_bridge.sh --frozen --group ci --group proxy-dev --extra proxy - name: Cache Prisma binaries uses: ./.github/actions/cache-prisma-binaries diff --git a/.github/workflows/mutation-test.yml b/.github/workflows/mutation-test.yml index 41dd008f5c4..c18568ac553 100644 --- a/.github/workflows/mutation-test.yml +++ b/.github/workflows/mutation-test.yml @@ -65,12 +65,12 @@ jobs: restore-keys: | ${{ runner.os }}-uv- - - name: Cache the Rust build - uses: ./.github/actions/cache-cargo-build + - name: Set up the Rust bridge + uses: ./.github/actions/rust-bridge - name: Install dependencies run: | - uv sync --frozen --group ci --group proxy-dev --extra google --extra proxy --extra semantic-router --extra saml + .github/scripts/uv_sync_with_rust_bridge.sh --frozen --group ci --group proxy-dev --extra google --extra proxy --extra semantic-router --extra saml - name: Cache Prisma binaries uses: ./.github/actions/cache-prisma-binaries diff --git a/.github/workflows/test-e2e-redis-chaos.yml b/.github/workflows/test-e2e-redis-chaos.yml index b954138c2ee..fe2f5359416 100644 --- a/.github/workflows/test-e2e-redis-chaos.yml +++ b/.github/workflows/test-e2e-redis-chaos.yml @@ -60,12 +60,12 @@ jobs: with: version: "0.10.9" - - name: Cache the Rust build - uses: ./.github/actions/cache-cargo-build + - name: Set up the Rust bridge + uses: ./.github/actions/rust-bridge - name: Install dependencies run: | - uv sync --frozen --group ci --group proxy-dev --group e2e-dev --extra proxy + .github/scripts/uv_sync_with_rust_bridge.sh --frozen --group ci --group proxy-dev --group e2e-dev --extra proxy - name: Cache Prisma binaries uses: ./.github/actions/cache-prisma-binaries diff --git a/.github/workflows/test-linting.yml b/.github/workflows/test-linting.yml index 24e3aaecc92..aee35b32a93 100644 --- a/.github/workflows/test-linting.yml +++ b/.github/workflows/test-linting.yml @@ -14,6 +14,7 @@ concurrency: cancel-in-progress: ${{ github.event_name == 'pull_request' }} jobs: + python: name: python permissions: @@ -91,14 +92,14 @@ 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 + - name: Set up the Rust bridge if: steps.changes.outputs.decision != 'skip' - uses: ./.github/actions/cache-cargo-build + uses: ./.github/actions/rust-bridge - name: Install dependencies if: steps.changes.outputs.decision != 'skip' run: | - uv sync --frozen --group proxy-dev --group e2e-dev + .github/scripts/uv_sync_with_rust_bridge.sh --frozen --group proxy-dev --group e2e-dev - name: Cache Prisma binaries if: steps.changes.outputs.decision != 'skip' @@ -171,7 +172,7 @@ jobs: env: GH_TOKEN: ${{ github.token }} run: | - uv sync --frozen --group proxy-dev --group e2e-dev --extra proxy + .github/scripts/uv_sync_with_rust_bridge.sh --frozen --group proxy-dev --group e2e-dev --extra proxy uv run --no-sync python scripts/openapi_docs_gate.py --base "$GATE_BASE_SHA" - name: Print OpenAI version @@ -406,13 +407,13 @@ jobs: restore-keys: | ${{ runner.os }}-uv- - - name: Cache the Rust build + - name: Set up the Rust bridge if: steps.changes.outputs.relevant == 'true' - uses: ./.github/actions/cache-cargo-build + uses: ./.github/actions/rust-bridge - name: Install backend dependencies if: steps.changes.outputs.relevant == 'true' - run: uv sync --frozen --group ci --group proxy-dev --extra google --extra proxy --extra semantic-router + run: .github/scripts/uv_sync_with_rust_bridge.sh --frozen --group ci --group proxy-dev --extra google --extra proxy --extra semantic-router - name: Cache Prisma binaries if: steps.changes.outputs.relevant == 'true' @@ -512,11 +513,11 @@ jobs: restore-keys: | ${{ runner.os }}-uv- - - name: Cache the Rust build - uses: ./.github/actions/cache-cargo-build + - name: Set up the Rust bridge + uses: ./.github/actions/rust-bridge - name: Install dependencies - run: uv sync --frozen --all-groups --all-extras + run: .github/scripts/uv_sync_with_rust_bridge.sh --frozen --all-groups --all-extras - name: check_licenses run: uv run --no-sync python ./tests/code_coverage_tests/check_licenses.py diff --git a/.github/workflows/test-merge-smoke.yml b/.github/workflows/test-merge-smoke.yml index 3f30c2e3666..72e1e2d9b6c 100644 --- a/.github/workflows/test-merge-smoke.yml +++ b/.github/workflows/test-merge-smoke.yml @@ -13,6 +13,7 @@ concurrency: cancel-in-progress: true jobs: + dashboard-build: name: dashboard-build runs-on: ubuntu-24.04 @@ -52,8 +53,11 @@ jobs: with: version: "0.10.9" + - name: Set up the Rust bridge + uses: ./.github/actions/rust-bridge + - name: Install dependencies - run: uv sync --frozen --extra proxy --extra cli --group dev --group proxy-dev --python ${{ matrix.python-version }} + run: .github/scripts/uv_sync_with_rust_bridge.sh --frozen --extra proxy --extra cli --group dev --group proxy-dev --python ${{ matrix.python-version }} - name: Create the loopback-only network namespace run: | @@ -123,8 +127,11 @@ jobs: with: version: "0.10.9" + - name: Set up the Rust bridge + uses: ./.github/actions/rust-bridge + - name: Install every extra and dependency group - run: uv sync --frozen --all-groups --all-extras --python ${{ matrix.python-version }} + run: .github/scripts/uv_sync_with_rust_bridge.sh --frozen --all-groups --all-extras --python ${{ matrix.python-version }} - name: Import the SDK, the proxy server and the enterprise package run: .venv/bin/python -c "import litellm, litellm.proxy.proxy_server, litellm_enterprise" @@ -132,7 +139,7 @@ jobs: windows-sdk: name: windows-sdk runs-on: windows-2025 - timeout-minutes: 10 + timeout-minutes: 30 env: LITELLM_LOCAL_MODEL_COST_MAP: "True" defaults: @@ -154,8 +161,11 @@ jobs: with: version: "0.10.9" + - name: Set up the Rust bridge + uses: ./.github/actions/rust-bridge + - name: Install dependencies - run: uv sync --frozen --no-install-workspace --group dev --python 3.11 + run: .github/scripts/uv_sync_with_rust_bridge.sh --frozen --group dev --python 3.11 - name: Run the Windows tests run: uv run --no-sync python -m pytest --tb=short -v tests/windows_tests diff --git a/.github/workflows/test-terraform-provider.yml b/.github/workflows/test-terraform-provider.yml index 78575d7cc7e..aeb775d777a 100644 --- a/.github/workflows/test-terraform-provider.yml +++ b/.github/workflows/test-terraform-provider.yml @@ -98,12 +98,12 @@ jobs: restore-keys: | ${{ runner.os }}-uv- - - name: Cache the Rust build - uses: ./.github/actions/cache-cargo-build + - name: Set up the Rust bridge + uses: ./.github/actions/rust-bridge - name: Install dependencies run: | - uv sync --frozen --group ci --group proxy-dev --extra google --extra proxy --extra semantic-router + .github/scripts/uv_sync_with_rust_bridge.sh --frozen --group ci --group proxy-dev --extra google --extra proxy --extra semantic-router - name: Cache Prisma binaries uses: ./.github/actions/cache-prisma-binaries diff --git a/.github/workflows/test-unit.yml b/.github/workflows/test-unit.yml index 7005ca0a1d7..1671f6b5b2f 100644 --- a/.github/workflows/test-unit.yml +++ b/.github/workflows/test-unit.yml @@ -18,96 +18,36 @@ concurrency: cancel-in-progress: ${{ github.event_name == 'pull_request' }} jobs: - rust-bridge: - name: rust-bridge + rust-bridge-windows: + name: rust-bridge-windows + if: github.ref == 'refs/heads/main' permissions: contents: read - pull-requests: read - outputs: - artifact: ${{ steps.rust-bridge-artifact.outputs.name }} - runs-on: ubuntu-latest - env: - UV_PYTHON: "3.12" + runs-on: windows-2025 + timeout-minutes: 30 + defaults: + run: + shell: bash steps: - uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 with: persist-credentials: false - - name: Detect relevant changes - id: changes - timeout-minutes: 2 - uses: ./.github/actions/detect-changes - - - name: Define editable Rust bridge cache key - id: rust-bridge-key - if: steps.changes.outputs.decision != 'skip' - env: - RUST_BRIDGE_CACHE_KEY: ${{ runner.os }}-rust-bridge-editable-${{ hashFiles('litellm-rust/Cargo.lock', 'litellm-rust/Cargo.toml', 'litellm-rust/crates/**', 'pyproject.toml') }} - run: echo "key=$RUST_BRIDGE_CACHE_KEY" >> "$GITHUB_OUTPUT" - - name: Set up Python - if: steps.changes.outputs.decision != 'skip' timeout-minutes: 3 uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 with: - python-version: ${{ env.UV_PYTHON }} + python-version: "3.11" - name: Set up uv - if: steps.changes.outputs.decision != 'skip' timeout-minutes: 3 uses: ./.github/actions/setup-uv-with-retries with: version: "0.10.9" - - name: Restore editable Rust bridge - id: rust-bridge-cache - if: steps.changes.outputs.decision != 'skip' - timeout-minutes: 5 - uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 - with: - path: rust-bridge-dist - key: ${{ steps.rust-bridge-key.outputs.key }} - - - name: Cache the Rust build - if: steps.changes.outputs.decision != 'skip' && steps.rust-bridge-cache.outputs.cache-hit != 'true' - timeout-minutes: 5 - uses: ./.github/actions/cache-cargo-build - - - name: Build editable Rust bridge - if: steps.changes.outputs.decision != 'skip' && steps.rust-bridge-cache.outputs.cache-hit != 'true' - timeout-minutes: 15 - run: | - mkdir -p rust-bridge-dist - uv run --no-project --with maturin==1.15.0 python -c 'import maturin; maturin.build_editable("rust-bridge-dist")' - strip --strip-debug litellm/rust_bridge/_native.abi3.so - mkdir -p rust-bridge-dist/litellm/rust_bridge - cp litellm/rust_bridge/_native.abi3.so rust-bridge-dist/litellm/rust_bridge/_native.abi3.so - - - name: Upload Rust bridge artifact - if: steps.changes.outputs.decision != 'skip' - timeout-minutes: 10 - uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 - with: - name: rust-bridge-${{ github.run_id }}-${{ github.run_attempt }} - path: rust-bridge-dist/ - retention-days: 1 - - - name: Save editable Rust bridge - if: steps.changes.outputs.decision != 'skip' && github.ref == 'refs/heads/main' && steps.rust-bridge-cache.outputs.cache-hit != 'true' - timeout-minutes: 10 - uses: actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830 - with: - path: rust-bridge-dist - key: ${{ steps.rust-bridge-key.outputs.key }} - - - name: Expose the Rust bridge artifact - id: rust-bridge-artifact - if: steps.changes.outputs.decision != 'skip' - timeout-minutes: 1 - env: - RUN_ID: ${{ github.run_id }} - RUN_ATTEMPT: ${{ github.run_attempt }} - run: echo "name=rust-bridge-${RUN_ID}-${RUN_ATTEMPT}" >> "$GITHUB_OUTPUT" + - name: Build the Rust bridge + timeout-minutes: 25 + uses: ./.github/actions/rust-bridge assert-shard-coverage: permissions: contents: read @@ -121,8 +61,7 @@ jobs: run: python3 .github/scripts/assert_ci_coverage.py --shards unit: name: ${{ matrix.shard }} - needs: [rust-bridge, assert-shard-coverage] - if: ${{ !cancelled() }} + needs: assert-shard-coverage runs-on: ubuntu-latest timeout-minutes: ${{ matrix.job-timeout-minutes }} permissions: @@ -982,30 +921,20 @@ jobs: timeout-minutes: 5 uses: ./.github/actions/cache-uv-downloads - - name: Set up the Rust build + - name: Set up the Rust bridge if: steps.changes.outputs.decision != 'skip' timeout-minutes: 5 uses: ./.github/actions/rust-bridge - with: - artifact: ${{ needs.rust-bridge.outputs.artifact }} - name: Install dependencies and check schema if: steps.changes.outputs.decision != 'skip' timeout-minutes: 8 env: - RUST_BRIDGE_ARTIFACT: ${{ needs.rust-bridge.outputs.artifact }} UNIT_SHARD: ${{ matrix.shard }} SCHEMA_BASE_REF: origin/${{ github.event.repository.default_branch }} run: | diff -u model_prices_and_context_window.json litellm/model_prices_and_context_window_backup.json - if [ -z "$RUST_BRIDGE_ARTIFACT" ]; then - uv sync --frozen --group ci --group proxy-dev --extra google --extra proxy --extra semantic-router --extra saml --extra caching --extra extra_proxy --extra proxy-runtime --extra utils - else - uv sync --frozen --group ci --group proxy-dev --extra google --extra proxy --extra semantic-router --extra saml --extra caching --extra extra_proxy --extra proxy-runtime --extra utils --no-install-project - uv pip install --no-deps --python .venv/bin/python rust-bridge-dist/*.whl - cp rust-bridge-dist/litellm/rust_bridge/_native.abi3.so litellm/rust_bridge/_native.abi3.so - uv run --no-sync python -c "import importlib.metadata; import litellm.rust_bridge._native; print(importlib.metadata.version('litellm'))" - fi + .github/scripts/uv_sync_with_rust_bridge.sh --frozen --group ci --group proxy-dev --extra google --extra proxy --extra semantic-router --extra saml --extra caching --extra extra_proxy --extra proxy-runtime --extra utils uv run --no-sync python -c 'import os, sys; print(sys.version); assert f"{sys.version_info.major}.{sys.version_info.minor}" == os.environ["UV_PYTHON"]' if [ "$UNIT_SHARD" = "db-and-spend" ]; then uv run --no-sync python scripts/check_schema_compatibility.py --base-ref "$SCHEMA_BASE_REF" @@ -1237,14 +1166,14 @@ jobs: restore-keys: | ${{ runner.os }}-uv- - - name: Cache the Rust build + - name: Set up the Rust bridge if: steps.changes.outputs.decision != 'skip' - uses: ./.github/actions/cache-cargo-build + uses: ./.github/actions/rust-bridge - name: Install dependencies if: steps.changes.outputs.decision != 'skip' run: | - uv sync --frozen --group ci --group proxy-dev --extra google --extra proxy --extra semantic-router + .github/scripts/uv_sync_with_rust_bridge.sh --frozen --group ci --group proxy-dev --extra google --extra proxy --extra semantic-router - name: Cache Prisma binaries if: steps.changes.outputs.decision != 'skip' @@ -1375,8 +1304,6 @@ jobs: run: uv run --no-sync basedpyright --pythonpath .venv/bin/python --project tests/typing/pyrightconfig.json redis-compat: name: redis-py ${{ matrix.redis-py }} compatibility - needs: rust-bridge - if: ${{ !cancelled() }} permissions: contents: read id-token: write @@ -1423,26 +1350,16 @@ jobs: timeout-minutes: 5 uses: ./.github/actions/cache-uv-downloads - - name: Set up the Rust build + - name: Set up the Rust bridge if: steps.changes.outputs.decision != 'skip' timeout-minutes: 5 uses: ./.github/actions/rust-bridge - with: - artifact: ${{ needs.rust-bridge.outputs.artifact }} - name: Install dependencies with redis-py ${{ matrix.redis-py }} if: steps.changes.outputs.decision != 'skip' timeout-minutes: 8 - env: - RUST_BRIDGE_ARTIFACT: ${{ needs.rust-bridge.outputs.artifact }} run: | - if [ -z "$RUST_BRIDGE_ARTIFACT" ]; then - uv sync --frozen --group ci --group proxy-dev --extra google --extra proxy --extra semantic-router --extra saml --extra caching --extra extra_proxy --extra proxy-runtime --extra utils - else - uv sync --frozen --group ci --group proxy-dev --extra google --extra proxy --extra semantic-router --extra saml --extra caching --extra extra_proxy --extra proxy-runtime --extra utils --no-install-project - uv pip install --no-deps --python .venv/bin/python rust-bridge-dist/*.whl - cp rust-bridge-dist/litellm/rust_bridge/_native.abi3.so litellm/rust_bridge/_native.abi3.so - fi + .github/scripts/uv_sync_with_rust_bridge.sh --frozen --group ci --group proxy-dev --extra google --extra proxy --extra semantic-router --extra saml --extra caching --extra extra_proxy --extra proxy-runtime --extra utils uv pip install --python .venv/bin/python "redis==${REDIS_PY_VERSION:?}" uv run --no-sync python -c 'import os, redis; assert redis.__version__ == os.environ["REDIS_PY_VERSION"], redis.__version__' @@ -1539,7 +1456,7 @@ jobs: unit-passed: name: unit passed permissions: {} - needs: [rust-bridge, assert-shard-coverage, unit, ui-unit, docs, helm, openai-sdk-compat, redis-compat] + needs: [assert-shard-coverage, unit, ui-unit, docs, helm, openai-sdk-compat, redis-compat] if: always() runs-on: ubuntu-latest timeout-minutes: 2 diff --git a/.github/workflows/weekly_load_anomaly.yml b/.github/workflows/weekly_load_anomaly.yml index 4d7b1852e13..8ff7c9e0000 100644 --- a/.github/workflows/weekly_load_anomaly.yml +++ b/.github/workflows/weekly_load_anomaly.yml @@ -47,12 +47,12 @@ jobs: with: version: "0.10.9" - - name: Cache the Rust build - uses: ./.github/actions/cache-cargo-build + - name: Set up the Rust bridge + uses: ./.github/actions/rust-bridge - name: Install dependencies run: | - uv sync --frozen --group ci --group proxy-dev --extra proxy + .github/scripts/uv_sync_with_rust_bridge.sh --frozen --group ci --group proxy-dev --extra proxy - name: Cache Prisma binaries uses: ./.github/actions/cache-prisma-binaries diff --git a/tests/code_coverage_tests/test_unit_passed_gate.py b/tests/code_coverage_tests/test_unit_passed_gate.py index 5a0d04681d4..418c45e5d3b 100644 --- a/tests/code_coverage_tests/test_unit_passed_gate.py +++ b/tests/code_coverage_tests/test_unit_passed_gate.py @@ -10,7 +10,7 @@ import yaml _WORKFLOWS_DIR: Final = Path(__file__).resolve().parents[2] / ".github" / "workflows" _TIERS: Final = ( ("test-linting.yml", "lint-passed", frozenset()), - ("test-unit.yml", "unit-passed", frozenset({"coverage"})), + ("test-unit.yml", "unit-passed", frozenset({"coverage", "rust-bridge-windows"})), ("test-merge-smoke.yml", "smoke-passed", frozenset()), ) _Tier = tuple[str, str, frozenset[str]]