Skip to content

Commit 25a4c22

Browse files
committed
fix(knowledge): withdraw only the exact dormant queue stamp
1 parent ccce52b commit 25a4c22

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

‎apps/sim/lib/knowledge/__integration__/dormant-search-processing.integration.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ describe('dormant Search document processing', () => {
133133
expect(stored).toEqual({ status: 'pending', token, queuedAt: null, attempts: 1 })
134134
})
135135

136-
it('leaves a newer queued generation untouched', async () => {
136+
it('leaves a newer queued generation untouched, even under a reused token', async () => {
137137
const queuedAt = new Date('2026-09-29T01:00:00.000Z')
138138
const newer = generateId()
139139
await db
@@ -144,6 +144,11 @@ describe('dormant Search document processing', () => {
144144
chargedAtDispatch: true,
145145
processingQueueToken: generateId(),
146146
})
147+
await processDocumentAsync(ids.knowledgeBaseId, documentId, source, {}, undefined, 'pass', {
148+
chargedAtDispatch: true,
149+
processingQueueToken: newer,
150+
processingQueuedAt: new Date('2026-09-29T00:30:00.000Z'),
151+
})
147152
const [stored] = await db
148153
.select({
149154
token: document.processingQueueToken,

‎apps/sim/lib/knowledge/documents/service.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,8 +1690,13 @@ export async function processDocumentAsync(
16901690
and(
16911691
eq(document.id, documentId),
16921692
eq(document.processingStatus, 'pending'),
1693-
/** A duplicate of an already-withdrawn generation must not refund again. */
1694-
isNotNull(document.processingQueuedAt),
1693+
/**
1694+
* Only the exact stamp this payload was queued with: a duplicate of an already
1695+
* withdrawn generation, or a newer stamp under a reused token, is left alone.
1696+
*/
1697+
attemptContext.processingQueuedAt
1698+
? eq(document.processingQueuedAt, attemptContext.processingQueuedAt)
1699+
: isNotNull(document.processingQueuedAt),
16951700
...queueGenerationConditions(attemptContext)
16961701
)
16971702
)

0 commit comments

Comments
 (0)