fix: stabilize DeepSeek streaming output#461
Open
avir4er wants to merge 4 commits into
Open
Conversation
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
This patch stabilizes DeepSeek/LiteLLM streaming in CAI by:
litellm.acompletion()calls whenstream=Truepanelreasoning_contentdisplay opt-in viaCAI_SHOW_REASONING=true(or legacyCAI_SHOW_THINKING=true) to prevent token-by-token terminal floodingCAI_MODEL_TIMEOUT(default180seconds,CAI_LLM_TIMEOUTaccepted as an alias;<=0disables CAI's injected timeout)Server disconnected/ LiteLLMInternalServerErrorlitellm.acompletion()call sites through the shared timeout wrapper, except an existing REPL recovery helper that already usesasyncio.wait_forLLMProviderUnavailableerrors so headless mode shows the existing concise provider-load message instead of a full traceback unlessCAI_DEBUG=2Why
During interactive Web App Pentester usage with
deepseek/deepseek-v4-pro, long tasks could remain stuck "in flight", flood the terminal with token-by-token DeepSeek reasoning, or print a long traceback when DeepSeek/LiteLLM disconnected while opening a stream.Four issues contributed:
InternalServerError: DeepseekException - Server disconnected.DeepSeek reasoning deltas were also printed by default, while the Rich thinking context path hit
name 'panel' is not defined.Tests
Result:
15 passedfor the targeted pytest slice.Additional audit:
rg -n "litellm\.acompletion" src/cai testsRuntime direct call sites now go through the shared timeout wrapper; the remaining runtime exception-recovery call already has an explicit
asyncio.wait_for, and the remaining direct references are tests.