{"record":{"id":"f47ba8a8605b5785","repo":"coleam00/Archon","slug":"failed-to-find-adopting-runs-err-message","errorCode":null,"errorMessage":"Failed to find adopting runs: ${err.message}","messagePattern":"Failed to find adopting runs: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/src/db/workflows.ts","lineNumber":2035,"sourceCode":"    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}`);\n  }\n}\n\n/**\n * Update parent_conversation_id on a workflow run.\n * Non-critical — logs error but does not throw.\n */\nexport async function updateWorkflowRunParent(\n  runId: string,\n  parentConversationId: string\n): Promise<void> {\n  try {\n    await pool.query(\n      'UPDATE remote_agent_workflow_runs SET parent_conversation_id = $1 WHERE id = $2',\n      [parentConversationId, runId]\n    );\n  } catch (error) {\n    const err = error as Error;","sourceCodeStart":2017,"sourceCodeEnd":2053,"githubUrl":"https://github.com/coleam00/Archon/blob/0773b9745896ef0612e709c80845a0f7db315b19/packages/core/src/db/workflows.ts#L2017-L2053","documentation":"Thrown by the adopting-runs lookup when the reverse-direction query on `adopted_from_run_id` fails. The driver error is logged as `db.workflow_run_adopters_lookup_failed` (with runId) and rethrown with this message. Zero adopters is a normal empty result, not an error.","triggerScenarios":"Calling the lookup with a runId when the DB is unreachable, the query fails at the driver, or the runs table is missing/unavailable due to schema drift.","commonSituations":"Tracing lineage of a run during a database outage; querying with a malformed runId that the driver rejects as a parameter; read-only replica rejecting the query.","solutions":["Read the `db.workflow_run_adopters_lookup_failed` log for the underlying driver error","Verify database connectivity and retry — the lookup is read-only","Validate the runId is a well-formed identifier before querying","Check schema state if the runs table appears missing after an upgrade"],"exampleFix":"// before\nconst adopters = await findAdoptingRuns(runId); // throws on DB failure\n// after\ntry {\n  const adopters = await findAdoptingRuns(runId);\n} catch (e) {\n  logger.error({ runId, err: e }, 'could not look up adopting runs');\n}","handlingStrategy":"try-catch","validationCode":"// validate runId shape before the query\nif (typeof runId !== 'string' || runId.length === 0) {\n  throw new Error(`invalid runId for adopter lookup: ${String(runId)}`);\n}","typeGuard":"function isValidRunId(v: unknown): v is string {\n  return typeof v === 'string' && v.length > 0 && /^[A-Za-z0-9_-]+$/.test(v);\n}","tryCatchPattern":"try {\n  const adopters = await findAdoptingRuns(runId);\n  if (adopters.length === 0) log.info({ runId }, 'no adopting runs');\n} catch (error) {\n  log.error({ runId, err: error }, 'adopter lookup failed — read-only, safe to retry');\n  throw error;\n}","preventionTips":["Validate runId provenance before querying (avoid raw external input)","Retry read-only lookups freely on transient failures","Keep adopted_from_run_id semantics intact; do not add parallel columns","Monitor `db.workflow_run_adopters_lookup_failed` for lineage-tracing outages"],"tags":["database","workflow","lineage"],"backgroundTag":"database-query-failed","analyzedSha":"0773b9745896ef0612e709c80845a0f7db315b19","analyzedAt":"2026-09-01T02:28:07.064Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}