Fix crash in vote_last_response when state is None after clear_history#3852
Open
Chessing234 wants to merge 1 commit intolm-sys:mainfrom
Open
Fix crash in vote_last_response when state is None after clear_history#3852Chessing234 wants to merge 1 commit intolm-sys:mainfrom
Chessing234 wants to merge 1 commit intolm-sys:mainfrom
Conversation
`clear_history` resets the Gradio state to `None` (see line 339). If a user clicks an upvote / downvote / flag button before the UI finishes updating, the stale button click runs `vote_last_response` with `state=None`, which then hits `state.dict()` and raises `AttributeError: 'NoneType' object has no attribute 'dict'`. Guard the function with an early return when `state` is `None` so the no-op path is safe; the button-disable behaviour from the caller (`upvote_last_response` etc.) is unaffected. Closes lm-sys#3787.
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.
Bug
vote_last_responseinfastchat/serve/gradio_web_server.pyunconditionally callsstate.dict(), butstatecan beNone. Reported in #3787.Root cause
clear_historyexplicitly resets the Gradio state:```python
def clear_history(request: gr.Request):
...
state = None
return (state, [], "") + (disable_btn,) * 5
```
The vote buttons are disabled as part of that return, but the UI update is asynchronous in Gradio. If a user clicks upvote / downvote / flag between `clear_history` firing and the button-disable reaching the browser, the stale event runs `vote_last_response(None, ...)`, hitting `state.dict()` and raising `AttributeError: 'NoneType' object has no attribute 'dict'`.
Fix
Early-return from `vote_last_response` when `state is None`. The callers (`upvote_last_response`, `downvote_last_response`, `flag_last_response`) ignore its return value, so a no-op is safe and they still return the same `disable_btn` tuple as before.
Fixes #3787.