Skip to content

fix(deploy): scope npm run deploy to --env production#175

Open
chitcommit wants to merge 1 commit intomainfrom
fix/wrangler-deploy-env-flag
Open

fix(deploy): scope npm run deploy to --env production#175
chitcommit wants to merge 1 commit intomainfrom
fix/wrangler-deploy-env-flag

Conversation

@chitcommit
Copy link
Copy Markdown
Contributor

⚠️ DO NOT ENABLE AUTO-MERGE

This PR's merge will trigger Workers Builds → production deploy. Verify the diff and manually merge when ready. The current production worker (3d46be98, healthy) is a manual rollback; the moment any commit lands on main, CI re-deploys.

Summary

package.json had "deploy": "wrangler deploy" with no --env flag. Workers Builds runs that verbatim. Without --env, wrangler reads only the top-level config block, where the only declared binding is secrets_store_secrets. Every other binding (KV / DO / D1 / R2 / Vectorize / queues / services / AI / Worker Loader / vars / routes / triggers) is correctly scoped under env.production per the canonical pattern documented in wrangler.jsonc:16-20.

Net effect: every CI deploy produces a worker with 17 secrets and zero resource bindings. The runtime tries to use env.MCP_AGENT / env.DB / env.OAUTH_KV / etc, gets undefined, and the OAuthProvider chain resolves to non-Response — Cloudflare returns 1101 across every path.

This was the regression mechanism for both:

Local wrangler deploy --env production reads the env block and produces a healthy bundle — same wrangler.jsonc, different invocation, opposite outcomes. The fix is one line of script change; no wrangler.jsonc edits needed.

Diff

-    "deploy": "wrangler deploy",
+    "deploy": "wrangler deploy --env production",
+    "deploy:staging": "wrangler deploy --env staging",
+    "deploy:production": "wrangler deploy --env production",

The aliases are belt-and-suspenders: npm run deploy always means production now, but explicit deploy:staging / deploy:production aliases let callers be unambiguous. Revertable in one line if Workers Builds is later configured to use a different command.

Verification plan (post-merge)

# 1. Wait for Workers Builds to complete (~30-60s after merge)
npx wrangler deployments list --env production | head -10

# 2. Inspect the new version's bindings — should show ~50 binding lines, not 17
npx wrangler versions view <new_version_id> --env production | tail -80

# 3. Health check
curl -s https://connect.chitty.cc/health | jq .status
# expect: "ok"

If the new deploy is broken, wrangler rollback 3d46be98-344c-4711-9e44-f5418ca84881 --env production restores the known-good state.

Why open this with auto-merge disabled

I broke prod once today by letting a merge trigger an auto-deploy from a CI invocation that was structurally wrong. Same root cause that broke prod yesterday after PR #168. Treating this PR as a controlled deploy gate so we observe the next CI build before allowing it to ship.

🤖 Generated with Claude Code

Workers Builds CI runs npm run deploy verbatim. With "deploy": "wrangler deploy"
(no --env), wrangler targets the top-level config block. Top-level only
declares secrets_store_secrets — every other binding (KV, DO, D1, R2,
Vectorize, queues, services, AI, Worker Loader, vars) is correctly scoped
under env.production but never read by the CI deploy.

Result: every CI deploy ships a worker with 16 secrets and zero other
bindings. The runtime tries to use env.MCP_AGENT, env.DB, env.OAUTH_KV,
etc, gets undefined, and Cloudflare returns 1101 across every path
because the fetch handler chain resolves to non-Response.

Local "wrangler deploy --env production" sees the env block and produces
a healthy bundle (this is how 3d46be98 was deployed). Same wrangler.jsonc,
different invocation, opposite outcomes.

Fix: scope the default deploy script to --env production. Add explicit
deploy:staging and deploy:production aliases for clarity. The existing
wrangler.jsonc already declares everything per-env (lines 16-20 even
warn that env blocks must be explicit) — no config change needed.

Verifying after merge: wrangler versions view <new_id> --env production
should show ~50 binding lines (full set) instead of just the 17
secrets_store_secrets entries.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 1, 2026 13:02
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@cloudflare-workers-and-pages
Copy link
Copy Markdown
Contributor

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
chittyconnect c295666 May 01 2026, 01:02 PM

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 1, 2026

Warning

Rate limit exceeded

@chitcommit has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 21 minutes and 31 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 06078c2f-b758-4908-9dd3-18a3a9a4562f

📥 Commits

Reviewing files that changed from the base of the PR and between 1828c1a and c295666.

📒 Files selected for processing (1)
  • package.json
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/wrangler-deploy-env-flag

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 21 minutes and 31 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Scopes the default npm deploy command to Cloudflare’s production environment to prevent CI/Workers Builds deployments from unintentionally using the top-level Wrangler config (missing most bindings) and causing production outages.

Changes:

  • Change npm run deploy to run wrangler deploy --env production.
  • Add explicit deploy:staging and deploy:production script aliases for clarity.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread package.json
Comment on lines +12 to +14
"deploy": "wrangler deploy --env production",
"deploy:staging": "wrangler deploy --env staging",
"deploy:production": "wrangler deploy --env production",
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