Skip to content

fix(core): Keep the longest active rate limit for each category - #26410

Merged
JPeer264 merged 3 commits into
developfrom
fix/core-keep-longest-rate-limit
Nov 17, 2026
Merged

JPeer264 merged 3 commits into
developfrom
fix/core-keep-longest-rate-limit

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

What

A shorter rate limit no longer replaces a longer one that is still active. This applies to a category repeated in one X-Sentry-Rate-Limits header, to limits from later responses, and to the all limit from Retry-After or a 429 without headers.

Why

The spec requires keeping the longer limit. @itsrayeedscodespace reported the same bug in the Rust SDK in getsentry/sentry-rust#1409, and getsentry/sentry-rust#1410 fixed it by putting the rule in one type instead of calling max at each assignment.

Here, the header parsing is in a module-private forEachRateLimit function. It has no reference to the stored limits and reports each category and deadline through a callback. That callback in updateRateLimits is the only code that writes a limit, and it keeps the later deadline, so a new update path in the parser cannot shorten a limit. The transport stores the limits as Readonly<RateLimits>, so it can only replace them with the result of updateRateLimits.

RateLimits (Record<string, number>) and updateRateLimits are exported from @sentry/core, and replay-internal passes a plain {}. A branded or readonly public type would break that API, so RateLimits stays a mutable record. TypeScript does not stop code inside updateRateLimits, or a caller outside the transport that holds a RateLimits object, from writing to it directly.

Closes #26409

via @szokeasaurusrex.

--

View Session [Sentry]

`updateRateLimits` stored the last limit it saw for a category, so a shorter limit could replace a longer one that was still active. The spec requires keeping the longer one.

The parsing of the response now lives in a module-private function that only reports each category and deadline through a callback. It has no access to the stored limits. The callback in `updateRateLimits` is the only code that writes a limit, and it keeps the later of the stored and the new deadline, so no update path can shorten an active limit.

Fixes #26409

Co-Authored-By: Daniel Szoke <7881302+szokeasaurusrex@users.noreply.github.com>
Comment thread packages/core/src/utils/ratelimit.ts Resolved
@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

size-limit report 📦

Compared: 28237c9 (PR test merge using develop at 93949c4)

Against: 93949c4 (develop) · base run #66413

✅ Baseline matches: this diff contains only this PR's changes.

