mirror of
https://github.com/RayLabsHQ/gitea-mirror.git
synced 2026-07-18 19:26:26 -05:00
[PR #300] [MERGED] fix: stop snapshot-row zombies + flapping force-push on deleted branches #6593
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/RayLabsHQ/gitea-mirror/pull/300
Author: @seanmousseau
Created: 5/25/2026
Status: ✅ Merged
Merged: 5/26/2026
Merged by: @arunavo4
Base:
main← Head:fix/snapshot-row-status-and-deleted-branch-flapping📝 Commits (2)
093b958fix: stop snapshot-row zombies + flapping force-push on deleted branchesc2dfbaafix: acknowledge deletion before backup, not after, to fix concurrent-sync race📊 Changes
4 files changed (+297 additions, -4 deletions)
View changed files
📝
src/lib/gitea-enhanced.ts(+57 -3)📝
src/lib/metadata-state.ts(+28 -0)📝
src/lib/utils/force-push-detection.test.ts(+185 -0)📝
src/lib/utils/force-push-detection.ts(+27 -1)📄 Description
Summary
Two bugs caused production gitea-mirror to accumulate one orphan "Snapshot created" job row per scheduled sync — 7 zombies in 24h on
Simple-WP-Helpdeskagainst a deleted GitHub branch (fix/v4.0.2-webhook-comment-author).Bug 1: snapshot job row stuck in non-terminal status
gitea-enhanced.tscreated the post-snapshotmirror_jobsrecord withstatus: \"syncing\". But the snapshot was already complete at that point (createPreSyncBundleBackupreturned successfully), and no later code path advanced the row to a terminal status. Each force-push-triggered backup leaked an orphan row. Fix:status: \"synced\".Bug 2: force-push detection flapping on deleted branches
force-push-detection.tstreated any Gitea branch missing from GitHub as a "deleted" force-push. But gitea-mirror is one-way (GitHub → Gitea), so deletions never propagate back to the Gitea mirror — the branch lingers in Gitea forever, the missing-from-GitHub condition holds on every subsequent sync, and detection re-fires endlessly. WithbackupBeforeSync: truethis triggered a fresh snapshot of the exact same state every cycle.Fix: extend
RepositoryMetadataStatewith anacknowledgedDeletions: { branch, giteaSha }[]list (persisted on the repository row). The detector accepts this list and suppresses deleted branches whose currentgiteaShamatches an entry. If thegiteaShalater changes (branch restored, then re-deleted with new history), the entry won't match and detection fires again — back up the new state, then acknowledge the new SHA.The acknowledge-push runs right after detection, not after backup success. The first iteration of this fix gated it on the backup
tryblock, which broke when concurrent sync invocations both detected the deletion but only one'screatePreSyncBundleBackupactually fired (the other short-circuited because the file already existed). The second invocation skipped the push, then raced its empty in-memoryacknowledgedDeletionsonto the metadata row, undoing the first invocation's write. Moving the push earlier makes the race benign: both invocations push the same entry, both write the same metadata.Production validation (2026-05-25)
Built
gitea-mirror:fix-snapshot-zombies-v2from this branch, deployed via Komodo API to the production gitea-mirror instance, and ran a controlled repro:claude-test/zombie-reproref directly in Gitea's bare repository forsean/Simple-WP-Helpdesk(branch table row + git ref) so that Gitea had a branch GitHub didn't — recreating the bug condition exactly.status=synced(Bug 1 fix verified — no zombies).acknowledgedDeletions; the final metadata persisted[{branch: \"claude-test/zombie-repro\", giteaSha: \"41c76615...\"}](Bug 2 fix verified — race-safe).acknowledgedDeletionsto[].Test plan
bun test src/lib/utils/force-push-detection.test.ts— 9 new structural test cases covering: suppression when giteaSha matches; re-flag when giteaSha differs; only-acknowledged-deletion suppression in mixed cases; undefined list back-compat; diverged branches not suppressed via deletions list; metadata-state round-trip; legacy-blob defaulting; malformed-entry resilience.bun test src/lib/gitea-enhanced.test.ts src/lib/repo-backup.test.ts— 59 tests pass, no regressions.Files
src/lib/gitea-enhanced.ts— status fix, hoisted metadataState, moved acknowledge-push to after detection (pre-backup) to fix racesrc/lib/metadata-state.ts— addedAcknowledgedDeletiontype + parse/serialize supportsrc/lib/utils/force-push-detection.ts— acceptsacknowledgedDeletions, suppresses matching entriessrc/lib/utils/force-push-detection.test.ts— 9 new test cases🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.