{"record":{"id":"53c0de3bc135f72f","repo":"coleam00/Archon","slug":"failed-to-get-workflow-run-status-err-message","errorCode":null,"errorMessage":"Failed to get workflow run status: ${err.message}","messagePattern":"Failed to get workflow run status: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/src/db/workflows.ts","lineNumber":522,"sourceCode":"    return result.rows.map(normalizeWorkflowRun);\n  } catch (error) {\n    const err = error as Error;\n    getLog().error({ err }, 'db.workflow_run_find_by_prefix_failed');\n    throw new Error(`Failed to find workflow runs by id prefix: ${err.message}`);\n  }\n}\n\nexport async function getWorkflowRunStatus(id: string): Promise<string | null> {\n  try {\n    const result = await pool.query<{ status: string }>(\n      'SELECT status FROM remote_agent_workflow_runs WHERE id = $1',\n      [id]\n    );\n    return result.rows[0]?.status ?? null;\n  } catch (error) {\n    const err = error as Error;\n    getLog().error({ err }, 'db.workflow_run_get_status_failed');\n    throw new Error(`Failed to get workflow run status: ${err.message}`);\n  }\n}\n\nexport async function getActiveWorkflowRun(conversationId: string): Promise<WorkflowRun | null> {\n  try {\n    const result = await pool.query<WorkflowRun>(\n      `SELECT * FROM remote_agent_workflow_runs\n       WHERE (conversation_id = $1 OR parent_conversation_id = $2) AND status = 'running'\n       ORDER BY started_at DESC LIMIT 1`,\n      [conversationId, conversationId]\n    );\n    const row = result.rows[0];\n    return row ? normalizeWorkflowRun(row) : null;\n  } catch (error) {\n    const err = error as Error;\n    getLog().error({ err }, 'db.workflow_run_get_active_failed');\n    throw new Error(`Failed to get active workflow run: ${err.message}`);\n  }","sourceCodeStart":504,"sourceCodeEnd":540,"githubUrl":"https://github.com/coleam00/Archon/blob/0773b9745896ef0612e709c80845a0f7db315b19/packages/core/src/db/workflows.ts#L504-L540","documentation":"getWorkflowRunStatus queries workflow_runs for the status of a single run id. Any database error (connection loss, permissions, malformed query, server crash) is logged with the event db.workflow_run_get_status_failed and rethrown wrapped in this message. The wrap exists to tell the caller which DB operation failed while preserving the underlying pg error text via err.message.","triggerScenarios":"Calling getWorkflowRunStatus(runId) when the Postgres/SQLite pool is unreachable, when the workflow_runs table is missing (fresh DB without migrations), when credentials lack SELECT on workflow_runs, or when the underlying driver throws a transient network error mid-query.","commonSituations":"Postgres container not running or restarted; DATABASE_URL pointing at the wrong host/port; running an older binary against a DB where the workflow_runs table was added by a later migration; TLS/connection-pool exhaustion under load.","solutions":["Check the inner err.message in the log event db.workflow_run_get_status_failed to identify the real driver error.","Verify DATABASE_URL and that the database server is reachable (psql/nc to host:port).","Run the project's schema setup/migrations so the workflow_runs table exists.","Check the DB user has SELECT on workflow_runs.","If the error is transient (connection reset), retry the call after the pool recovers."],"exampleFix":"// before\nconst status = await getWorkflowRunStatus(runId);\n// after\nlet status: string | null;\ntry {\n  status = await getWorkflowRunStatus(runId);\n} catch (err) {\n  status = null; // surface degraded status instead of crashing the request\n}","handlingStrategy":"try-catch","validationCode":"// Optionally confirm DB reachability before querying\nconst ping = await pool.query('SELECT 1');\nif (!ping) throw new Error('database unavailable');","typeGuard":"function isDbWrappedError(err: unknown): err is Error & { message: string } {\n  return err instanceof Error && err.message.startsWith('Failed to get workflow run status:');\n}","tryCatchPattern":"try {\n  const status = await getWorkflowRunStatus(runId);\n} catch (err) {\n  // inner err.message carries the driver-level cause\n  getLog().error({ err }, 'run_status_lookup_failed');\n  status = null;\n}","preventionTips":["Run migrations before app startup so workflow_runs exists.","Health-check the DB (SELECT 1) before workflow operations.","Keep pool size below the server's max_connections.","Alert on db.workflow_run_get_status_failed log events."],"tags":["database","postgresql","workflow-run"],"backgroundTag":"database-query-failed","analyzedSha":"0773b9745896ef0612e709c80845a0f7db315b19","analyzedAt":"2026-09-01T02:28:07.064Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}