on main help sign in
fix(pubsub): raise default per-subscriber buffer (64 -> 4096)

There still seems to be a TUI-sync issue on upstream/main where the assistant cuts off mid-sentence on screen even though the DB has the full response. Two recent PRs probably get most of the way to fixing it: #2840 reordered the agent's TypeAgentFinished notification past the activeRequests cleanup, and #2836 made channelBufferSize actually honored. In power-user cases the default (64) is still too small, though. A streaming turn calls messages.Update on every OnTextDelta / OnReasoningDelta callback, and the TUI's glamour re-render periodically stalls the Update loop for tens to hundreds of milliseconds at a time. 64 slots fill before drain catches up and the non-blocking publish in broker.go silently drops the rest. This diff adopts a pretty aggressive fix -- 64 -> 4096 covers a long turn at typical SSE rates even under pathological View() stalls. Cost is a few MB of ring-buffer allocation across all brokers, comfortably inside any modern dev machine's budget; users on tighter memory targets can still tune via NewBrokerWithOptions. Drive-by cleanup: maxEvents (struct field + NewBrokerWithOptions param) is set to 1000 by default but never read anywhere in tree -- it's bufferSize, not maxEvents, that actually bounds the queue. Drop maxEvents on the theory that misleading dead code is worse than no code. ๐Ÿ’˜ Generated with Crush Assisted-by: Claude Opus 4.7 via Crush <crush@charm.land>

commit0585f498ba16b43902708aec87914fbd63c68e8d authorSven Olsen <sven2718@gmail.com> dateMon 11 May 2026, 14:48 (5 months ago) parenta19dd58
1 file changed+7โˆ’5
internal/pubsub/broker.go+7โˆ’5
internal/pubsub/broker.go+7โˆ’5
@@ -5,26 +5,28 @@ import (
55 "sync"
66)
77
8โˆ’const bufferSize = 64
8+// bufferSize is the per-subscriber channel capacity for any broker
9+// created via NewBroker. Publish is non-blocking, so a full buffer
10+// silently drops events; sized to cover a long streaming assistant
11+// turn (~one UpdatedEvent per token) even under TUI render stalls.
12+const bufferSize = 4096
913
1014type Broker[T any] struct {
1115 subs map[chan Event[T]]struct{}
1216 mu sync.RWMutex
1317 done chan struct{}
1418 subCount int
15โˆ’ maxEvents int
1619 channelBufferSize int
1720}
1821
1922func NewBroker[T any]() *Broker[T] {
20โˆ’ return NewBrokerWithOptions[T](bufferSize, 1000)
23+ return NewBrokerWithOptions[T](bufferSize)
2124}
2225
23โˆ’func NewBrokerWithOptions[T any](channelBufferSize, maxEvents int) *Broker[T] {
26+func NewBrokerWithOptions[T any](channelBufferSize int) *Broker[T] {
2427 return &Broker[T]{
2528 subs: make(map[chan Event[T]]struct{}),
2629 done: make(chan struct{}),
27โˆ’ maxEvents: maxEvents,
2830 channelBufferSize: channelBufferSize,
2931 }
3032}