{"record":{"id":"b0387343a6daf384","repo":"coleam00/Archon","slug":"failed-to-find-child-workflow-runs-err-message","errorCode":null,"errorMessage":"Failed to find child workflow runs: ${err.message}","messagePattern":"Failed to find child workflow runs: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/src/db/workflows.ts","lineNumber":756,"sourceCode":"}\n\n/**\n * Find every run spawned as a child of `parentRunId` (#2121 Phase 2), oldest\n * first. Callers filter further by `metadata.parent_node_id` (a parent may have\n * several `workflow:` nodes) or by status (the abandon cascade cancels\n * non-terminal children).\n */\nexport async function findChildRuns(parentRunId: string): Promise<WorkflowRun[]> {\n  try {\n    const result = await pool.query<WorkflowRun>(\n      'SELECT * FROM remote_agent_workflow_runs WHERE parent_run_id = $1 ORDER BY started_at ASC',\n      [parentRunId]\n    );\n    return result.rows.map(row => normalizeWorkflowRun(row));\n  } catch (error) {\n    const err = error as Error;\n    getLog().error({ err, parentRunId }, 'db.workflow_run_find_children_failed');\n    throw new Error(`Failed to find child workflow runs: ${err.message}`);\n  }\n}\n\n/**\n * Safety cap on the `parent_run_id` walk. The load-time and runtime cycle guards\n * prevent creating a cyclic run tree, but a hand-edited DB must never hang the\n * walk — deeper than the runtime depth cap (5) so a legitimately deep-but-bounded\n * tree still resolves fully.\n */\nconst MAX_RUN_ANCESTRY_DEPTH = 32;\n\n/**\n * Walk `parent_run_id` from `runId` up to the root, returning ancestors nearest\n * first (the immediate parent at index 0). Depth-capped and cycle-safe (a\n * repeated id stops the walk). Used by the runtime cycle guard and to build the\n * path-lock exclusion set for a shared-checkout sub-run.\n */\nexport async function getRunAncestry(runId: string): Promise<WorkflowRun[]> {","sourceCodeStart":738,"sourceCodeEnd":774,"githubUrl":"https://github.com/coleam00/Archon/blob/0773b9745896ef0612e709c80845a0f7db315b19/packages/core/src/db/workflows.ts#L738-L774","documentation":"findChildRuns selects all workflow runs whose parent_run_id equals the given parent run id, oldest first. Driver/query errors are logged (db.workflow_run_find_children_failed) and rethrown wrapped in this message. An empty child list is a normal result, not an error.","triggerScenarios":"Calling findChildRuns(parentRunId) during a DB outage, against a schema missing the parent_run_id column (pre-#2121 Phase 2 database), or when the driver throws a timeout/connection error on the SELECT.","commonSituations":"Older binary reading a database before parent_run_id was added, or vice versa (older DB opened by newer binary before upgrade steps); DB restart mid-walk; connection limit exceeded.","solutions":["Read the wrapped err.message; 'column parent_run_id does not exist' means migrations are pending.","Run the schema upgrade so parent_run_id exists, then retry.","For transient connection errors, retry after the pool recovers — the query is read-only."],"exampleFix":"// before\nconst children = await findChildRuns(parentRunId);\n// after\nlet children: WorkflowRun[] = [];\ntry {\n  children = await findChildRuns(parentRunId);\n} catch (err) {\n  getLog().error({ err, parentRunId }, 'children_walk_failed');\n}","handlingStrategy":"try-catch","validationCode":"// Verify the parent_run_id column exists (added in #2121 Phase 2)\nconst check = await pool.query(\n  `SELECT 1 FROM information_schema.columns WHERE table_name='workflow_runs' AND column_name='parent_run_id'`\n);\nif (check.rowCount === 0) throw new Error('schema upgrade required: parent_run_id missing');","typeGuard":"function isChildWalkError(err: unknown): err is Error {\n  return err instanceof Error && err.message.startsWith('Failed to find child workflow runs:');\n}","tryCatchPattern":"try {\n  const children = await findChildRuns(parentRunId);\n} catch (err) {\n  if (/does not exist/.test(String(err))) throw new Error('apply schema upgrades first', { cause: err });\n  children = []; // only for acceptable degraded walks\n}","preventionTips":["Keep binaries and schema in step: run the documented upgrade path when parent_run_id was added.","An empty array is a valid answer — only catch for real DB errors.","Cap retry attempts on transient connection errors.","Alert on db.workflow_run_find_children_failed events."],"tags":["database","postgresql","schema-migration"],"backgroundTag":"database-query-failed","analyzedSha":"0773b9745896ef0612e709c80845a0f7db315b19","analyzedAt":"2026-09-01T02:28:07.064Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}