Skip to content

Fix the crash opening Settings → Second brain - #24

Merged
moderniselife merged 1 commit into
mainfrom
fix-second-brain-crash
Nov 16, 2026
Merged

moderniselife merged 1 commit into
mainfrom
fix-second-brain-crash

Conversation

@moderniselife

Copy link
Copy Markdown
Owner

Clicking Second brain in the sidebar crashed Prism 1.5.0 (EXC_BREAKPOINT, BUG IN CLIENT OF LIBDISPATCH: trying to lock recursively).

Cause: BrainiumSetup.hasGit is a lazy static let that ran xcode-select -p the first time the Second brain page read it while drawing. Process.waitUntilExit() spins the main run loop while it waits, so SwiftUI redrew the page mid-call, read hasGit again while its dispatch_once was still running, and libdispatch trapped.

Fix

  • hasGit checks for git on disk (DEVELOPER_DIR, the folder xcode-select points at, the Command Line Tools, Xcode) without running anything.
  • New Process.launchForBlockingWait() waits on a semaphore signalled by the termination handler. It replaces all four waitUntilExit() calls (Brainium setup, the Brainium CLI bridge, the ps snapshot, the self-updater), so none of them can re-enter SwiftUI when called on the main thread.
  • The Brainium CLI's stderr is drained on its own thread so a chatty run can't stall on a full pipe.

Tested on macOS 27.2.1: ./build.sh builds with no warnings. A probe drew SecondBrainSettingsView in a window and forced 40 redraws while running tools on the main thread: no crash, and hasGit found Xcode at its non-default path.


Generated by Claude Code

BrainiumSetup.hasGit ran xcode-select the first time a view read it, and
Process.waitUntilExit() spins the main run loop while it waits. SwiftUI
then redrew the Second brain page mid-call, read hasGit again while its
dispatch_once was still running, and libdispatch trapped ("trying to lock
recursively").

- hasGit now checks for git on disk: DEVELOPER_DIR, the folder
  xcode-select points at, the Command Line Tools, then Xcode.
- Every waitUntilExit() is replaced by Process.launchForBlockingWait(),
  which waits on a semaphore signalled from the termination handler, so
  no call that runs a tool on the main thread can re-enter SwiftUI.
- The Brainium CLI's stderr is drained on its own thread so a chatty run
  can't stall on a full pipe.
@moderniselife
moderniselife merged commit d25d573 into main Nov 16, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant