Skip to content

Fix crash in vote_last_response when state is None after clear_history#3852

Open
Chessing234 wants to merge 1 commit intolm-sys:mainfrom
Chessing234:fix/vote-last-response-null-state
Open

Fix crash in vote_last_response when state is None after clear_history#3852
Chessing234 wants to merge 1 commit intolm-sys:mainfrom
Chessing234:fix/vote-last-response-null-state

Conversation

@Chessing234
Copy link
Copy Markdown

Bug

vote_last_response in fastchat/serve/gradio_web_server.py unconditionally calls state.dict(), but state can be None. Reported in #3787.

Root cause

clear_history explicitly 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.

`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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No null check on state in vote functions can cause crash

1 participant