{"record":{"id":"95743b3beb162adf","repo":"stablyai/orca","slug":"branch-branchname-already-has-pr-lastexist","errorCode":null,"errorMessage":"Branch \"${branchName}\" already has PR #${lastExistingReviewNumber}. Pick a different ${branchConflictSubject}.","messagePattern":"Branch \"(.+?)\" already has PR #(.+?)\\. Pick a different (.+?)\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/main/ipc/worktree-remote.ts","lineNumber":2198,"sourceCode":"      }\n    }\n\n    worktreePath = ensurePathWithinWorkspace(\n      computeWorktreePath(effectiveSanitizedName, repo.path, worktreePathSettings),\n      workspaceRoot\n    )\n    if (existsSync(worktreePath)) {\n      continue\n    }\n\n    resolved = true\n    break\n  }\n\n  if (!resolved) {\n    // Why: every suffix collided; reject with a specific reason so the user sees why create failed instead of a generic error or hung spinner.\n    if (lastExistingReviewNumber !== null) {\n      throw new Error(\n        `Branch \"${branchName}\" already has PR #${lastExistingReviewNumber}. Pick a different ${branchConflictSubject}.`\n      )\n    }\n    if (lastBranchConflictKind) {\n      throw new Error(\n        `Branch \"${branchName}\" already exists ${lastBranchConflictKind === 'local' ? 'locally' : 'on a remote'}. Pick a different ${branchConflictSubject}.`\n      )\n    }\n    throw new Error(\n      `Could not find an available worktree name for \"${sanitizedName}\". Pick a different worktree name.`\n    )\n  }\n\n  validateWorkspaceLineageParentBeforeCreate(\n    store,\n    args.parentWorkspace,\n    worktreeWorkspaceKey(`${repo.id}::${worktreePath}`)\n  )","sourceCodeStart":2180,"sourceCodeEnd":2216,"githubUrl":"https://github.com/stablyai/orca/blob/1136503c6a231a16dce8f921f6fadb63d181e8db/src/main/ipc/worktree-remote.ts#L2180-L2216","documentation":"Local worktree create exhausted all suffixed candidate paths and the last collision was due to an existing PR/MR on the branch (lastExistingReviewNumber is set). Every suffix produced a name whose branch already has an open review, so the loop could not find a free name. The message cites the PR number so the user knows the conflict is review-based, not a bare branch or path collision.","triggerScenarios":"Local create name-collision loop where each candidate branch name maps to a branch with an existing PR/MR; resolved stays false; lastExistingReviewNumber is the last seen PR number. Reached at worktree-remote.ts:2198.","commonSituations":"Naming template collides with a series of branches that each already have PRs; a reused worktree base name where '-2', '-3' etc. all have reviews; CI/automation creating sequentially-numbered branches that accumulate PRs.","solutions":["Pick a different base worktree/branch name that has no associated PR.","Close or merge the stale PRs blocking those branch names.","Change the naming template so generated names avoid the colliding series."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Pre-check: does the candidate branch already have an open PR?\nconst pr = await getOpenReviewNumber(repo, candidateBranch)\nif (pr !== null) {\n  return { ok: false, fieldError: 'branchName', message: `Branch \"${candidateBranch}\" already has PR #${pr}.` }\n}","typeGuard":null,"tryCatchPattern":"catch (err) {\n  if (err instanceof Error && /already has PR #/.test(err.message)) {\n    suggestNamesWithoutOpenReviews(repo, sanitizedName)\n  } else { throw err }\n}","preventionTips":["Pick base names that don't collide with branches holding open PRs.","Close or merge stale PRs to free up branch names.","Adjust naming templates to avoid colliding series."],"tags":["worktree-create","naming","pr-conflict","local","review"],"backgroundTag":null,"analyzedSha":"1136503c6a231a16dce8f921f6fadb63d181e8db","analyzedAt":"2026-08-12T23:15:58.167Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}