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; }