Skip to content

fix: eagerly validate conversation before generator to prevent hanging#37224

Open
functionkiller wants to merge 1 commit into
langgenius:mainfrom
functionkiller:fix/chatflow-hang-invalid-conversation
Open

fix: eagerly validate conversation before generator to prevent hanging#37224
functionkiller wants to merge 1 commit into
langgenius:mainfrom
functionkiller:fix/chatflow-hang-invalid-conversation

Conversation

@functionkiller

Copy link
Copy Markdown

Summary

When a non-existing conversation_id is provided to the chat-messages API, 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 instead of returning a proper 4xx error.

Root Cause

The ConversationNotExistsError is raised inside the generate() 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. The try/except in 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 endpoint
  • controllers/service_api/app/completion.py — Service API completion endpoint
  • controllers/console/app/completion.py — Console (debugger) completion endpoint

The pre-validation calls ConversationService.get_conversation() which raises ConversationNotExistsError immediately, outside the generator context, so it's properly caught and returns 404.

Test plan

  • Invalid conversation_id now returns 404 immediately instead of hanging
  • Valid conversation_id works unchanged
  • No conversation_id provided works unchanged

Fixes #37197

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
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Jun 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Chatflow hangs on non-existing conversation id

1 participant