Skip to content

feat: delete pending canceled prebuilds (#20499)#20554

Merged
ssncferreira merged 1 commit into
release/2.28from
ssncferreira/2.28-backport-20499
Oct 30, 2025
Merged

feat: delete pending canceled prebuilds (#20499)#20554
ssncferreira merged 1 commit into
release/2.28from
ssncferreira/2.28-backport-20499

Conversation

@ssncferreira
Copy link
Copy Markdown
Contributor

Related to PR: #20499

(cherry picked from commit c3e3bb5)

## Description

PR #20387 introduced canceling
pending prebuild jobs from inactive template versions to avoid
provisioning obsolete workspaces. However, the associated prebuilds
remained in the database with "Canceled" status, visible in the UI.

This PR now orphan-deletes these canceled prebuilt workspaces. Since the
canceled jobs were never processed by a provisioner, no Terraform
resources were created, making orphan deletion safe.

Orphan deletion always creates a provisioner job, but behaves
differently based on provisioner availability:
- If no provisioner daemon is available, the job is immediately marked
as completed and the workspace is marked as deleted without any
provisioner processing
- If a provisioner daemon is available, it processes the delete job with
empty Terraform state (no actual resources to destroy)

The job cancellation and workspace deletion occur atomically in the same
transaction. We don't split this into two separate reconciliation runs
because there's no way to distinguish between system-canceled prebuilds
and user-canceled workspaces. If we deleted canceled workspaces in a
later run, we'd delete user-canceled workspaces that users may want to
keep for troubleshooting.

Note: This only applies to system-generated prebuilds from inactive
template versions.

## Changes

* Update `UpdatePrebuildProvisionerJobWithCancel` query to return job
ID, workspace ID, template ID, and template version preset ID
* Add `DeprovisionMode` enum to support orphan deletion in the provision
flow
* Update `ActionTypeCancelPending` handler to cancel jobs and
orphan-delete associated workspaces atomically

(cherry picked from commit c3e3bb5)
@johnstcn johnstcn added the cherry-pick/v2.28 Needs to be cherry-picked to the 2.28 release branch label Oct 29, 2025
@ssncferreira ssncferreira merged commit a7b3efb into release/2.28 Oct 30, 2025
27 of 29 checks passed
@ssncferreira ssncferreira deleted the ssncferreira/2.28-backport-20499 branch October 30, 2025 10:38
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 30, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cherry-pick/v2.28 Needs to be cherry-picked to the 2.28 release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants