Skip to content

Commit cbb5970

Browse files
fix(desktop): order inbox items by microsecond persistence time
1 parent 5fccf71 commit cbb5970

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

‎apps/sim/lib/desktop/executor/repository.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,11 @@ export async function listDesktopInboxRows(identity: Omit<DesktopDeviceIdentity,
171171
permissionDecision: copilotAsyncToolCalls.permissionDecision,
172172
claimed: sql<boolean>`${copilotAsyncToolCalls.executionOwnerToken} IS NOT NULL`,
173173
createdAt: copilotAsyncToolCalls.createdAt,
174+
// A Date's milliseconds would tie calls written within the same millisecond.
175+
persistedAtMicros:
176+
sql<number>`(extract(epoch from ${copilotAsyncToolCalls.createdAt}) * 1000000)::bigint`.mapWith(
177+
Number
178+
),
174179
chatId: copilotRuns.chatId,
175180
chatTitle: copilotChats.title,
176181
workspaceId: copilotRuns.workspaceId,
@@ -208,8 +213,7 @@ export async function listDesktopInboxRows(identity: Omit<DesktopDeviceIdentity,
208213
),
209214
])
210215
return [...waiting, ...cancelled].sort(
211-
(a, b) =>
212-
a.createdAt.getTime() - b.createdAt.getTime() || a.toolCallId.localeCompare(b.toolCallId)
216+
(a, b) => a.persistedAtMicros - b.persistedAtMicros || a.toolCallId.localeCompare(b.toolCallId)
213217
)
214218
}
215219

0 commit comments

Comments
 (0)