File tree 1 file changed +17
-4
lines changed
1 file changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -655,13 +655,26 @@ def update_from_output(
655
655
if new_token_ids and request .use_structured_output :
656
656
advance_fsm = False
657
657
reasoner = self .structured_output_manager .reasoner
658
+ is_reasoning_end_this_step = False # Flag the transition
659
+
658
660
if reasoner is None or request .reasoning_ended :
661
+ # Reasoning was already off or never active
659
662
advance_fsm = True
660
- elif reasoner .is_reasoning_end (request .all_token_ids ):
661
- request .reasoning_ended = True
662
- advance_fsm = True
663
+ else :
664
+ # Reasoning is active, check if it ends now
665
+ if reasoner .is_reasoning_end (request .all_token_ids ):
666
+ request .reasoning_ended = True
667
+ is_reasoning_end_this_step = True
668
+ # Don't advance FSM in the step the transition occurs,
669
+ # as new_token_ids might contain the end marker.
670
+ advance_fsm = False
671
+ else :
672
+ # Reasoning continues, don't advance FSM
673
+ advance_fsm = False
663
674
664
- if advance_fsm :
675
+ # Only advance FSM if reasoning was already off OR
676
+ # if we are not in the specific step where reasoning just ended.
677
+ if advance_fsm and not is_reasoning_end_this_step :
665
678
# NOTE: structured_output_request
666
679
# should not be None if use_structured_output, we have
667
680
# check above, so safe to ignore type warning
You can’t perform that action at this time.
0 commit comments