Repository navigation
Sweep orphaned Xata branches in the cleanup cron - #63
Merged
Merged
Conversation
The nightly cleanup only deleted branches still tracked by a userBranch row. Branches orphaned in Xata — delete failures swallowed on the user path after the row was removed, or a crash between createBranch and the row insert — were never revisited and lingered indefinitely. Add an orphan sweep to cleanupIdleBranches: delete any branch that is not the parent (main), not a tpl-* template, and not referenced by a userBranch row, with a one-hour createdAt grace period so an in-flight create is never swept mid-provisioning. Also make the manual scripts/xata-cleanup.ts keep tpl-* templates instead of deleting everything except main. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Sandbox branches in the Xata project were lingering for many days. The nightly cleanup cron (
/api/cron/cleanup-branches) only deleted branches still tracked by auserBranchrow, but several paths orphan branches in Xata with no row:dropBranchForLessonand the quota evictor rundeleteBranch(...).catch(() => {})and then delete the DB row regardless — a transient Xata API failure leaves the branch untracked forever.ensureBranchForLessonswallow delete failures the same way.createBranchand the DB insert leaves a branch with no row at all.Once orphaned, no code ever looked at those branches again. A dry-run of
scripts/xata-cleanup.tsagainst the sandbox project currently shows dozens of stalelp-*branches.Fix
lib/branch-manager.ts: addsweepOrphanBranches, run bycleanupIdleBranchesafter the idle pass and template prune. It deletes any Xata branch that is not the parent (main/XATA_PARENT_BRANCH), not atpl-*template, and not referenced by anyuserBranchrow. A one-hourcreatedAtgrace period avoids racing an in-flight create (the branch exists in Xata up to ~2 minutes before its row lands). Results are reported in a neworphans: { scanned, dropped }field of the cron response; failures land in the existingerrorsarray.scripts/xata-cleanup.ts: the manual script kept onlymainand would have deleted all templates; it now also keepstpl-*, matching the keep policy (main + templates, remove the rest).Testing
npx tsc --noEmitandeslintpass.scripts/xata-cleanup.tsagainst the live sandbox project (read-only) confirmsmainand everytpl-*branch are tagged KEEP and onlylp-*sandboxes are tagged DELETE.orphans.droppedin the response will show the backlog being cleared.🤖 Generated with Claude Code