fix: eagerly validate conversation before generator to prevent hanging#37224
Open
functionkiller wants to merge 1 commit into
Open
fix: eagerly validate conversation before generator to prevent hanging#37224functionkiller wants to merge 1 commit into
functionkiller wants to merge 1 commit into
Conversation
When a non-existing conversation_id is provided, the error was raised inside a generator function, making it impossible for the outer try/except to catch. This caused the request to hang with only ping events. Add pre-validation before the generator is created so that ConversationNotExistsError is raised eagerly and properly caught. fixes langgenius#37197
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
When a non-existing
conversation_idis provided to the chat-messages API, the error was raised inside a generator function, making it impossible for the outertry/exceptto catch. This caused the request to hang with only ping events instead of returning a proper 4xx error.Root Cause
The
ConversationNotExistsErroris raised inside thegenerate()generator method of the app generator. Since Python generators execute lazily, the exception happens during iteration (inside Flask's SSE stream processing), not during the function call. Thetry/exceptin the controller can't catch it.Fix
Add eager pre-validation of the conversation before calling
AppGenerateService.generate()in three completion endpoints:controllers/web/completion.py— Web app chat-messages endpointcontrollers/service_api/app/completion.py— Service API completion endpointcontrollers/console/app/completion.py— Console (debugger) completion endpointThe pre-validation calls
ConversationService.get_conversation()which raisesConversationNotExistsErrorimmediately, outside the generator context, so it's properly caught and returns 404.Test plan
conversation_idnow returns 404 immediately instead of hangingconversation_idworks unchangedconversation_idprovided works unchangedFixes #37197