Claude commited on
Commit
56b0d37
·
unverified ·
1 Parent(s): 33657f8

Make the HF Space deploy fail loudly on a concurrent-write collision

Browse files

git push --force to the Space was a blind overwrite: it never checked
what was currently there, so if anyone else has independent push access
to the same Space (direct git push, HF's web editor, their own CI) and
deploys around the same time, whichever push landed second would win
silently. The loser gets no error - git push --force always succeeds
regardless of what it's overwriting - so neither side would know a
collision happened without manually diffing the Space's history after
the fact.

Switched to `git push --force-with-lease`, which refuses to push if the
remote's current value doesn't match what we last fetched - i.e. someone
else changed it since we looked. Needs an explicit `git fetch space main`
right before the push: --force-with-lease compares against the local
remote-tracking ref, and this job adds the `space` remote fresh each run
with nothing to compare against otherwise (it would either fail every
single deploy, or on some git versions silently fall back to acting like
plain --force - the opposite of what we want).

Validated with a local three-repo simulation (bare "space" repo + our CI
clone + an "other dev" clone): pushed v1, had the other-dev clone push v2
directly to the space, then had a CI clone with a stale fetch (from
before v2) attempt to deploy v3 - the push was correctly rejected with
"! [rejected] ... (stale info)", and v2 stayed intact on the space
instead of being clobbered.

Files changed (1) hide show
  1. .github/workflows/deploy-to-hf.yml +7 -1
.github/workflows/deploy-to-hf.yml CHANGED
@@ -41,4 +41,10 @@ jobs:
41
  HF_TOKEN: ${{ secrets.HF_TOKEN }}
42
  run: |
43
  git remote add space https://hf-actions-bot:${HF_TOKEN}@huggingface.co/spaces/OrganizedProgrammers/SERPent
44
- git push --force space HEAD:main
 
 
 
 
 
 
 
41
  HF_TOKEN: ${{ secrets.HF_TOKEN }}
42
  run: |
43
  git remote add space https://hf-actions-bot:${HF_TOKEN}@huggingface.co/spaces/OrganizedProgrammers/SERPent
44
+ # Fetch first so --force-with-lease has a remote-tracking ref to
45
+ # compare against - without this it either fails every run or
46
+ # (depending on git version) silently behaves like plain --force.
47
+ # This makes the push fail instead of silently overwriting anyone
48
+ # else who deployed to this same Space since our last fetch.
49
+ git fetch space main
50
+ git push --force-with-lease space HEAD:main