Which mechanism triggers automatic rollbacks for failed Cloudflare Worker deployments?
0 reputation · 11 Sept 2022, 07:32 UTC
0 reputation · 11 Sept 2022, 07:32 UTC
Cloudflare Workers utilize atomic deployments, ensuring that if a script upload fails, the previous version remains active. While the Workers API and Wrangler CLI provide a rollback operation to restore a specific deployment ID, this process is currently manual.
In a continuous deployment pipeline, there is uncertainty regarding whether the platform supports a native, automated trigger to revert to the last known good version based on runtime health checks or deployment failure signals, rather than requiring an external API call.
Cloudflare Workers does not provide a built-in, native trigger that automatically rolls back a Worker after a failed deployment or a runtime health-check failure. The only automatic safety behavior is atomic deployment: if a script upload fails validation, the previously active version keeps serving. A valid script that crashes at runtime is considered a successful deployment and will not be reverted by the platform.
Confirmed: Deployments are atomic. A failed upload does not replace the active version. Rollback is an explicit, manual operation available through the Cloudflare dashboard, the Workers API, and Wrangler.
Recommended pattern: Because no native health-check trigger exists, automated recovery must be built in your CI/CD pipeline. Record each deployment ID, run post-deploy verification, and invoke the documented rollback operation with the last known good ID when checks fail.
An illustrative pipeline step (verify exact flags against your Wrangler version):
# Capture the active deployment ID before deploy
GOOD_ID=$(wrangler deployments list --name my-worker --json | jq -r '.[0].id')
# Deploy the new version
wrangler deploy --name my-worker
# Run a health check; roll back if it fails
if ! curl -fsS https://my-worker.example.workers.dev/health; then
wrangler rollback --name my-worker "$GOOD_ID"
fi
Cloudflare's deployment history, gradual rollout features, and CI integrations evolve. Treat automatic rollback as unsupported unless current product documentation explicitly lists a health-check or auto-revert setting. Also, Workers for Platforms and service-environment deployments may expose a different API surface than a standalone Worker script.
One diagnostic question: Are you deploying a standalone Worker script or using Workers for Platforms? The answer determines which rollback endpoint and deployment history API you should target.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.