Skip to content

fix(github): preview limit check should not block updates to existing previews#4139

Open
mixelburg wants to merge 2 commits intoDokploy:canaryfrom
mixelburg:fix/preview-deployment-limit-blocks-updates
Open

fix(github): preview limit check should not block updates to existing previews#4139
mixelburg wants to merge 2 commits intoDokploy:canaryfrom
mixelburg:fix/preview-deployment-limit-blocks-updates

Conversation

@mixelburg
Copy link
Copy Markdown
Contributor

@mixelburg mixelburg commented Apr 3, 2026

Fixes #4074

What happened

The preview deployment limit check in the GitHub webhook handler ran before findPreviewDeploymentByApplicationId(). Pushing a commit to an open PR whose application had already reached its preview limit would silently drop the rebuild event — the deployment was never queued even though no new preview was being created.

Fix

Moved the limit check inside the if (!previewDeploymentResult && shouldCreateDeployment) block so it only fires when a new preview deployment would be created. Updates to existing previews (i.e. new commits pushed to already-open PRs) always proceed regardless of the limit.

Also fixed two secondary issues noted in the bug report:

  • const previewLimit = app?.previewLimit || 0 was defaulting to 0 when the app's configured limit was falsy. The DB schema default is 3. Changed to ?? 3 so a deliberately configured value of 0 is also respected.
  • Changed > to >= so the limit is enforced at exactly previewLimit previews rather than allowing one extra beyond the limit.

Greptile Summary

This PR fixes two related bugs in the GitHub webhook preview deployment flow: (1) the preview limit check was running before the existing-preview lookup, blocking updates to already-open PRs, and (2) the deployment worker's catch block never updated statuses to "error" on failure.

The restructuring in github.ts is logically correct — moving the limit guard inside if (!previewDeploymentResult && shouldCreateDeployment) ensures only new preview creation is gated by the limit, while commits to existing previews always proceed. The ?? 3 / >= corrections are also accurate fixes.

Confidence Score: 5/5

This PR is safe to merge — both changes are targeted, correct fixes for well-described bugs with no new risk introduced.

All three sub-fixes (limit-check relocation, ?? 3 default, >= comparison) are logically sound, and the new error-status handling in the worker's catch block mirrors the existing try-block pattern. No new logic paths or edge cases are introduced that could cause regressions.

No files require special attention.

Reviews (1): Last reviewed commit: "fix(github): preview limit check should ..." | Re-trigger Greptile

… fails

When the deployment worker catches an error, the service status was left
permanently in 'running' state because the catch block only logged the
error without rolling back the status set at the beginning of the job.

Add status rollback in the catch block for all three applicationType
branches (application, compose, application-preview). Each rollback call
is wrapped in .catch(() => {}) so that a secondary DB failure cannot mask
the original error in the logs.
… previews

The limit check in the GitHub webhook handler was running before
findPreviewDeploymentByApplicationId(), so pushing a commit to an open
PR whose app had already reached the preview limit would silently drop
the deployment even though no new preview was being created.

Moved the limit check inside the 'if (!previewDeploymentResult &&
shouldCreateDeployment)' block so it only fires when a NEW preview
would be created. Existing previews always rebuild on push.

Also fixed two secondary issues noted in Dokploy#4074:
- The default for previewLimit was 0 (via || 0) instead of the DB
  schema default of 3; changed to ?? 3 so a configured value of 0 is
  respected.
- Changed > to >= so the limit is enforced at exactly previewLimit
  previews, not previewLimit + 1.
@mixelburg mixelburg requested a review from Siumauricio as a code owner April 3, 2026 22:16
@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. bug Something isn't working labels Apr 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Preview Deployment limit check blocks updating existing previews

1 participant