fix: eagerly validate conversation on service-api and explore chat endpoints#38801
Merged
fatelei merged 2 commits intoJul 12, 2026
Conversation
…dpoints langgenius#37224 fixed the hang on the web chat-messages endpoint by validating the conversation before AppGenerateService.generate(), but the merged change only touched controllers/web/completion.py. The same non-existing conversation_id still hangs on the Service API and Explore chat endpoints: both pass a user-supplied conversation_id straight into the streaming generator, where ConversationNotExistsError is raised lazily and can no longer be turned into a clean 4xx by the surrounding try/except. Add the same eager ConversationService.get_conversation() pre-check before generate() on both endpoints so an invalid id fails fast as 404. The lookup mirrors the one the generate pipeline already runs at entry (core/app/apps/chat/app_generator.py), so valid conversations are unaffected. issue: langgenius#37197 From Claude Code Signed-off-by: Yufeng He <40085740+he-yufeng@users.noreply.github.com>
Contributor
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-07-12 12:46:04.422424881 +0000
+++ /tmp/pyrefly_pr.txt 2026-07-12 12:45:54.078256717 +0000
@@ -2253,7 +2253,7 @@
ERROR `None` is not subscriptable [unsupported-operation]
--> tests/unit_tests/controllers/service_api/app/test_audio.py:186:16
ERROR Argument `list[dict[str, Any]] | None` is not assignable to parameter `obj` with type `Sized` in function `len` [bad-argument-type]
- --> tests/unit_tests/controllers/service_api/app/test_completion.py:154:20
+ --> tests/unit_tests/controllers/service_api/app/test_completion.py:155:20
ERROR Argument value `Literal[0]` violates Pydantic `ge` constraint `Literal[1]` for field `limit` [bad-argument-type]
--> tests/unit_tests/controllers/service_api/app/test_conversation.py:82:35
ERROR Argument value `Literal[101]` violates Pydantic `le` constraint `Literal[100]` for field `limit` [bad-argument-type]
|
Contributor
Pyrefly Type Coverage
|
fatelei
approved these changes
Jul 12, 2026
BlueSkyXN
added a commit
to BlueSkyXN/dify
that referenced
this pull request
Jul 12, 2026
* fix(web): improve marketplace install dialog accessibility (langgenius#38798) * refactor(web): normalize z-index layering (langgenius#38796) * fix(web): correct knowledge dialog draft state (langgenius#38794) * fix(agent-v2): restore keyboard access to row actions (langgenius#38792) * fix(web): split model selection and settings actions (langgenius#38797) Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> * fix: eagerly validate conversation on service-api and explore chat endpoints (langgenius#38801) Signed-off-by: Yufeng He <40085740+he-yufeng@users.noreply.github.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --------- Signed-off-by: Yufeng He <40085740+he-yufeng@users.noreply.github.com> Co-authored-by: yyh <92089059+lyzno1@users.noreply.github.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Yufeng He <40085740+he-yufeng@users.noreply.github.com>
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
Follow-up to #37224, which fixed the "hang on non-existing conversation_id" bug (#37197) on the web chat-messages endpoint. The merged commit (
31a50a3b20) only changedcontrollers/web/completion.py, although its description also listed the Service API and console endpoints. As a result the same hang still reproduces on two other chat entry points:controllers/service_api/app/completion.py→ChatApicontrollers/console/explore/completion.py→ChatApiBoth pass a user-supplied
conversation_idstraight into the streaming generator, whereConversationNotExistsErroris raised lazily — after the controller'stry/excepthas already returned the SSE response — so an invalid id hangs on ping events instead of returning404.This adds the same eager
ConversationService.get_conversation()pre-check beforeAppGenerateService.generate()on both endpoints. The lookup is identical to the one the generate pipeline already runs at entry (core/app/apps/chat/app_generator.py— sameapp_model/user/session=db.session()arguments), so valid conversations are unaffected; it only moves the existing check earlier so the error surfaces synchronously and is mapped to404.controllers/console/app/completion.py(the debuggerChatMessageApi) was also named in #37224 but routes through_create_chat_message, which already validates the id for AGENT apps and uses a different error-mapping path; it's left as a separate follow-up (tracked in #38800) to keep this change focused and low-risk.Fixes #38800
Screenshots
N/A — backend error-handling change (an invalid
conversation_idnow returns404instead of hanging on SSE ping events).Test plan
test_invalid_conversation_id_fails_fast_as_not_foundto both endpoints' unit tests: an invalidconversation_idreturns404, andAppGenerateService.generateis never reached (assert_not_called).if payload.conversation_id:, so the no-id and valid-id paths are unchanged.ruff checkclean; both controller test suites pass (74 passed). I did not run the fullmake type-checklocally; CI will cover it.Checklist
make lint && make type-check(backend) andcd web && pnpm exec vp staged(frontend) to appease the lint godsFrom Claude Code