From ceb8218b9ea85d8a123a9412dc2847b9e6186af8 Mon Sep 17 00:00:00 2001 From: Duyet Le Date: Fri, 17 Jul 2026 08:56:04 +0700 Subject: [PATCH] docs(api): flag SSE backlog-replay ordering + deadlock in state-stream-hub Inline note for reviewers ahead of the fix: `watch()` currently registers the writer before the backlog replay completes (the known ordering bug from plans/008), and separately, `writeBacklog`'s writes cannot resolve until a reader attaches to `stream.readable`, which never happens because the Response wrapping it is only returned after the backlog write loop finishes -- deadlocking any request with a non-empty backlog. Verified against the real Durable Object runtime. Functional fix follows in a subsequent commit on this branch. Co-Authored-By: Duyet Le Co-Authored-By: duyetbot --- packages/api/src/state-stream-hub.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/api/src/state-stream-hub.ts b/packages/api/src/state-stream-hub.ts index 391b8c36..066c1c29 100644 --- a/packages/api/src/state-stream-hub.ts +++ b/packages/api/src/state-stream-hub.ts @@ -42,6 +42,16 @@ export class StateStreamHub extends DurableObject { } private async watch(projectId: string, after: number, signal: AbortSignal): Promise { + // FIXME(ordering + deadlock, see PR): `this.writers.add(writer)` below runs + // before `writeBacklog` completes, so a concurrent `/notify` can interleave + // or duplicate events ahead of the backlog replay. Separately (verified + // against the real DO runtime via vitest-pool-workers): `writer.write()` + // cannot resolve until something reads `stream.readable`, but the + // `Response` wrapping it is only returned after `await writeBacklog(...)` + // below completes -- so any backlog with 1+ rows deadlocks the request + // today. Fix in progress: return the Response immediately and run + // backlog-write + buffered-broadcast-flush + writer-registration as + // background work. const stream = new TransformStream(); const writer = stream.writable.getWriter(); this.writers.add(writer);