Skip to content

fix(cloudflare): dispatch for multiple queue consumers#466

Open
focux wants to merge 1 commit into
alchemy-run:mainfrom
focux:fix-worker-dispatch-multiple-listeners
Open

fix(cloudflare): dispatch for multiple queue consumers#466
focux wants to merge 1 commit into
alchemy-run:mainfrom
focux:fix-worker-dispatch-multiple-listeners

Conversation

@focux

@focux focux commented May 29, 2026

Copy link
Copy Markdown

Summary

Fix WorkerRuntimeContext.dispatch so it runs every listener that returns an Effect for a Worker event type instead of returning after the first one.

This matters for Cloudflare.messages(queue).subscribe(...): each queue subscription registers a queue listener, and that listener checks batch.queue inside the returned Effect. Since every queue listener returns an Effect before that internal queue-name check runs, the first registered queue listener can swallow events for later queue subscriptions by no-oping on queue mismatch.

Changes

  • collect all listener Effects for the dispatched event type
  • run multiple listener Effects concurrently, preserving the single-listener fast path
  • add a focused WorkerRuntimeContext unit test proving all listeners for an event type are invoked
  • extend the existing live Queue round-trip fixture with a second queue subscription on the same Worker, using different consumer settings, so the public Cloudflare.messages(...).subscribe(...) path catches this regression too

Verification

  • bun tsc -b packages/alchemy/tsconfig.test.json
  • git diff --check

Note: local bun vitest run ... currently fails before test collection in this checkout because the installed rolldown/oxfmt path hits a Bun node:util.styleText compatibility error. The new tests typecheck and follow the existing @/… test import convention.

@focux focux force-pushed the fix-worker-dispatch-multiple-listeners branch from 096d77e to ae9a332 Compare May 29, 2026 03:57
@john-royal john-royal changed the title Fix worker dispatch for multiple event listeners fix(cloudflare): dispatch for multiple queue consumers May 29, 2026
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