{"record":{"id":"4f43240003ffebea","repo":"coleam00/Archon","slug":"cannot-delete-workflow-run-in-check-rows-0-sta","errorCode":null,"errorMessage":"Cannot delete workflow run in '${check.rows[0].status}' status — cancel it first","messagePattern":"Cannot delete workflow run in '(.+?)' status — cancel it first","errorType":"validation","errorClass":"WorkflowRunGuardError","httpStatus":null,"severity":"error","filePath":"packages/core/src/db/workflows.ts","lineNumber":2131,"sourceCode":"}\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    }\n    if (!TERMINAL_WORKFLOW_STATUSES.includes(check.rows[0].status as WorkflowRunStatus)) {\n      throw new WorkflowRunGuardError(\n        `Cannot delete workflow run in '${check.rows[0].status}' status — cancel it first`\n      );\n    }\n    await pool.query('DELETE FROM remote_agent_workflow_events WHERE workflow_run_id = $1', [id]);\n    await pool.query('DELETE FROM remote_agent_workflow_runs WHERE id = $1', [id]);\n    await pool.query('COMMIT', []);\n  } catch (error) {\n    await rollback();\n    if (error instanceof WorkflowRunGuardError) throw error;\n    const err = error as Error;\n    getLog().error({ err, workflowRunId: id }, 'db.workflow_run_delete_failed');\n    throw new Error(`Failed to delete workflow run: ${err.message}`);\n  }\n}\n","sourceCodeStart":2113,"sourceCodeEnd":2146,"githubUrl":"https://github.com/coleam00/Archon/blob/0773b9745896ef0612e709c80845a0f7db315b19/packages/core/src/db/workflows.ts#L2113-L2146","documentation":"Error \"Cannot delete workflow run in '${check.rows[0].status}' status — cancel it first\" thrown in coleam00/Archon.","triggerScenarios":"Thrown at packages/core/src/db/workflows.ts:2131 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"}