{"record":{"id":"21f0b061daf90e0a","repo":"coleam00/Archon","slug":"failed-to-clean-up-old-workflow-runs-err-messag","errorCode":null,"errorMessage":"Failed to clean up old workflow runs: ${err.message}","messagePattern":"Failed to clean up old workflow runs: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/src/db/workflows.ts","lineNumber":2111,"sourceCode":"        SELECT id FROM remote_agent_workflow_runs\n        WHERE status IN ('completed', 'failed', 'cancelled')\n          AND started_at < ${cutoff}\n      )`,\n      []\n    );\n    const result = await pool.query(\n      `DELETE FROM remote_agent_workflow_runs\n       WHERE status IN ('completed', 'failed', 'cancelled')\n         AND started_at < ${cutoff}`,\n      []\n    );\n    await pool.query('COMMIT', []);\n    return { count: result.rowCount ?? 0 };\n  } catch (error) {\n    await rollback();\n    const err = error as Error;\n    getLog().error({ err, olderThanDays }, 'db.workflow_runs_cleanup_failed');\n    throw new Error(`Failed to clean up old workflow runs: ${err.message}`);\n  }\n}\n\n/**\n * Delete a workflow run and its associated events.\n * Only terminal runs (completed, failed, cancelled) can be deleted.\n */\nexport async function deleteWorkflowRun(id: string): Promise<void> {\n  try {\n    await pool.query('BEGIN', []);\n    // Guard: verify run exists and is terminal before deleting\n    const check = await pool.query<{ status: string }>(\n      'SELECT status FROM remote_agent_workflow_runs WHERE id = $1',\n      [id]\n    );\n    if (check.rows.length === 0) {\n      throw new WorkflowRunGuardError(`Workflow run not found: ${id}`);\n    }","sourceCodeStart":2093,"sourceCodeEnd":2129,"githubUrl":"https://github.com/coleam00/Archon/blob/0773b9745896ef0612e709c80845a0f7db315b19/packages/core/src/db/workflows.ts#L2093-L2129","documentation":"Error \"Failed to clean up old workflow runs: ${err.message}\" thrown in coleam00/Archon.","triggerScenarios":"Thrown at packages/core/src/db/workflows.ts:2111 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"0773b9745896ef0612e709c80845a0f7db315b19","analyzedAt":"2026-09-01T02:28:07.064Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}