fix(events): dedupe SSE emission, scope live streams, fix reconnect leak - #26
Merged
Merged
Conversation
Fixes the July 2026 audit's SSE/event-streaming cluster: - Add an EventPollCursor to @agentops/db pairing an inclusive (gte) since boundary with the event IDs already emitted at that timestamp, so polling emits each event exactly once without dropping a second event that shares the boundary timestamp. Used by both the web SSE route and CLI 'events tail', which previously re-emitted the newest event on every poll. - useEvents: hold events + total in one state object updated through a pure applyLiveEvent reducer, so the 'N total' counter only increments when an event is genuinely new instead of on every SSE delivery. - useEventSource: store the backoff reconnect timer handle and clear it on cleanup and on (re)connect, so unmount/filter changes can no longer leak a pending reconnect that opens an EventSource nobody closes. - Forward view/userId scope params on the SSE connection from useRuns and useEvents (plus a client-side run.userId guard in useRuns), so an admin viewing ?userId=X no longer sees other users' live runs/events. - SSE route: re-resolve the owned sourceId set on each poll so runs and sessions created after connect appear in the owner's live stream without a reconnect. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the SSE/event-streaming bug cluster from the July audit's medium tier:
sincetimestamp, so the newest event (and any sharing its timestamp) was re-enqueued every 2s forever. New sharedEventPollCursorin@agentops/dbtracks seen IDs at the boundary timestamp: no re-emits, and a late arrival sharing an already-emitted timestamp still gets delivered exactly once (a baregtwould drop it).applyLiveEventreducer, unit-tested).setTimeouthandle is stored and cleared on unmount/filter change, so a pending reconnect can't open an orphan EventSource (each leaked stream kept a server-side 2s poll + 15s ping alive).useRuns/useEventsnow forward the admin'sview/userIdscope to the SSE URL (previously the filter silently stopped applying the moment anything streamed), with a client-side guard inuseRunsas belt-and-suspenders.agentops events tailreuses the same cursor, fixing its identical reprint-every-second bug.Tests
Cursor pure-function + real-SQLite integration tests (incl. shared-timestamp insert between polls), an explicit test pinning
listEvents' inclusive-sincesemantics the cursor relies on, and reducer tests for the total counter. No React-rendering tests — the repo has no jsdom setup, so hook changes are covered via extracted pure logic (noted in-code). Full workspace suite green (1,302 tests), web lint clean.Known pre-existing gap left as-is: a poll reads at most 100 events, so a >100-event burst between polls can skip the overflow.
🤖 Generated with Claude Code