Skip to content

Commit e8eec7c

Browse files
authored
chore: centralize BUG panic for invalid model in domain computation (#30310)
1 parent 178adc3 commit e8eec7c

4 files changed

Lines changed: 14 additions & 15 deletions

File tree

pkg/workflow/crush_engine.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,17 +171,13 @@ func (e *CrushEngine) GetExecutionSteps(workflowData *WorkflowData, logFile stri
171171
// The model was validated by validateUniversalLLMConsumerModel before reaching here,
172172
// so a malformed model (e.g. leading slash) must never occur. Panic is the correct
173173
// response to an internal invariant violation.
174-
var err error
175-
allowedDomains, err = GetAllowedDomainsForEngineWithModel(
174+
allowedDomains = mustGetAllowedDomainsForEngineWithModel(
176175
constants.CrushEngine,
177176
model,
178177
workflowData.NetworkPermissions,
179178
workflowData.Tools,
180179
workflowData.Runtimes,
181180
)
182-
if err != nil {
183-
panic(fmt.Sprintf("BUG: invalid model %q reached domain computation (should have been caught by validation): %v", model, err))
184-
}
185181
}
186182

187183
npmPathSetup := GetNpmBinPathSetup()

pkg/workflow/domains.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,17 @@ func GetAllowedDomainsForEngineWithModel(engine constants.EngineName, model stri
775775
return mergeDomainsWithNetworkToolsAndRuntimes(defaults, network, tools, runtimes), nil
776776
}
777777

778+
// mustGetAllowedDomainsForEngineWithModel is like GetAllowedDomainsForEngineWithModel but
779+
// panics if the model is malformed. It is intended for call sites where the model has
780+
// already been validated and an error represents an internal invariant violation (BUG).
781+
func mustGetAllowedDomainsForEngineWithModel(engine constants.EngineName, model string, network *NetworkPermissions, tools map[string]any, runtimes map[string]any) string {
782+
result, err := GetAllowedDomainsForEngineWithModel(engine, model, network, tools, runtimes)
783+
if err != nil {
784+
panic(fmt.Sprintf("BUG: invalid model %q reached domain computation (should have been caught by validation): %v", model, err))
785+
}
786+
return result
787+
}
788+
778789
// GetAllowedDomainsForEngine merges the engine's default domains with NetworkPermissions,
779790
// HTTP MCP server domains, and runtime ecosystem domains.
780791
// Returns a deduplicated, sorted, comma-separated string suitable for AWF's --allow-domains flag.

pkg/workflow/opencode_engine.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,13 @@ func (e *OpenCodeEngine) GetExecutionSteps(workflowData *WorkflowData, logFile s
129129
// The model was validated by validateUniversalLLMConsumerModel before reaching here,
130130
// so a malformed model (e.g. leading slash) must never occur. Panic is the correct
131131
// response to an internal invariant violation.
132-
var err error
133-
allowedDomains, err = GetAllowedDomainsForEngineWithModel(
132+
allowedDomains = mustGetAllowedDomainsForEngineWithModel(
134133
constants.OpenCodeEngine,
135134
model,
136135
workflowData.NetworkPermissions,
137136
workflowData.Tools,
138137
workflowData.Runtimes,
139138
)
140-
if err != nil {
141-
panic(fmt.Sprintf("BUG: invalid model %q reached domain computation (should have been caught by validation): %v", model, err))
142-
}
143139
}
144140

145141
npmPathSetup := GetNpmBinPathSetup()

pkg/workflow/pi_engine.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -337,11 +337,7 @@ func (e *PiEngine) GetExecutionSteps(workflowData *WorkflowData, logFile string)
337337
}
338338
// The model was validated before reaching here; a malformed model (leading slash)
339339
// must never occur at this point — panic is the correct invariant guard.
340-
var err error
341-
allowedDomains, err = GetAllowedDomainsForEngineWithModel(constants.PiEngine, model, workflowData.NetworkPermissions, workflowData.Tools, workflowData.Runtimes)
342-
if err != nil {
343-
panic(fmt.Sprintf("BUG: invalid Pi model %q reached domain computation (should have been caught by validation): %v", model, err))
344-
}
340+
allowedDomains = mustGetAllowedDomainsForEngineWithModel(constants.PiEngine, model, workflowData.NetworkPermissions, workflowData.Tools, workflowData.Runtimes)
345341
}
346342
if workflowData.EngineConfig != nil && workflowData.EngineConfig.APITarget != "" {
347343
allowedDomains = mergeAPITargetDomains(allowedDomains, workflowData.EngineConfig.APITarget)

0 commit comments

Comments
 (0)