stablyai/orca · error

A worktree cannot be attached to itself.

Error message

A worktree cannot be attached to itself.

What it means

Thrown by validateWorkspaceLineageParentBeforeCreate when the supplied parentWorkspace key equals the childWorkspaceKey being created. A worktree cannot be its own parent in the workspace lineage graph — that would create a self-referential cycle. The check is a strict equality on the composite workspace keys and fires before any broader parent-existence validation.

Source

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

}

function getSetupRunnerCommandPlatformForLaunch(
  setup: CreateWorktreeResult['setup'],
  fallbackPlatform: 'windows' | 'posix'
): 'windows' | 'posix' {
  return getSetupRunnerCommandPlatformForPath(setup?.runnerScriptPath ?? '', fallbackPlatform)
}

function validateWorkspaceLineageParentBeforeCreate(
  store: Store,
  parentWorkspace: CreateWorktreeArgs['parentWorkspace'],
  childWorkspaceKey: ReturnType<typeof worktreeWorkspaceKey>
): void {
  if (!parentWorkspace) {
    return
  }
  if (parentWorkspace === childWorkspaceKey) {
    throw new Error('A worktree cannot be attached to itself.')
  }
  const parentScope = parseWorkspaceKey(parentWorkspace)
  if (!parentScope) {
    throw new Error(`Invalid parent workspace: ${parentWorkspace}`)
  }
  if (parentScope.type === 'folder' && !store.getFolderWorkspace(parentScope.folderWorkspaceId)) {
    throw new Error(`Parent folder workspace not found: ${parentWorkspace}`)
  }
  if (parentScope.type === 'worktree' && !store.getWorktreeMeta(parentScope.worktreeId)) {
    throw new Error(`Parent worktree workspace not found: ${parentWorkspace}`)
  }
}

function recordWorkspaceLineageForCreatedWorktree(
  store: Store,
  args: CreateWorktreeArgs,
  worktree: Worktree,
  createdAt: number

View on GitHub (pinned to 1136503c6a)

Solutions

  1. Pass a distinct parent workspace key (or omit parentWorkspace to create a top-level worktree).
  2. Fix the caller so the parent key is sourced from a different workspace than the child.
  3. Add an upstream equality check in the UI to disable self-attachment before submission.

Example fix

// before
createWorktree({ ..., parentWorkspace: childKey })
// after
createWorktree({ ..., parentWorkspace: distinctParentKey })
// or top-level:
createWorktree({ ..., parentWorkspace: undefined })
Defensive patterns

Strategy: validation

Validate before calling

function isSelfAttachment(parentWorkspace: string | undefined, childKey: string): boolean {
  return !!parentWorkspace && parentWorkspace === childKey
}
if (isSelfAttachment(args.parentWorkspace, childKey)) {
  throw new Error('Cannot attach a worktree to itself')
}

Try / catch

try {
  await createWorktree(args)
} catch (e) {
  if (/A worktree cannot be attached to itself/.test((e as Error).message)) {
    showFieldError('parent', 'Select a different parent or none.')
    return
  } else throw e
}

Prevention

When it happens

Trigger: createWorktree is called with parentWorkspace set to the same worktreeWorkspaceKey value computed for the new child. The lineage validation detects parentWorkspace === childWorkspaceKey and throws.

Common situations: A UI bug passes the currently-selected workspace's key as the parent of a worktree being created inside that same workspace. A programmatic caller computes both keys from the same source without distinguishing them. State desync after a workspace rename leaves parent and child keys identical.

Related errors


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