{"record":{"id":"6ed586aad266a57d","repo":"coleam00/Archon","slug":"workflow-run-runid-references-codebase-cod","errorCode":null,"errorMessage":"Workflow run '${runId}' references codebase '${codebaseId}', but that codebase no longer exists.\nCannot safely discover workflows from the run worktree because project workflow files may be missing.\nRe-register the project or restore the codebase row, then retry.","messagePattern":"Workflow run '(.+?)' references codebase '(.+?)', but that codebase no longer exists\\.\nCannot safely discover workflows from the run worktree because project workflow files may be missing\\.\nRe-register the project or restore the codebase row, then retry\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/commands/workflow.ts","lineNumber":4181,"sourceCode":"    // Precheck failures follow each mode's error contract: --json emits the\n    // standard { ok: false } line; human mode throws like the inline path.\n    if (json) {\n      await printJsonWriteError(runId, action, error);\n      return;\n    }\n    throw error;\n  }\n}\n\nasync function resolveDiscoveryCwdForCodebase(\n  runId: string,\n  codebaseId: string,\n  action: 'resume' | 'approve' | 'reject' | 'respond'\n): Promise<string> {\n  try {\n    const codebase = await codebaseDb.getCodebase(codebaseId);\n    if (!codebase) {\n      throw new Error(\n        `Workflow run '${runId}' references codebase '${codebaseId}', but that codebase no longer exists.\\n` +\n          'Cannot safely discover workflows from the run worktree because project workflow files may be missing.\\n' +\n          'Re-register the project or restore the codebase row, then retry.'\n      );\n    }\n    return codebase.default_cwd;\n  } catch (error) {\n    const err = error as Error;\n    if (err.message.includes('references codebase')) {\n      throw err;\n    }\n    getLog().error(\n      { err, errorType: err.constructor.name, runId, codebaseId },\n      `cli.workflow_${action}_codebase_lookup_failed`\n    );\n    throw new Error(\n      `Failed to load codebase '${codebaseId}' for workflow run '${runId}': ${err.message}\\n` +\n        'Cannot safely discover workflows from the run worktree because project workflow files may be missing.\\n' +","sourceCodeStart":4163,"sourceCodeEnd":4199,"githubUrl":"https://github.com/coleam00/Archon/blob/0773b9745896ef0612e709c80845a0f7db315b19/packages/cli/src/commands/workflow.ts#L4163-L4199","documentation":"Before discovering workflows from a run's worktree, commands like resume/approve/reject/respond load the run's codebase row. If the row is gone (dangling foreign reference), the CLI refuses to proceed because project workflow files may no longer be discoverable.","triggerScenarios":"Invoking `workflow resume/approve/reject/respond <runId>` where runs.codebase_id points to a codebases row deleted via re-registration cleanup or manual DB pruning.","commonSituations":"Re-registering or deleting a project while old runs still reference it; pruning the database without cascading run rows; restoring a partial DB backup.","solutions":["Re-register the project (`archon project register` from the checkout) so a codebase row exists again, then retry the action.","If re-registration creates a new id, restore the original codebase row (or update the run's codebase_id) in the database.","If the runs are stale, drop the orphaned run rows instead of acting on them."],"exampleFix":"// before\narchon workflow approve ab12   # codebase row deleted\n// after\ncd ~/projects/my-app && archon project register && archon workflow approve ab12","handlingStrategy":"validation","validationCode":"const run = await getRun(runId, { json: true }); const cb = await db.getCodebase(run.codebaseId); if (!cb) throw new Error('codebase row missing; re-register project first');","typeGuard":"function codebaseExists(c: Codebase | null | undefined): c is Codebase { return c != null && typeof c.default_cwd === 'string'; }","tryCatchPattern":"try { await approve(runId); } catch (e) { if (String(e.message).includes('no longer exists')) { await exec('archon project register'); await approve(runId); } else throw e; }","preventionTips":["Re-register (not delete) projects you intend to keep acting on; cascade or clean run rows when a project is truly removed.","Avoid manual DB pruning of the codebases table while runs reference it.","Restore codebase rows when restoring partial database backups."],"tags":["cli","database","referential-integrity","workflow"],"backgroundTag":"dangling-foreign-reference","analyzedSha":"0773b9745896ef0612e709c80845a0f7db315b19","analyzedAt":"2026-09-01T02:28:07.064Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}