Skip to content

Commit d1975b7

Browse files
authored
fix: add deterministic ordering to chat_ids pagination query to prevent duplicates (open-webui#22383)
1 parent 459a60a commit d1975b7

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

backend/open_webui/models/chat_messages.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,13 @@ def get_chat_ids_by_model_id(
292292
query = query.filter(ChatMessage.created_at <= end_date)
293293

294294
# Group by chat_id and order by most recent message in each chat
295+
# Secondary sort on chat_id ensures deterministic pagination
296+
# (prevents duplicates across pages when timestamps tie)
295297
chat_ids = (
296298
query.group_by(ChatMessage.chat_id)
297-
.order_by(func.max(ChatMessage.created_at).desc())
299+
.order_by(
300+
func.max(ChatMessage.created_at).desc(), ChatMessage.chat_id
301+
)
298302
.offset(skip)
299303
.limit(limit)
300304
.all()

0 commit comments

Comments
 (0)