{"record":{"id":"b03b3a84b8346c1d","repo":"coleam00/Archon","slug":"failed-to-get-active-workflow-run-by-path-err-m","errorCode":null,"errorMessage":"Failed to get active workflow run by path: ${err.message}","messagePattern":"Failed to get active workflow run by path: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/src/db/workflows.ts","lineNumber":736,"sourceCode":"    const idParam = selfIdParam ?? '$2';\n    const colExpr = isPostgres ? 'started_at' : 'datetime(started_at)';\n    const paramExpr = isPostgres ? `${startedAtParam}::timestamptz` : `datetime(${startedAtParam})`;\n    clauses.push(`(${colExpr} < ${paramExpr} OR (${colExpr} = ${paramExpr} AND id < ${idParam}))`);\n  }\n\n  try {\n    const result = await pool.query<WorkflowRun>(\n      `SELECT * FROM remote_agent_workflow_runs\n       WHERE ${clauses.join(' AND ')}\n       ORDER BY started_at ASC, id ASC LIMIT 1`,\n      params\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, workingPath }, 'db.workflow_run_get_active_by_path_failed');\n    throw new Error(`Failed to get active workflow run by path: ${err.message}`);\n  }\n}\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;","sourceCodeStart":718,"sourceCodeEnd":754,"githubUrl":"https://github.com/coleam00/Archon/blob/0773b9745896ef0612e709c80845a0f7db315b19/packages/core/src/db/workflows.ts#L718-L754","documentation":"getActiveWorkflowRunByPath finds the run currently holding the lock on a workingPath. Failures from pool.query are logged (db.workflow_run_get_active_by_path_failed) and rethrown wrapped in this message. No active run for the path returns null — only actual DB failures throw.","triggerScenarios":"Calling getActiveWorkflowRunByPath(workingPath) with an unreachable database, a stale/missing workflow_runs schema (e.g. working_path or lock-related columns not yet migrated), a pool timeout, or a permission failure on the SELECT.","commonSituations":"App started before migrations ran; path-lock lookup firing during a DB failover; connection pool saturated by long-running workflow transactions; wrong DSN environment.","solutions":["Check the db.workflow_run_get_active_by_path_failed log for the underlying driver error.","Apply pending migrations so workflow_runs has the path/lock columns the query filters on.","Verify DB connectivity and pool headroom, then retry the read-only lookup."],"exampleFix":"// before\nconst holder = await getActiveWorkflowRunByPath(repoPath);\n// after\nlet holder: WorkflowRun | null = null;\ntry {\n  holder = await getActiveWorkflowRunByPath(repoPath);\n} catch (err) {\n  getLog().error({ err, repoPath }, 'worktree.lock_probe_failed');\n}","handlingStrategy":"try-catch","validationCode":"// Confirm migrations ran: the path-lock query needs current workflow_runs columns\nconst cols = await pool.query(\n  `SELECT column_name FROM information_schema.columns WHERE table_name = 'workflow_runs'`\n);\nif (cols.rows.length === 0) throw new Error('workflow_runs table missing; run migrations');","typeGuard":"function isPathLockProbeError(err: unknown): err is Error {\n  return err instanceof Error && err.message.startsWith('Failed to get active workflow run by path:');\n}","tryCatchPattern":"try {\n  const holder = await getActiveWorkflowRunByPath(workingPath);\n} catch (err) {\n  // Do NOT assume the path is free on error — fail closed to avoid double-claiming a worktree.\n  throw new Error('cannot verify worktree lock; refusing to start run', { cause: err });\n}","preventionTips":["Fail closed: an errored lock probe must not be treated as 'path is free'.","Run schema upgrades before enabling path-lock workflows.","Add pool health metrics so timeouts are visible before they hit this query.","Retry transient connection errors before giving up."],"tags":["database","postgresql","worktree-lock"],"backgroundTag":"database-query-failed","analyzedSha":"0773b9745896ef0612e709c80845a0f7db315b19","analyzedAt":"2026-09-01T02:28:07.064Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}