Skip to content

fix: resolve 4 critical AI bugs#617

Merged
datlechin merged 1 commit intomainfrom
fix/ai-critical-bugs
Apr 7, 2026
Merged

fix: resolve 4 critical AI bugs#617
datlechin merged 1 commit intomainfrom
fix/ai-critical-bugs

Conversation

@datlechin
Copy link
Copy Markdown
Member

Summary

Fixes 4 ship-blocking bugs found during AI system audit:

  • B1 — Ghost text at wrong offset: Inline suggestion ghost text rendered at position 0 (or previous suggestion's offset) during progressive streaming. suggestionOffset was set after fetchSuggestion() returned, but showGhostText was called during streaming using the stale value. Fix: set offset before the await.
  • B2 — Tab key race condition: Pressing Tab to accept a suggestion did nothing because acceptSuggestion() was deferred via Task { @MainActor } to the next runloop tick, but handleTextChange() fired synchronously first and cleared currentSuggestion. Fix: call acceptSuggestion() synchronously (already inside MainActor.assumeIsolated).
  • B3 — Trim breaks Anthropic API: trimMessagesIfNeeded() could leave the conversation starting with an assistant message after removing oldest messages, causing Anthropic API 400 errors ("messages must start with user role"). Fix: drop leading assistant messages after trim.
  • B4 — Storage thread safety: AIChatStorage was a plain final class with no isolation. loadAll() ran on a detached thread while save()/delete() ran on MainActor — concurrent file I/O on the same directory. Fix: convert to actor, update all callers to await, rewrite deleteAll() to enumerate files instead of removing the directory.

Test plan

  • Build succeeds with no new warnings
  • Enable inline suggestions, type SQL — ghost text appears at cursor position (not at line start)
  • Wait for ghost text, press Tab — suggestion inserts correctly
  • Send 200+ messages in AI chat — no API errors from role ordering
  • Open AI chat and send messages rapidly during app startup — no crashes or data loss

@datlechin datlechin force-pushed the fix/ai-critical-bugs branch from 89bea8b to 71199cd Compare April 7, 2026 09:56
@datlechin datlechin merged commit 00259a6 into main Apr 7, 2026
2 checks passed
@datlechin datlechin deleted the fix/ai-critical-bugs branch April 7, 2026 09:57
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