Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions apps/sim/lib/desktop/application/executor.integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,27 @@ describe.runIf(Boolean(redisUrl))('desktop background executor protocol', () =>
).toEqual([first, second, vfs])
})

it('lists calls persisted within the same millisecond in persistence order', async () => {
const desktop = await signedInDesktop()
const run = await boundRun(desktop)
/** Ids sorted against persistence order, so an id tiebreak would reverse them. */
const persisted = [generateId(), generateId(), generateId()].sort().reverse()
await db.insert(copilotAsyncToolCalls).values(
persisted.map((toolCallId, index) => ({
runId: run.runId,
toolCallId,
toolName: 'browser_click',
args: { ref: 'e1' },
pickupDeadlineAt: sql`now() + interval '1 minute'`,
createdAt: sql`date_trunc('milliseconds', localtimestamp) + ${index + 1} * interval '1 microsecond'`,
}))
)

expect(
(await inbox(desktop)).items.map((item) => item.kind === 'call' && item.toolCallId)
).toEqual(persisted)
})

it('counts the device online after a pull or a stream open, and keeps it online when the stream closes', async () => {
const desktop = await signedInDesktop()
const presenceKey = `desktop:presence:${desktop.deviceId}`
Expand Down
8 changes: 6 additions & 2 deletions apps/sim/lib/desktop/executor/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ export async function listDesktopInboxRows(identity: Omit<DesktopDeviceIdentity,
permissionDecision: copilotAsyncToolCalls.permissionDecision,
claimed: sql<boolean>`${copilotAsyncToolCalls.executionOwnerToken} IS NOT NULL`,
createdAt: copilotAsyncToolCalls.createdAt,
// A Date's milliseconds would tie calls written within the same millisecond.
persistedAtMicros:
sql<number>`(extract(epoch from ${copilotAsyncToolCalls.createdAt}) * 1000000)::bigint`.mapWith(
Number
),
Comment thread
TheodoreSpeaks marked this conversation as resolved.
chatId: copilotRuns.chatId,
chatTitle: copilotChats.title,
workspaceId: copilotRuns.workspaceId,
Expand Down Expand Up @@ -208,8 +213,7 @@ export async function listDesktopInboxRows(identity: Omit<DesktopDeviceIdentity,
),
])
return [...waiting, ...cancelled].sort(
(a, b) =>
a.createdAt.getTime() - b.createdAt.getTime() || a.toolCallId.localeCompare(b.toolCallId)
(a, b) => a.persistedAtMicros - b.persistedAtMicros || a.toolCallId.localeCompare(b.toolCallId)
)
}

Expand Down
Loading