Skip to content

Crash loop on launch after deleting a worktree with an open window #2

@tJala

Description

@tJala

Summary

Ghostree enters a crash loop on launch after deleting a git worktree that had an open terminal window. The app crashes within ~2 seconds of launch every time, until the laptop is restarted (which clears macOS's restoration state).

Root Cause

macOS saves window restoration state in ~/Library/Saved Application State/dev.sidequery.Ghostree.savedState/. When a worktree is deleted while Ghostree has a window open in that directory, the saved state still references the now-nonexistent path. On next launch, AppKit tries to restore the window with that working directory and crashes (EXC_BREAKPOINT in AppKit).

The windows.plist in the saved state contains an entry like:

"NSTitle" => "~/Projects/myrepo.feature-branch"

...but the worktree (and directory) no longer exists.

Steps to Reproduce

  1. Create a git worktree (e.g., git worktree add ../myrepo.feature-branch feature-branch)
  2. Open a Ghostree window with the working directory set to the worktree path
  3. Delete the worktree (git worktree remove ../myrepo.feature-branch or just rm -rf the directory)
  4. Quit Ghostree
  5. Relaunch Ghostree — it crashes immediately, every time

Crash Details

  • Crash reason: EXC_BREAKPOINT / EXC_ARM_BREAKPOINT
  • Crashed in: AppKit + 0x315388 (main thread, during window restoration/run loop)
  • Process uptime at crash: ~2 seconds
  • Version: Ghostree 0.3.9
  • OS: macOS 14.1.0 (Sonoma), arm64

Workaround

Delete the saved application state:

rm -rf ~/Library/Saved\ Application\ State/dev.sidequery.Ghostree.savedState

Or restart the laptop (macOS eventually gives up on restoration after repeated crashes).

Suggested Fix

The window restoration codepath should gracefully handle missing working directories — e.g., fall back to $HOME or skip restoring that window — instead of passing a nonexistent path to AppKit which triggers a crash.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions