@@ -1443,43 +1443,39 @@ async def _run_optimization(
14431443 if self ._options .on_turn is not None :
14441444 try :
14451445 on_turn_result = self ._options .on_turn (optimize_context )
1446- if on_turn_result :
1447- logger .info (
1448- "[Iteration %d] -> on_turn returned True — turn passed" ,
1449- iteration ,
1450- )
1451- return self ._handle_success (optimize_context , iteration )
1452- else :
1453- logger .info (
1454- "[Iteration %d] -> on_turn returned False — turn failed (attempt %d/%d)" ,
1455- iteration ,
1456- iteration ,
1457- self ._options .max_attempts ,
1458- )
1459- if iteration >= self ._options .max_attempts :
1460- return self ._handle_failure (optimize_context , iteration )
1461- self ._history .append (optimize_context )
1462- await self ._generate_new_variation (
1463- iteration , optimize_context .current_variables
1464- )
1465- self ._safe_status_update (
1466- "turn completed" , optimize_context , iteration
1467- )
1468- continue
1469- except Exception as e :
1446+ except Exception :
14701447 logger .exception (
14711448 "[Iteration %d] -> on_turn evaluation failed" , iteration
14721449 )
1473- if iteration >= self ._options .max_attempts :
1474- return self ._handle_failure (optimize_context , iteration )
1475- self ._history .append (optimize_context )
1450+ on_turn_result = False
1451+
1452+ if on_turn_result :
1453+ logger .info (
1454+ "[Iteration %d] -> on_turn returned True — turn passed" ,
1455+ iteration ,
1456+ )
1457+ return self ._handle_success (optimize_context , iteration )
1458+
1459+ logger .info (
1460+ "[Iteration %d] -> on_turn returned False — turn failed (attempt %d/%d)" ,
1461+ iteration ,
1462+ iteration ,
1463+ self ._options .max_attempts ,
1464+ )
1465+ if iteration >= self ._options .max_attempts :
1466+ return self ._handle_failure (optimize_context , iteration )
1467+ self ._history .append (optimize_context )
1468+ try :
14761469 await self ._generate_new_variation (
14771470 iteration , optimize_context .current_variables
14781471 )
1479- self ._safe_status_update (
1480- "turn completed" , optimize_context , iteration
1472+ except Exception :
1473+ logger .exception (
1474+ "[Iteration %d] -> variation generation failed" , iteration
14811475 )
1482- continue
1476+ return self ._handle_failure (optimize_context , iteration )
1477+ self ._safe_status_update ("turn completed" , optimize_context , iteration )
1478+ continue
14831479 else :
14841480 # Auto-path: judge scores determine pass/fail via _evaluate_response
14851481 passes = self ._evaluate_response (optimize_context )
@@ -1499,9 +1495,15 @@ async def _run_optimization(
14991495 if iteration >= self ._options .max_attempts :
15001496 return self ._handle_failure (optimize_context , iteration )
15011497 self ._history .append (optimize_context )
1502- await self ._generate_new_variation (
1503- iteration , optimize_context .current_variables
1504- )
1498+ try :
1499+ await self ._generate_new_variation (
1500+ iteration , optimize_context .current_variables
1501+ )
1502+ except Exception :
1503+ logger .exception (
1504+ "[Iteration %d] -> variation generation failed" , iteration
1505+ )
1506+ return self ._handle_failure (optimize_context , iteration )
15051507 self ._safe_status_update (
15061508 "turn completed" , optimize_context , iteration
15071509 )
0 commit comments