plandex-ai/plandex · error
Failed to import custom models/providers/model packs:
Error message
Failed to import custom models/providers/model packs:
What it means
Thrown at models.go:332 when the db.WithTx transaction that upserts/deletes custom models, providers, and model packs fails or the context is canceled. The transaction wraps UpsertCustomModel, UpsertCustomProvider, UpsertModelPack, DeleteCustomModels, DeleteCustomProviders, and DeleteModelPacks; any error rolls back all changes. The client sees a 500 with the wrapped DB error appended.
Source
Thrown at app/server/handlers/models.go:332
if len(toDeleteCustomProviderIds) > 0 {
if err := db.DeleteCustomProviders(tx, auth.OrgId, toDeleteCustomProviderIds); err != nil {
return fmt.Errorf("error deleting custom providers: %w", err)
}
}
if len(toDeleteModelPackIds) > 0 {
if err := db.DeleteModelPacks(tx, auth.OrgId, toDeleteModelPackIds); err != nil {
return fmt.Errorf("error deleting model packs: %w", err)
}
}
return nil
})
if err != nil {
log.Printf("Error: %v\n", err)
http.Error(w, "Failed to import custom models/providers/model packs: "+err.Error(), http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusOK)
log.Println("Successfully imported custom models/providers/model packs")
}
func GetCustomModelHandler(w http.ResponseWriter, r *http.Request) {
log.Println("Received request for GetCustomModelHandler")
auth := Authenticate(w, r, true)
if auth == nil {
return
}
id := mux.Vars(r)["modelId"]
View on GitHub (pinned to e2d772072e)
Solutions
- Read the server log 'Error: ...' line for the wrapped root cause (constraint, FK, connection)
- Check for unique-constraint or foreign-key conflicts implied by the message and fix the payload ordering (create referenced providers/models before packs)
- Retry the request; ensure the client does not abort mid-request
- Check DB health, locks, and statement timeouts if imports are large
Defensive patterns
Strategy: retry
Try / catch
// 500 during tx — retry whole upsert with backoff; tx rollback means no partial state
if resp.StatusCode == 500 && strings.Contains(bodyText, "Failed to import custom models/providers/model packs") {
return backoffRetry(func() error { return upsert(input) }, 3)
} Prevention
- Serialize upserts per org to avoid concurrent constraint conflicts
- Keep the HTTP client alive for the full request duration (long timeouts)
- Ensure referenced providers/models are imported before packs to satisfy FKs
- Monitor DB locks and statement timeouts during large imports
When it happens
Trigger: POST to the upsert custom models endpoint passes all validation, but the transaction fails: unique constraint violation (duplicate model id/name inserted concurrently), FK violation (deleting a provider still referenced), DB connection lost mid-transaction, or r.Context() canceled (client disconnected / timeout).
Common situations: Concurrent upserts from two clients causing constraint conflicts; deleting a provider while another custom model still references it in the DB; long transactions hitting statement timeouts; client closing the connection while the import runs.
Related errors
- Error creating branch:
- Error inviting user:
- Error updating default settings
- Error deleting org user: {err.Error()}
- error creating invite: %v
AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05).
Data as JSON: /api/errors/2c470a8d170a323b.
Report an issue: GitHub.