From 961cd38afba591902bb014b0dc6f702a6ddccb4f Mon Sep 17 00:00:00 2001 From: Vishal Bala Date: Wed, 4 Nov 2026 14:42:53 +0100 Subject: [PATCH 1/7] ci: prefetch notebook HF models into their own cache The notebook job shared the fixed `Linux-hf-cache` key with the test jobs. Whichever test job misses first saves that entry, so it holds only the models the tests load, and actions/cache never re-saves after an exact hit. redis/langcache-embed-v2 and BAAI/bge-reranker-base are loaded only by notebooks, so they were downloaded inside nbval cells on every run; PR run 41813891110 timed out at 60s in huggingface_hub's xet_get right after an exact cache hit. The notebook job now restores a cache keyed on the hash of .github/scripts/prefetch_notebook_models.py, downloads the listed models before nbval, and saves straight after that step, so a failing notebook cannot stop the save. nbval runs with HF_HUB_OFFLINE=1, so a notebook that loads an unlisted model fails at once instead of downloading against the cell timeout. The `needs: service-tests` ordering existed only to wait for the shared cache, so it is dropped. --- .github/scripts/prefetch_notebook_models.py | 40 +++++++++++++++++++++ .github/workflows/test.yml | 38 ++++++++++++++++---- 2 files changed, 71 insertions(+), 7 deletions(-) create mode 100644 .github/scripts/prefetch_notebook_models.py diff --git a/.github/scripts/prefetch_notebook_models.py b/.github/scripts/prefetch_notebook_models.py new file mode 100644 index 000000000..5681628de --- /dev/null +++ b/.github/scripts/prefetch_notebook_models.py @@ -0,0 +1,40 @@ +"""Download the HuggingFace models that the user-guide notebooks load. + +The Notebook Validation job runs this before nbval, so model downloads happen +outside nbval's per-cell timeout. The job's HF cache key hashes this file, so +editing either list below produces a new cache entry that includes the change. +nbval then runs with HF_HUB_OFFLINE=1, so a notebook that loads a model missing +from these lists fails immediately instead of downloading inside a cell. +""" + +import time + +from redisvl.utils.rerank import HFCrossEncoderReranker +from redisvl.utils.vectorize import HFTextVectorizer + +EMBEDDING_MODELS = [ + "redis/langcache-embed-v1", # SemanticCache default + "redis/langcache-embed-v2", + "sentence-transformers/all-mpnet-base-v2", # HFTextVectorizer default +] + +RERANKER_MODELS = [ + "BAAI/bge-reranker-base", +] + + +def main() -> None: + # Load through the same classes the notebooks use, so exactly the files + # they need end up in the cache. + for loader, models in ( + (HFTextVectorizer, EMBEDDING_MODELS), + (HFCrossEncoderReranker, RERANKER_MODELS), + ): + for model in models: + start = time.monotonic() + loader(model=model) + print(f"{model}: {time.monotonic() - start:.1f}s", flush=True) + + +if __name__ == "__main__": + main() diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c95f7a7e7..49892541b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -145,22 +145,28 @@ jobs: notebooks: name: Notebook Validation runs-on: ubuntu-latest - # Ordered after the HF cache is primed, not gated on it; see the `test` job. - needs: service-tests # Needs API-key secrets, unavailable to fork PRs and Dependabot. Keep in # sync with service-tests. - if: ${{ !cancelled() && (github.event_name != 'pull_request' || (github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]')) }} + if: github.event_name != 'pull_request' || (github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]') env: HF_HOME: ${{ github.workspace }}/hf_cache steps: - name: Check out repository uses: actions/checkout@v6 - - name: Cache HuggingFace Models - uses: actions/cache@v4 + # Separate from the `Linux-hf-cache` entry the test jobs share. That one + # is saved by whichever test job misses first and holds only the models + # the tests load, and actions/cache never re-saves after an exact hit, so + # models only the notebooks use were downloaded inside nbval cells on + # every run. This key changes whenever the model list does. + - name: Restore HuggingFace models + id: hf-cache + uses: actions/cache/restore@v4 with: path: hf_cache - key: ${{ runner.os }}-hf-cache + key: ${{ runner.os }}-hf-notebooks-${{ hashFiles('.github/scripts/prefetch_notebook_models.py') }} + restore-keys: | + ${{ runner.os }}-hf-notebooks- - name: Install Python uses: actions/setup-python@v5 @@ -181,6 +187,21 @@ jobs: run: | uv sync --all-extras --frozen + - name: Download HuggingFace models + env: + HF_TOKEN: ${{ secrets.HF_TOKEN }} + run: | + uv run --no-sync python .github/scripts/prefetch_notebook_models.py + + # Saved here rather than in a post-job step, so a failing notebook does + # not stop the models from being cached. + - name: Save HuggingFace models + if: steps.hf-cache.outputs.cache-hit != 'true' + uses: actions/cache/save@v4 + with: + path: hf_cache + key: ${{ steps.hf-cache.outputs.cache-primary-key }} + - name: Start Redis run: | set -euo pipefail @@ -228,7 +249,10 @@ jobs: OPENAI_API_VERSION: ${{ secrets.OPENAI_API_VERSION }} AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - HF_TOKEN: ${{ secrets.HF_TOKEN }} + # Every model the notebooks load is downloaded above. A notebook that + # loads one not listed in .github/scripts/prefetch_notebook_models.py + # fails fast here rather than downloading against the cell timeout. + HF_HUB_OFFLINE: "1" run: | make test-notebooks From 877094df49c45c443afd4b0b1157704cadc038cd Mon Sep 17 00:00:00 2001 From: Vishal Bala Date: Wed, 4 Nov 2026 16:04:19 +0100 Subject: [PATCH 2/7] docs: use langcache-embed-v2 throughout the user guide 03_llmcache loaded v2 for its first cache but fell back to the SemanticCache default, v1, for the private and multi-field caches, and 10_embeddings_cache named v1 explicitly. The notebook job therefore downloaded and cached two 572 MB models where one does. 03 now builds one v2 vectorizer and passes it to all three caches, and 10 uses v2. The prefetch list drops v1. Outputs that depend on the model were refreshed by re-running those cells; the filtered check() results in 03 are unchanged under v2. The library default stays v1. --- .github/scripts/prefetch_notebook_models.py | 1 - docs/user_guide/03_llmcache.ipynb | 33 ++++++--------------- docs/user_guide/10_embeddings_cache.ipynb | 10 +++---- 3 files changed, 14 insertions(+), 30 deletions(-) diff --git a/.github/scripts/prefetch_notebook_models.py b/.github/scripts/prefetch_notebook_models.py index 5681628de..cde476a59 100644 --- a/.github/scripts/prefetch_notebook_models.py +++ b/.github/scripts/prefetch_notebook_models.py @@ -13,7 +13,6 @@ from redisvl.utils.vectorize import HFTextVectorizer EMBEDDING_MODELS = [ - "redis/langcache-embed-v1", # SemanticCache default "redis/langcache-embed-v2", "sentence-transformers/all-mpnet-base-v2", # HFTextVectorizer default ] diff --git a/docs/user_guide/03_llmcache.ipynb b/docs/user_guide/03_llmcache.ipynb index ab431aad5..11f027625 100644 --- a/docs/user_guide/03_llmcache.ipynb +++ b/docs/user_guide/03_llmcache.ipynb @@ -141,11 +141,14 @@ "from redisvl.extensions.cache.llm import SemanticCache\n", "from redisvl.utils.vectorize import HFTextVectorizer\n", "\n", + "# embedding model, shared by every cache in this guide\n", + "vectorizer = HFTextVectorizer(\"redis/langcache-embed-v2\")\n", + "\n", "llmcache = SemanticCache(\n", - " name=\"llmcache\", # underlying search index name\n", - " redis_url=\"redis://localhost:6379\", # redis connection url string\n", - " distance_threshold=0.1, # semantic cache distance threshold (Redis COSINE [0-2], lower is stricter)\n", - " vectorizer=HFTextVectorizer(\"redis/langcache-embed-v2\"), # embedding model\n", + " name=\"llmcache\", # underlying search index name\n", + " redis_url=\"redis://localhost:6379\", # redis connection url string\n", + " distance_threshold=0.1, # semantic cache distance threshold (Redis COSINE [0-2], lower is stricter)\n", + " vectorizer=vectorizer,\n", ")" ] }, @@ -1020,16 +1023,6 @@ } }, "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "You try to use a model that was created with version 4.1.0, however, your version is 3.4.1. This might cause unexpected behavior or errors. In that case, try to update to the latest version.\n", - "\n", - "\n", - "\n" - ] - }, { "data": { "text/plain": [ @@ -1044,6 +1037,7 @@ "source": [ "private_cache = SemanticCache(\n", " name=\"private_cache\",\n", + " vectorizer=vectorizer,\n", " filterable_fields=[{\"name\": \"user_id\", \"type\": \"tag\"}]\n", ")\n", "\n", @@ -1132,16 +1126,6 @@ } }, "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "You try to use a model that was created with version 4.1.0, however, your version is 3.4.1. This might cause unexpected behavior or errors. In that case, try to update to the latest version.\n", - "\n", - "\n", - "\n" - ] - }, { "data": { "text/plain": [ @@ -1157,6 +1141,7 @@ "\n", "complex_cache = SemanticCache(\n", " name='account_data',\n", + " vectorizer=vectorizer,\n", " filterable_fields=[\n", " {\"name\": \"user_id\", \"type\": \"tag\"},\n", " {\"name\": \"account_type\", \"type\": \"tag\"},\n", diff --git a/docs/user_guide/10_embeddings_cache.ipynb b/docs/user_guide/10_embeddings_cache.ipynb index ddf9b9e1a..e85e22b1e 100644 --- a/docs/user_guide/10_embeddings_cache.ipynb +++ b/docs/user_guide/10_embeddings_cache.ipynb @@ -79,7 +79,7 @@ "source": [ "# Initialize the vectorizer\n", "vectorizer = HFTextVectorizer(\n", - " model=\"redis/langcache-embed-v1\",\n", + " model=\"redis/langcache-embed-v2\",\n", " cache_folder=os.getenv(\"SENTENCE_TRANSFORMERS_HOME\")\n", ")" ] @@ -146,14 +146,14 @@ "name": "stdout", "output_type": "stream", "text": [ - "Stored with key: embedcache:909f...\n" + "Stored with key: embedcache:7edf...\n" ] } ], "source": [ "# Text to embed\n", "text = \"What is machine learning?\"\n", - "model_name = \"redis/langcache-embed-v1\"\n", + "model_name = \"redis/langcache-embed-v2\"\n", "\n", "# Generate the embedding\n", "embedding = vectorizer.embed(text)\n", @@ -198,7 +198,7 @@ "output_type": "stream", "text": [ "Found in cache: What is machine learning?\n", - "Model: redis/langcache-embed-v1\n", + "Model: redis/langcache-embed-v2\n", "Metadata: {'category': 'ai', 'source': 'user_query'}\n", "Embedding shape: (768,)\n" ] @@ -322,7 +322,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "Stored with key: embedcache:909f...\n", + "Stored with key: embedcache:7edf...\n", "Exists by key: True\n", "Retrieved by key: What is machine learning?\n" ] From 83d51e871676ac3744eb7f6e97b0efdabd2b5d95 Mon Sep 17 00:00:00 2001 From: Vishal Bala Date: Mon, 9 Nov 2026 10:20:39 +0100 Subject: [PATCH 3/7] ci: share pruned uv caches with restore-keys and cancel superseded PR runs (FDE-205) - Replace setup-uv's built-in cache (no restore-keys) with actions/cache/restore + save, pruned with `uv cache prune --ci` and saved after install, before the tests. A uv.lock change now gets a partial hit instead of a cold rebuild. - One saver per Python version: service-tests saves 3.11, the redis-py 8.x x redis:8.4 leg saves the others; every other job is restore-only. docs and lint's lock job no longer cache. - HuggingFace cache: versioned key (-v2), restore-only in the matrix and notebooks, saved only by the canary; off actions/cache@v4. - test-fork-pr.yml runs the service-tests action from this repository with save-cache false, so a fork PR cannot save main-scoped caches. - Cancel superseded PR runs in test.yml and lint.yml; never cancel pushes, schedule or dispatch. - Pin runs-on: ubuntu-24.04 (the cache key names the OS), drop the docs group from test legs, setup-python v5 -> v6. --- .github/actions/run-service-tests/action.yml | 60 +++++++++-- .github/workflows/lint.yml | 36 +++++-- .github/workflows/test-fork-pr.yml | 21 +++- .github/workflows/test.yml | 103 ++++++++++++++----- 4 files changed, 173 insertions(+), 47 deletions(-) diff --git a/.github/actions/run-service-tests/action.yml b/.github/actions/run-service-tests/action.yml index aae42e55d..a53a28408 100644 --- a/.github/actions/run-service-tests/action.yml +++ b/.github/actions/run-service-tests/action.yml @@ -8,15 +8,26 @@ inputs: uv-version: description: 'uv version to use' required: true + save-cache: + description: >- + Save the uv and HuggingFace caches. Only one job per cache key should + save; pass "false" from every other caller, and always from a run that + executes untrusted code. + required: false + default: 'true' runs: using: 'composite' steps: - - name: Cache HuggingFace Models - uses: actions/cache@v5 + # Bump the version suffix to drop a stale model cache; the key is static, + # so a saved cache is never refreshed otherwise. Keep it in sync with the + # restore steps in test.yml. + - name: Restore HuggingFace models + id: hf-cache + uses: actions/cache/restore@v5 with: path: hf_cache - key: ${{ runner.os }}-hf-cache + key: ${{ runner.os }}-hf-cache-v2 - name: Set HuggingFace token shell: bash @@ -29,15 +40,26 @@ runs: with: python-version: ${{ inputs.python-version }} + # Caching is done by the restore/save steps around the install instead of + # by setup-uv, which has no restore-keys fallback. See test.yml. - name: Install uv uses: astral-sh/setup-uv@v10.0.0 with: version: ${{ inputs.uv-version }} - enable-cache: true + enable-cache: false + cache-local-path: ~/.cache/uv # sets UV_CACHE_DIR python-version: ${{ inputs.python-version }} - cache-dependency-glob: | - pyproject.toml - uv.lock + + # The runner OS is hard-coded in the key; callers pin runs-on: ubuntu-24.04. + # Key format is shared with test.yml and lint.yml; keep all three in sync. + - name: Restore uv cache + id: uv-cache + uses: actions/cache/restore@v5 + with: + path: ~/.cache/uv + key: uv-v1-ubuntu-24.04-${{ runner.arch }}-py${{ inputs.python-version }}-pruned-${{ hashFiles('pyproject.toml', 'uv.lock') }} + restore-keys: | + uv-v1-ubuntu-24.04-${{ runner.arch }}-py${{ inputs.python-version }}-pruned- - name: Install required dependencies shell: bash @@ -54,6 +76,20 @@ runs: run: | uv sync --all-extras + # Saved before the tests, so a failing test doesn't cost the next run its + # cache. `prune --ci` keeps only wheels built from source. + - name: Prune uv cache + if: inputs.save-cache == 'true' && steps.uv-cache.outputs.cache-hit != 'true' + shell: bash + run: uv cache prune --ci + + - name: Save uv cache + if: inputs.save-cache == 'true' && steps.uv-cache.outputs.cache-hit != 'true' + uses: actions/cache/save@v5 + with: + path: ~/.cache/uv + key: ${{ steps.uv-cache.outputs.cache-primary-key }} + - name: Authenticate to Google Cloud uses: google-github-actions/auth@v1 with: @@ -63,3 +99,13 @@ runs: shell: bash run: | make test-all + + # After the tests, which download the models. Only on success, because the + # key is static: a cache saved after an early failure would be missing + # models until the key is bumped. + - name: Save HuggingFace models + if: inputs.save-cache == 'true' && steps.hf-cache.outputs.cache-hit != 'true' + uses: actions/cache/save@v5 + with: + path: hf_cache + key: ${{ steps.hf-cache.outputs.cache-primary-key }} diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 9d6b162b3..3bdd69efd 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -6,26 +6,33 @@ on: branches: - main +# A new push to a PR cancels that PR's previous run; pushes to main are never +# cancelled. Same rule as test.yml. +concurrency: + group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.event.pull_request.number || github.run_id }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + env: UV_VERSION: "0.13.1" + # The uv cache key below hard-codes the runner OS, so the jobs pin + # `runs-on: ubuntu-24.04`. Change both together. jobs: lock: name: Check uv.lock is up to date - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - name: Check out repository uses: actions/checkout@v6 + # No cache: `uv lock --check` installs nothing, so a cache would only take + # up space. - name: Install uv uses: astral-sh/setup-uv@v10.0.0 with: version: ${{ env.UV_VERSION }} - enable-cache: true - cache-dependency-glob: | - pyproject.toml - uv.lock + enable-cache: false # Fails a pyproject.toml change that was never locked, before the drift # lands on main and dirties the next contributor's tree. @@ -34,7 +41,7 @@ jobs: check: name: Style-check ${{ matrix.python-version }} - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 strategy: matrix: python-version: @@ -58,11 +65,20 @@ jobs: uses: astral-sh/setup-uv@v10.0.0 with: version: ${{ env.UV_VERSION }} - enable-cache: true + enable-cache: false + cache-local-path: ~/.cache/uv # sets UV_CACHE_DIR python-version: ${{ matrix.python-version }} # sets UV_PYTHON - cache-dependency-glob: | - pyproject.toml - uv.lock + + # Restore-only: the Test Suite workflow saves these caches (same key format + # as test.yml; keep them in sync). This job installs the same + # `--all-extras` environment, so it reuses them as they are. + - name: Restore uv cache + uses: actions/cache/restore@v5 + with: + path: ~/.cache/uv + key: uv-v1-ubuntu-24.04-${{ runner.arch }}-py${{ matrix.python-version }}-pruned-${{ hashFiles('pyproject.toml', 'uv.lock') }} + restore-keys: | + uv-v1-ubuntu-24.04-${{ runner.arch }}-py${{ matrix.python-version }}-pruned- - name: Install dependencies run: | diff --git a/.github/workflows/test-fork-pr.yml b/.github/workflows/test-fork-pr.yml index 715102084..a3c2b6676 100644 --- a/.github/workflows/test-fork-pr.yml +++ b/.github/workflows/test-fork-pr.yml @@ -13,6 +13,9 @@ permissions: checks: write pull-requests: read +# No `concurrency` block: cancelling a run would leave the check run created +# below stuck at in_progress on the fork PR. + env: PYTHON_VERSION: "3.11" UV_VERSION: "0.13.1" @@ -20,7 +23,7 @@ env: jobs: setup: name: Validate PR - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 outputs: head_sha: ${{ steps.pr-info.outputs.head_sha }} head_repo: ${{ steps.pr-info.outputs.head_repo }} @@ -59,7 +62,7 @@ jobs: service-tests: name: Service Tests - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 needs: setup steps: - name: Create check run @@ -83,11 +86,23 @@ jobs: repository: ${{ needs.setup.outputs.head_repo }} ref: ${{ needs.setup.outputs.head_sha }} + # This run is on the dispatching ref (main), so any cache it saved would + # be restored by every later run on main and by every PR. Run the action + # from this repository rather than from the fork checkout, so the fork + # cannot edit away `save-cache: "false"`. + - name: Check out trusted actions + uses: actions/checkout@v6 + with: + path: trusted-actions + sparse-checkout: .github/actions + persist-credentials: false + - name: Run service tests - uses: ./.github/actions/run-service-tests + uses: ./trusted-actions/.github/actions/run-service-tests with: python-version: ${{ env.PYTHON_VERSION }} uv-version: ${{ env.UV_VERSION }} + save-cache: "false" env: HF_HOME: ${{ github.workspace }}/hf_cache HF_TOKEN: ${{ secrets.HF_TOKEN }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c95f7a7e7..d48902776 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,14 +12,24 @@ on: workflow_dispatch: +# A new push to a PR cancels that PR's previous run. Every other event gets a +# group of its own (the run ID), so pushes to main, the nightly schedule and +# manual dispatches are never cancelled. +concurrency: + group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.event.pull_request.number || github.run_id }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + env: PYTHON_VERSION: "3.11" UV_VERSION: "0.13.1" + # The uv cache keys below hard-code the runner OS, so every job pins + # `runs-on: ubuntu-24.04` rather than following ubuntu-latest. Change both + # together. jobs: service-tests: name: Service Tests - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 # Needs API-key secrets. Fork PRs and Dependabot-triggered runs get none, so # they skip here; a maintainer runs them via test-fork-pr.yml instead. if: github.event_name != 'pull_request' || (github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]') @@ -27,11 +37,15 @@ jobs: - name: Check out repository uses: actions/checkout@v6 + # The canary saves the Python 3.11 uv cache and the HuggingFace model + # cache. It finishes before the matrix starts, so the matrix legs and + # notebooks restore what it saved and never save themselves. - name: Run service tests uses: ./.github/actions/run-service-tests with: python-version: ${{ env.PYTHON_VERSION }} uv-version: ${{ env.UV_VERSION }} + save-cache: "true" env: HF_HOME: ${{ github.workspace }}/hf_cache HF_TOKEN: ${{ secrets.HF_TOKEN }} @@ -64,7 +78,7 @@ jobs: test: name: Python ${{ matrix.python-version }} - redis-py ${{ matrix.redis-py-version }} [${{ matrix.redis-image }}] - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 # `needs` is here to order this job after the HF model cache is primed, not # to gate it on the service suite passing (it was `needs: prime-cache` when # it was introduced in #306). Without a status check function, `needs` also @@ -97,32 +111,45 @@ jobs: - name: Check out repository uses: actions/checkout@v6 - - name: Cache HuggingFace Models - uses: actions/cache@v4 + # Restore-only: service-tests is the one job that saves this cache. + - name: Restore HuggingFace models + uses: actions/cache/restore@v5 with: path: hf_cache - key: ${{ runner.os }}-hf-cache + key: ${{ runner.os }}-hf-cache-v2 - name: Install Python - uses: actions/setup-python@v5 + uses: actions/setup-python@v6 with: python-version: ${{ matrix.python-version }} + # setup-uv's own cache has no restore-keys fallback, so any uv.lock change + # (the release bot's version bump included) would start every leg cold. + # The restore and save steps around the install do the caching instead. - name: Install uv uses: astral-sh/setup-uv@v10.0.0 with: version: ${{ env.UV_VERSION }} - enable-cache: true + enable-cache: false + cache-local-path: ~/.cache/uv # sets UV_CACHE_DIR python-version: ${{ matrix.python-version }} # sets UV_PYTHON - cache-dependency-glob: | - pyproject.toml - uv.lock + + # Key format is shared with lint.yml and the run-service-tests action; + # keep all three in sync. + - name: Restore uv cache + id: uv-cache + uses: actions/cache/restore@v5 + with: + path: ~/.cache/uv + key: uv-v1-ubuntu-24.04-${{ runner.arch }}-py${{ matrix.python-version }}-pruned-${{ hashFiles('pyproject.toml', 'uv.lock') }} + restore-keys: | + uv-v1-ubuntu-24.04-${{ runner.arch }}-py${{ matrix.python-version }}-pruned- - name: Install dependencies run: | set -euo pipefail - uv sync --all-extras --frozen + uv sync --all-extras --no-group docs --frozen # Must cover every redis-py-version matrix value; unhandled values fail. case "$REDIS_PY_VERSION" in @@ -138,13 +165,29 @@ jobs: uv pip install "$spec" uv run python -c 'import redis; print("redis-py:", redis.__version__)' + # One saver per Python version, so legs don't race to save the same key. + # service-tests saves 3.11; for the other versions the redis-py 8.x x + # redis:8.4 leg saves. Saving here rather than after the tests keeps the + # cache when a test fails. `prune --ci` keeps only wheels built from + # source; pre-built wheels download faster than they restore. + - name: Prune uv cache + if: ${{ matrix.python-version != env.PYTHON_VERSION && matrix.redis-py-version == '8.x' && matrix.redis-image == 'redis:8.4' && steps.uv-cache.outputs.cache-hit != 'true' }} + run: uv cache prune --ci + + - name: Save uv cache + if: ${{ matrix.python-version != env.PYTHON_VERSION && matrix.redis-py-version == '8.x' && matrix.redis-image == 'redis:8.4' && steps.uv-cache.outputs.cache-hit != 'true' }} + uses: actions/cache/save@v5 + with: + path: ~/.cache/uv + key: ${{ steps.uv-cache.outputs.cache-primary-key }} + - name: Run tests run: | make test notebooks: name: Notebook Validation - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 # Ordered after the HF cache is primed, not gated on it; see the `test` job. needs: service-tests # Needs API-key secrets, unavailable to fork PRs and Dependabot. Keep in @@ -156,14 +199,15 @@ jobs: - name: Check out repository uses: actions/checkout@v6 - - name: Cache HuggingFace Models - uses: actions/cache@v4 + # Restore-only, like the uv cache below: service-tests saves both. + - name: Restore HuggingFace models + uses: actions/cache/restore@v5 with: path: hf_cache - key: ${{ runner.os }}-hf-cache + key: ${{ runner.os }}-hf-cache-v2 - name: Install Python - uses: actions/setup-python@v5 + uses: actions/setup-python@v6 with: python-version: ${{ env.PYTHON_VERSION }} @@ -171,11 +215,17 @@ jobs: uses: astral-sh/setup-uv@v10.0.0 with: version: ${{ env.UV_VERSION }} - enable-cache: true + enable-cache: false + cache-local-path: ~/.cache/uv # sets UV_CACHE_DIR python-version: ${{ env.PYTHON_VERSION }} # sets UV_PYTHON - cache-dependency-glob: | - pyproject.toml - uv.lock + + - name: Restore uv cache + uses: actions/cache/restore@v5 + with: + path: ~/.cache/uv + key: uv-v1-ubuntu-24.04-${{ runner.arch }}-py${{ env.PYTHON_VERSION }}-pruned-${{ hashFiles('pyproject.toml', 'uv.lock') }} + restore-keys: | + uv-v1-ubuntu-24.04-${{ runner.arch }}-py${{ env.PYTHON_VERSION }}-pruned- - name: Install dependencies run: | @@ -233,26 +283,25 @@ jobs: make test-notebooks docs: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - name: Check out repository uses: actions/checkout@v6 - name: Install Python - uses: actions/setup-python@v5 + uses: actions/setup-python@v6 with: python-version: ${{ env.PYTHON_VERSION }} + # No cache: the docs install is small, and its cache used to claim the + # shared 3.11 key before the test jobs could save a useful one. - name: Install uv uses: astral-sh/setup-uv@v10.0.0 with: version: ${{ env.UV_VERSION }} - enable-cache: true + enable-cache: false python-version: ${{ env.PYTHON_VERSION }} # sets UV_PYTHON - cache-dependency-glob: | - pyproject.toml - uv.lock - + - name: Install dependencies run: | uv sync --group docs --frozen From e964e9f0d8425da733401cd5cfa4dce4c9a4981c Mon Sep 17 00:00:00 2001 From: Vishal Bala Date: Mon, 9 Nov 2026 10:25:24 +0100 Subject: [PATCH 4/7] ci: harden the fork-PR cache path and pick a stable uv saver leg (FDE-205) - test-fork-pr.yml: cache-mode: read on the job that runs fork code, and persist-credentials: false on the fork checkout; the comment now says what this does and does not stop. - Pick the non-3.11 uv saver by redis:latest, the image value that never rotates, and note the dependency beside the matrix. - Correct comments on the docs group, the canary's HF save and the runs-on pins. --- .github/workflows/lint.yml | 7 ++++--- .github/workflows/test-fork-pr.yml | 17 +++++++++++++---- .github/workflows/test.yml | 20 ++++++++++++++------ 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 3bdd69efd..06dd01003 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -15,7 +15,7 @@ concurrency: env: UV_VERSION: "0.13.1" # The uv cache key below hard-codes the runner OS, so the jobs pin - # `runs-on: ubuntu-24.04`. Change both together. + # `runs-on: ubuntu-24.04` (all of them, for uniformity). Change both together. jobs: lock: @@ -70,8 +70,9 @@ jobs: python-version: ${{ matrix.python-version }} # sets UV_PYTHON # Restore-only: the Test Suite workflow saves these caches (same key format - # as test.yml; keep them in sync). This job installs the same - # `--all-extras` environment, so it reuses them as they are. + # as test.yml; keep them in sync). This job installs the test legs' + # `--all-extras` environment plus the docs group, so it reuses them as + # they are. - name: Restore uv cache uses: actions/cache/restore@v5 with: diff --git a/.github/workflows/test-fork-pr.yml b/.github/workflows/test-fork-pr.yml index a3c2b6676..ea0dacd94 100644 --- a/.github/workflows/test-fork-pr.yml +++ b/.github/workflows/test-fork-pr.yml @@ -64,6 +64,11 @@ jobs: name: Service Tests runs-on: ubuntu-24.04 needs: setup + # This job runs fork code on the dispatching ref (main), and a cache saved + # here would be restored by every later run on main and by every PR. + # `read` lets it restore but makes the cache toolkit skip every save, + # whichever step attempts it. + cache-mode: read steps: - name: Create check run id: check @@ -85,11 +90,15 @@ jobs: with: repository: ${{ needs.setup.outputs.head_repo }} ref: ${{ needs.setup.outputs.head_sha }} + # Keep GITHUB_TOKEN (checks: write) out of .git/config, where the + # fork's code could read it. + persist-credentials: false - # This run is on the dispatching ref (main), so any cache it saved would - # be restored by every later run on main and by every PR. Run the action - # from this repository rather than from the fork checkout, so the fork - # cannot edit away `save-cache: "false"`. + # Run the action from this repository rather than from the fork + # checkout, so the fork cannot edit away `save-cache: "false"`. Together + # with `cache-mode: read` this stops the workflow's own steps saving a + # cache; it cannot stop fork code that obtains the runner's cache token + # and calls the cache service itself. - name: Check out trusted actions uses: actions/checkout@v6 with: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d48902776..588e30a0f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -37,9 +37,11 @@ jobs: - name: Check out repository uses: actions/checkout@v6 - # The canary saves the Python 3.11 uv cache and the HuggingFace model - # cache. It finishes before the matrix starts, so the matrix legs and - # notebooks restore what it saved and never save themselves. + # The canary saves the Python 3.11 uv cache and, when its tests pass, the + # HuggingFace model cache. It finishes before the matrix starts, so the + # matrix legs and notebooks restore what it saved and never save these + # themselves. When it is skipped (fork and Dependabot PRs) they restore + # from the base branch instead. - name: Run service tests uses: ./.github/actions/run-service-tests with: @@ -103,6 +105,8 @@ jobs: redis-py-version: ["6.x", "7.x", "8.x"] # `redis:latest` floats, so a failure on it is not reproducible from a # SHA; it is advisory below. Pinned tags carry the blocking coverage. + # The uv cache saver below matches redis-py-version 8.x and + # redis:latest; update it if either value goes. redis-image: ["redis:8.2", "redis:8.4", "redis:latest"] include: - redis-image: "redis:latest" @@ -149,6 +153,8 @@ jobs: run: | set -euo pipefail + # The docs group (Sphinx and friends) is only for building docs; + # no test imports it. uv sync --all-extras --no-group docs --frozen # Must cover every redis-py-version matrix value; unhandled values fail. @@ -167,15 +173,17 @@ jobs: # One saver per Python version, so legs don't race to save the same key. # service-tests saves 3.11; for the other versions the redis-py 8.x x - # redis:8.4 leg saves. Saving here rather than after the tests keeps the + # redis:latest leg saves (`redis:latest` is the image value that never + # rotates; its continue-on-error doesn't matter because the save comes + # before the tests). Saving here rather than after the tests keeps the # cache when a test fails. `prune --ci` keeps only wheels built from # source; pre-built wheels download faster than they restore. - name: Prune uv cache - if: ${{ matrix.python-version != env.PYTHON_VERSION && matrix.redis-py-version == '8.x' && matrix.redis-image == 'redis:8.4' && steps.uv-cache.outputs.cache-hit != 'true' }} + if: ${{ matrix.python-version != env.PYTHON_VERSION && matrix.redis-py-version == '8.x' && matrix.redis-image == 'redis:latest' && steps.uv-cache.outputs.cache-hit != 'true' }} run: uv cache prune --ci - name: Save uv cache - if: ${{ matrix.python-version != env.PYTHON_VERSION && matrix.redis-py-version == '8.x' && matrix.redis-image == 'redis:8.4' && steps.uv-cache.outputs.cache-hit != 'true' }} + if: ${{ matrix.python-version != env.PYTHON_VERSION && matrix.redis-py-version == '8.x' && matrix.redis-image == 'redis:latest' && steps.uv-cache.outputs.cache-hit != 'true' }} uses: actions/cache/save@v5 with: path: ~/.cache/uv From b52a76d46db803f2e4833146a8e670598a3651c3 Mon Sep 17 00:00:00 2001 From: Vishal Bala Date: Mon, 9 Nov 2026 17:13:12 +0100 Subject: [PATCH 5/7] ci: keep notebooks ordered after service-tests; use cache@v5 Dropping `needs: service-tests` was wrong: besides the shared HF cache, it orders the notebook job after the job that saves the Python 3.11 uv cache, which the notebook job restores. Restore it with the same `!cancelled()` guard the test matrix uses. Move the notebook HF restore and save steps to actions/cache@v5, the version the service-tests action already uses. --- .github/workflows/test.yml | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 49892541b..43e10ddcb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -145,23 +145,26 @@ jobs: notebooks: name: Notebook Validation runs-on: ubuntu-latest + # Ordered after service-tests so it restores the uv cache that job saves; + # not gated on it; see the `test` job. + needs: service-tests # Needs API-key secrets, unavailable to fork PRs and Dependabot. Keep in # sync with service-tests. - if: github.event_name != 'pull_request' || (github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]') + if: ${{ !cancelled() && (github.event_name != 'pull_request' || (github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]')) }} env: HF_HOME: ${{ github.workspace }}/hf_cache steps: - name: Check out repository uses: actions/checkout@v6 - # Separate from the `Linux-hf-cache` entry the test jobs share. That one - # is saved by whichever test job misses first and holds only the models - # the tests load, and actions/cache never re-saves after an exact hit, so + # Separate from the HF cache the test jobs share, which holds only the + # models the tests load and is never re-saved after an exact hit, so # models only the notebooks use were downloaded inside nbval cells on - # every run. This key changes whenever the model list does. + # every run. This job is the only one that saves this key, and the key + # changes whenever the model list does. - name: Restore HuggingFace models id: hf-cache - uses: actions/cache/restore@v4 + uses: actions/cache/restore@v5 with: path: hf_cache key: ${{ runner.os }}-hf-notebooks-${{ hashFiles('.github/scripts/prefetch_notebook_models.py') }} @@ -197,7 +200,7 @@ jobs: # not stop the models from being cached. - name: Save HuggingFace models if: steps.hf-cache.outputs.cache-hit != 'true' - uses: actions/cache/save@v4 + uses: actions/cache/save@v5 with: path: hf_cache key: ${{ steps.hf-cache.outputs.cache-primary-key }} From 9439e87ab617cb5f5dd02c9f39686f4a76732fa6 Mon Sep 17 00:00:00 2001 From: Vishal Bala Date: Mon, 9 Nov 2026 17:29:50 +0100 Subject: [PATCH 6/7] ci: drop the notebook HF cache's restore-keys fallback A prefix restore brought back the previous entry whole, so a model removed from prefetch_notebook_models.py stayed in every later entry. A notebook still loading it would pass nbval offline until the chain of entries was evicted, which hid exactly the drift HF_HUB_OFFLINE=1 is there to catch. A model-list change now costs one cold download in the prefetch step, outside nbval's per-cell timeout. --- .github/workflows/test.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 248e1fb48..bd206ca6a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -213,15 +213,15 @@ jobs: # one under a static key after its tests, so it holds only the models the # tests load, and models only the notebooks use were downloaded inside # nbval cells on every run. This job is the only one that saves this key, - # and the key changes whenever the model list does. + # and the key changes whenever the model list does. There is deliberately + # no restore-keys fallback: an older entry would still hold models since + # removed from the list, and nbval would pass offline on them. - name: Restore HuggingFace models id: hf-cache uses: actions/cache/restore@v5 with: path: hf_cache key: ${{ runner.os }}-hf-notebooks-${{ hashFiles('.github/scripts/prefetch_notebook_models.py') }} - restore-keys: | - ${{ runner.os }}-hf-notebooks- - name: Install Python uses: actions/setup-python@v6 From ca4e2a74e13ff8cb79524f85484a7f651379cc6b Mon Sep 17 00:00:00 2001 From: Vishal Bala Date: Thu, 19 Nov 2026 16:22:20 +0100 Subject: [PATCH 7/7] ci: stop the release workflow caching and correct the cache comments (FDE-205) - auto-release.yml: enable-cache false in all three setup-uv steps. Its saves competed with the test caches for the 10 GB, and the publish job should not restore anything from the shared cache. - test-fork-pr.yml: cache-mode read is enforced through a read-only cache token, so say so; the trusted-actions checkout is now described as the second guard it is. - test.yml: name PYTHON_VERSION rather than 3.11 where the code keys off it, and drop two stale reasons from the coverage and docs comments. --- .github/workflows/auto-release.yml | 24 ++++++++++++------------ .github/workflows/test-fork-pr.yml | 12 +++++------- .github/workflows/test.yml | 9 ++++----- 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/.github/workflows/auto-release.yml b/.github/workflows/auto-release.yml index 6b89c2590..4e243e8cb 100644 --- a/.github/workflows/auto-release.yml +++ b/.github/workflows/auto-release.yml @@ -111,11 +111,11 @@ jobs: uses: astral-sh/setup-uv@v10.0.0 with: version: ${{ env.UV_VERSION }} - enable-cache: true + # No cache: a release job must not run anything restored from the + # shared cache, and its saves would only compete with the test + # jobs' caches for the repository's 10 GB. + enable-cache: false python-version: ${{ env.PYTHON_VERSION }} - cache-dependency-glob: | - pyproject.toml - uv.lock - name: Install dependencies run: uv sync --frozen @@ -194,11 +194,11 @@ jobs: uses: astral-sh/setup-uv@v10.0.0 with: version: ${{ env.UV_VERSION }} - enable-cache: true + # No cache: a release job must not run anything restored from the + # shared cache, and its saves would only compete with the test + # jobs' caches for the repository's 10 GB. + enable-cache: false python-version: ${{ env.PYTHON_VERSION }} - cache-dependency-glob: | - pyproject.toml - uv.lock - name: Apply release version to pyproject.toml and uv.lock run: | @@ -320,11 +320,11 @@ jobs: uses: astral-sh/setup-uv@v10.0.0 with: version: ${{ env.UV_VERSION }} - enable-cache: true + # No cache: a release job must not run anything restored from the + # shared cache, and its saves would only compete with the test + # jobs' caches for the repository's 10 GB. + enable-cache: false python-version: ${{ env.PYTHON_VERSION }} - cache-dependency-glob: | - pyproject.toml - uv.lock - name: Install dependencies run: uv sync --frozen diff --git a/.github/workflows/test-fork-pr.yml b/.github/workflows/test-fork-pr.yml index ea0dacd94..f16ea33ae 100644 --- a/.github/workflows/test-fork-pr.yml +++ b/.github/workflows/test-fork-pr.yml @@ -66,8 +66,8 @@ jobs: needs: setup # This job runs fork code on the dispatching ref (main), and a cache saved # here would be restored by every later run on main and by every PR. - # `read` lets it restore but makes the cache toolkit skip every save, - # whichever step attempts it. + # `read` gives the job a cache token that can restore but not save, so + # the cache service refuses a save from any step, fork code included. cache-mode: read steps: - name: Create check run @@ -94,11 +94,9 @@ jobs: # fork's code could read it. persist-credentials: false - # Run the action from this repository rather than from the fork - # checkout, so the fork cannot edit away `save-cache: "false"`. Together - # with `cache-mode: read` this stops the workflow's own steps saving a - # cache; it cannot stop fork code that obtains the runner's cache token - # and calls the cache service itself. + # A second guard, in case `cache-mode` is ever not honoured: run the + # action from this repository rather than from the fork checkout, so + # the fork cannot edit away `save-cache: "false"`. - name: Check out trusted actions uses: actions/checkout@v6 with: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3b208f684..a24b14726 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -37,7 +37,7 @@ jobs: - name: Check out repository uses: actions/checkout@v6 - # The canary saves the Python 3.11 uv cache and, when its tests pass, the + # The canary saves the PYTHON_VERSION uv cache and, when its tests pass, the # HuggingFace model cache. It finishes before the matrix starts, so the # matrix legs and notebooks restore what it saved and never save these # themselves. When it is skipped (fork and Dependabot PRs) they restore @@ -184,7 +184,7 @@ jobs: uv run python -c 'import redis; print("redis-py:", redis.__version__)' # One saver per Python version, so legs don't race to save the same key. - # service-tests saves 3.11; for the other versions the redis-py 8.x x + # service-tests saves PYTHON_VERSION; for the others the redis-py 8.x x # redis:latest leg saves (`redis:latest` is the image value that never # rotates; its continue-on-error doesn't matter because the save comes # before the tests). Saving here rather than after the tests keeps the @@ -238,7 +238,7 @@ jobs: python-version: ${{ env.PYTHON_VERSION }} # No cache: this job installs only the dev group, without the project, - # so a cache would hold little and claim a key the test jobs need. + # so a cache would hold little. - name: Install uv uses: astral-sh/setup-uv@v10.0.0 with: @@ -559,8 +559,7 @@ jobs: with: python-version: ${{ env.PYTHON_VERSION }} - # No cache: the docs install is small, and its cache used to claim the - # shared 3.11 key before the test jobs could save a useful one. + # No cache: the docs install is small. - name: Install uv uses: astral-sh/setup-uv@v10.0.0 with: