@@ -15,7 +15,6 @@ type RingBuffer struct {
1515 mu sync.RWMutex
1616 buf []BrowserEvent
1717 head int // next write position (mod cap)
18- count int // items currently stored (0..cap)
1918 written uint64 // total ever published (monotonic)
2019 notify chan struct {}
2120}
@@ -35,9 +34,6 @@ func (rb *RingBuffer) Publish(ev BrowserEvent) {
3534 rb .mu .Lock ()
3635 rb .buf [rb .head ] = ev
3736 rb .head = (rb .head + 1 ) % len (rb .buf )
38- if rb .count < len (rb .buf ) {
39- rb .count ++
40- }
4137 rb .written ++
4238 old := rb .notify
4339 rb .notify = make (chan struct {})
@@ -54,7 +50,7 @@ func (rb *RingBuffer) oldestSeq() uint64 {
5450 return rb .written - uint64 (len (rb .buf ))
5551}
5652
57- // NewReader returns a Reader positioned at seq 0 .
53+ // NewReader returns a Reader positioned at publish index 0 (the very beginning of the ring) .
5854// If the ring has already published events, the reader will receive an
5955// events_dropped BrowserEvent on the first Read call if it has fallen behind
6056// the oldest retained event.
@@ -63,9 +59,13 @@ func (rb *RingBuffer) NewReader() *Reader {
6359}
6460
6561// Reader tracks an independent read position in a RingBuffer.
62+ // A Reader must not be used concurrently from multiple goroutines.
63+ //
64+ // nextSeq is a monotonic count of publishes consumed by this reader — it is
65+ // an index into the ring, not the BrowserEvent.Seq field.
6666type Reader struct {
6767 rb * RingBuffer
68- nextSeq uint64
68+ nextSeq uint64 // publish index, not BrowserEvent.Seq
6969}
7070
7171// Read blocks until the next event is available or ctx is cancelled.
@@ -85,7 +85,7 @@ func (r *Reader) Read(ctx context.Context) (BrowserEvent, error) {
8585 r .nextSeq = oldest
8686 r .rb .mu .RUnlock ()
8787 data := json .RawMessage (fmt .Sprintf (`{"dropped":%d}` , dropped ))
88- return BrowserEvent {Type : "events_dropped" , Data : data }, nil
88+ return BrowserEvent {Type : "events.dropped" , Category : CategorySystem , SourceKind : SourceKernelAPI , Data : data }, nil
8989 }
9090
9191 // Event is available — read it.
0 commit comments