fix(cloudflare): use queue dev.id for consumer resource ID in local dev mode#1364
Open
xiaoyu2er wants to merge 1 commit intoalchemy-run:mainfrom
Open
fix(cloudflare): use queue dev.id for consumer resource ID in local dev mode#1364xiaoyu2er wants to merge 1 commit intoalchemy-run:mainfrom
xiaoyu2er wants to merge 1 commit intoalchemy-run:mainfrom
Conversation
e6c94ab to
11f6ae2
Compare
commit: |
…ev mode
In local dev mode, Queue resources return an empty string for `id`
(Cloudflare API ID) since no remote API call is made. When a Worker
has multiple eventSources, all QueueConsumers were derived as
`${queue.id}-consumer` which all resolved to "-consumer",
causing concurrent Promise.all writes to the same state file.
This led to corrupted JSON state files and silently broken queue
consumers — the Worker HTTP endpoint would respond normally but
queue messages were never consumed.
Fix: use `queue.dev.id` (the resource ID, e.g. "email-queue") in
local dev mode, which is always unique per queue.
Fixes alchemy-run#1363
11f6ae2 to
f08822f
Compare
Mkassabov
requested changes
Mar 16, 2026
| // all consumers colliding on the same "-consumer" resource ID. | ||
| // See: https://github.com/alchemy-run/alchemy/issues/1363 | ||
| const queueConsumerId = options.local | ||
| ? eventSource.queue.dev?.id || eventSource.queue.id |
Collaborator
There was a problem hiding this comment.
wouldn't we want this the other way around?
const queueConsumerId = options.local
? eventSource.queue.id ?? eventSource.queue.dev?.id
: eventSource.queue.id;or if we know that the non-dev queue id is always going to be bad just
const queueConsumerId = options.local
? eventSource.queue.dev?.id
: eventSource.queue.id;
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In local dev mode,
Queueresources return an empty string forid(Cloudflare API ID) since no remote API call is made. When a Worker has multipleeventSources, all QueueConsumers are derived as${queue.id}-consumerwhich all resolve to"-consumer", causing concurrentPromise.allwrites to the same state file.This leads to:
alchemy devfails withSyntaxError: JSON Parse errorFix
Use
queue.dev.id(the resource ID, e.g."email-queue") in local dev mode instead ofqueue.id(empty""). Thedev.idis always unique per queue and available in dev mode.Reproduction
See #1363 for full details and a diagnostic script.
Quick summary: any Worker with 2+
eventSourcesinalchemy devmode will have all queue consumers writing to the same-consumer.jsonstate file.