on main help sign in
feat(logs): add a log line for dropped events
b223e24Kieran Klukas
internal/pubsub/broker.go+7−4
@@ -2,13 +2,15 @@ package pubsub
2
2
3import (
3import (
4 "context"
4 "context"
5+ "log/slog"
5 "sync"
6 "sync"
6)
7)
7
8
8// bufferSize is the per-subscriber channel capacity for any broker
9// bufferSize is the per-subscriber channel capacity for any broker
9// created via NewBroker. Publish is non-blocking, so a full buffer
10// created via NewBroker. Publish is non-blocking, so a full buffer
10−// silently drops events; sized to cover a long streaming assistant
11+// drops events (with a warning log); sized to cover a long streaming
11−// turn (~one UpdatedEvent per token) even under TUI render stalls.
12+// assistant turn (~one UpdatedEvent per token) even under TUI render
13+// stalls.
12const bufferSize = 4096
14const bufferSize = 4096
13
15
14type Broker[T any] struct {
16type Broker[T any] struct {
@@ -108,8 +110,9 @@ func (b *Broker[T]) Publish(t EventType, payload T) {
108 select {
110 select {
109 case sub <- event:
111 case sub <- event:
110 default:
112 default:
111− // Channel is full, subscriber is slow - skip this event
113+ // Channel is full, subscriber is slow — skip this event.
112− // This prevents blocking the publisher
114+ // This prevents blocking the publisher.
115+ slog.Warn("Pubsub buffer full; dropping event", "type", t)
113 }
116 }
114 }
117 }
115}
118}