Yeachan-Heo/oh-my-codex · error · Error

autoresearch_active_run_exists

autoresearch_active_run_exists

Error message

autoresearch_active_run_exists:${state.run_id}

What it means

assertAutoresearchLockAvailable throws (code autoresearch_active_run_exists) when the active-run state file records an active run with a run_id. Autoresearch enforces a single active run per project root to prevent concurrent runs from corrupting shared worktrees and ledgers.

Source

Thrown at src/autoresearch/runtime.ts:291

async function readJsonFile<T>(filePath: string): Promise<T> {
  return JSON.parse(await readFile(filePath, 'utf-8')) as T;
}

async function readActiveRunState(projectRoot: string): Promise<AutoresearchActiveRunState | null> {
  const file = activeRunStateFile(projectRoot);
  if (!existsSync(file)) return null;
  return readJsonFile<AutoresearchActiveRunState>(file);
}

async function writeActiveRunState(projectRoot: string, value: AutoresearchActiveRunState): Promise<void> {
  await writeJsonFile(activeRunStateFile(projectRoot), value);
}

async function assertAutoresearchLockAvailable(projectRoot: string): Promise<void> {
  const state = await readActiveRunState(projectRoot);
  if (state?.active && state.run_id) {
    throw new Error(`autoresearch_active_run_exists:${state.run_id}`);
  }
}

async function activateAutoresearchRun(manifest: AutoresearchRunManifest): Promise<void> {
  await writeActiveRunState(manifest.repo_root, {
    schema_version: 1,
    active: true,
    run_id: manifest.run_id,
    mission_slug: manifest.mission_slug,
    repo_root: manifest.repo_root,
    worktree_path: manifest.worktree_path,
    status: manifest.status,
    updated_at: nowIso(),
  });
}

async function deactivateAutoresearchRun(manifest: AutoresearchRunManifest): Promise<void> {
  const previous = await readActiveRunState(manifest.repo_root);

View on GitHub (pinned to 3ad79a8a6f)

Solutions

  1. Check if a run with that run_id is genuinely active (process list / CI logs); if so, wait for it or cancel it
  2. If the previous run crashed, clear the active run state through the supported finalize/cancel command for the run_id in the message
  3. Inspect the active-run state file under projectRoot/.omx and verify before manually clearing it
  4. Avoid launching concurrent autoresearch runs against the same repo root; serialize them in your pipeline
Defensive patterns

Strategy: validation

Validate before calling

// before preparing/resuming, inspect the active-run state file
import { readFile } from 'node:fs/promises';
try {
  const s = JSON.parse(await readFile(join(repoRoot, '.omx', 'active-run.json'), 'utf-8'));
  if (s?.active && s.run_id) throw new Error(`Run ${s.run_id} still active`);
} catch (e) { if ((e as NodeJS.ErrnoException).code !== 'ENOENT') throw e; }

Type guard

function isActiveRunState(v: unknown): v is { active: true; run_id: string } {
  return typeof v === 'object' && v !== null && (v as any).active === true && typeof (v as any).run_id === 'string';
}

Try / catch

try { await prepareAutoresearchRuntime(repoRoot, task); }
catch (e) { if (e instanceof Error && e.message.startsWith('autoresearch_active_run_exists')) { const id = e.message.split(':')[1]; /* cancel/finalize run id, then retry */ } throw e; }

Prevention

When it happens

Trigger: Calling prepareAutoresearchRuntime or resumeAutoresearchRuntime while another run is already active — including a stale lock left behind by a crashed process that never finalized its run state.

Common situations: Running two autoresearch commands in parallel terminals, a previous run killed by SIGKILL/OOM without cleanup, CI retrying a job while the first is still active, or a stale .omx active-run state file after an interrupted session.

Related errors


AI-assisted analysis of Yeachan-Heo/oh-my-codex@3ad79a8a6f (2026-08-27). Data as JSON: /api/errors/f5256a71275ea31b. Report an issue: GitHub.