Path Size % Change Change
@sentry/browser 30.12 kB +0.08% +22 B 🔺
@sentry/browser - with treeshaking flags 28.32 kB +0.08% +21 B 🔺
@sentry/browser - with treeshaking flags tracing without tracing 28.22 kB +0.09% +23 B 🔺
@sentry/browser (incl. Tracing) 52.3 kB +0.04% +16 B 🔺
@sentry/browser (incl. Tracing + Span Streaming) 52.3 kB +0.04% +16 B 🔺
@sentry/browser (incl. Tracing, Profiling) 55.27 kB +0.03% +14 B 🔺
@sentry/browser (incl. Tracing, Replay) 92.83 kB +0.02% +11 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 81.62 kB +0.03% +18 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 97.22 kB +0.02% +12 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 110.61 kB +0.02% +12 B 🔺
@sentry/browser (incl. Feedback) 47.74 kB +0.04% +15 B 🔺
@sentry/browser (incl. sendFeedback) 30.7 kB +0.06% +16 B 🔺
@sentry/browser (incl. FeedbackAsync) 35.71 kB +0.05% +16 B 🔺
@sentry/browser (incl. Metrics) 31.44 kB +0.05% +15 B 🔺
@sentry/browser (incl. Logs) 31.72 kB +0.05% +15 B 🔺
@sentry/browser (incl. Metrics & Logs) 32.38 kB +0.06% +19 B 🔺
@sentry/react 32.13 kB +0.05% +16 B 🔺
@sentry/react (incl. Tracing) 54.97 kB +0.04% +17 B 🔺
@sentry/vue 38.31 kB +0.06% +21 B 🔺
@sentry/vue (incl. Tracing) 55.26 kB +0.03% +16 B 🔺
@sentry/svelte 30.13 kB +0.05% +14 B 🔺
@sentry/remix (Remix 3 client bundle) 58.08 kB +0.03% +17 B 🔺
CDN Bundle 31.89 kB +0.06% +16 B 🔺
CDN Bundle (incl. Tracing) 52.72 kB +0.03% +14 B 🔺
CDN Bundle (incl. Logs, Metrics) 34.68 kB +0.05% +17 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) 55.28 kB +0.04% +17 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) 75.72 kB +0.03% +16 B 🔺
CDN Bundle (incl. Tracing, Replay) 90.74 kB +0.02% +17 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 93.34 kB +0.02% +13 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 96.11 kB +0.02% +17 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 98.7 kB +0.02% +15 B 🔺
CDN Bundle - uncompressed 93.05 kB +0.07% +65 B 🔺
CDN Bundle (incl. Tracing) - uncompressed 155.52 kB +0.05% +65 B 🔺
CDN Bundle (incl. Logs, Metrics) - uncompressed 101.39 kB +0.07% +65 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 163.15 kB +0.04% +65 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 231.51 kB +0.03% +65 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 275.67 kB +0.03% +65 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 283.3 kB +0.03% +65 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 287.47 kB +0.03% +65 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 295.09 kB +0.03% +65 B 🔺
@sentry/nextjs (client) 58.59 kB +0.04% +20 B 🔺
@sentry/sveltekit (client) 53.59 kB +0.04% +18 B 🔺
@sentry/core/server 44.8 kB - -
@sentry/core/browser 14.4 kB - -
@sentry/node 151.37 kB +0.01% +2 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 83.3 kB - -
@sentry/node - without tracing 88.57 kB +0.01% +8 B 🔺
@sentry/node - without channel injection 140.32 kB +0.01% +7 B 🔺
@sentry/aws-serverless 98.94 kB +0.01% +4 B 🔺
@sentry/cloudflare (withSentry) - minified 206.56 kB +0.05% +95 B 🔺
@sentry/cloudflare (withSentry) 479.47 kB +0.06% +250 B 🔺
@sentry/nextjs/cloudflare (withSentry) - minified 231.93 kB +0.05% +95 B 🔺

View base workflow run

The transport keeps the rate limits across responses. Typing them as readonly makes a direct write to a deadline fail to compile, so the transport can only replace them with the result of `updateRateLimits`, which never shortens a limit. This also removes the comment on the writer callback.
@szokeasaurusrex
szokeasaurusrex marked this pull request as ready for review November 16, 2026 13:17
@szokeasaurusrex
szokeasaurusrex requested review from a team and JPeer264 November 16, 2026 13:17
@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Optional E2E tests

Some optional checks were not successful. They do not block the merge. 2 not successful, 61 successful. See the run.

