Skip to content

fix(core): address the #656 rate-limit review follow-ups - #740

Merged
d-klotz merged 7 commits into
nextfrom
feat/core-rate-limit-followups
Nov 24, 2026
Merged

d-klotz merged 7 commits into
nextfrom
feat/core-rate-limit-followups

Conversation

@d-klotz

@d-klotz d-klotz commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Stacked on #656. Fixes the 5 non-blocking notes from the #656 review (seanspeaks, review 6003031198). One commit per note, each test-first.

Changes

  1. RateLimitError type (acb78b8b): types/core/index.d.ts re-exports it from @friggframework/errors. New types/core/index.test.js compiles a strict TS consumer of @friggframework/core; it gave TS2305 before the fix.
  2. requestTimeoutMs: 0 reserve (48c92254): 0, null or missing now means "no request timeout", so inProcessBudgetMs keeps the largest reserve, half the time left. With no deadline it keeps none. Fits ADR-049 §2 ("the request timeout, or half the time left when that is smaller").
  3. Millisecond reset deltas (e27965b3): opt-in static rateLimit.resetDeltaUnit = 'ms'. No size rule works: 60000 s (16.7 h) is also a real daily reset. HubSpot, Pipedrive and Salesforce in api-module-library#102 send no ms delta (Pipedrive x-ratelimit-reset is seconds; HubSpot's X-HubSpot-RateLimit-Interval-Milliseconds is an interval no parser reads). Epoch s/ms rules stay as they are. An unknown unit throws a TypeError, like an unknown parser. Types updated.
  4. 429 over HTTP (4b0843c3): the express boundary (handlers/app-handler-helpers.js) and the user-facing createHandler catch map any error with isRateLimited to 429, Retry-After in seconds from retryAt (none when unknown) and { error: 'Too Many Requests', retryAt }. One WARN record per request (frigg.http.request_rate_limited / frigg.handler.rate_limited) with the error, so the serializer adds retryAt and reason. The mapping lives in the HTTP adapter (core/rate-limited-response.js), not on the error. Server-to-server handlers still rethrow, so the queue worker can defer (feat(core): defer rate-limited queue messages through a RATE_LIMITED event #657).
  5. classify warning (0c48fec5): Rate Limits reference warns that a classify that names a non-limit (a 404) as a limit makes up to 10 hinted retries, then throws RateLimitError. A requester test pins that (mutating MAX_HINTED_RETRIES breaks it).

Decisions to check

  • 429, not 503 for item 4: the default scope counts the limit against the caller's own entity, clients handle 429 + Retry-After, and a 503 fires 5xx alarms for an expected state. Easy to flip in one file if you prefer 503.
  • Opt-in unit, not a heuristic for item 3.

Tests

  • cd packages/core && npx jest -i: 212/212 suites, 3042/3042 tests pass.
  • ESLint on changed files: 0 errors (2 warnings on unchanged lines). Package-wide errors are only in *.md and types/tsconfig.json, which this PR does not touch.

Caveats

  • FetchError, HaltError and the other errors are also not declared on @friggframework/core types (only on @friggframework/errors). Out of scope here; separate follow-up.

🤖 Generated with Claude Code

d-klotz and others added 5 commits November 24, 2026 06:23
index.js re-exports RateLimitError at runtime, but types/core/index.d.ts
did not declare it, so a strict TypeScript import gave TS2305. Re-export
the declaration from @friggframework/errors and type-check a strict
consumer in a test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
inProcessBudgetMs read requestTimeoutMs: 0 as a 0 ms reserve, so a
Requester with no request timeout could sleep until the invocation
deadline and leave no time for the next request. 0, null or a missing
value means the request has no time limit, so keep the largest reserve:
half the time left. With no deadline there is nothing to keep.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
parseResetValue read a millisecond delta such as X-RateLimit-Reset:
60000 as 60000 s. The size of a delta cannot show its unit: 60000 s
(16.7 h) is also a real daily reset, and HubSpot, Pipedrive and
Salesforce (api-module-library#102) send no millisecond delta. So a
module that gets one declares static rateLimit.resetDeltaUnit = 'ms'.
Epoch seconds and epoch milliseconds keep their size rules, and an
unknown unit throws a TypeError, like an unknown parser.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The express boundary and the user-facing createHandler catch answered
a RateLimitError with a generic 500. Both now map any error with
isRateLimited to 429, Retry-After in seconds from retryAt (none when
retryAt is unknown) and { error: 'Too Many Requests', retryAt }, and
log one WARN record with the error. The mapping lives in the HTTP
adapter (core/rate-limited-response.js), not in the error. A
server-to-server handler still rethrows, so the queue worker can defer.

429, not 503: the default scope counts the limit against the caller's
own entity, and a 503 would fire 5xx alarms for an expected state.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A classify that names a 404 (or another response that is not a limit)
as a limit with a time makes the Requester retry it up to 10 times
and then throw RateLimitError. Say so in the Rate Limits reference,
and pin the behaviour with a test so the warning stays true.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@d-klotz d-klotz added release Create a release when this pr is merged prerelease This change is available in a prerelease. labels Nov 24, 2026

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Code review skipped — your organization has no extra usage available to pay for this review.

If your organization's extra usage balance is empty, an organization admin can add extra usage credits at claude.ai/admin-settings/usage. If its monthly spend limit was reached, an admin can raise it on the same page. If neither applies, contact Anthropic support.

Once extra usage is available, someone with write access to this repository can comment @claude review on this pull request to trigger a review.

@cursor

cursor Bot commented Nov 24, 2026

Copy link
Copy Markdown

Bugbot is paused — on-demand spend limit reached

Bugbot uses usage-based billing for this team and has hit its on-demand spend limit.

A team admin can raise the spend limit in the Cursor dashboard, or wait for the next billing cycle to continue.

d-klotz added a commit that referenced this pull request Nov 24, 2026
Add resetDeltaUnit for a reset delta in milliseconds, the 429 answer of an
HTTP route, scopeKey on the rate-limited token error, and the queue
actions that the functions get on an external queue.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…it-followups

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@d-klotz
d-klotz changed the base branch from feat/core-rate-limit-requester to next November 24, 2026 19:09
Keeps the requestTimeoutMs: 0 note from this branch and the 0 s queue-worker budget from #657.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@netlify

netlify Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

👷 Deploy Preview for friggframework-org processing.

Name Link
🔨 Latest commit ce06ea0
🔍 Latest deploy log https://app.netlify.com/projects/friggframework-org/deploys/6b05e16fbbb9253bb2f2e5fc

@d-klotz
d-klotz merged commit 1db342c into next Nov 24, 2026
13 of 14 checks passed
@sonarqubecloud

Copy link
Copy Markdown

@seanspeaks

Copy link
Copy Markdown
Contributor

🚀 PR was released in v2.0.0-next.129 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

prerelease This change is available in a prerelease. release Create a release when this pr is merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants