fix(iace): prevent mitigation explosion — fallback only for unassigned
Pattern-suggested measures go to all hazards in category (correct). Category-based fallback only for hazards WITHOUT pattern suggestions (max 3 per hazard). Prevents 1654 mitigations explosion. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -276,19 +276,37 @@ func (h *IACEHandler) InitializeProject(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback: assign category-based measures to ALL hazards per category
|
||||
// Fallback: assign category-based measures only to hazards that
|
||||
// didn't get any measures from pattern suggestions (max 3 per hazard)
|
||||
hazardsWithMeasures := make(map[uuid.UUID]bool)
|
||||
for _, sm := range matchOutput.SuggestedMeasures {
|
||||
entry, ok := measureByID[sm.MeasureID]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
for _, ids := range hazardIDsByCategory {
|
||||
for _, id := range ids {
|
||||
_ = entry // suppress unused
|
||||
hazardsWithMeasures[id] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
for hazCat, hazIDs := range hazardIDsByCategory {
|
||||
measCat := patternCatToMeasureCat(hazCat)
|
||||
added := 0
|
||||
for _, m := range measuresByCat[measCat] {
|
||||
if added >= 5 {
|
||||
break
|
||||
measures := measuresByCat[measCat]
|
||||
for _, hazID := range hazIDs {
|
||||
if hazardsWithMeasures[hazID] {
|
||||
continue // Already has pattern-suggested measures
|
||||
}
|
||||
rt := iace.ReductionType(m.ReductionType)
|
||||
if rt == "" {
|
||||
rt = iace.ReductionTypeInformation
|
||||
}
|
||||
for _, hazID := range hazIDs {
|
||||
added := 0
|
||||
for _, m := range measures {
|
||||
if added >= 3 {
|
||||
break
|
||||
}
|
||||
rt := iace.ReductionType(m.ReductionType)
|
||||
if rt == "" {
|
||||
rt = iace.ReductionTypeInformation
|
||||
}
|
||||
_, cerr := h.store.CreateMitigation(ctx, iace.CreateMitigationRequest{
|
||||
HazardID: hazID, ReductionType: rt,
|
||||
Name: m.Name, Description: m.Description,
|
||||
@@ -296,8 +314,8 @@ func (h *IACEHandler) InitializeProject(c *gin.Context) {
|
||||
if cerr == nil {
|
||||
created++
|
||||
}
|
||||
added++
|
||||
}
|
||||
added++
|
||||
}
|
||||
}
|
||||
mitStep = InitStep{Name: "Massnahmen erstellt", Status: "done", Count: created}
|
||||
|
||||
Reference in New Issue
Block a user