if err := tx.Table("attempts").Joins("JOIN steps ON steps.id = attempts.step_id").Where("attempts.containment = ? AND (steps.capability IN ? OR EXISTS (SELECT 1 FROM runner_assignments ra WHERE ra.attempt_id=attempts.id AND json_extract(ra.brief,'$.step.SpecialistKey')=?))", "pending", capabilities, key).Count(&live).Error; err != nil {