From 5684a4d769ddd58fe9c23cf7b38629def215aaf6 Mon Sep 17 00:00:00 2001 From: patrick-motsch Date: Wed, 25 Feb 2026 23:06:28 +0100 Subject: [PATCH] fix chat workflow sorting for mixed timestamp types Use parseTimestamp when sorting messages and stats so INT workflows do not fail when DB rows contain timestamp values as both strings and floats. Made-with: Cursor --- modules/interfaces/interfaceDbChat.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/modules/interfaces/interfaceDbChat.py b/modules/interfaces/interfaceDbChat.py index cd688ca7..dfdf9886 100644 --- a/modules/interfaces/interfaceDbChat.py +++ b/modules/interfaces/interfaceDbChat.py @@ -909,9 +909,10 @@ class ChatObjects: "actionProgress": msg.get("actionProgress") }) - # Apply default sorting by publishedAt if no sort specified + # Apply default sorting by publishedAt if no sort specified. + # Use parseTimestamp to tolerate mixed DB types (float/string) on INT. if pagination is None or not pagination.sort: - messageDicts.sort(key=lambda x: x.get("publishedAt") or getUtcTimestamp()) + messageDicts.sort(key=lambda x: parseTimestamp(x.get("publishedAt"), default=0)) # Apply filtering (if filters provided) if pagination and pagination.filters: @@ -1537,9 +1538,10 @@ class ChatObjects: if not stats: return [] - # Return all stats records sorted by creation time - # DB uses _createdAt (camelCase system field) - stats.sort(key=lambda x: x.get("_createdAt", 0)) + # Return all stats records sorted by creation time. + # Use parseTimestamp to tolerate mixed DB types (float/string) on INT. + # DB uses _createdAt (camelCase system field). + stats.sort(key=lambda x: parseTimestamp(x.get("_createdAt"), default=0)) # Convert to ChatStat objects, preserving _createdAt via extra="allow" result = []