Skip to content

refactor(ratelimit): record procedure and path with each rate-limit check - #1885

Merged
dinwwwh merged 1 commit into
middleapi:mainfrom
dinwwwh:feat/ratelimit-check-context
Aug 18, 2026
Merged

refactor(ratelimit): record procedure and path with each rate-limit check#1885
dinwwwh merged 1 commit into
middleapi:mainfrom
dinwwwh:feat/ratelimit-check-context

Conversation

@dinwwwh

@dinwwwh dinwwwh commented Aug 18, 2026

Copy link
Copy Markdown
Member

The ratelimit handler plugin context now records which procedure each rate-limit check ran on. Each entry in the plugin context is { procedure, path, result } (renamed from a bare RateLimitResult[] under results to checks), so response interceptors and future consumers can tell which procedure produced which limit result.

Changes

  • The ratelimit middleware pushes the current procedure and path alongside the limiter result into the handler plugin context.
  • Header selection behavior is unchanged: the plugin still picks the most constrained result across all checks for the ratelimit-* and retry-after headers.

Testing

  • Plugin and middleware tests updated to the new entry shape; all ratelimit tests pass.
  • pnpm type:check passes across all packages.

@vercel

vercel Bot commented Aug 18, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
orpc Ready Ready Preview Aug 18, 2026 4:35am

@pkg-pr-new

pkg-pr-new Bot commented Aug 18, 2026

Copy link
Copy Markdown
More templates

@orpc/ai-sdk

npm i https://pkg.pr.new/@orpc/ai-sdk@1885

@orpc/arktype

npm i https://pkg.pr.new/@orpc/arktype@1885

@orpc/bun

npm i https://pkg.pr.new/@orpc/bun@1885

@orpc/client

npm i https://pkg.pr.new/@orpc/client@1885

@orpc/cloudflare

npm i https://pkg.pr.new/@orpc/cloudflare@1885

@orpc/contract

npm i https://pkg.pr.new/@orpc/contract@1885

@orpc/experimental-effect

npm i https://pkg.pr.new/@orpc/experimental-effect@1885

@orpc/evlog

npm i https://pkg.pr.new/@orpc/evlog@1885

@orpc/hibernation

npm i https://pkg.pr.new/@orpc/hibernation@1885

@orpc/json-schema

npm i https://pkg.pr.new/@orpc/json-schema@1885

@orpc/nest

npm i https://pkg.pr.new/@orpc/nest@1885

@orpc/next

npm i https://pkg.pr.new/@orpc/next@1885

@orpc/node

npm i https://pkg.pr.new/@orpc/node@1885

@orpc/openapi

npm i https://pkg.pr.new/@orpc/openapi@1885

@orpc/opentelemetry

npm i https://pkg.pr.new/@orpc/opentelemetry@1885

@orpc/pinia-colada

npm i https://pkg.pr.new/@orpc/pinia-colada@1885

@orpc/pino

npm i https://pkg.pr.new/@orpc/pino@1885

@orpc/publisher

npm i https://pkg.pr.new/@orpc/publisher@1885

@orpc/ratelimit

npm i https://pkg.pr.new/@orpc/ratelimit@1885

@orpc/server

npm i https://pkg.pr.new/@orpc/server@1885

@orpc/shared

npm i https://pkg.pr.new/@orpc/shared@1885

@orpc/swr

npm i https://pkg.pr.new/@orpc/swr@1885

@orpc/tanstack-query

npm i https://pkg.pr.new/@orpc/tanstack-query@1885

@orpc/trpc

npm i https://pkg.pr.new/@orpc/trpc@1885

@orpc/valibot

npm i https://pkg.pr.new/@orpc/valibot@1885

@orpc/zod

npm i https://pkg.pr.new/@orpc/zod@1885

commit: 687e0cd

@codecov

codecov Bot commented Aug 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@codspeed-hq

codspeed-hq Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 30 untouched benchmarks


Comparing dinwwwh:feat/ratelimit-check-context (687e0cd) with main (b6a88ad)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (b084274) during the generation of this report, so b6a88ad was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ℹ️ Minor suggestions only — the feature works and is well-covered; one stale doc comment inline.

Reviewed changes

  • Record procedure & path per check (middleware.ts): the ratelimit middleware now pushes { path, procedure, result } into the handler plugin context instead of a bare result.
  • Rename & reshape plugin context (handler-plugin.ts): results: RateLimitResult[] becomes checks: { procedure, path, result }[]; the header-selection and retry-after logic now reads .result.* with identical semantics.
  • Tests updated (middleware.test.ts, handler-plugin.test.ts): assertions migrated to the new entry shape; the middleware test asserts the recorded path and procedure exactly, so it fails if the feature regresses.

The types are consistent (MiddlewareOptions.path: string[] / procedure: AnyProcedure), the rename has no in-repo consumers outside packages/ratelimit, and the dedupe short-circuit reflecting no limiter call is coherent. Looks good.

Pullfrog  | Fix all ➔Fix 👍s ➔View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Comment thread packages/ratelimit/src/handler-plugin.ts
@dinwwwh dinwwwh changed the title feat(ratelimit): record procedure and path with each rate-limit check refactor(ratelimit): record procedure and path with each rate-limit check Aug 18, 2026
@dinwwwh
dinwwwh merged commit a8a244d into middleapi:main Aug 18, 2026
12 checks passed
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.

1 participant