{"record":{"id":"8aa6570d5482bd0b","repo":"coleam00/Archon","slug":"cannot-create-worktree-database-lookup-failed-er","errorCode":null,"errorMessage":"Cannot create worktree: database lookup failed.\nError: ${resolved.lookupError.message}\nHint: Check your database connection, or use --no-worktree to skip isolation.","messagePattern":"Cannot create worktree: database lookup failed\\.\nError: (.+?)\nHint: Check your database connection, or use --no-worktree to skip isolation\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/commands/workflow.ts","lineNumber":700,"sourceCode":"/**\n * Refuse an isolated run that has no project to isolate, naming which step failed.\n *\n * One owner because two callers enforce the same policy at different times: the\n * `--detach` pre-flight, which must refuse before the fork (#2872), and the isolation\n * block, which is where a foreground run reaches it. Two copies of this decision is\n * exactly how the detached path came to skip it.\n *\n * A no-op once a codebase resolved — the isolation block only reaches it with none, and\n * the pre-flight calls it unconditionally for an isolating run.\n */\nfunction assertCodebaseResolvedForIsolation(resolved: {\n  codebase: Awaited<ReturnType<typeof codebaseDb.getCodebase>>;\n  lookupError: Error | null;\n  registrationError: Error | null;\n}): void {\n  if (resolved.codebase) return;\n  if (resolved.lookupError) {\n    throw new Error(\n      'Cannot create worktree: database lookup failed.\\n' +\n        `Error: ${resolved.lookupError.message}\\n` +\n        'Hint: Check your database connection, or use --no-worktree to skip isolation.'\n    );\n  }\n  if (resolved.registrationError) {\n    throw buildRegistrationFailureError('create worktree', resolved.registrationError);\n  }\n  throw new Error(\n    'Cannot create worktree: not in a git repository.\\n' +\n      'Run from within a git repo, or use --no-worktree to skip isolation.'\n  );\n}\n\n/** The refusal when `--resume` finds nothing to continue. */\nfunction buildNoResumableRunError(workflowName: string, cwd: string): Error {\n  return new Error(`No resumable run found for workflow '${workflowName}' at path '${cwd}'.`);\n}","sourceCodeStart":682,"sourceCodeEnd":718,"githubUrl":"https://github.com/coleam00/Archon/blob/0773b9745896ef0612e709c80845a0f7db315b19/packages/cli/src/commands/workflow.ts#L682-L718","documentation":"assertCodebaseResolvedForIsolation() gates worktree isolation on the codebase having been resolved from the database. When getCodebase returned no codebase AND an explicit lookupError was captured (as opposed to 'simply not registered'), the CLI throws this refusal rather than attempting worktree creation against unknown repository state. The original DB error message and an actionable hint are embedded.","triggerScenarios":"runWorkflowWithOwnedSource calls the resolver, codebaseDb.getCodebase throws (connection failure, DB locked, adapter crash), resolved.codebase stays null and resolved.lookupError is set; the check then throws during worktree pre-flight.","commonSituations":"SQLite file moved/missing or unreadable; Postgres DSN wrong or server down; permissions on the DB file; database locked by another process; transient network outage to a remote Postgres.","solutions":["Check your database connection (DSN in config, server reachable, SQLite file present).","If worktree isolation is not needed, re-run with --no-worktree to skip isolation.","Inspect the embedded Error message — it carries the original database failure.","Restart the database service or fix file permissions, then retry the run."],"exampleFix":"// before: DSN points at a stopped server\n$ archon workflow run foo\nError: Cannot create worktree: database lookup failed.\nError: connect ECONNREFUSED 127.0.0.1:5432\n// after: start the DB or point the DSN at a live server\n$ docker start archon-postgres && archon workflow run foo","handlingStrategy":"try-catch","validationCode":"// pre-flight: confirm the database is reachable before starting an isolated run\nimport { getDatabase } from '@archon/core';\ntry {\n  await getDatabase().query('SELECT 1');\n} catch (e) {\n  console.error('DB unreachable; fix the connection or plan to use --no-worktree');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await runWorkflow(name, opts);\n} catch (e) {\n  const msg = String((e as Error).message);\n  if (msg.includes('database lookup failed')) {\n    console.error('Fix DB connectivity or retry with --no-worktree:', msg);\n  }\n}","preventionTips":["Verify the DSN / SQLite path before launching runs (`archon doctor` or a SELECT 1 probe).","Keep the SQLite file on writable local storage; avoid moving it between runs.","Monitor database availability for remote Postgres installs.","Use --no-worktree when isolation is unnecessary and the DB is known-flaky."],"tags":["database","worktree","connection","cli"],"backgroundTag":"database-connection-failed","analyzedSha":"0773b9745896ef0612e709c80845a0f7db315b19","analyzedAt":"2026-09-01T02:28:07.064Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}