coleam00/Archon · error

Failed to get active workflow run by path: ${err.message}

Error message

Failed to get active workflow run by path: ${err.message}

What it means

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.

Source

Thrown at packages/core/src/db/workflows.ts:736

    const idParam = selfIdParam ?? '$2';
    const colExpr = isPostgres ? 'started_at' : 'datetime(started_at)';
    const paramExpr = isPostgres ? `${startedAtParam}::timestamptz` : `datetime(${startedAtParam})`;
    clauses.push(`(${colExpr} < ${paramExpr} OR (${colExpr} = ${paramExpr} AND id < ${idParam}))`);
  }

  try {
    const result = await pool.query<WorkflowRun>(
      `SELECT * FROM remote_agent_workflow_runs
       WHERE ${clauses.join(' AND ')}
       ORDER BY started_at ASC, id ASC LIMIT 1`,
      params
    );
    const row = result.rows[0];
    return row ? normalizeWorkflowRun(row) : null;
  } catch (error) {
    const err = error as Error;
    getLog().error({ err, workingPath }, 'db.workflow_run_get_active_by_path_failed');
    throw new Error(`Failed to get active workflow run by path: ${err.message}`);
  }
}

/**
 * Find every run spawned as a child of `parentRunId` (#2121 Phase 2), oldest
 * first. Callers filter further by `metadata.parent_node_id` (a parent may have
 * several `workflow:` nodes) or by status (the abandon cascade cancels
 * non-terminal children).
 */
export async function findChildRuns(parentRunId: string): Promise<WorkflowRun[]> {
  try {
    const result = await pool.query<WorkflowRun>(
      'SELECT * FROM remote_agent_workflow_runs WHERE parent_run_id = $1 ORDER BY started_at ASC',
      [parentRunId]
    );
    return result.rows.map(row => normalizeWorkflowRun(row));
  } catch (error) {
    const err = error as Error;

View on GitHub (pinned to 0773b97458)

Solutions

  1. Check the db.workflow_run_get_active_by_path_failed log for the underlying driver error.
  2. Apply pending migrations so workflow_runs has the path/lock columns the query filters on.
  3. Verify DB connectivity and pool headroom, then retry the read-only lookup.

Example fix

// before
const holder = await getActiveWorkflowRunByPath(repoPath);
// after
let holder: WorkflowRun | null = null;
try {
  holder = await getActiveWorkflowRunByPath(repoPath);
} catch (err) {
  getLog().error({ err, repoPath }, 'worktree.lock_probe_failed');
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Confirm migrations ran: the path-lock query needs current workflow_runs columns
const cols = await pool.query(
  `SELECT column_name FROM information_schema.columns WHERE table_name = 'workflow_runs'`
);
if (cols.rows.length === 0) throw new Error('workflow_runs table missing; run migrations');

Type guard

function isPathLockProbeError(err: unknown): err is Error {
  return err instanceof Error && err.message.startsWith('Failed to get active workflow run by path:');
}

Try / catch

try {
  const holder = await getActiveWorkflowRunByPath(workingPath);
} catch (err) {
  // Do NOT assume the path is free on error — fail closed to avoid double-claiming a worktree.
  throw new Error('cannot verify worktree lock; refusing to start run', { cause: err });
}

Prevention

When it happens

Trigger: 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.

Common situations: App started before migrations ran; path-lock lookup firing during a DB failover; connection pool saturated by long-running workflow transactions; wrong DSN environment.

Understand the failure class

Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.

Related errors


AI-assisted analysis of coleam00/Archon@0773b97458 (2026-09-01). Data as JSON: /api/errors/b03b3a84b8346c1d. Report an issue: GitHub.