fix: apply SSE timeout to HTTP client and fix mutable default argument in llms.py#25
Open
amathxbt wants to merge 2 commits into
Open
fix: apply SSE timeout to HTTP client and fix mutable default argument in llms.py#25amathxbt wants to merge 2 commits into
amathxbt wants to merge 2 commits into
Conversation
Two bugs in llms.py: 1. sse_message_handler accepted a 'timeout' parameter but passed timeout=None to the HTTP client, making it hang indefinitely regardless of the timeout value. Now passes the actual timeout. 2. perform_inference used a mutable list [] as the default value for 'history'. Python creates this list once at function definition time, so mutations across calls can leak state between sessions. Changed default to None and uses 'history or []' at call site.
Two bugs fixed in llms.py: 1. sse_message_handler accepted a timeout parameter but passed timeout=None to httpx, so connections could hang forever regardless of the timeout value. Now correctly passes the timeout argument. 2. perform_inference used history=[] as a default argument. Python creates the list object once at definition time, so state can leak between calls if the list is ever mutated. Changed to None with an "or []" guard at the call site.
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.
Bugs
Two bugs in
demo/nesa/backend/llms.py:Bug 1 — SSE timeout silently ignored
sse_message_handleraccepts atimeoutparameter (default 60s) but passestimeout=Noneto thehttpxclient:Impact: SSE connections to the inference backend can hang indefinitely regardless of the
timeoutargument. This blocks the event loop and can deadlock the server under network failures.Bug 2 — Mutable default argument
perform_inferenceuses a mutable list as a default value:Impact: Python creates this list object once at function-definition time. If any caller mutates
historyin place, the mutation persists across subsequent calls — a classic Python footgun that can cause cross-session state corruption.Fix
timeoutargument to thehttpxstream call.Nonewith anor []guard at the call site.