Skip to content

fix: SyntaxHighlighter crashes on background queue due to implicit MainActor isolation #693

@batonogov

Description

@batonogov

Summary

Pine crashes immediately on launch when opening a file. SyntaxHighlighter.resolveGrammar(language:fileName:) is called on the background com.pine.syntax-highlight serial queue, but Swift runtime asserts MainActor isolation and triggers dispatch_assert_queue_failSIGTRAP.

Crash Stack

Thread 1 Crashed:: Dispatch queue: com.pine.syntax-highlight (QOS: USER_INITIATED)
_dispatch_assert_queue_fail
dispatch_assert_queue
_swift_task_checkIsolatedSwift
swift_task_isCurrentExecutorWithFlagsImpl
closure #1 in SyntaxHighlighter.resolveGrammar(language:fileName:) (SyntaxHighlighter.swift:500)
SyntaxHighlighter.resolveGrammar(language:fileName:) (SyntaxHighlighter.swift:500)
SyntaxHighlighter.computeMatches (SyntaxHighlighter.swift:674)
SyntaxHighlighter.highlightAsync (SyntaxHighlighter.swift:802)

Root Cause

SWIFT_DEFAULT_ACTOR_ISOLATION = MainActor in build settings makes SyntaxHighlighter (a class) implicitly @MainActor. But highlightAsync dispatches work to a background serial queue (com.pine.syntax-highlight), and resolveGrammar accesses @MainActor-isolated state from that queue. Swift runtime detects the violation and crashes.

Motivation

App crashes on launch — completely blocks usage.

Implementation ideas

  • Mark SyntaxHighlighter as nonisolated (it manages its own thread safety via NSLock + serial queue)
  • Or mark specific methods/closures as nonisolated / @Sendable
  • Same pattern may affect other classes that do background work: GitStatusProvider, ProjectSearchProvider, WorkspaceManager
  • Audit all classes that dispatch to background queues

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpriority: highCritical priority

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions