{"record":{"id":"82a8dde8f2333e2e","repo":"coleam00/Archon","slug":"cannot-resume-database-lookup-failed-error-er","errorCode":null,"errorMessage":"Cannot resume: Database lookup failed.\nError: ${error.message}\nHint: Check your database connection before using --resume.","messagePattern":"Cannot resume: Database lookup failed\\.\nError: (.+?)\nHint: Check your database connection before using --resume\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/commands/workflow.ts","lineNumber":2079,"sourceCode":"      } else if (options.supersedesRunId !== undefined) {\n        supersededRunId = await resolveRunIdArg(\n          options.supersedesRunId,\n          cwd,\n          false,\n          detachCodebase.id\n        );\n        await resolveSupersededRun(supersededRunId);\n      }\n    }\n\n    // The run id the ack hands back. A continuation already has one; a fresh launch\n    // gets a row written below, before the fork.\n    let detachedRunId: string;\n    // Only a row THIS process created may be failed when the child never takes it.\n    // A continuation's row belongs to its own run.\n    let launchedRunId: string | undefined;\n    if (isContinuation) {\n      if (resumeLookupError) throw buildResumeLookupFailureError(resumeLookupError);\n      if (!continuationRun) throw buildNoResumableRunError(workflowName, cwd);\n      detachedRunId = continuationRun.id;\n    } else {\n      // `Started` must mean a queryable run, so the row is written before the fork and\n      // the child executes it rather than creating its own. Modeled on the\n      // orchestrator's pre-created row (dispatchBackgroundWorkflowOwned), including\n      // the stamps the executor only writes when IT creates the row. `working_path` is\n      // the one field this process cannot know — the child cuts the worktree — so it\n      // stays null until the child fills it in (write-once in the store).\n      let detachedConversation;\n      try {\n        detachedConversation = await conversationDb.getOrCreateConversation(\n          'cli',\n          childConversationId\n        );\n      } catch (error) {\n        const err = error as Error;\n        throw new Error(","sourceCodeStart":2061,"sourceCodeEnd":2097,"githubUrl":"https://github.com/coleam00/Archon/blob/0773b9745896ef0612e709c80845a0f7db315b19/packages/cli/src/commands/workflow.ts#L2061-L2097","documentation":"During a detached launch with --resume (a continuation), the CLI must look up the prior run row before forking. If the database lookup itself failed (resumeLookupError set), the pre-flight throws buildResumeLookupFailureError with the message 'Cannot resume: Database lookup failed.\\nError: <detail>\\nHint: Check your database connection before using --resume.' This refuses the launch synchronously rather than letting the child die after the parent printed 'Started' (#2872, #2747).","triggerScenarios":"Running `archon workflow run <name> --detach --resume` (isContinuation branch at workflow.ts:2079) where the database query for the continuation run raised — unreachable database, missing/misconfigured DATABASE_URL, network failure, or credentials rejected.","commonSituations":"Postgres not running or restarted; DATABASE_URL unset in the shell or .env not loaded; connecting from a machine/network that cannot reach the database; expired credentials.","solutions":["Verify the database is running and reachable (e.g. psql with the same DSN)","Check DATABASE_URL is set and correct in the environment or .env","Re-run the command after connectivity is restored; nothing was forked so no run row was left behind","If the run genuinely does not exist (rather than a lookup failure), drop --resume or pick the right workflow/cwd"],"exampleFix":"// before\nDATABASE_URL= pnpm archon workflow run deploy --detach --resume\n// after\nexport DATABASE_URL=postgres://user:pass@localhost:5432/archon\npg_isready -d \"$DATABASE_URL\" && pnpm archon workflow run deploy --detach --resume","handlingStrategy":"validation","validationCode":"import { Client } from 'pg';\nasync function assertDbReachable(dsn) {\n  const c = new Client({ connectionString: dsn });\n  await c.connect(); await c.end();\n}\nif (!process.env.DATABASE_URL) throw new Error('DATABASE_URL not set');\nawait assertDbReachable(process.env.DATABASE_URL); // before `run --detach --resume`","typeGuard":null,"tryCatchPattern":"try {\n  await runWorkflow(name, { detach: true, resume: true });\n} catch (e) {\n  if (String(e.message).startsWith('Cannot resume: Database lookup failed.')) {\n    // verify DB connectivity/DATABASE_URL, then retry once connectivity is restored\n  } else throw e;\n}","preventionTips":["Check DATABASE_URL is exported in the shell and .env is loaded before detached launches","Health-check the database (pg_isready) before scripted resume calls","Avoid rotating credentials mid-flight; update DSN everywhere first","Remember detached pre-flight fails before forking, so a retry is always safe"],"tags":["cli","database","resume","connectivity"],"backgroundTag":"database-lookup-failed","analyzedSha":"0773b9745896ef0612e709c80845a0f7db315b19","analyzedAt":"2026-09-01T02:28:07.064Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}