@@ -41,6 +41,54 @@ export class OptionsComponent implements OnInit {
4141 "novaMobianXL_v10" : "Illustrious" ,
4242 "novaFurryXL_ilV140" : "Illustrious"
4343 }
44+
45+ private readonly defaultModelId : string = "novaMobianXL_v10" ;
46+
47+ private getAvailableModelIds ( ) : string [ ] {
48+ return Object . keys ( this . models_types || { } ) ;
49+ }
50+
51+ private getDefaultModelId ( ) : string {
52+ const available = this . getAvailableModelIds ( ) ;
53+ if ( available . includes ( this . defaultModelId ) ) return this . defaultModelId ;
54+ return available [ 0 ] || this . defaultModelId ;
55+ }
56+
57+ private normalizeModelId ( model : unknown ) : string {
58+ const raw = ( typeof model === 'string' ? model : '' ) . trim ( ) ;
59+ if ( ! raw ) return this . getDefaultModelId ( ) ;
60+
61+ const available = this . getAvailableModelIds ( ) ;
62+ if ( available . includes ( raw ) ) return raw ;
63+
64+ // Case-insensitive fallback (helps if casing changed).
65+ const lowerMap = new Map ( available . map ( m => [ m . toLowerCase ( ) , m ] as const ) ) ;
66+ const mapped = lowerMap . get ( raw . toLowerCase ( ) ) ;
67+ return mapped || this . getDefaultModelId ( ) ;
68+ }
69+
70+ private applyModelDefaultsIfChanged ( prevModel : string | undefined , nextModel : string ) : void {
71+ if ( prevModel === nextModel ) return ;
72+
73+ // Keep existing behavior: default CFG depends on model family.
74+ if ( nextModel == "autismMix" || nextModel == "novaFurryXL_ilV140" || nextModel == "novaMobianXL_v10" ) {
75+ this . generationRequest . guidance_scale = 4 ;
76+ } else {
77+ this . generationRequest . guidance_scale = 7 ;
78+ }
79+ }
80+
81+ private ensureValidModelSelected ( persist : boolean = true ) : void {
82+ const previous = this . generationRequest ?. model ;
83+ const normalized = this . normalizeModelId ( previous ) ;
84+ this . generationRequest . model = normalized ;
85+ this . applyModelDefaultsIfChanged ( previous , normalized ) ;
86+
87+ // Keep aspect ratio config in sync with the selected model.
88+ if ( this . aspectRatio ) this . aspectRatio . model = normalized ;
89+
90+ if ( persist ) localStorage . setItem ( 'model' , normalized ) ;
91+ }
4492 enableGenerationButton : boolean = true ;
4593 showLoading : boolean = false ;
4694 showStrength : boolean = false ;
@@ -472,6 +520,10 @@ export class OptionsComponent implements OnInit {
472520 // Handle the error appropriately
473521 }
474522
523+ // If model names change between deployments, users may have an invalid saved model.
524+ // Coerce to a valid model so generation requests never send an empty/unknown model.
525+ this . ensureValidModelSelected ( true ) ;
526+
475527 this . sharedService . setGenerationRequest ( this . generationRequest ) ;
476528 this . updateSharedPrompt ( ) ;
477529
@@ -526,6 +578,11 @@ export class OptionsComponent implements OnInit {
526578 this . queueType = pending . request . queue_type ;
527579 }
528580 }
581+
582+ // Pending job restore can also carry stale/invalid model values.
583+ this . ensureValidModelSelected ( true ) ;
584+ this . sharedService . setGenerationRequest ( this . generationRequest ) ;
585+
529586 this . getJob ( pending . job_id ) ;
530587 }
531588 }
@@ -772,6 +829,9 @@ export class OptionsComponent implements OnInit {
772829 if ( localStorage . getItem ( "model" ) != null ) {
773830 this . generationRequest . model = localStorage . getItem ( "model" ) ! ;
774831 }
832+
833+ // Ensure model is valid before downstream logic uses it.
834+ this . ensureValidModelSelected ( false ) ;
775835 if ( localStorage . getItem ( "lossy-images" ) != null ) {
776836 console . log ( "Loading lossy images setting" ) ;
777837 console . log ( "Value from localStorage:" , localStorage . getItem ( "lossy-images" ) ) ;
0 commit comments