diff --git a/src/auto-reply/reply/queue/drain.ts b/src/auto-reply/reply/queue/drain.ts index cabba31273b..e6cfeee2de7 100644 --- a/src/auto-reply/reply/queue/drain.ts +++ b/src/auto-reply/reply/queue/drain.ts @@ -9,6 +9,7 @@ import { drainCollectQueueStep, drainNextQueueItem, hasCrossChannelItems, + removeQueuedItemsByRef, previewQueueSummaryPrompt, waitForQueueDebounce, } from "../../../utils/queue-helpers.js"; @@ -497,7 +498,7 @@ export function scheduleFollowupDrain( } else { await drainGroup(); } - queue.items.splice(0, groupItems.length); + removeQueuedItemsByRef(queue.items, groupItems); if (pendingSummary) { clearFollowupQueueSummaryState(queue); pendingSummary = undefined; diff --git a/src/utils/queue-helpers.ts b/src/utils/queue-helpers.ts index 89b9f2c7c7a..b1933d8b927 100644 --- a/src/utils/queue-helpers.ts +++ b/src/utils/queue-helpers.ts @@ -166,6 +166,15 @@ export function beginQueueDrain( return queue; } +export function removeQueuedItemsByRef(items: T[], processed: readonly T[]): void { + for (const item of processed) { + const idx = items.indexOf(item); + if (idx !== -1) { + items.splice(idx, 1); + } + } +} + /** Run and remove the next queued item, returning false when empty. */ export async function drainNextQueueItem( items: T[], @@ -176,7 +185,7 @@ export async function drainNextQueueItem( return false; } await run(next); - items.shift(); + removeQueuedItemsByRef(items, [next]); return true; }