ci: deploy with wrangler 4 and declare the rate limit as [[ratelimits]] - #245
Conversation
The KEY_EXCHANGE_LIMIT binding was declared under [[unsafe.bindings]] because the workflows pinned wrangler 3, which doesn't know the first-class [[ratelimits]] key (it needs wrangler 4.36.0 or later). Pin wrangler@4 in ci.yml, deploy.yml, preview.yml and the README, and declare the binding as [[ratelimits]] in all three environments, so wrangler validates it. The worker reads it through env.rate_limiter either way, so no code changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Claude finished @alukach's task in 10s —— View job ✅ No blocking issues — safe to merge. The diff is a mechanical change: Before the first production deploy, confirm that the Simplify (ponytail)
💰 Estimated review cost: $0.10 · 0m10s · 4 turns |
|
🚀 Latest commit deployed to https://source-data-proxy-pr-245.source-coop.workers.dev
|
What I'm changing
Follow-up to #235. The
KEY_EXCHANGE_LIMITrate limit binding is declared under[[unsafe.bindings]]because the workflows pin wrangler 3, and the first-class[[ratelimits]]key needs wrangler 4.36.0 or later. This moves the proxy to wrangler 4 and declares the binding the documented way, so wrangler validates it instead of passing anunsafeblock through unchecked.workers/public-log-streamis already on wrangler 4 (4.77.0 in its lockfile), so after this the whole repo is on v4.Decision to flag: wrangler 4 will start applying observability settings that wrangler 3 ignores. Wrangler 3 warns on the current
wrangler.tomlwithUnexpected fields found in observability field: "traces","destinations". So the Axiomdestinations = ["axiom-logs"]/["axiom-traces"]and the[observability.traces]block added in d0b46cb have probably never been applied from config, since every deploy since then went throughwrangler@3. The first wrangler 4 production deploy may start applying them. If theaxiom-logsandaxiom-tracesdestinations don't exist in the Cloudflare account, that deploy may fail; the preview and staging deploys won't catch it, because staging and preview setdestinations = []. Please confirm both destinations exist under Workers Observability → Destinations before this reaches production.How I did it
.github/workflows/ci.yml,deploy.yml,preview.ymlandREADME.md:wrangler@3→wrangler@4.wrangler.toml(production andenv.staging) andwrangler.preview.toml:[[unsafe.bindings]]→[[ratelimits]], droppingtype = "ratelimit". Name,namespace_id(1001, 1002, 1003) andsimple = { limit = 100, period = 60 }are unchanged.env.rate_limiter("KEY_EXCHANGE_LIMIT"), which doesn't care how it was declared.The pin bump and the config change have to land together. Wrangler 3 reports
Unexpected fields found in top-level field: "ratelimits"and would deploy without the binding.How to test it
wrangler deploy --dry-runwith wrangler 4.86.0 on a copy of each config (build step stubbed): production,--env stagingandwrangler.preview.toml --name …each listenv.KEY_EXCHANGE_LIMIT (100 requests/60s) Rate Limitwith no config warnings. The same production dry run on wrangler 3 shows theratelimitsand observability warnings quoted above.cargo fmt --check, clippy and check for wasm32,cargo test.wrangler devon wrangler 4 againsttests/test_api_keys.py, and this PR's preview deploy exerciseswrangler deployon v4.PR Checklist
Related Issues
Follows #235. Checked the ADRs: ADR-013 describes the per-IP limit, not how the binding is declared, so it still holds. ADR-008 says "In production, logs and traces ship to Axiom"; given the observability note above, that may not have been true while production deployed on wrangler 3, and this change makes it true, so ADR-008 needs no edit.
🤖 Generated with Claude Code