fix: implement complete goroutine cleanup on exit
Prevents application from hanging on exit by ensuring all goroutines terminate cleanly and resources are released in proper order. Event Bus Cleanup: - Event bus already closed via onQuit callback before tea.Quit processes - Added explicit bus.Close() in main cleanup (idempotent) - Removed redundant StopAll() from signal handler (avoid double-stop) - Signal handler only closes bus and quits TUI WaitGroup Tracking: - Add sync.WaitGroup to Commander to track running mysis goroutines - Increment WaitGroup in StartMysis before starting - Decrement WaitGroup in Mysis.run() defer when exiting - StopAll() now waits for all goroutines with c.wg.Wait() - Commander reference added to Mysis (optional variadic parameter) Provider Cleanup: - Add Close() method to Provider interface - Ollama and OpenCode providers already implement Close() - Add Close() to MockProvider (no-op) - Call provider.Close() in Mysis.Stop() after releasing account Goroutine Leak Detection: - Import runtime package - Log goroutine count at startup - Log goroutine count during shutdown - Log final count at exit - Enables detection of goroutine leaks during testing Shutdown Sequence: 1. User presses 'q' OR signal received 2. onQuit callback closes event bus (unblocks listener) 3. tea.Quit processed, TUI exits 4. program.Run() returns 5. StopAll() stops all myses, waits for goroutines 6. bus.Close() called (idempotent) 7. Accounts released 8. Store closed (deferred) 9. Log file closed (deferred) All resources now cleaned up properly without hangs. Implements: documentation/plans/2026-02-06-goroutine-cleanup-fixes.md Fixes: GOROUTINE_CLEANUP_ANALYSIS.md issues 1-5 Test status: All tests passing (76.8% core, 85.6% TUI)
xonecas2026-02-06
4c82dba1f4cccbe0c9c7da761306c2359225fafc
parent cac04bc