From 3488905ccc4a44fc31fbd5203148871ca8151eb2 Mon Sep 17 00:00:00 2001 From: Kelly Date: Tue, 16 Dec 2025 21:19:20 -0700 Subject: [PATCH] fix: Delete completed tasks from pool instead of marking complete MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Completed tasks are now deleted from worker_tasks table. Only failed tasks remain in the pool for retry/review. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- backend/src/tasks/task-service.ts | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/backend/src/tasks/task-service.ts b/backend/src/tasks/task-service.ts index 0076f9a4..775e0d68 100644 --- a/backend/src/tasks/task-service.ts +++ b/backend/src/tasks/task-service.ts @@ -261,28 +261,24 @@ class TaskService { } /** - * Mark a task as completed with verification - * Returns true if completion was verified in DB, false otherwise + * Mark a task as completed and remove from pool + * Completed tasks are deleted - only failed tasks stay in the pool for retry/review + * Returns true if task was successfully deleted */ async completeTask(taskId: number, result?: Record): Promise { - await pool.query( - `UPDATE worker_tasks - SET status = 'completed', completed_at = NOW(), result = $2, error_message = NULL - WHERE id = $1`, - [taskId, result ? JSON.stringify(result) : null] - ); - - // Verify completion was recorded - const verify = await pool.query( - `SELECT status FROM worker_tasks WHERE id = $1`, + // Delete the completed task from the pool + // Only failed tasks stay in the table for retry/review + const deleteResult = await pool.query( + `DELETE FROM worker_tasks WHERE id = $1 RETURNING id`, [taskId] ); - if (verify.rows[0]?.status !== 'completed') { - console.error(`[TaskService] Task ${taskId} completion NOT VERIFIED - DB shows status: ${verify.rows[0]?.status}`); + if (deleteResult.rowCount === 0) { + console.error(`[TaskService] Task ${taskId} completion FAILED - task not found or already deleted`); return false; } + console.log(`[TaskService] Task ${taskId} completed and removed from pool`); return true; }