Repository navigation
🐛 fix(sink/git): fail instead of silently dropping snapshot superseded on non-fast-forward push (REL-08) - #191
Conversation
…d on non-fast-forward push (REL-08) Under the default PushPolicyCommit, a non-fast-forward rejection made pushCommitted run syncRemoteBeforePush, whose force-fetch (+refs/heads/<branch>:refs/heads/<branch>) resets the local branch to the diverged remote tip and ORPHANS the just-committed snapshot. The retry push then no-ops (already-up-to-date), pushCommitted returned nil, the export fingerprint was recorded, and shouldSkip suppressed every subsequent reconcile: the snapshot was silently never delivered until the inventory checksum changed or the operator restarted. Fix: positive delivery verification (the REL-06 direction). After the push loop, pushCommitted verifies the pushed branch ref equals or descends from the captured snapshot commit (verifySnapshotDelivered). A superseded snapshot surfaces as errSnapshotSuperseded, so exportErr is non-nil, the fingerprint stays unrecorded, and the next reconcile re-exports the snapshot on top of the new remote tip. Any resolution or ancestry-walk failure is a FAIL-SAFE error -- delivery is never reported on an unverifiable state, mirroring the REL-06 ls-remote fail-safe. Verification deliberately runs OUTSIDE the transport-retry closure: a verdict raised inside it could be re-run into a trivially already-up-to-date push that would mask the drop again (and its message avoids raw hashes so hex substrings can never match the transient-error keywords). This was chosen over only skipping the fingerprint record because it also fails loudly on any other future path that ends with the remote not holding the snapshot. Tests (TDD, red first): - TestPushCommitted_SupersededSnapshotFailsInsteadOfSilentDrop reproduces the diverged-remote supersession against a local bare remote and locks the non-nil verdict + untouched remote tip. - TestVerifySnapshotDelivered pins delivered (equal/ancestor), superseded, and both fail-safe branches (missing branch ref, unknown snapshot commit).
There was a problem hiding this comment.
Pull request overview
This PR fixes a correctness hole in the go-git export path where a non-fast-forward recovery could orphan the just-created snapshot commit and still report success, causing silent non-delivery (REL-08). It adds post-push delivery verification to ensure the pushed branch ref equals or descends from the snapshot commit and introduces tests that reproduce the supersession scenario and pin the verification behavior.
Changes:
- Add
verifySnapshotDeliveredanderrSnapshotSupersededto positively verify that a snapshot commit was actually delivered after the push loop. - Update
pushCommittedto verify delivery against the originally captured snapshot hash (even if non-ff recovery rewrites the working branch). - Add TDD-style local-repo tests covering the superseded-snapshot regression and verification fail-safe behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
internal/sink/git/export.go |
Adds snapshot-delivery verification and returns a typed supersession error instead of reporting false success. |
internal/sink/git/push_committed_local_test.go |
Adds regression and helper tests reproducing the REL-08 silent-drop scenario and pinning verification semantics. |
Suppressed comments (3)
internal/sink/git/export.go:382
- Same concern as above: avoid %w here if you need to guarantee the verification error messages never contain raw hashes or transient-keyword substrings coming from go-git’s error text.
return fmt.Errorf("verify snapshot delivery: load branch tip: %w", err)
internal/sink/git/export.go:377
- Same concern as above: using %w here will include the inner error string (potentially with commit hashes) in the surfaced message and can interfere with substring-based transient error classification. Prefer a sanitized message (or at least only the underlying error type) for this verification path.
return fmt.Errorf("verify snapshot delivery: load snapshot commit: %w", err)
internal/sink/git/export.go:387
- Same concern as above: wrapping with %w will surface the inner message verbatim. If these errors are intended to be message-stable and hash-free, return a sanitized error string (optionally annotating with the error type) instead of including the full inner text.
return fmt.Errorf("verify snapshot delivery: ancestry walk: %w", err)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| func verifySnapshotDelivered(repo *git.Repository, branch string, snapshot plumbing.Hash) error { | ||
| ref, err := repo.Reference(plumbing.NewBranchReferenceName(branch), true) | ||
| if err != nil { | ||
| return fmt.Errorf("verify snapshot delivery: resolve branch %s: %w", branch, err) |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|



Problem (REL-08, from PR #187 review)
Under the default
PushPolicyCommit, a non-fast-forward push rejection makespushCommittedrunsyncRemoteBeforePush, whose force-fetch (+refs/heads/<branch>:refs/heads/<branch>) resets the local branch to the diverged remote tip and orphans the just-committed snapshot. The retry push no-ops (already-up-to-date),pushCommittedreturned nil, the export fingerprint got recorded, andshouldSkipsuppressed every subsequent reconcile — the dropped snapshot was silently never delivered until the inventory checksum changed or the in-memory tracker reset on restart. Requires a diverged remote push-branch (external/concurrent writer): edge path, but silent non-delivery.Fix
Positive delivery verification (the preferred direction, following REL-06 #173/#188): after the push loop,
pushCommittedverifies the pushed branch ref equals or descends from the captured snapshot commit (verifySnapshotDelivered).errSnapshotSuperseded→exportErr != nil→ fingerprint not recorded → the next reconcile re-exports on top of the new remote tip (warm-mirror recovery confirmed: checkout resets the staged orphan state, the snapshot is re-committed onto the new tip and fast-forwards).503/429/eof).pull --rebase+ REL-06'sremoteHasLocalHead); only the go-git path had the drop.Tests (TDD, red first)
TestPushCommitted_SupersededSnapshotFailsInsteadOfSilentDrop— reproduces diverged remote → force-fetch supersession against a local bare remote; was red (error = <nil>) before the fix; also locks that the orphaned snapshot is not force-pushed (remote tip untouched).TestVerifySnapshotDelivered— pins delivered (branch equals / contains snapshot), the typed supersession verdict, and both fail-safe branches (missing branch ref, unknown snapshot commit).Gates
go build ./...go vet ./...task lint(golangci-lint)task arch-lintgo test ./internal/sink/... -count=1go test ./... -count=1(with envtest assets)