@@ -538,14 +538,19 @@ func (m *appModel) handleStartSpeak() (tea.Model, tea.Cmd) {
538538 return m , nil
539539 }
540540
541- m .transcriptCh = make (chan string , 100 )
541+ // Close any previous channel to unblock stale waitForTranscript goroutines.
542+ m .closeTranscriptCh ()
543+
544+ ch := make (chan string , 100 )
545+ m .transcriptCh = ch
542546 err := m .transcriber .Start (context .Background (), func (delta string ) {
543547 select {
544- case m . transcriptCh <- delta :
548+ case ch <- delta :
545549 default :
546550 }
547551 })
548552 if err != nil {
553+ m .closeTranscriptCh ()
549554 return m , notification .ErrorCmd (fmt .Sprintf ("Failed to start listening: %v" , err ))
550555 }
551556
@@ -562,6 +567,8 @@ func (m *appModel) handleStopSpeak() (tea.Model, tea.Cmd) {
562567 }
563568
564569 m .transcriber .Stop ()
570+ m .closeTranscriptCh ()
571+
565572 return m , tea .Batch (m .editor .SetRecording (false ), notification .SuccessCmd ("Stopped listening" ))
566573}
567574
@@ -578,6 +585,15 @@ func (m *appModel) waitForTranscript() tea.Cmd {
578585 }
579586}
580587
588+ // closeTranscriptCh closes the transcript channel and sets it to nil,
589+ // unblocking any goroutines waiting in waitForTranscript.
590+ func (m * appModel ) closeTranscriptCh () {
591+ if m .transcriptCh != nil {
592+ close (m .transcriptCh )
593+ m .transcriptCh = nil
594+ }
595+ }
596+
581597func (m * appModel ) handleElicitationResponse (action tools.ElicitationAction , content map [string ]any ) (tea.Model , tea.Cmd ) {
582598 if err := m .application .ResumeElicitation (context .Background (), action , content ); err != nil {
583599 slog .Error ("Failed to resume elicitation" , "action" , action , "error" , err )
0 commit comments