Skip to content

🐛 fix(sink/git): fail instead of silently dropping snapshot superseded on non-fast-forward push (REL-08) - #191

Merged
konih merged 1 commit into
mainfrom
fix/rel-08-push-supersession-drop
Aug 3, 2026
Merged

konih merged 1 commit into
mainfrom
fix/rel-08-push-supersession-drop

Conversation

@konih

@konih konih commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Problem (REL-08, from PR #187 review)

Under the default PushPolicyCommit, a non-fast-forward push rejection makes 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 no-ops (already-up-to-date), pushCommitted returned nil, the export fingerprint got recorded, and shouldSkip suppressed 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, pushCommitted verifies the pushed branch ref equals or descends from the captured snapshot commit (verifySnapshotDelivered).

  • Supersession surfaces as 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).
  • Fail-safe: any branch-ref resolution, commit-load, or ancestry-walk failure is an error — delivery is never reported on an unverifiable state (mirrors the REL-06 ls-remote fail-safe).
  • Verification 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. Its messages avoid raw hashes so hex substrings can never match the transient-error keywords (503/429/eof).
  • The CLI engine path is unaffected (it recovers via pull --rebase + REL-06's remoteHasLocalHead); 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

Gate Result
go build ./... pass
go vet ./... pass
task lint (golangci-lint) pass, 0 issues
task arch-lint pass, no warnings
go test ./internal/sink/... -count=1 pass
go test ./... -count=1 (with envtest assets) pass

…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).
Copilot AI review requested due to automatic review settings August 3, 2026 22:59

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 verifySnapshotDelivered and errSnapshotSuperseded to positively verify that a snapshot commit was actually delivered after the push loop.
  • Update pushCommitted to 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

codecov Bot commented Aug 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/sink/git/export.go 80.00% 2 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@sonarqubecloud

sonarqubecloud Bot commented Aug 3, 2026

Copy link
Copy Markdown

@konih
konih merged commit 0a2867b into main Aug 3, 2026
30 of 31 checks passed
@konih
konih deleted the fix/rel-08-push-supersession-drop branch August 3, 2026 23:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants