acoustic-spring-13969
04/09/2026, 8:49 AMhappy-kitchen-89482
04/09/2026, 4:37 PM--shard=x/n ?acoustic-spring-13969
04/09/2026, 5:26 PMhappy-kitchen-89482
04/12/2026, 11:10 AMhappy-kitchen-89482
04/12/2026, 11:10 AMhappy-kitchen-89482
04/12/2026, 11:10 AMacoustic-spring-13969
04/13/2026, 11:10 AM- name: Set up Pants Caching
uses: pantsbuild/actions/init-pants@main
with:
gha-cache-key: v0-test-shard-${{ matrix.shard }}
named-caches-hash: ${{ hashFiles('uv.lock', 'pants.toml') }}
cache-lmdb-store: "false" # Managed explicitly below so saves survive cancel-in-progress
- name: Restore Pants LMDB Store
id: restore-lmdb
uses: actions/cache/restore@v4
with:
path: ~/.cache/pants/lmdb_store/
key: pants-lmdb-v1-shard-${{ matrix.shard }}-${{ github.event.pull_request.base.sha || github.sha }}
restore-keys: |
pants-lmdb-v1-shard-${{ matrix.shard }}-
- name: Test (shard ${{ matrix.shard }}/2)
run: |
pants test \
--changed-since=origin/${{ github.base_ref }} \
--changed-dependents=transitive \
--shard=$((${{ matrix.shard }}))/N
- name: Save Pants LMDB Store
# always() ensures this runs even when the job is cancelled via concurrency
# cancel-in-progress — otherwise a new push cancels the running job before
# the init-pants post-step can persist the LMDB, creating a cold-cache cycle.
# GHA save is a no-op when the exact key already exists (immutable keys),
# so we always attempt the save without checking cache-hit.
if: always()
uses: actions/cache/save@v4
with:
path: ~/.cache/pants/lmdb_store/
key: pants-lmdb-v1-shard-${{ matrix.shard }}-${{ github.event.pull_request.base.sha || github.sha }}
Arrived at this fix / conclusion after observing Pants' built-in cache save runs as a post-step which gets killed on cancellation. So I manage the LMDB store manually. We use cancel-in-progress: true for concurrency groups in our CI e.g ( Most recent changes trigger CI all old runs are cancelled to conserve cost ). Thoughts and feedback are welcome on this approach or if pants can handle this nativelyhappy-kitchen-89482
04/13/2026, 1:04 PMhappy-kitchen-89482
04/13/2026, 1:05 PMinit-pants action? https://github.com/pantsbuild/actions/tree/main/init-pantshappy-kitchen-89482
04/13/2026, 1:10 PM<https://github.com/actions/cache> under the hood. It sounds like that should use actions/cache/restore and actions/cache/save explicitly as you've done above?acoustic-spring-13969
04/13/2026, 6:06 PMactions/cache@v5 which saves via a post-step hook that it registers at restore time. Post-steps run on success/failure but do not run on cancellation
So with cancel-in-progress: true
1. Run gets cancelled mid-way → post-step save never fires
2. Next run starts with a cold cache (nothing was saved)
3. Repeat indefinitely until whole workflow completes ( We run numerous checks in parallel and developers start their fixes immediately with A.I thus cancel in progress is quite likely)
Might be worth considering this pattern in the init-pants action itself as using cancel-in-progress: true (which is pretty common) would hit the same issue with the LMDB store cachehappy-kitchen-89482
04/13/2026, 11:00 PMacoustic-spring-13969
04/14/2026, 7:18 AM