@@ -146,8 +146,8 @@ async def run_generation(self, check_client_disconnected: Callable):
146146 await self .page .keyboard .press ('Escape' )
147147 await asyncio .sleep (0.15 )
148148 run_btn = self .page .locator (SUBMIT_BUTTON_SELECTOR )
149- await expect_async (run_btn ).to_be_visible (timeout = 5000 )
150- await expect_async (run_btn ).to_be_enabled (timeout = 5000 )
149+ await expect_async (run_btn ).to_be_visible (timeout = 10000 )
150+ await expect_async (run_btn ).to_be_enabled (timeout = 10000 )
151151 if not await safe_click (run_btn , 'Run 按钮' , self .req_id ):
152152 if attempt < max_retries :
153153 continue
@@ -160,7 +160,7 @@ async def run_generation(self, check_client_disconnected: Callable):
160160 raise
161161 self .logger .warning (f'[{ self .req_id } ] 点击 Run 失败 (尝试 { attempt } ): { e } ' )
162162 if attempt < max_retries :
163- await asyncio .sleep (0.15 )
163+ await asyncio .sleep (0.5 )
164164 raise Exception ('点击 Run 按钮失败' )
165165
166166 async def wait_for_content (self , check_client_disconnected : Callable , timeout_seconds : int = 120 ) -> GeneratedContent :
@@ -172,6 +172,7 @@ async def wait_for_content(self, check_client_disconnected: Callable, timeout_se
172172 result = GeneratedContent ()
173173 last_chunk_count = 0
174174 stable_count = 0
175+ no_progress_count = 0
175176
176177 while True :
177178 elapsed = asyncio .get_event_loop ().time () - start_time
@@ -183,6 +184,10 @@ async def wait_for_content(self, check_client_disconnected: Callable, timeout_se
183184 await self ._check_disconnect (check_client_disconnected , f'等待内容 ({ int (elapsed )} s)' )
184185
185186 try :
187+ error_detected = await self ._check_for_error ()
188+ if error_detected :
189+ self .logger .error (f'[{ self .req_id } ] ❌ 检测到生成错误: { error_detected } ' )
190+ raise Exception (f'生成失败: { error_detected } ' )
186191 chunk_count = await image_chunk_locator .count ()
187192 self .logger .info (f'[{ self .req_id } ] 检测到图片块数量: { chunk_count } ' )
188193
@@ -225,12 +230,41 @@ async def wait_for_content(self, check_client_disconnected: Callable, timeout_se
225230 else :
226231 stable_count = 0
227232 last_chunk_count = chunk_count
233+ elif not is_generating and chunk_count == 0 and not result .text :
234+ no_progress_count += 1
235+ if no_progress_count >= 40 :
236+ self .logger .warning (f'[{ self .req_id } ] ⚠️ 长时间无进展,可能生成失败' )
237+ raise Exception ('生成无响应,可能失败' )
238+ else :
239+ no_progress_count = 0
228240
229241 except Exception as e :
242+ if 'ClientDisconnected' in str (type (e ).__name__ ):
243+ raise
244+ if '生成失败' in str (e ) or '生成无响应' in str (e ):
245+ raise
230246 self .logger .warning (f'[{ self .req_id } ] 检查内容时出错: { e } ' )
231247
232248 await asyncio .sleep (0.25 )
233249
250+ async def _check_for_error (self ):
251+ error_selectors = [
252+ 'mat-snack-bar-container .mdc-snackbar__label' ,
253+ '.error-toast span.content-text' ,
254+ 'ms-callout[severity="error"] .content-container' ,
255+ '.mat-mdc-snack-bar-label'
256+ ]
257+ for sel in error_selectors :
258+ try :
259+ locator = self .page .locator (sel )
260+ if await locator .count () > 0 and await locator .first .is_visible ():
261+ text = await locator .first .inner_text (timeout = 1000 )
262+ if text and text .strip ():
263+ return text .strip ()
264+ except :
265+ pass
266+ return None
267+
234268 async def _extract_images_via_download (self , count : int ) -> List [GeneratedImage ]:
235269 import tempfile
236270 import os
0 commit comments