{"record":{"id":"77ea533699ef9735","repo":"coleam00/Archon","slug":"failed-to-list-open-workflow-runs-err-message","errorCode":null,"errorMessage":"Failed to list open workflow runs: ${err.message}","messagePattern":"Failed to list open workflow runs: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/src/db/workflows.ts","lineNumber":2017,"sourceCode":"\n  try {\n    const result = await pool.query<WorkflowRun>(\n      `SELECT * FROM remote_agent_workflow_runs r\n       WHERE r.status = 'failed'\n         ${codebaseClause}\n         AND NOT EXISTS (\n           SELECT 1 FROM remote_agent_workflow_runs a\n           WHERE a.adopted_from_run_id = r.id\n         )\n       ORDER BY r.started_at DESC\n       LIMIT ${limitParam}`,\n      values\n    );\n    return result.rows.map(normalizeWorkflowRun);\n  } catch (error) {\n    const err = error as Error;\n    getLog().error({ err }, 'db.workflow_open_work_list_failed');\n    throw new Error(`Failed to list open workflow runs: ${err.message}`);\n  }\n}\n\n/**\n * Runs that adopted or superseded `runId` (#2747) — the reverse direction of\n * `adopted_from_run_id`, same column, no second column. Newest first.\n */\nexport async function findAdoptingRuns(runId: string): Promise<WorkflowRun[]> {\n  try {\n    const result = await pool.query<WorkflowRun>(\n      'SELECT * FROM remote_agent_workflow_runs WHERE adopted_from_run_id = $1 ORDER BY started_at DESC',\n      [runId]\n    );\n    return result.rows.map(normalizeWorkflowRun);\n  } catch (error) {\n    const err = error as Error;\n    getLog().error({ err, runId }, 'db.workflow_run_adopters_lookup_failed');\n    throw new Error(`Failed to find adopting runs: ${err.message}`);","sourceCodeStart":1999,"sourceCodeEnd":2035,"githubUrl":"https://github.com/coleam00/Archon/blob/0773b9745896ef0612e709c80845a0f7db315b19/packages/core/src/db/workflows.ts#L1999-L2035","documentation":"Thrown by the open-work inbox listing (#2747) when its status-derived query (terminal, failed, unadopted runs) fails. Errors are logged as `db.workflow_open_work_list_failed` and rethrown with this message. An empty inbox is a normal result; only a query failure throws.","triggerScenarios":"Calling the open-work list function when the database connection fails, the status-derivation SQL errors for the configured dialect, or the query times out on large tables.","commonSituations":"Opening the open-work inbox view during a database outage or migration drift; dialect mismatch in status-derivation expressions; slow full scans timing out as run history grows.","solutions":["Check the `db.workflow_open_work_list_failed` log entry for the real driver error","Verify database connectivity and that the deployed schema matches the configured engine","Add/refresh indexes if the open-work scan times out on large history","Retry after transient failures — the listing is read-only and safe to re-run"],"exampleFix":"// before\nconst open = await listOpenWorkflowRuns(); // throws on DB failure\n// after\nlet open = [];\ntry {\n  open = await listOpenWorkflowRuns();\n} catch (e) {\n  logger.error({ err: e }, 'open-work inbox unavailable');\n}","handlingStrategy":"fallback","validationCode":"// pre-flight reachability check\nawait getDatabase().query('SELECT 1');","typeGuard":"function isWorkflowRunArray(v: unknown): v is WorkflowRun[] {\n  return Array.isArray(v) && v.every(r => typeof r === 'object' && r !== null && 'id' in r);\n}","tryCatchPattern":"let openRuns: WorkflowRun[] = [];\ntry {\n  openRuns = await listOpenWorkflowRuns();\n} catch (error) {\n  log.error({ err: error }, 'open-work inbox query failed; showing empty inbox');\n}","preventionTips":["Ensure indexes support the open-work status-derivation predicate","Keep engines and schema aligned; retest after SQLite/Postgres switches","Refresh statistics/vacuum as run history grows to avoid scan timeouts","Track `db.workflow_open_work_list_failed` events as inbox health"],"tags":["database","workflow","inbox"],"backgroundTag":"database-query-failed","analyzedSha":"0773b9745896ef0612e709c80845a0f7db315b19","analyzedAt":"2026-09-01T02:28:07.064Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}