fix: deduplicate re-delivered session sends on the client message id
Typed-3-shown-5 forensics (project 000): the WS client queues session_send payloads while disconnected and flushes the queue after a reconnect, and the server minted a fresh row id per delivery — so one typed message could land as several user turns, each dispatched to the engine. Every send now carries a client-generated ui_message_id (dispatchSessionSend injects one when the caller didn't). The handler persists the user row under that id and answers any later delivery in the same channel with an idempotent ack instead of inserting and dispatching again. Because the row id now equals the optimistic bubble's ui_message_id, the echo also merges with the local message even after the transcript sync rewrites row metadata. Same text intentionally sent again gets a fresh id and still starts a new turn. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -288,6 +288,17 @@ class ChatStore:
|
||||
return None
|
||||
return str(row[0] or ""), str(row[1] or "default")
|
||||
|
||||
async def message_scope(self, message_id: str) -> tuple[str, str] | None:
|
||||
"""(channel_id, project_id) of a persisted message, or None if absent.
|
||||
|
||||
Used for idempotent client sends: a re-delivered ``session_send`` carries
|
||||
the same client-generated ``ui_message_id``, so an existing row in the
|
||||
same scope identifies the duplicate.
|
||||
"""
|
||||
if not str(message_id or "").strip():
|
||||
return None
|
||||
return await self._message_scope(str(message_id).strip())
|
||||
|
||||
async def _allocate_scoped_message_id(
|
||||
self,
|
||||
message_id: str,
|
||||
|
||||
Reference in New Issue
Block a user