Repository navigation
fix(deploy): set Email Routing routes to a Worker after the upload - #6
Merged
Merged
Conversation
A rule or catch-all whose action is `worker` was reconciled in deploy preparation, before Wrangler uploaded the script. Cloudflare refuses such a route while the Worker does not exist (`2016: Workers Script Info not found`), so an app routing mail to its own Worker failed on its first deploy into an account. Preparation (`provisionZoneResources`) now skips every `worker` route and hands back `provisionAfterUpload`, bound to the same account and API. The deploy command runs it once the upload is proven (and, for a percentage rollout, after the traffic split), so a failed upload never reaches it. A failure there exits 1 with a message saying the Worker WAS uploaded, which route failed and why, and what this run had already set. Everything else (sending onboarding, enabling routing, destinations, forward/drop rules and catch-alls, DNS) keeps its place and order in preparation. Deferral covers every `worker` action, not only self-targeted ones: one predicate, deterministic, and harmless for a Worker that already exists. A version-only upload (percentage rollout) runs the step too, because the script exists after it and preparation has already reconciled the zone's other routes. Previews still have no zone work at all. `--dry-run` runs the step against the stubbed API and lists its would-creates as "after the upload". Rule priority stays the index in the whole declared list. Rule and catch-all reads and writes now throw `EmailRouteError`, naming the route and keeping Cloudflare's error as the cause. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review follow-up to 1c84635. - Order: the step runs only after the upload is proven. New command-flow cases cover a Wrangler exit 0 with no upload evidence (no catch-all write) and a percentage rollout (split first, then the route; a failed split skips it). - Messages: `EmailRouteError` now carries the operation (read/write) and the target Worker. A failed read says nothing about the route changed; a failed write names the Worker it hands mail to; a route to ANOTHER Worker says to deploy that one first instead of suggesting a re-run that cannot fix it. - Early exits: a reused live version runs the step before a required-fresh deployment is refused (adding a worker rule never changes the upload, so that refusal used to block the route forever). The failed-upload, unproven-upload, unresolved-account, failed-verification and failed-rollout exits now name the Worker routes left unset (`describeWorkerEmailRoutes`). - Propagation: a write answered with 2016 is retried three times, 3 s apart (`DEVFLARE_EMAIL_ROUTE_RETRY_DELAY_MS` overrides the delay; tests inject a sleep). Nothing else is retried. How long Email Routing actually takes to see a new Worker is not measured; the changeset and docs say only what the code does. - The after-upload result field is now `afterUpload: { routes, provision }`. - Dropped the "waiting costs nothing" claim: a route to a misspelled Worker now fails after the Worker ships. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: fc5de95 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
github-actions
Bot
had a problem deploying
to
testing branch preview / fix/email-routing-after-upload
December 1, 2026 01:27
Failure
…wn file, under the size ceiling The after-upload deferral and the 2016 retry took deploy-zones.test.ts from 950 to 1281 lines, past the 1000-line ceiling source-file-size.test.ts enforces. The two describe blocks for the routes set after the upload move to deploy-zones-after-upload.test.ts, and the mock zone API and the two pass runners both files use move to tests/helpers/zone-provision-api.ts. 54 tests before, 54 after. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
github-actions
Bot
had a problem deploying
to
testing branch preview / fix/email-routing-after-upload
December 1, 2026 01:36
Failure
This branch had an error being deployed
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.
Why
devflare deploy --prodof an app whosezones[domain].emailRoutingroutes mail to a Worker — for examplecatchAll: { worker: '<its own worker>' }— failed on its first deploy into an account where that Worker did not exist yet:Zone provisioning ran during deploy preparation, before Wrangler uploaded the script, so a route to the app's own Worker could never be set on a first deploy.
What changes
workeris now set after the upload is proven, and after a percentage rollout's traffic split. Everything else stays in preparation, in its old order: Email Sending, enabling routing, destination addresses, forward and drop routes, DNS, event subscriptions.DEVFLARE_REQUIRE_FRESH_PRODUCTION_DEPLOYMENTsets the routes before refusing, so the refusal can no longer block a route for good.DEVFLARE_EMAIL_ROUTE_RETRY_DELAY_MSoverrides the wait. How long Email Routing takes to see a new Worker is not measured, so the docs only describe the retry.--dry-runlists the deferred routes as "after the upload" and still makes no write.Checks
tests/unit/config/deploy-zones.test.ts,tests/unit/cli/deploy-after-upload.test.tsandtests/integration/cli/deploy-email-routing-after-upload.test.ts: 69 pass, 0 fail.tsgo --noEmitis clean.🤖 Generated with Claude Code