stablyai/orca · error · Error

Worktree created but not found in listing

Error message

Worktree created but not found in listing

What it means

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.

Source

Thrown at src/main/ipc/worktree-remote.ts:1760

        .removeWorktree(remotePath, true, {
          deleteBranch: !checkoutExistingBranch,
          // Why: sparse setup failed before any work happened, so rollback removes the just-created remote branch.
          forceBranchDelete: !checkoutExistingBranch
        })
        .catch(() => undefined)
      throw err
    }
  }

  // Re-list to get the created worktree info
  const gitWorktrees = await timing.time('list_created_worktree', async () =>
    provider.listWorktrees(repo.path)
  )
  const created = gitWorktrees.find(
    (gw) => gw.branch?.endsWith(branchName) || gw.path.endsWith(effectiveSanitizedName)
  )
  if (!created) {
    throw new Error('Worktree created but not found in listing')
  }

  const worktreeId = `${repo.id}::${created.path}`
  const now = Date.now()
  // Why: PR/MR worktrees start from a head ref/SHA but Source Control must compare against the review target branch.
  const metadataBaseRef = args.compareBaseRef ?? remoteTrackingBase?.ref ?? baseBranch
  let configuredPushTarget: GitPushTarget | undefined
  if (preparedPushTarget) {
    configuredPushTarget = await configureCreatedWorktreePushTargetWithExec(
      (args, cwd) => provider.exec(args, cwd),
      created.path,
      branchName,
      preparedPushTarget
    )
  }
  const metaUpdates: Partial<WorktreeMeta> = {
    // Why: path-derived IDs get reused after external deletion; rotate instance identity so stale lineage can't attach to the new occupant.
    instanceId: randomUUID(),

View on GitHub (pinned to 1136503c6a)

Solutions

  1. Retry the create — a transient listing lag often clears on the next listWorktrees call.
  2. Reconnect the SSH host to refresh the relay state and ensure listWorktrees is current.
  3. 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).
  4. Check for a concurrent process deleting or moving the worktree between add and list.

Example fix

// before
const created = gitWorktrees.find(
  (gw) => gw.branch?.endsWith(branchName) || gw.path.endsWith(effectiveSanitizedName)
)
if (!created) {
  throw new Error('Worktree created but not found in listing')
}

// after — reuse the shared reconciler that handles path canonicalization
const created = findCreatedWorktree(gitWorktrees, requestedPath, branchName)
if (!created) {
  throw new WorktreeCreatedButUnlistedError({ requestedPath, branchName, listed: gitWorktrees })
}
Defensive patterns

Strategy: retry

Validate before calling

// Optional preflight: confirm listing reflects recent state
const listed = await provider.listWorktrees(repo.path)
// if listing looks stale, force a refresh before relying on it
if (!listed.some(gw => gw.branch?.endsWith(branchName))) {
  await provider.refreshWorktreeList?.(repo.path)
}

Try / catch

catch (err) {
  if (err instanceof Error && err.message === 'Worktree created but not found in listing') {
    // listing lag: wait briefly and re-list once
    await delay(200)
    const retry = await provider.listWorktrees(repo.path)
    const found = retry.find(gw => gw.branch?.endsWith(branchName) || gw.path.endsWith(effectiveSanitizedName))
    if (!found) throw err
    return found
  }
  throw err
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of stablyai/orca@1136503c6a (2026-08-12). Data as JSON: /api/errors/9beabb809424d574. Report an issue: GitHub.