From 9710e10acac2f426829776f72d062f99feae7933 Mon Sep 17 00:00:00 2001 From: justsisyphus Date: Mon, 19 Jan 2026 10:19:48 +0900 Subject: [PATCH] fix(background-agent): use queuedAt for pending task TTL --- src/features/background-agent/manager.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/features/background-agent/manager.ts b/src/features/background-agent/manager.ts index 3a3512b7e..b9a2dd728 100644 --- a/src/features/background-agent/manager.ts +++ b/src/features/background-agent/manager.ts @@ -1025,11 +1025,23 @@ Use \`background_output(task_id="${task.id}")\` to retrieve this result when rea const now = Date.now() for (const [taskId, task] of this.tasks.entries()) { - const age = now - task.startedAt.getTime() + const timestamp = task.status === "pending" + ? task.queuedAt?.getTime() + : task.startedAt?.getTime() + + if (!timestamp) { + continue + } + + const age = now - timestamp if (age > TASK_TTL_MS) { - log("[background-agent] Pruning stale task:", { taskId, age: Math.round(age / 1000) + "s" }) + const errorMessage = task.status === "pending" + ? "Task timed out while queued (30 minutes)" + : "Task timed out after 30 minutes" + + log("[background-agent] Pruning stale task:", { taskId, status: task.status, age: Math.round(age / 1000) + "s" }) task.status = "error" - task.error = "Task timed out after 30 minutes" + task.error = errorMessage task.completedAt = new Date() if (task.concurrencyKey) { this.concurrencyManager.release(task.concurrencyKey)