Skip to content

fix: resolve AI Chat crash and hang during streaming on macOS 15.x#860

Merged
datlechin merged 3 commits intomainfrom
fix/ai-chat-scroll-crash
Apr 24, 2026
Merged

fix: resolve AI Chat crash and hang during streaming on macOS 15.x#860
datlechin merged 3 commits intomainfrom
fix/ai-chat-scroll-crash

Conversation

@datlechin
Copy link
Copy Markdown
Collaborator

Closes #852

Summary

  • Scroll to stable "bottomAnchor" (1pt fixed view) instead of streaming message whose height changes every flush
  • No animation during streaming auto-scroll to prevent conflicting with user scroll gestures
  • Remove .fixedSize(horizontal: false, vertical: true) from AIChatMessageView — redundant in LazyVStack and forces expensive re-measurement on every content flush
  • Pre-compute turn-spacing Set<UUID> outside ForEach to replace O(n) firstIndex per visible message per frame
  • Increase streaming flush interval from 80ms to 150ms to reduce layout churn (still smooth to read)
  • Reset isUserScrolledUp on conversation switch to prevent stale scroll state

Root cause

On macOS 15.2, three sources compete for scroll position during streaming: (1) animated scrollTo targeting a growing message, (2) the user's scroll gesture, (3) LazyVStack recalculating layout from height changes forced by .fixedSize. This triggers an NSScrollView layout assertion. Apple fixed the framework issue in later macOS versions, which is why it doesn't reproduce on macOS 26.

Test plan

  • Small window: send message while AI streams — content should stay visible, not blank
  • Scroll up during streaming — auto-scroll stops, "scroll to bottom" button appears
  • Scroll back to bottom — auto-scroll resumes
  • Tap scroll-to-bottom button — smooth animated scroll
  • Conversation switch — scrolls to bottom of new conversation
  • Streaming ends — smooth animated settle to bottom
  • Long responses with code blocks, tables — render full height (no truncation from .fixedSize removal)
  • Turn spacing: extra gap between assistant→user turns, no gap between consecutive user messages

@datlechin datlechin merged commit eedc914 into main Apr 24, 2026
2 checks passed
@datlechin datlechin deleted the fix/ai-chat-scroll-crash branch April 24, 2026 09:26
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.

Crash in Chat AI

1 participant