Compress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.
Python agentaianthropicclaude-codecompressioncontext-engineeringcontext-windowcursorfastapilangchainllmmcpopenaiprompt-engineeringproxypythonragtoken-optimizationtokenstypescript
ci: prefetch HF model once + run shards offline (kill the 429 herd)
Tejas Chopra9a16a59df432
diff --git a/.github/workflows/ci-fast.yml b/.github/workflows/ci-fast.ymlindex ac80073fb..28c9307d5 100644--- a/.github/workflows/ci-fast.yml+++ b/.github/workflows/ci-fast.yml@@ -90,16 +90,49 @@ jobs:- name: mypyrun: mypy headroom --ignore-missing-imports+ # Download the embedding model ONCE and warm the shared cache, so the 4 test+ # shards don't all hammer HuggingFace in parallel (that 429'd a shard on a+ # cold cache). Uses huggingface_hub directly — no torch needed just to fetch.+ prefetch-model:+ needs: changes+ if: needs.changes.outputs.code == 'true'+ runs-on: ubuntu-latest+ steps:+ - uses: actions/setup-python@v5+ with:+ python-version: ${{ env.PY_VERSION }}+ - name: Cache HuggingFace model+ id: hfcache+ uses: actions/cache@v4+ with:+ path: ~/.cache/huggingface+ key: ${{ runner.os }}-models-allMiniLM-v2+ - name: Fetch all-MiniLM-L6-v2 (resilient to HF rate limits)+ if: steps.hfcache.outputs.cache-hit != 'true'+ env:+ HF_TOKEN: ${{ secrets.HF_TOKEN }}+ HF_HUB_DISABLE_TELEMETRY: "1"+ run: |+ python -m pip install --upgrade pip huggingface_hub+ for i in 1 2 3 4 5 6; do+ if python -c "from huggingface_hub import snapshot_download; snapshot_download('sentence-transformers/all-MiniLM-L6-v2')"; then exit 0; fi+ echo "::warning::model fetch attempt $i failed; backing off"; sleep $((i * 30))+ done+ echo "::error::could not fetch all-MiniLM-L6-v2 from HuggingFace"; exit 1+test:- needs: [changes, build-wheel]+ needs: [changes, build-wheel, prefetch-model]if: needs.changes.outputs.code == 'true'runs-on: ubuntu-lateststrategy:fail-fast: falsematrix:shard: [1, 2, 3, 4]+ # Shards read the model purely from the cache warmed by prefetch-model — no+ # HF network calls at all (so no rate-limit HEAD requests can fail them).env:- FASTEMBED_CACHE_PATH: ${{ github.workspace }}/.fastembed-cache+ HF_HUB_OFFLINE: "1"+ TRANSFORMERS_OFFLINE: "1"steps:- uses: actions/checkout@v4- uses: actions/setup-python@v5@@ -113,13 +146,11 @@ jobs:key: ${{ runner.os }}-pipfast-${{ env.PY_VERSION }}-${{ hashFiles('pyproject.toml') }}restore-keys: ${{ runner.os }}-pipfast-${{ env.PY_VERSION }}-- - name: Cache HuggingFace + fastembed models+ - name: Restore HuggingFace model cache (warmed by prefetch-model)uses: actions/cache@v4with:- path: |- ~/.cache/huggingface- ${{ github.workspace }}/.fastembed-cache- key: ${{ runner.os }}-models-allMiniLM-v1+ path: ~/.cache/huggingface+ key: ${{ runner.os }}-models-allMiniLM-v2- name: Download prebuilt wheeluses: actions/download-artifact@v4@@ -143,17 +174,6 @@ jobs:cp "${SITE}/headroom/"_core*.so headroom/python -c "from headroom._core import DiffCompressor; print('headroom._core OK')"- - name: Pre-fetch embedding model (resilient to HF rate limits)- env:- HF_TOKEN: ${{ secrets.HF_TOKEN }}- HF_HUB_DISABLE_TELEMETRY: "1"- run: |- for i in 1 2 3 4 5; do- if python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('all-MiniLM-L6-v2')"; then exit 0; fi- echo "::warning::model fetch attempt $i failed; backing off"; sleep $((i * 20))- done- echo "::error::could not fetch all-MiniLM-L6-v2 from HuggingFace"; exit 1-- name: Run test shard ${{ matrix.shard }}/4run: |pytest tests scripts/tests \