fix(spec): track current_token in ReasonerGrammarObject (#29102)

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
IvanShan177
2026-06-26 16:43:35 -07:00
committed by GitHub
co-authored by Claude Opus 4.8
parent da0f4f6f92
commit 13b5bd962a
2 changed files with 68 additions and 0 deletions
@@ -109,6 +109,14 @@ class ReasonerGrammarObject(BaseGrammarObject):
self.tokens_after_end -= 1
def accept_token(self, token: int):
# Track the last accepted token on the wrapper itself (mirroring
# XGrammarGrammar.accept_token). Disaggregation's process_prebuilt uses
# `grammar.current_token is None` to detect a retracted request whose
# token was already accepted and must not be re-accepted. Without this,
# a ReasonerGrammarObject's current_token stays None forever (the inner
# grammar's is updated, not the wrapper's), so the guard never fires and
# the token is accepted twice -> "Tokens not accepted" -> FINISH_ABORT.
self.current_token = token
if self._is_generation() and self.grammar is not None:
self.grammar.accept_token(token)
self.transfer_state(token)