Repository: microsoft/onefuzz
File: src/ApiService/ApiService/onefuzzlib/ScalesetOperations.cs (C#)

Code before:

                // Overwrite any existing scaling rules with one that will
                //   try to scale in by 1 node at every opportunity
                profile.Rules.Clear();
                profile.Rules.Add(AutoScaleOperations.ShutdownScalesetRule(queueUri));

                // Auto scale (the azure service) will not allow you to
                //   set the minimum number of instances to a number
                //   smaller than the number of instances
                //   with scale in protection enabled.
                //
                // Since:
                //   * Nodes can no longer pick up work once the scale set is
                //       in `shutdown` state
                //   * All scale out rules are removed
                // Then: The number of nodes in the scale set with scale in
                //   protection enabled _must_ strictly decrease over time.
                //
                //  This guarantees that _eventually_
                //   auto scale will scale in the remaining nodes,
                //   the scale set will have 0 instances,
                //   and once the scale set is empty, we will delete it.
                _logTracer.Info($"Getting nodes with scale in protection");
                var vmsWithProtection = await _context.VmssOperations.ListVmss(
                    scaleset.ScalesetId,
                    (vmResource) => vmResource.Data.ProtectionPolicy.ProtectFromScaleIn != null
                        && vmResource.Data.ProtectionPolicy.ProtectFromScaleIn.HasValue
                        && vmResource.Data.ProtectionPolicy.ProtectFromScaleIn.Value
                );

                _logTracer.Info($"{JsonSerializer.Serialize(vmsWithProtection):Tag:VMsWithProtection}");
                if (vmsWithProtection != null && vmsWithProtection.Any()) {
                    var numVmsWithProtection = vmsWithProtection.Count;
                    profile.Capacity.Minimum = numVmsWithProtection.ToString();
                    profile.Capacity.Default = numVmsWithProtection.ToString();
                } else {
                    _logTracer.Error($"Failed to list vmss for scaleset {scaleset.ScalesetId:Tag:ScalesetId}");
                }
            }

            var updatedAutoScale = await _context.AutoScaleOperations.UpdateAutoscale(autoScalePolicy.OkV.Data);
            if (!updatedAutoScale.IsOk) {
                _logTracer.Error($"Failed to update auto scale {updatedAutoScale.ErrorV:Tag:Error}");
            }
        } else if (!autoScalePolicy.IsOk) {
            _logTracer.Error(autoScalePolicy.ErrorV);
        } else {
            _logTracer.Info($"No existing auto scale settings found for {scaleset.ScalesetId:Tag:ScalesetId}");
        }

        if (size == 0) {

Review comment (suggestion):
```suggestion

                    (vmResource) => vmResource?.Data?.ProtectionPolicy?.ProtectFromScaleIn != null
```

Code after:

                // Overwrite any existing scaling rules with one that will
                //   try to scale in by 1 node at every opportunity
                profile.Rules.Clear();
                profile.Rules.Add(AutoScaleOperations.ShutdownScalesetRule(queueUri));

                // Auto scale (the azure service) will not allow you to
                //   set the minimum number of instances to a number
                //   smaller than the number of instances
                //   with scale in protection enabled.
                //
                // Since:
                //   * Nodes can no longer pick up work once the scale set is
                //       in `shutdown` state
                //   * All scale out rules are removed
                // Then: The number of nodes in the scale set with scale in
                //   protection enabled _must_ strictly decrease over time.
                //
                //  This guarantees that _eventually_
                //   auto scale will scale in the remaining nodes,
                //   the scale set will have 0 instances,
                //   and once the scale set is empty, we will delete it.
                _logTracer.Info($"Getting nodes with scale in protection");

                var vmsWithProtection = await _context.VmssOperations.ListVmss(
                    scaleset.ScalesetId,
                    (vmResource) => vmResource?.Data?.ProtectionPolicy?.ProtectFromScaleIn != null
                        && vmResource.Data.ProtectionPolicy.ProtectFromScaleIn.Value
                );

                _logTracer.Info($"{JsonSerializer.Serialize(vmsWithProtection):Tag:VMsWithProtection}");
                if (vmsWithProtection != null) {
                    var numVmsWithProtection = vmsWithProtection.Count;
                    profile.Capacity.Minimum = numVmsWithProtection.ToString();
                    profile.Capacity.Default = numVmsWithProtection.ToString();
                } else {
                    _logTracer.Error($"Failed to list vmss for scaleset {scaleset.ScalesetId:Tag:ScalesetId}");
                }
            }

            var updatedAutoScale = await _context.AutoScaleOperations.UpdateAutoscale(autoScalePolicy.OkV.Data);
            if (!updatedAutoScale.IsOk) {
                _logTracer.Error($"Failed to update auto scale {updatedAutoScale.ErrorV:Tag:Error}");
            }
        } else if (!autoScalePolicy.IsOk) {
            _logTracer.Error(autoScalePolicy.ErrorV);
        } else {
            _logTracer.Info($"No existing auto scale settings found for {scaleset.ScalesetId:Tag:ScalesetId}");
        }

        if (size == 0) {