Fix AssistantTracker.is_active() returning False after activation with empty lists#44524
Merged
Rocketknight1 merged 1 commit intohuggingface:mainfrom Mar 9, 2026
Conversation
After activation, _rendered_blocks and _generation_indices are set to list arguments which may be empty []. The previous truthiness check returned False for empty lists, incorrectly indicating the tracker was inactive. Use `is not None` instead to correctly distinguish between unset (None) and active-but-empty ([]) state. Signed-off-by: JiangNan <1394485448@qq.com>
Rocketknight1
approved these changes
Mar 9, 2026
Member
Rocketknight1
left a comment
There was a problem hiding this comment.
Yes, LGTM! Thanks for the fix.
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a bug in
AssistantTracker.is_active()inchat_template_utils.py.After activation via
activate_tracker(),_rendered_blocksand_generation_indicesare set to list arguments which may be empty[]. Theis_active()method checks truthiness (return self._rendered_blocks or self._generation_indices), which returnsFalsefor empty lists, incorrectly indicating the tracker is inactive.This means calling
activate_trackerwith empty lists, then checkingis_active(), returnsFalseeven though the tracker was activated. This breaks the re-entrance guard inactivate_trackerwhich relies onis_active()to detect double activation.Test plan
_rendered_blocksis initialized asNoneand set to list on activationis_active()is used as re-entrance guard inactivate_tracker