Skip to content

fix: AI chat freeze, performance, code quality (#774)#796

Merged
datlechin merged 3 commits intomainfrom
fix/ai-chat-freeze
Apr 19, 2026
Merged

fix: AI chat freeze, performance, code quality (#774)#796
datlechin merged 3 commits intomainfrom
fix/ai-chat-freeze

Conversation

@datlechin
Copy link
Copy Markdown
Collaborator

Closes #774

Summary

Fixes AI chat freezing when query results are included, plus 14 additional performance and code quality improvements.

Critical (freeze fix)

  • Cap currentQuery to 2000 chars in system prompt (was embedding full editor text, potentially MB)
  • Move buildSystemPrompt off @mainactor into Task.detached (was blocking main thread)
  • Cap cell values in query results summary to 200 chars (large JSONB/TEXT columns)
  • Pre-send size check: warns if total context exceeds 100KB

Performance

  • Inline suggestion token batching (50ms intervals instead of per-token MainActor dispatch)
  • Code block highlighting dedup (~190 lines of copy-paste reduced to shared function)
  • Scroll-to-bottom with defaultScrollAnchor(.bottom) (macOS 14+)

Features

  • maxOutputTokens configurable per provider (was hardcoded 4096/8192)
  • Gemini fallback model list when API fetch fails
  • Conversation file size cap (500KB, trims to last 50 messages)

Cleanup

  • Non-actor-isolated overloads for AIPromptTemplates
  • Deleted dead test code (CoordinatorShowAIChatTests)
  • Distinct provider icons in settings
  • Connection refresh on change in AI panel

Test plan

  • Build passes
  • Open large SQL file, enable include query/results, send AI message - no freeze
  • Query table with large JSONB column - AI chat works without lag
  • Stream long AI response - chat stays at bottom
  • Inline suggestions on fast model - no UI jank
  • Gemini with wrong endpoint - shows fallback model list

@datlechin datlechin merged commit ea06920 into main Apr 19, 2026
2 checks passed
@datlechin datlechin deleted the fix/ai-chat-freeze branch April 19, 2026 14:39
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.

AI chat freezes app when query results are included

1 participant