Check Status
❌ CI: Optional E2E Tests / E2E nextjs-16-cacheComponents (cloudflare) Test (optional) Failing after 10m Details
❌ CI: Optional E2E Tests / E2E cloudflare-workers-send-to-sentry Test (optional) Failing after 5m Details
Successful checks
Check Status
✅ CI: Optional E2E Tests / E2E cloudflare-agent Test (optional) Successful in 37s Details
✅ CI: Optional E2E Tests / E2E cloudflare-workers-without-tracing-send-to-sentry Test (optional) Successful in 56s Details
✅ CI: Optional E2E Tests / E2E cloudflare-think (ai v6) Test (optional) Successful in 56s Details
✅ CI: Optional E2E Tests / E2E debug-id-sourcemaps Test (optional) Successful in 47s Details
✅ CI: Optional E2E Tests / E2E nestjs-12 (bun) Test (optional) Successful in 48s Details
✅ CI: Optional E2E Tests / E2E cloudflare-pi-durable Test (optional) Successful in 41s Details
✅ CI: Optional E2E Tests / E2E nextjs-15 (turbo) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nextjs-orpc Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (vinext, bun) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nestjs-12 (cloudflare) Test (optional) Successful in 33s Details
✅ CI: Optional E2E Tests / E2E astro-7-static Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nestjs-12 (deno) Test (optional) Successful in 59s Details
✅ CI: Optional E2E Tests / E2E gen-ai-libraries Test (optional) Successful in 47s Details
✅ CI: Optional E2E Tests / E2E node-eve (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E supabase-nextjs Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E deno (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-express-mcp-v1 Test (optional) Successful in 24s Details
✅ CI: Optional E2E Tests / E2E cloudflare-mastra Test (optional) Successful in 55s Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (vinext) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E cloudflare-think Test (optional) Successful in 57s Details
✅ CI: Optional E2E Tests / E2E gen-ai-libraries (cloudflare) Test (optional) Successful in 42s Details
✅ CI: Optional E2E Tests / E2E node-eve Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-16-tunnel (cloudflare) Test (optional) Successful in 56s Details
✅ CI: Optional E2E Tests / E2E cloudflare-pi-durable (latest) Test (optional) Successful in 47s Details
✅ CI: Optional E2E Tests / E2E node-openai-decisions (latest) Test (optional) Successful in 26s Details
✅ CI: Optional E2E Tests / E2E node-pi-durable Test (optional) Successful in 34s Details
✅ CI: Optional E2E Tests / E2E nuxt-5-tunnel Test (optional) Successful in 38s Details
✅ CI: Optional E2E Tests / E2E astro-7 Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-mastra Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-express-send-to-sentry-static Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (cloudflare, latest) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (client source maps kept) Test (optional) Successful in 31s Details
✅ CI: Optional E2E Tests / E2E node-fastify-6 Test (optional) Successful in 33s Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (static / nuxt generate) Test (optional) Successful in 33s Details
✅ CI: Optional E2E Tests / E2E nuxt-5-cloudflare Test (optional) Successful in 34s Details
✅ CI: Optional E2E Tests / E2E nuxt-5 (kv-cache) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-flue Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-15 (latest) Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E nuxt-5 Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-sourcemaps Test (optional) Successful in 31s Details
✅ CI: Optional E2E Tests / E2E node-express-send-to-sentry Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-mastra (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E cloudflare-flue-send-to-sentry Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E react-send-to-sentry Test (optional) Successful in 4m Details
✅ CI: Optional E2E Tests / E2E react-router-7-framework-instrumentation Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E node-openai-decisions Test (optional) Successful in 27s Details
✅ CI: Optional E2E Tests / E2E node-pi-durable (latest) Test (optional) Successful in 32s Details
✅ CI: Optional E2E Tests / E2E node-eve (orchestrion) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-eve (content off, latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nuxt-5 (development) Test (optional) Successful in 55s Details
✅ CI: Optional E2E Tests / E2E node-express-mcp-v2 Test (optional) Successful in 28s Details
✅ CI: Optional E2E Tests / E2E nextjs-14 (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E gen-ai-libraries (latest) Test (optional) Successful in 49s Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-cloudflare Test (optional) Successful in 35s Details
✅ CI: Optional E2E Tests / E2E solidstart-2-tunnel Test (optional) Successful in 45s Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps Test (optional) Successful in 38s Details
✅ CI: Optional E2E Tests / E2E solidstart-2 Test (optional) Successful in 55s Details
✅ CI: Optional E2E Tests / E2E nestjs-12 (latest) Test (optional) Successful in 49s Details
✅ CI: Optional E2E Tests / E2E vue-3 (no Options API) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-flue (latest) Test (optional) Successful in 1m Details

@JPeer264 JPeer264 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for bringing that to our SDK as well

With the longest entry in the middle of the header, the test fails if the code keeps the first or the last entry for a category instead of the longest one.
@JPeer264
JPeer264 merged commit d25e075 into develop Nov 17, 2026
467 of 469 checks passed
@JPeer264
JPeer264 deleted the fix/core-keep-longest-rate-limit branch November 17, 2026 15:09
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.

Rate limits from later headers shorten longer active limits

2 participants