Skip to content

docs: add vercel preview branch cleanup guide#4617

Open
philip wants to merge 1 commit intomainfrom
vercel-branch-cleanup
Open

docs: add vercel preview branch cleanup guide#4617
philip wants to merge 1 commit intomainfrom
vercel-branch-cleanup

Conversation

@philip
Copy link
Collaborator

@philip philip commented Mar 10, 2026

Under review, do not merge. Main Preview.

Explains why Neon preview branches can persist for months with the Vercel-Managed integration due to Vercel's deployment retention policy (default 180 days + 30-day recovery period).

Adds a dedicated guide covering the cleanup timeline, retention exceptions, how to reduce retention, and workarounds including a GitHub Action for immediate cleanup on PR close. Slims down cleanup sections in the existing integration pages to link to the new guide, and adds cross-references from the Vercel overview and cost optimization pages.

@philip philip requested a review from danieltprice as a code owner March 10, 2026 19:29
@vercel
Copy link

vercel bot commented Mar 10, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
neon-next Ready Ready Preview, Comment Mar 10, 2026 7:42pm

Request Review


1. **Vercel retains preview deployments for 6 months by default.** As of [October 2025](https://vercel.com/changelog/updated-defaults-for-deployment-retention), Vercel's default retention for pre-production deployments is 180 days. The clock starts when the deployment is created, not when the PR is closed.
2. **After retention expires, there's a 30-day recovery period.** During this window, Vercel holds the deployment in a recoverable state. Only after this period ends is the deployment permanently deleted. See [Restoring a deleted deployment](https://vercel.com/docs/deployment-retention#restoring-a-deleted-deployment).
3. **Neon deletes the branch after permanent deletion.** Neon receives a cleanup webhook from Vercel only after the deployment is permanently removed.
Copy link
Contributor

Choose a reason for hiding this comment

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

We delete the branch when we receive the webhook from Vercel, and based on my tests, when I manually delete the deployment, we received the webhook immediately (not after 30 days). I don't remember if I checked if this grace period applies only to the retention policy. Could you please double-check this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, manually deleting the deployment via vercel does immediately delete it and the associated neon branch. I'm still testing the other scenarios in relation to retention policy. Once done testing I'll clarify.

2. **After retention expires, there's a 30-day recovery period.** During this window, Vercel holds the deployment in a recoverable state. Only after this period ends is the deployment permanently deleted. See [Restoring a deleted deployment](https://vercel.com/docs/deployment-retention#restoring-a-deleted-deployment).
3. **Neon deletes the branch after permanent deletion.** Neon receives a cleanup webhook from Vercel only after the deployment is permanently removed.

In the worst case (a deployment created moments before the PR is closed), this means up to **~7 months** before the Neon branch is automatically deleted. In practice, the delay is often shorter for long-running PRs.
Copy link
Contributor

Choose a reason for hiding this comment

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

the delay is often shorter for long-running PRs.

You meant longer, didn't you?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I meant longer but it's poorly worded and confusing, so will update. Thanks!

- The last 10 deployments created in the project
- Deployments with custom aliases or branch aliases

Neon branches associated with these retained deployments won't be automatically deleted regardless of your Vercel retention settings. In practice, this means that if your project has 20 or fewer preview deployments, **none of them will be auto-deleted by Vercel's retention policy** since they all fall within the "last 20" exception.
Copy link
Contributor

Choose a reason for hiding this comment

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

What?! I didn't know this.


---

## Workarounds for immediate cleanup
Copy link
Contributor

Choose a reason for hiding this comment

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

It's worth noting that deleting branches (whether via a GH Action, CLI/API, or TTL) invalidates the existing Vercel deployments.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point, will mention this.

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