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 {
|
for hazCat, hazIDs := range hazardIDsByCategory {
|
||||||
measCat := patternCatToMeasureCat(hazCat)
|
measCat := patternCatToMeasureCat(hazCat)
|
||||||
added := 0
|
measures := measuresByCat[measCat]
|
||||||
for _, m := range measuresByCat[measCat] {
|
for _, hazID := range hazIDs {
|
||||||
if added >= 5 {
|
if hazardsWithMeasures[hazID] {
|
||||||
break
|
continue // Already has pattern-suggested measures
|
||||||
}
|
}
|
||||||
rt := iace.ReductionType(m.ReductionType)
|
added := 0
|
||||||
if rt == "" {
|
for _, m := range measures {
|
||||||
rt = iace.ReductionTypeInformation
|
if added >= 3 {
|
||||||
}
|
break
|
||||||
for _, hazID := range hazIDs {
|
}
|
||||||
|
rt := iace.ReductionType(m.ReductionType)
|
||||||
|
if rt == "" {
|
||||||
|
rt = iace.ReductionTypeInformation
|
||||||
|
}
|
||||||
_, cerr := h.store.CreateMitigation(ctx, iace.CreateMitigationRequest{
|
_, cerr := h.store.CreateMitigation(ctx, iace.CreateMitigationRequest{
|
||||||
HazardID: hazID, ReductionType: rt,
|
HazardID: hazID, ReductionType: rt,
|
||||||
Name: m.Name, Description: m.Description,
|
Name: m.Name, Description: m.Description,
|
||||||
@@ -296,8 +314,8 @@ func (h *IACEHandler) InitializeProject(c *gin.Context) {
|
|||||||
if cerr == nil {
|
if cerr == nil {
|
||||||
created++
|
created++
|
||||||
}
|
}
|
||||||
|
added++
|
||||||
}
|
}
|
||||||
added++
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mitStep = InitStep{Name: "Massnahmen erstellt", Status: "done", Count: created}
|
mitStep = InitStep{Name: "Massnahmen erstellt", Status: "done", Count: created}
|
||||||
|
|||||||
Reference in New Issue
Block a user