alibaba/open-code-review · error
failed to save models
Error message
failed to save models: %w
What it means
In the custom-provider TUI, after appending a model to a custom provider, saveConfig fails to persist the updated config to disk. The model rolls back the in-memory entry to its previous state (prevEntry); if reloadConfigAfterSaveFailure also cannot restore by re-reading the file, this error propagates. It means the model was added in the UI but the config file could not be written (permissions, disk full, bad path).
Solutions
- Check disk space and file permissions on the config file's directory
- Inspect the wrapped error for the actual write failure (permission denied, disk full, invalid path)
- Retry the save after fixing the filesystem issue; the TUI rolls back the in-memory entry when the save fails
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at cmd/opencodereview/provider_tui.go:843 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of alibaba/open-code-review@5cf97d0d15 (2026-09-02).
Data as JSON: /api/errors/58b5cb44514e5594.
Report an issue: GitHub.
Appendix: source
Thrown at cmd/opencodereview/provider_tui.go:843
return false, nil
}
entry := m.customProviderEntry(cp.name, cp.entry)
prevEntry := cloneProviderEntry(entry)
entry.Models = append(entry.Models, name)
if m.existingCfg.CustomProviders == nil {
m.existingCfg.CustomProviders = make(map[string]ProviderEntry)
}
m.existingCfg.CustomProviders[cp.name] = entry
cp.entry = entry
m.customProviders[m.customIdx] = cp
if m.configPath != "" {
if err := saveConfig(m.configPath, m.existingCfg); err != nil {
if !m.reloadConfigAfterSaveFailure() {
m.existingCfg.CustomProviders[cp.name] = prevEntry
cp.entry = prevEntry
m.customProviders[m.customIdx] = cp
}
return false, fmt.Errorf("failed to save models: %w", err)
}
}
m.savedInSession = true
return true, nil
case tabOfficial:
provider := m.currentProvider()
if provider.Name == "" {
return false, nil
}
if m.existingCfg.Providers == nil {
m.existingCfg.Providers = make(map[string]ProviderEntry)
}
entry := m.existingCfg.Providers[provider.Name]
prevEntry := cloneProviderEntry(entry)
entry.Models = append(entry.Models, name)
m.existingCfg.Providers[provider.Name] = entry
// Intentionally do not mutate m.providers[officialIdx].Models: that slice
// is a read-only snapshot from the provider registry (llm.ListProviders).View on GitHub (pinned to 5cf97d0d15)