Skip to content

fix: await live SSE protocol writes before terminal done event#361

Merged
schmug merged 2 commits into
mainfrom
cursor/critical-correctness-bugs-986c
May 24, 2026
Merged

fix: await live SSE protocol writes before terminal done event#361
schmug merged 2 commits into
mainfrom
cursor/critical-correctness-bugs-986c

Conversation

@cursor
Copy link
Copy Markdown
Contributor

@cursor cursor Bot commented May 24, 2026

Bug and impact

On cache-miss /api/check/stream scans, protocol SSE events were emitted with unawaited stream.writeSSE() calls. The terminal done event was fixed in #303, but protocol frames could still be dropped when the stream closed—users could see the grade header/footer while protocol cards stayed on skeleton placeholders.

Root cause

Same race as #303: Hono streamSSE can close before fire-and-forget writes flush. Only done was awaited after that fix.

Fix

  • Collect pending protocol writeSSE promises during scanStreaming callbacks
  • await Promise.all(protocolWrites) before emitting done
  • Added cache-miss regression test that drains the live SSE body

Validation

  • npm run lint
  • npm run typecheck
  • npm test (1051 tests)
Open in Web View Automation 

The live /api/check/stream path awaited only the terminal `done` write
(#303) while protocol events were still fire-and-forget. Under Hono’s
streamSSE lifecycle those frames can be dropped before the client reads
them, leaving skeleton cards on the progressive /check page.

Collect pending protocol writeSSE promises, flush them with Promise.all,
then emit `done`. Add a cache-miss regression test that drains the body.

Co-authored-by: schmug <schmug@users.noreply.github.com>
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented May 24, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
dmarcheck ba44b90 May 24 2026, 03:01 PM

@schmug schmug marked this pull request as ready for review May 24, 2026 15:00
@schmug schmug self-requested a review as a code owner May 24, 2026 15:00
Copy link
Copy Markdown
Owner

@schmug schmug left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@schmug schmug merged commit 441b652 into main May 24, 2026
5 checks passed
@schmug schmug deleted the cursor/critical-correctness-bugs-986c branch May 24, 2026 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants