mirror of
https://github.com/n8n-io/n8n.git
synced 2026-10-17 21:49:36 +02:00
fix(core): order agent sessions by turn start
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
bbcd70bad8
commit
e5ac59adec
|
|
@ -166,7 +166,7 @@ export class AgentExecutionThreadRepository extends Repository<AgentExecutionThr
|
|||
.where('latestExecution.threadId = thread.id')
|
||||
// A queued turn has not started; the thread's status is its last run.
|
||||
.andWhere("latestExecution.status != 'queued'")
|
||||
.orderBy('latestExecution.createdAt', 'DESC')
|
||||
.orderBy('COALESCE(latestExecution.startedAt, latestExecution.createdAt)', 'DESC')
|
||||
.addOrderBy('latestExecution.id', 'DESC')
|
||||
.limit(1)
|
||||
.getQuery()
|
||||
|
|
|
|||
|
|
@ -329,7 +329,7 @@ export class AgentExecutionRepository extends BaseRepository<AgentExecution> {
|
|||
.andWhere(
|
||||
`e.id = (SELECT e2.id FROM ${tableName} e2 ` +
|
||||
'WHERE e2."threadId" = e."threadId" AND e2."status" != \'queued\' ' +
|
||||
'ORDER BY e2."createdAt" DESC, e2.id DESC LIMIT 1)',
|
||||
'ORDER BY COALESCE(e2."startedAt", e2."createdAt") DESC, e2.id DESC LIMIT 1)',
|
||||
)
|
||||
.getRawMany<{ threadId: string; status: Exclude<AgentExecutionStatus, 'queued'> }>();
|
||||
|
||||
|
|
|
|||
|
|
@ -344,6 +344,14 @@ describe('AgentExecutionRepository', () => {
|
|||
status: 'running',
|
||||
failureSummary: null,
|
||||
createdAt: new Date('2026-01-02T00:00:00Z'),
|
||||
startedAt: new Date('2026-01-04T00:00:00Z'),
|
||||
});
|
||||
await createExecution({
|
||||
threadId: running.id,
|
||||
status: 'success',
|
||||
failureSummary: null,
|
||||
createdAt: new Date('2026-01-03T00:00:00Z'),
|
||||
startedAt: new Date('2026-01-03T00:00:00Z'),
|
||||
});
|
||||
await createExecution({
|
||||
threadId: succeeded.id,
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user