ghost-os icon indicating copy to clipboard operation
ghost-os copied to clipboard

ghost setup: Vision model download fails — python3 resolved as relative path instead of via PATH

Open mcheemaa opened this issue 8 months ago • 1 comments

Bug Summary

ghost setup step 6 (Vision) fails to download the ShowUI-2B model on every fresh Homebrew install. The error is:

ERROR: Failed to run python3: Error Domain=NSCocoaErrorDomain Code=4
"The file "python3" doesn't exist."
UserInfo={NSFilePath=/Users/user/my-project/python3}

Notice the path: /Users/user/my-project/python3 — that's the current working directory prepended to python3. Swift's URL(fileURLWithPath:) resolves bare strings as relative paths against CWD, not via the system PATH.

Reproduction

100% reproducible on any fresh Homebrew install:

brew install ghostwright/ghost-os/ghost-os
cd /any/directory
ghost setup
# → Step 6 vision model download fails

Tested on macOS Sequoia 15.5, Apple Silicon, ghost-os v2.0.6 installed from Homebrew. Python 3.x is installed and available on PATH.

Root Cause

There are two interacting bugs in Sources/ghost/SetupWizard.swift:

Bug 1: Logic flaw skips venv creation when ghost-vision launcher exists (line 343)

if !hasPython && !hasLauncher {
    // setupPythonVenv() — only runs if BOTH conditions are true
}

On a Homebrew install, ghost-vision exists at /opt/homebrew/bin/ghost-vision, so hasLauncher = true. This makes the condition false, and setupPythonVenv() is never called. The venv at ~/.ghost-os/venv/bin/python3 is never created.

But having the bash launcher doesn't mean Python is available for the model download step that follows. The launcher is only needed at runtime to start the vision sidecar — the model download is a separate operation that needs Python directly.

Bug 2: downloadModel() uses bare "python3" with runShellLive (lines 480-486, 776)

// In downloadModel():
let venvPython = NSHomeDirectory() + "/.ghost-os/venv/bin/python3"
let python: String
if FileManager.default.isExecutableFile(atPath: venvPython) {
    python = venvPython
} else {
    python = "python3"  // ← bare string, not an absolute path
}

// In runShellLive():
process.executableURL = URL(fileURLWithPath: executable)  // ← resolves "python3" against CWD

Since the venv was never created (Bug 1), downloadModel() falls back to python = "python3". This bare string is passed to runShellLive(), which uses URL(fileURLWithPath: "python3"). Swift resolves this as <CWD>/python3 — a file that doesn't exist.

The irony

The codebase already solves this problem correctly in two other places:

  1. setupPythonVenv() (line 417-428) — checks hardcoded paths (/opt/homebrew/bin/python3, etc.) then falls back to which python3
  2. ghost-vision bash script (line 62) — uses command -v python3 for proper PATH resolution

But downloadModel() has neither of these safeguards.

Secondary issue: VisionBridge.findPython() (line 284-299)

private static func findPython() -> String? {
    let venvPython = NSHomeDirectory() + "/.ghost-os/venv/bin/python3"
    if FileManager.default.isExecutableFile(atPath: venvPython) {
        return venvPython
    }
    for path in ["/opt/homebrew/bin/python3", "/usr/local/bin/python3"] {
        if FileManager.default.isExecutableFile(atPath: path) {
            return path
        }
    }
    return nil  // ← No PATH fallback, misses pyenv/conda/nix/asdf installs
}

This function returns nil instead of falling back to a PATH-based lookup, which would break for users with Python installed via pyenv, conda, nix, asdf, or other non-standard locations.

Who This Affects

Every user who:

  • Installs Ghost OS from Homebrew (the recommended install method)
  • Runs ghost setup for the first time
  • Does NOT already have mlx_vlm installed in a system Python

This is the default path for all new users following the README instructions.

Expected Behavior

ghost setup should successfully find the system Python and download the ShowUI-2B model regardless of the user's current working directory or Python installation method.

Environment

  • macOS Sequoia 15.5 (Darwin 24.6.0)
  • Apple Silicon (arm64)
  • ghost-os v2.0.6 (Homebrew)
  • Python 3.x installed via Homebrew, available on PATH

mcheemaa avatar Mar 10 '26 04:03 mcheemaa

Fix submitted in #2 — changes SetupWizard.swift and VisionBridge.swift to always resolve python3 to an absolute path before passing it to Process.

mcheemaa avatar Mar 10 '26 04:03 mcheemaa