{"record":{"id":"29a3767c253c2455","repo":"coleam00/Archon","slug":"cannot-create-worktree-repository-registration-fa","errorCode":null,"errorMessage":"Cannot create worktree: repository registration failed.\nError: ${error.message}\n${hint}","messagePattern":"Cannot create worktree: repository registration failed\\.\nError: (.+?)\n(.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/commands/workflow.ts","lineNumber":709,"sourceCode":" * 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}\n\n/** The refusal when the resumable-run lookup itself could not answer. */\nfunction buildResumeLookupFailureError(error: Error): Error {\n  return new Error(\n    'Cannot resume: Database lookup failed.\\n' +\n      `Error: ${error.message}\\n` +\n      'Hint: Check your database connection before using --resume.'\n  );\n}","sourceCodeStart":691,"sourceCodeEnd":727,"githubUrl":"https://github.com/coleam00/Archon/blob/0773b9745896ef0612e709c80845a0f7db315b19/packages/cli/src/commands/workflow.ts#L691-L727","documentation":"assertCodebaseResolvedForIsolation() distinguishes a failed lookup (previous error) from a failed registration. When the codebase was absent and codebaseDb's register attempt failed, buildRegistrationFailureError produces this refusal: the repo could not be registered, so a worktree cannot be safely created. The original error and a hint are appended (hint varies per call site context).","triggerScenarios":"First run in a git repository that is not yet in the codebase table; the registration INSERT/UPSERT to the workflow/codebase DB throws (DB unwritable, constraint failure, connection drop); assertCodebaseResolvedForIsolation then throws via buildRegistrationFailureError('create worktree', error).","commonSituations":"Read-only database file while Archon needs to write a new repo row; schema/adapter mismatch; unique-constraint race when two runs register the same repo concurrently; remote DB temporarily unavailable during first-time setup.","solutions":["Read the embedded registration error and fix the underlying DB write problem (permissions, disk space, connectivity).","Retry the run — a concurrent-registration race often resolves on a second attempt.","Use --no-worktree to skip worktree isolation if registration is not required for this run.","Verify database migrations/adapter health if constraint errors persist."],"exampleFix":"// before: SQLite db is read-only\nError: Cannot create worktree: repository registration failed.\nError: attempt to write a readonly database\n// after\n$ chmod u+w ~/.archon/archon.db && archon workflow run foo","handlingStrategy":"try-catch","validationCode":"// ensure the codebase is already registered to avoid a registration write at run time\nimport { codebaseDb } from '@archon/core';\nconst resolved = await codebaseDb.getCodebase(cwd);\nif (!resolved.codebase) console.warn('Repo not registered yet; registration write will occur during the run.');","typeGuard":null,"tryCatchPattern":"try {\n  await runWorkflow(name, opts);\n} catch (e) {\n  const msg = String((e as Error).message);\n  if (msg.includes('repository registration failed')) {\n    console.error('Fix the DB write problem (permissions/space/connectivity) per the embedded error:', msg);\n  }\n}","preventionTips":["Keep the Archon database writable by the user running the CLI.","Watch disk space on the volume holding the DB.","Register repos ahead of time instead of relying on first-run registration.","Retry once on transient DB errors before escalating."],"tags":["database","worktree","registration","cli"],"backgroundTag":"database-write-failed","analyzedSha":"0773b9745896ef0612e709c80845a0f7db315b19","analyzedAt":"2026-09-01T02:28:07.064Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}