From d12c6d7814f6aea2bb5ccfc4777ca87d076d4d37 Mon Sep 17 00:00:00 2001 From: Benjamin Lu Date: Wed, 21 Jan 2026 15:13:27 -0800 Subject: [PATCH] fix: sort queue jobs by create time (#8225) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sort queue overlay ordering by create_time instead of priority so queued jobs keep their order when completions arrive. ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-8225-fix-sort-queue-jobs-by-create-time-2ef6d73d3650815a8a81ec9d0b23a4e6) by [Unito](https://www.unito.io) --- src/composables/queue/useJobList.test.ts | 28 +++++++++++++++++++----- src/composables/queue/useJobList.ts | 7 +++++- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/composables/queue/useJobList.test.ts b/src/composables/queue/useJobList.test.ts index a2a061f78..0aaaa892c 100644 --- a/src/composables/queue/useJobList.test.ts +++ b/src/composables/queue/useJobList.test.ts @@ -305,24 +305,40 @@ describe('useJobList', () => { expect(vi.getTimerCount()).toBe(0) }) - it('sorts all tasks by priority descending', async () => { + it('sorts all tasks by create time', async () => { queueStoreMock.pendingTasks = [ - createTask({ promptId: 'p', queueIndex: 1, mockState: 'pending' }) + createTask({ + promptId: 'p', + queueIndex: 1, + mockState: 'pending', + createTime: 3000 + }) ] queueStoreMock.runningTasks = [ - createTask({ promptId: 'r', queueIndex: 5, mockState: 'running' }) + createTask({ + promptId: 'r', + queueIndex: 5, + mockState: 'running', + createTime: 2000 + }) ] queueStoreMock.historyTasks = [ - createTask({ promptId: 'h', queueIndex: 3, mockState: 'completed' }) + createTask({ + promptId: 'h', + queueIndex: 3, + mockState: 'completed', + createTime: 1000, + executionEndTimestamp: 5000 + }) ] const { allTasksSorted } = initComposable() await flush() expect(allTasksSorted.value.map((task) => task.promptId)).toEqual([ + 'p', 'r', - 'h', - 'p' + 'h' ]) }) diff --git a/src/composables/queue/useJobList.ts b/src/composables/queue/useJobList.ts index b745a7103..aa37d99e0 100644 --- a/src/composables/queue/useJobList.ts +++ b/src/composables/queue/useJobList.ts @@ -197,13 +197,18 @@ export function useJobList() { const selectedWorkflowFilter = ref<'all' | 'current'>('all') const selectedSortMode = ref('mostRecent') + const mostRecentTimestamp = (task: TaskItemImpl) => task.createTime ?? 0 + const allTasksSorted = computed(() => { const all = [ ...queueStore.pendingTasks, ...queueStore.runningTasks, ...queueStore.historyTasks ] - return all.sort((a, b) => b.queueIndex - a.queueIndex) + return all.sort((a, b) => { + const delta = mostRecentTimestamp(b) - mostRecentTimestamp(a) + return delta === 0 ? 0 : delta + }) }) const tasksWithJobState = computed(() =>