Skip to content

Commit 860891d

Browse files
Callum Styanclaude
andcommitted
fix(scaletest/prebuilds): fail immediately if workspaces remain after deletion retries
Log every deletion attempt (not just retries) and return an error if workspaces remain after all attempts, rather than logging an error and proceeding to template deletion which would fail anyway. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 250303a commit 860891d

1 file changed

Lines changed: 6 additions & 16 deletions

File tree

scaletest/prebuilds/run.go

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -346,13 +346,11 @@ func (r *Runner) Cleanup(ctx context.Context, _ string, logs io.Writer) error {
346346
if len(remaining) == 0 {
347347
break
348348
}
349-
if attempt > 0 {
350-
logger.Info(ctx, "retrying workspace deletions",
351-
slog.F("attempt", attempt+1),
352-
slog.F("remaining", len(remaining)),
353-
slog.F("template_name", r.template.Name),
354-
)
355-
}
349+
logger.Info(ctx, "trying to delete workspaces",
350+
slog.F("attempt", attempt+1),
351+
slog.F("remaining", len(remaining)),
352+
slog.F("template_name", r.template.Name),
353+
)
356354
var failed []codersdk.Workspace
357355
for _, ws := range remaining {
358356
cr := workspacebuild.NewCleanupRunner(r.client, ws.ID)
@@ -373,17 +371,9 @@ func (r *Runner) Cleanup(ctx context.Context, _ string, logs io.Writer) error {
373371
for i, ws := range remaining {
374372
ids[i] = ws.ID.String()
375373
}
376-
logger.Error(ctx, "CLEANUP INCOMPLETE: could not delete all workspaces after retries; template deletion will likely fail",
377-
slog.F("template_name", r.template.Name),
378-
slog.F("remaining_count", len(remaining)),
379-
slog.F("remaining_workspace_ids", ids),
380-
)
374+
return xerrors.Errorf("could not delete all workspaces after %d attempts; remaining: %v", maxDeletionAttempts, ids)
381375
}
382376

383-
// Always attempt template deletion even if some workspaces could not be
384-
// removed. The delete call will fail with a 400 if workspaces remain, but
385-
// the error — combined with the log above — makes the state clear to the
386-
// operator.
387377
logger.Info(ctx, "deleting template", slog.F("template_name", r.template.Name))
388378
if err := r.client.DeleteTemplate(ctx, r.template.ID); err != nil {
389379
return xerrors.Errorf("delete template: %w", err)

0 commit comments

Comments
 (0)