-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix: ensure message stream order #4487
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -296,6 +296,8 @@ async def chat(self): | |
| # 构建用户消息段(包含 path 用于传递给 adapter) | ||
| message_parts = await self._build_user_message_parts(message) | ||
|
|
||
| message_id = str(uuid.uuid4()) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (bug_risk): 直接丢弃 如果 Original comment in Englishissue (bug_risk): Dropping mismatched If |
||
|
|
||
| async def stream(): | ||
| client_disconnected = False | ||
| accumulated_parts = [] | ||
|
|
@@ -319,6 +321,13 @@ async def stream(): | |
| if not result: | ||
| continue | ||
|
|
||
| if ( | ||
| "message_id" in result | ||
| and result["message_id"] != message_id | ||
| ): | ||
| logger.warning("webchat stream message_id mismatch") | ||
| continue | ||
|
|
||
| result_text = result["data"] | ||
| msg_type = result.get("type") | ||
| streaming = result.get("streaming", False) | ||
|
|
@@ -456,6 +465,7 @@ async def stream(): | |
| "selected_provider": selected_provider, | ||
| "selected_model": selected_model, | ||
| "enable_streaming": enable_streaming, | ||
| "message_id": message_id, | ||
| }, | ||
| ), | ||
| ) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): 直接依赖客户端提供的
message_id,可能会引入None/ 无效 ID 以及信任问题。之前这里始终是由服务端生成的 UUID,因此下游代码可以依赖
message_id一定存在、非空且唯一。现在直接使用客户端提供的值,它可能缺失、为None,或者是任意值,这会破坏原有假设并削弱对关联 ID 的信任度。请增加基础校验(存在性 / 类型 / 格式),并在客户端值缺失或无效时回退到服务端生成的 UUID。Original comment in English
issue (bug_risk): Relying directly on client-provided
message_idmay introduceNone/invalid IDs and trust issues.Previously this was always a server-generated UUID, so downstream code could rely on
message_idbeing present, non-empty, and unique. With the client value used directly, it can be missing,None, or arbitrary, which may break that assumption and weakens correlation ID trust. Please add basic validation (presence/type/format) and fall back to a server-generated UUID when the client value is absent or invalid.