fix(planetscale): delete the branch an apply created when it fails before its deploy request - #963
Draft
aparajon wants to merge 1 commit into
Draft
fix(planetscale): delete the branch an apply created when it fails before its deploy request#963aparajon wants to merge 1 commit into
aparajon wants to merge 1 commit into
Conversation
…fore its deploy request Branch teardown rides on AutoDeleteBranch, which is set on the deploy request. An apply that fails while preparing the branch — the ordinary failure, DDL the engine refuses — never gets that far, so the branch is stranded with nothing to reclaim it. Branches are quota'd, so the strand eventually surfaces as a branch-creation error on an unrelated schema change. The apply now owns the branch it created until the deploy request takes over, and deletes it on the way out of a failure. An operator-supplied branch is never touched. The delete runs on its own deadline, detached from the apply's context, so a cancelled apply still cleans up; a branch that cannot be deleted is logged at error level with the identifiers needed to remove it by hand. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes a PlanetScale operational leak where an apply that fails before creating a deploy request can strand the newly-created branch (because AutoDeleteBranch is only set on the deploy request). It introduces explicit cleanup ownership for SchemaBot-created branches until the deploy request exists.
Changes:
- Add an Engine helper to delete a SchemaBot-owned branch on apply failure using a detached, bounded-timeout context.
- Track “owned branch” lifetime inside
Apply()and trigger cleanup via a deferred failure handler until deploy-request creation transfers ownership. - Add a focused test covering both SchemaBot-created branch cleanup and the “operator-supplied branch must not be touched” case.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pkg/engine/planetscale/branch_cleanup.go | Adds bounded, detached branch deletion helper with operator-actionable logging on failure. |
| pkg/engine/planetscale/branch_cleanup_test.go | Tests that applies delete only the branches they create when failing pre–deploy request, and never delete operator-supplied branches. |
| pkg/engine/planetscale/apply.go | Tracks branch ownership and defers cleanup on failure until deploy request creation transfers teardown responsibility. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Why this matters
Branch teardown rides on
AutoDeleteBranch, which is set on the deploy request. An apply that fails while preparing the branch — the ordinary failure, DDL the engine refuses — never gets that far, so the branch is stranded with nothing to reclaim it. Branches are quota'd, so the strand does not surface where it was created: it surfaces later as a branch-creation error on an unrelated schema change.What it does
The apply owns the branch it created until the deploy request takes over, and deletes it on the way out of a failure. An operator-supplied branch is never touched. The delete runs on its own deadline, detached from the apply's context, so a cancelled apply still cleans up; a branch that cannot be deleted is logged at error level with the identifiers needed to remove it by hand.
🤖 Generated with Claude Code