Skip to content

Commit 32feddb

Browse files
authored
Merge pull request #2286 from dgageot/board/fix-docker-agent-issue-2266-38c40343
fix: make chanSend non-blocking to prevent panic on closed channel
2 parents f010c3f + 94bb50b commit 32feddb

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

pkg/runtime/loop.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,17 @@ func formatToolWarning(a *agent.Agent, warnings []string) string {
576576
return strings.TrimSuffix(builder.String(), "\n")
577577
}
578578

579-
// chanSend wraps a channel as a func(Event) for use with emitAgentWarnings.
579+
// chanSend wraps a channel as a func(Event) for use with emitAgentWarnings
580+
// and RAG event forwarding. The send is non-blocking: if the channel is full
581+
// or closed, the event is silently dropped. This prevents a panic when a
582+
// long-lived goroutine (e.g. RAG file watcher) tries to forward an event
583+
// after the per-message events channel has been closed.
580584
func chanSend(ch chan Event) func(Event) {
581-
return func(e Event) { ch <- e }
585+
return func(e Event) {
586+
defer func() { recover() }() //nolint:errcheck // swallow send-on-closed-channel panic
587+
select {
588+
case ch <- e:
589+
default:
590+
}
591+
}
582592
}

0 commit comments

Comments
 (0)