{"record":{"id":"9beabb809424d574","repo":"stablyai/orca","slug":"worktree-created-but-not-found-in-listing","errorCode":null,"errorMessage":"Worktree created but not found in listing","messagePattern":"Worktree created but not found in listing","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/main/ipc/worktree-remote.ts","lineNumber":1760,"sourceCode":"        .removeWorktree(remotePath, true, {\n          deleteBranch: !checkoutExistingBranch,\n          // Why: sparse setup failed before any work happened, so rollback removes the just-created remote branch.\n          forceBranchDelete: !checkoutExistingBranch\n        })\n        .catch(() => undefined)\n      throw err\n    }\n  }\n\n  // Re-list to get the created worktree info\n  const gitWorktrees = await timing.time('list_created_worktree', async () =>\n    provider.listWorktrees(repo.path)\n  )\n  const created = gitWorktrees.find(\n    (gw) => gw.branch?.endsWith(branchName) || gw.path.endsWith(effectiveSanitizedName)\n  )\n  if (!created) {\n    throw new Error('Worktree created but not found in listing')\n  }\n\n  const worktreeId = `${repo.id}::${created.path}`\n  const now = Date.now()\n  // Why: PR/MR worktrees start from a head ref/SHA but Source Control must compare against the review target branch.\n  const metadataBaseRef = args.compareBaseRef ?? remoteTrackingBase?.ref ?? baseBranch\n  let configuredPushTarget: GitPushTarget | undefined\n  if (preparedPushTarget) {\n    configuredPushTarget = await configureCreatedWorktreePushTargetWithExec(\n      (args, cwd) => provider.exec(args, cwd),\n      created.path,\n      branchName,\n      preparedPushTarget\n    )\n  }\n  const metaUpdates: Partial<WorktreeMeta> = {\n    // Why: path-derived IDs get reused after external deletion; rotate instance identity so stale lineage can't attach to the new occupant.\n    instanceId: randomUUID(),","sourceCodeStart":1742,"sourceCodeEnd":1778,"githubUrl":"https://github.com/stablyai/orca/blob/1136503c6a231a16dce8f921f6fadb63d181e8db/src/main/ipc/worktree-remote.ts#L1742-L1778","documentation":"Remote create reported success from git, but re-listing worktrees via provider.listWorktrees did not contain a row matching the just-created worktree. The match looks for a gitWorktree whose branch ends with branchName OR whose path ends with effectiveSanitizedName. A miss means git and the listing disagree — usually because the relay's listWorktrees is stale, the path was canonicalized differently, or the branch/path suffix matching is too strict.","triggerScenarios":"After a successful remote git worktree add, provider.listWorktrees(repo.path) returns rows none of which match by branch suffix or path suffix. Reached at worktree-remote.ts:1760.","commonSituations":"Relay caches the worktree list and hasn't refreshed; path canonicalization (symlinks, case-insensitive FS) means the stored path differs from the create path; branch name has a suffix/prefix that defeats endsWith; concurrent delete racing the re-list; relay listWorktrees implementation filtered out the new entry.","solutions":["Retry the create — a transient listing lag often clears on the next listWorktrees call.","Reconnect the SSH host to refresh the relay state and ensure listWorktrees is current.","If persistent, verify the created path/branch directly on the host (git worktree list) and loosen the match (use findCreatedWorktree's path-equality + full ref match).","Check for a concurrent process deleting or moving the worktree between add and list."],"exampleFix":"// before\nconst created = gitWorktrees.find(\n  (gw) => gw.branch?.endsWith(branchName) || gw.path.endsWith(effectiveSanitizedName)\n)\nif (!created) {\n  throw new Error('Worktree created but not found in listing')\n}\n\n// after — reuse the shared reconciler that handles path canonicalization\nconst created = findCreatedWorktree(gitWorktrees, requestedPath, branchName)\nif (!created) {\n  throw new WorktreeCreatedButUnlistedError({ requestedPath, branchName, listed: gitWorktrees })\n}","handlingStrategy":"retry","validationCode":"// Optional preflight: confirm listing reflects recent state\nconst listed = await provider.listWorktrees(repo.path)\n// if listing looks stale, force a refresh before relying on it\nif (!listed.some(gw => gw.branch?.endsWith(branchName))) {\n  await provider.refreshWorktreeList?.(repo.path)\n}","typeGuard":null,"tryCatchPattern":"catch (err) {\n  if (err instanceof Error && err.message === 'Worktree created but not found in listing') {\n    // listing lag: wait briefly and re-list once\n    await delay(200)\n    const retry = await provider.listWorktrees(repo.path)\n    const found = retry.find(gw => gw.branch?.endsWith(branchName) || gw.path.endsWith(effectiveSanitizedName))\n    if (!found) throw err\n    return found\n  }\n  throw err\n}","preventionTips":["Reconnect the SSH host if the relay's listing is persistently stale.","Use the shared findCreatedWorktree reconciler for symlink/case-tolerant matching.","Avoid concurrent deletes that race the post-create re-list."],"tags":["worktree-create","reconciliation","ssh","listing","git"],"backgroundTag":null,"analyzedSha":"1136503c6a231a16dce8f921f6fadb63d181e8db","analyzedAt":"2026-08-12T23:15:58.167Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}