From 54f448583cee559e3d1a741a05379f6ae4c39b30 Mon Sep 17 00:00:00 2001 From: justsisyphus Date: Sun, 18 Jan 2026 14:36:06 +0900 Subject: [PATCH] feat(background-agent): implement per-key queue processor --- src/features/background-agent/manager.ts | 31 +++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/features/background-agent/manager.ts b/src/features/background-agent/manager.ts index d008d7ff..ea1e4992 100644 --- a/src/features/background-agent/manager.ts +++ b/src/features/background-agent/manager.ts @@ -130,7 +130,36 @@ export class BackgroundManager { } private async processKey(key: string): Promise { - // TODO: Implement in Task 4 + if (this.processingKeys.has(key)) { + return + } + + this.processingKeys.add(key) + + try { + const queue = this.queuesByKey.get(key) + while (queue && queue.length > 0) { + const item = queue[0] + + await this.concurrencyManager.acquire(key) + + if (item.task.status === "cancelled") { + this.concurrencyManager.release(key) + queue.shift() + continue + } + + try { + await this.startTask(item) + } catch (error) { + log("[background-agent] Error starting task:", error) + } + + queue.shift() + } + } finally { + this.processingKeys.delete(key) + } } private async startTask(item: QueueItem): Promise {