vxcontrol/pentagi · error
failed to set provider: %w
Error message
failed to set provider: %w
What it means
flowWorker.switchProvider wraps any failure from fw.flowCtx.Provider.SetProvider(ctx, prv) — the in-memory runtime swap of the flow's LLM provider — with this message. SetProvider decides whether the provider actually changed and resolves the tool_call_id_template; an error here means the running flow could not adopt the new provider and keeps operating with the previous one. The wrapped underlying error carries the real cause (e.g. the new provider is unhealthy or rejected).
Source
Thrown at backend/pkg/controller/flow.go:905
// Fixing that properly means keeping a per-model template registry, which is out
// of scope here; if real users hit it, this is the place to start.
func (fw *flowWorker) switchProvider(ctx context.Context, prv provider.Provider) error {
ctx, span := obs.Observer.NewSpan(ctx, obs.SpanKindInternal, "controller.flowWorker.switchProvider")
defer span.End()
if prv == nil {
return nil // no provider to switch to
}
logger := fw.logger.WithFields(logrus.Fields{
"new_provider_name": prv.Name().String(),
"new_provider_type": prv.Type().String(),
})
changed, tcIDTemplate, err := fw.flowCtx.Provider.SetProvider(ctx, prv)
if err != nil {
logger.WithError(err).Error("failed to set provider")
return fmt.Errorf("failed to set provider: %w", err)
}
if !changed {
logger.Debug("provider is the same, skipping switch")
return nil
}
logger.Info("switching flow provider")
// Every persisted value is taken from prv (and the template SetProvider
// resolved for it) rather than re-read from the shared flow provider, so a
// concurrent switch cannot interleave into a mixed-provider row.
flow, err := fw.flowCtx.DB.UpdateFlowProvider(ctx, database.UpdateFlowProviderParams{
ModelProviderName: prv.Name().String(),
ModelProviderType: database.ProviderType(prv.Type()),
ToolCallIDTemplate: tcIDTemplate,
Model: prv.Model(pconfig.OptionsTypePrimaryAgent),
ID: fw.flowCtx.FlowID,View on GitHub (pinned to ea665308ba)
Solutions
- Inspect the wrapped cause in the log line 'failed to set provider' to see which step failed
- Verify the target provider's config (API key, server URL, model) is valid and non-empty in Settings or env vars
- Test the provider with a trivial call before switching a live flow
- Retry the switch after correcting the provider configuration
Example fix
// before: switch fails at runtime with opaque provider
prv, err := providerCtrl.GetProvider(ctx, cfgName)
_ = worker.switchProvider(ctx, prv)
// after: validate provider availability before switching
prv, err := providerCtrl.GetProvider(ctx, cfgName)
if err != nil { return err }
if _, err := prv.Model(pconfig.OptionsTypePrimaryAgent); err != nil {
return fmt.Errorf("provider %s misconfigured: %w", prv.Name(), err)
}
return worker.switchProvider(ctx, prv) Defensive patterns
Strategy: try-catch
Validate before calling
func canSwitch(prv provider.Provider) error {
if prv == nil { return errors.New("provider is nil") }
if _, err := prv.Model(pconfig.OptionsTypePrimaryAgent); err != nil {
return fmt.Errorf("primary model unavailable: %w", err)
}
return nil
} Type guard
func isSwitchable(prv provider.Provider) bool { return prv != nil } Try / catch
changed, tpl, err := fw.flowCtx.Provider.SetProvider(ctx, prv)
if err != nil {
var cfgErr *provider.ConfigError
if errors.As(err, &cfgErr) {
return fmt.Errorf("provider %s misconfigured, keeping current: %w", prv.Name(), err)
}
return fmt.Errorf("failed to set provider: %w", err)
} Prevention
- Validate provider config (API key, URL, model) in Settings before offering it for a live switch
- Test a provider with a minimal call at configuration time
- Never pass a nil provider; switchProvider silently no-ops on nil
- Watch the logrus log line 'failed to set provider' for the wrapped root cause
When it happens
Trigger: A runtime provider switch is requested for a live flow (user changes the model/provider via UI or API) and SetProvider returns an error — typically because the new provider instance fails its initialization/validation, the provider cannot serve the flow's agent options, or an internal consistency check in the provider set fails.
Common situations: User switches to a provider whose API key/server URL is unset or wrong; provider was configured but its endpoint is unreachable; switching to a custom/user provider that shadows a built-in name with an invalid config; environment changed after the flow started so the new provider's config is now invalid.
Related errors
- failed to switch provider: %w
- failed to update flow provider in DB: %w
- failed to perform agent chain for subtask %d: %w
- summarization failed: %w
- failed to get subtask result: %w
AI-assisted analysis of vxcontrol/pentagi@ea665308ba (2026-09-01).
Data as JSON: /api/errors/728283f16b96ee05.
Report an issue: GitHub.