Skip to content

[api] SSE backlog replay interleaves and duplicates events, breaking the ordering contract #366

Description

@duyet

Severity: P2 · Effort: M · Risk: MED (Durable Object streaming) · Category: bug

Plan: plans/008-sse-backlog-ordering.md

Why this matters

StateStreamHub.watch() adds the client's writer to the broadcast set before replaying the backlog. A /notify broadcast arriving during the (awaited, D1-backed) backlog drain writes to that same writer — interleaving a new event among, possibly ahead of, older backlog events. An event present in both the backlog query and the concurrent broadcast is delivered twice.

This breaks the ordered, gap-free replay contract implied by after/Last-Event-ID (id: <sequence> lines). Clients tracking sequence see regressions or duplicates.

Blocked on a deeper bug

Plan 008's target design preserves the await-before-return structure that causes the deadlock in the linked issue below, so the plan as written is unimplementable — its own regression test would hang. Both are being fixed together, since the ordering fix is unreachable without the deadlock fix.

From automated audit 2026-07-17.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    auditbugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions