@@ -16,6 +16,7 @@ import (
1616 "github.com/charmbracelet/crush/internal/format"
1717 "github.com/charmbracelet/crush/internal/history"
1818 "github.com/charmbracelet/crush/internal/llm/agent"
19+ "github.com/charmbracelet/crush/internal/log"
1920 "github.com/charmbracelet/crush/internal/pubsub"
2021
2122 "github.com/charmbracelet/crush/internal/lsp"
@@ -230,6 +231,11 @@ func (app *App) InitCoderAgent() error {
230231}
231232
232233func (app *App) Subscribe(program *tea.Program) {
234+ defer log.RecoverPanic("app.Subscribe", func() {
235+ slog.Info("TUI subscription panic - attempting graceful shutdown")
236+ program.Quit()
237+ })
238+
233239 app.tuiWG.Add(1)
234240 tuiCtx, tuiCancel := context.WithCancel(app.globalCtx)
235241 app.cleanupFuncs = append(app.cleanupFuncs, func() {