@@ -361,15 +361,22 @@ func (c *StoreReconciler) ReconcilePreset(ctx context.Context, ps prebuilds.Pres
361
361
slog .F ("preset_name" ,ps .Preset .Name ),
362
362
)
363
363
364
- if ! ps .Preset .Deleted && ps .Preset .UsingActiveVersion {
365
- c .metrics .trackHardLimitedStatus (ps .Preset .OrganizationName ,ps .Preset .TemplateName ,ps .Preset .Name ,ps .IsHardLimited )
366
- }
364
+ // Report a preset as hard-limited only if all the following conditions are met:
365
+ // - The preset is marked as hard-limited
366
+ // - The preset is using the active version of its template, and the template has not been deleted
367
+ //
368
+ // The second condition is important because a hard-limited preset that has become outdated is no longer relevant.
369
+ // Its associated prebuilt workspaces were likely deleted, and it's not meaningful to continue reporting it
370
+ // as hard-limited to the admin.
371
+ reportAsHardLimited := ps .IsHardLimited && ps .Preset .UsingActiveVersion && ! ps .Preset .Deleted
372
+ c .metrics .trackHardLimitedStatus (ps .Preset .OrganizationName ,ps .Preset .TemplateName ,ps .Preset .Name ,reportAsHardLimited )
367
373
368
374
// If the preset reached the hard failure limit for the first time during this iteration:
369
375
// - Mark it as hard-limited in the database
370
376
// - Send notifications to template admins
377
+ // - Continue execution, we disallow only creation operation for hard-limited presets. Deletion is allowed.
371
378
if ps .Preset .PrebuildStatus != database .PrebuildStatusHardLimited && ps .IsHardLimited {
372
- logger .Warn (ctx ,"skipping hard limited preset " )
379
+ logger .Warn (ctx ,"preset is hard limited, notifying template admins " )
373
380
374
381
err := c .store .UpdatePresetPrebuildStatus (ctx , database.UpdatePresetPrebuildStatusParams {
375
382
Status :database .PrebuildStatusHardLimited ,
@@ -447,12 +454,11 @@ func (c *StoreReconciler) ReconcilePreset(ctx context.Context, ps prebuilds.Pres
447
454
actions .Create = desired
448
455
}
449
456
450
- if actions .Create > 0 {
451
- // If the preset is hard-limited, log it and exit early.
452
- if ps .Preset .PrebuildStatus == database .PrebuildStatusHardLimited || ps .IsHardLimited {
453
- logger .Warn (ctx ,"skipping hard limited preset" )
454
- return nil
455
- }
457
+ // If preset is hard-limited, and it's a create operation, log it and exit early.
458
+ // Creation operation is disallowed for hard-limited preset.
459
+ if ps .IsHardLimited && actions .Create > 0 {
460
+ logger .Warn (ctx ,"skipping hard limited preset for create operation" )
461
+ return nil
456
462
}
457
463
458
464
var multiErr multierror.Error