Repository navigation
fix: keep in-flight builds from blocking the prebuild hard limit - #30060
Merged
BobbyHo merged 3 commits intoNov 9, 2026
Merged
Conversation
…d hard limit GetPresetsAtFailureLimit ranked a preset's builds across every status and then counted only the failed ones among the newest hard_limit. A pending or running build took a slot without being counted, so a preset that kept a build in flight at every reconcile snapshot never reached the limit and failed indefinitely. Rank only finished builds. The querier test helper now marks successful jobs as completed, since the existing "successful" cases were really pending jobs. Fixes coder#30058
Collaborator
|
Manual test I ran this change against a local coderd built in a Coder workspace, first on the merge base ( To keep a build in flight at every reconcile cycle, the server ran with one provisioner daemon, a 20 s reconciliation interval, backoff set to 0 and the default hard limit of 3. The template had one preset with two prebuild instances whose build slept 40 s and then exited 1. What happened:
The change behaved as described in every case I tried. |
BobbyHo
self-requested a review
November 9, 2026 16:46
This branch was previously 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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Fixes #30058.
GetPresetsAtFailureLimitranks a preset's newest start builds across every status, then counts only thefailedones among the tophard_limit. Apendingorrunningbuild takes a slot without being counted, so while a build is in flight the count cannot reach the limit. The reconciler reads this once per cycle and then creates prebuilds one at a time. When a create takes about as long as a failing build, every snapshot sees a build in flight and the preset is never hard-limited.The query now ranks only finished builds (
succeeded,failed,canceled). An in-flight build neither hides earlier failures nor counts as one. A canceled or succeeded build still breaks a failure streak, as before, and once the in-flight build finishes it is ranked like any other.Tests
TestGetPresetsAtFailureLimitgains two table cases with a pending build newer than the rest: three failures before it hit the limit, and a success before it does not.TestHardLimitedPresetWithBuildInFlight, modelled onTestSkippingHardLimitedPresets: withfailure_hard_limit = 1, a failed prebuild and a newer pending one, reconciling marks the preset hard-limited and creates nothing.createPrebuiltWorkspaceleft "successful" jobs pending, since it never setCompletedAt. It now completes them whensucceededJobis set, and the existing success cases use it, so they test what their names say.Without the query change (the new tests only):
With it:
coderd/database,coderd/prebuildsandenterprise/coderd/prebuildspass, andgolangci-lintreports no issues.We have also run this on a live deployment. A schedule-driven preset whose builds fail after 90s (longer than the 60s reconcile interval, so a build was in flight at every snapshot) stopped after 4 failed builds and created nothing more for the rest of the 20-minute observation. Before, the same shape produced 156 failed builds in about 2 hours.
AI disclosure
Written with AI assistance (Claude Code). I reviewed the change, ran the tests above myself, and verified the behaviour on a live deployment.