Repository navigation
feat: declare the rate-limit policy of the HubSpot, Salesforce and Pipedrive modules - #102
Conversation
HubSpot limits each account that installs a marketplace OAuth app to 110 requests per 10 seconds, and answers a throttled call with a 429 whose body names the limit in `policyName`. The Requester met every such 429 with its fixed 1, 3, 10, 30, 60 and 180 second ladder, whatever the response said. Declare `static rateLimit` so the Requester can use what the response says: - A burst 429 (`TEN_SECONDLY_ROLLING`) returns a reason-only hint. A real `Retry-After` then wins, and the 10 second burst window is the fallback. - A `DAILY` 429 returns a one hour probe (`source: 'static'`). HubSpot resets the daily limit at midnight in the account's time zone, which the module does not know, so no UTC reset time is computed. One hour is over the in-process budget, so the Requester throws a `RateLimitError` with `reason: 'daily'` and `retryAt` and does not sleep. - Any other status is not a limit. - `userHints.daily.links` points at the API usage guidelines. `maxConcurrency` (10) is a pacing figure that HubSpot does not document. It is declared for the pacing phase and nothing reads it yet. The tests use recorded-style 429 responses and a stubbed fetch. They need a `@friggframework/core` that exports `RateLimitError` (friggframework/frigg#656). The dependency range is unchanged until the release that ships it is known. Refs ADR-049. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Salesforce counts the API calls of an org over a rolling 24 hours. An org over its limit gets a 403 whose error code is `REQUEST_LIMIT_EXCEEDED`, and no reset time. The module drives jsforce, not the Requester, and a jsforce error has no `statusCode` (`HttpApiError`: `name` equals `errorCode`), so the Requester never sees it and the queue worker gets an opaque error. `REQUEST_LIMIT_EXCEEDED` is also the error for too many concurrent requests that run 20 seconds or longer, which clears in seconds. Reporting it as a daily limit would put a sync on hold for an hour. - Declare `static rateLimit`: a per-org daily rolling window and a `classify` that recognises `REQUEST_LIMIT_EXCEEDED`. Salesforce documents no field that tells the two limits apart, so `classify` reads the message: one that contains "concurrent" is a concurrency limit with a 30 second wait, and any other message is a daily limit. The message text is not documented, so the default stays daily. With no reset time to read, a daily limit gets a static one hour probe. Both reasons link to the API request limits page. - Add the public `withLimits(call)`. On a failed call it runs `classifyRateLimit` and throws a `RateLimitError`, with the jsforce error kept as `cause`. It rethrows any other error unchanged. The data methods use it. A consumer that calls `api.conn` directly wraps its own calls with `api.withLimits(() => api.conn.query(soql))`, as the README says. - Before it throws, `withLimits` tells the delegate with `_notifyRateLimited`, as the Requester does when it throws a `RateLimitError`, so the integration can record a warning for the user. Core writes that warning only for a limit longer than its in-process cap, so the daily limit gets one and the 30 second concurrency limit does not. A core without that method skips the call. - `module` on the error is `_telemetryModuleLabel()`, the label the Requester puts on its own `RateLimitError`. An API instance has no `name`. `RateLimitError` and `classifyRateLimit` come from `@friggframework/core` (friggframework/frigg#656) and are read at runtime. The dependency range is unchanged. On a core that does not export both yet, `withLimits` rethrows the original jsforce error, so the module can be released before an app upgrades its core. The token and refresh code is untouched, and `conn.limitInfo` is not read yet. Refs ADR-049. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Pipedrive limits an OAuth app per token over a rolling 2 second window and sends `x-ratelimit-reset` with the throttled response. A recorded 429 also carries `Retry-After`. The Requester met every such 429 with its fixed 1, 3, 10, 30, 60 and 180 second ladder. Declare `static rateLimit`: - `scope: 'entity'` and a burst window of 80 requests per 2 seconds. That is the lowest OAuth allowance in the docs (Lite 80, Growth 160, Premium 400, Ultimate 480). Pipedrive reports the real figure in `x-ratelimit-limit`. - `parsers: ['retryAfter', 'resetHeaders']`, the two header families Pipedrive sends. `x-ratelimit-reset` is a wait in seconds. - No `classify`. A spent daily token budget answers with a 429 and no documented wait time. Unless the response carries one of those headers, it keeps the fixed ladder and then the redelivery it has today. Add `RateLimitPolicy` and the types it uses to the module's `frigg-core.d.ts` shim, copied from the core types (friggframework/frigg#656). The subclass declares its own static, so the shim's `OAuth2Requester` needs no change. Core reads `x-ratelimit-reset` by default, so the wait tests characterise the behaviour with recorded headers, and the declaration test pins the numbers. The tests need a `@friggframework/core` with rate-limit awareness. The dependency range is unchanged until the release that ships it is known. Refs ADR-049. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
358b809 to
1b8f325
Compare
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1b8f32580a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| RateLimitError, | ||
| classifyRateLimit, |
There was a problem hiding this comment.
Upgrade core before using the rate-limit exports
A clean npm ci still resolves the committed core versions (next.89 for HubSpot, next.75 for Pipedrive, and next.110 for Salesforce), which predate RateLimitError, classifyRateLimit, and requester support for static rateLimit. Consequently the new Salesforce/HubSpot tests receive undefined for these exports, while the HubSpot and Pipedrive policies are silently ignored in production. Update each module's core dependency and the lockfile to the release that provides this API before landing the feature.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed, this blocks the merge. The exports ship with frigg#656, which is not released yet. Once it is, I bump @friggframework/core in all three modules and the lockfile (npm 10). Leaving this open until then.
The CRM search endpoints have their own limit of 5 requests per second per account. A throttled search returns 429 with policyName SECONDLY and no rate-limit headers, so the Requester waited the 10 second burst window. classify now gives a 1 second wait for SECONDLY, and the policy declares the search window. The probe interval test now sets the in-process budget through runWithInvocationDeadline: core no longer reads maxInProcessWaitMs from the module policy. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Core no longer reads maxInProcessWaitMs from the module policy. The caller sets the in-process budget through runWithInvocationDeadline. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
HubSpot, Salesforce and Pipedrive declare rate-limit policies that only core 2.0.0-next.129 reads (ADR-049: RateLimitError, classifyRateLimit and the RATE_LIMITED queue event). Raise the range of the three modules to ^2.0.0-next.129 and drop the HubSpot README note about cores without rate-limit awareness. Lockfile updated with npm 10.8.2, the npm of the Node 18 release job. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…mits Core 2.0.0-next.129 exports RateLimitError and classifyRateLimit and records the user warning from the RATE_LIMITED event of the queue worker, so withLimits no longer: - calls _notifyRateLimited, which this core does not have; - returns the jsforce error when the rate-limit exports are missing. The tests for both fallbacks go with them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The RateLimitPolicy types were copied from core into frigg-core.d.ts before core was released. Core ships them only as ambient declarations that this module's build does not load, so the static is now an untyped literal. The rateLimit test still pins the declared values. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…dget Pipedrive rejects every call with a 429 once a company's daily token budget is spent, until midnight server time. The module had no classify, so the Requester read x-ratelimit-reset and retried every 2 seconds. Pipedrive documents no header or body that marks the daily budget. x-ratelimit-remaining is documented as the requests left in the 2 second burst window, so a 429 that still has requests left there is not the burst limit. classify reports it as reason 'daily' with a static one hour probe, and links the rate limiting guide. A 429 with no requests left, or without the header, keeps its current handling. Also declare the search limit of 10 requests per 2 seconds. classify receives only the status, headers and body, not the URL, so a throttled search cannot be told apart and is handled like any other 429. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…as burst 3d7189f read any 429 with requests left in the 2 second window as the spent daily budget and held it for an hour. Pipedrive documents no marker for that 429, and a throttled search (10 per 2 seconds) can arrive with burst requests left, so a search would wait an hour instead of about 2 seconds. Remove the rule, its probe constant, the daily user hint and the search window, which core never reads. classify now returns reason 'burst' for a 429 with x-ratelimit-remaining of 0, so its RateLimitError is no longer 'unknown'. Retry-After and x-ratelimit-reset still supply the wait. The README lists the daily budget and the search limit as known gaps. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The search window: classify returns reason 'burst' for SECONDLY and core picks a window only by reason, so a window named search is never read. The 1 second SECONDLY wait stays. - maxConcurrency: core does not pace on it, and HubSpot documents no concurrency figure. - The resetHeaders parser: HubSpot sends X-HubSpot-RateLimit-* headers, not x-ratelimit-reset. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
HubSpot's docs name DAILY and TEN_SECONDLY_ROLLING, not SECONDLY, so the README says the module treats SECONDLY as the search limit if it appears. It also gives the burst limits of privately distributed apps next to the 110 per 10 seconds of marketplace apps. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The HubSpot, Salesforce and Pipedrive modules now tell the Frigg Requester their provider's limits and how to read a throttled response. HubSpot and Pipedrive declare a
static rateLimit. Salesforce also getswithLimits, because its calls go through jsforce, not through the Requester. This is phase 3 of ADR-049 (friggframework/frigg#655).Depends on
@friggframework/core@2.0.0-next.129, which ships ADR-049 (friggframework/frigg#656, friggframework/frigg#657, friggframework/frigg#740). The three modules require^2.0.0-next.129. No core work is pending.What each module declares
retryAfterparser. A privately distributed app gets 100, 190 or 250 per 10 s by tier; the module declares the marketplace figure. HubSpot's docs name twopolicyNamevalues,DAILYandTEN_SECONDLY_ROLLING.classifyreadspolicyNamefrom the 429 body:DAILYis a daily limit with a one hour probe. HubSpot resets it at midnight in the account's time zone, which the module cannot know.SECONDLYis not in HubSpot's docs. If it appears, the module reads it as the CRM search limit (5 per second per account) and waits 1 s.Retry-Afterwins and the 10 s window is the fallback.REQUEST_LIMIT_EXCEEDED(a 403 with nostatusCodein jsforce) is a daily limit with a one hour probe: the window is a rolling 24 hours and has no reset time. The same code means too many concurrent long-running requests; a message that contains "concurrent" is a concurrency limit with a 30 s wait. The data methods go through the publicwithLimits(call), which throws aRateLimitErrorwith the jsforce error ascause. A caller that usesapi.connwraps its own calls.retryAfterandresetHeadersparsers.classifyreports a 429 withx-ratelimit-remaining: 0as a burst limit; the headers supply the wait.Each README has a "Rate limits" section.
Behaviour change
SECONDLY), or theRetry-Afterwhen there is one, instead of the 1 s of the fixed ladder.reason: 'burst'instead of'unknown'. Its wait does not change.Known gaps
x-daily-requests-leftcovers onlyapi_tokenPOST/PUT requests, counted in UTC; this module uses OAuth.classifyonly the status, headers and body, not the URL, and reads a window only when its name is the hint's reason. A throttled search gets the wait of any other 429.Fixing either needs a real 429 sample that marks it, or a core that passes the URL to
classify.Caveats
withLimitsran against real jsforce 3.10.14 and a local server that answersREQUEST_LIMIT_EXCEEDED.RateLimitErrorhas noscopeKey. The Requester computes one;withLimitsdoes not, so theRATE_LIMITEDevent of a Salesforce limit carriesscopeKey: undefined.static rateLimitis untyped. Core shipsRateLimitPolicyonly as an ambient declaration that the module's build does not load. The tests pin the values.RateLimitErrormessage readsGET <instance url> REQUEST_LIMIT_EXCEEDED, because jsforce does not say which verb failed.packages/v1-ready/salesforce/streamHandler.jshas a Salesforce consumer key and secret in the source, and a deadnforceimport. Rotate that secret and delete the file in a separate PR.Test plan
Against
@friggframework/core@2.0.0-next.129, lockfile from npm 10.8.2 (the release job's Node 18):npx jest tests/rateLimit.test.js: 10 pass.npm run test:unit: 75 pass.npx vitest run test/rateLimit.test.ts: 7 pass.tsc --noEmit: clean.@friggframework/eslint-config) on the changed files: 0 errors.🤖 Generated with Claude Code
📦 Published PR as canary version:
Canary Versions✨ Test out this PR locally via:
npm install @friggframework/api-module-hubspot@1.1.8-canary.102.8b6ec50.0 npm install @friggframework/api-module-pipedrive@2.0.1-canary.102.8b6ec50.0 npm install @friggframework/api-module-salesforce@1.0.3-canary.102.8b6ec50.0 # or yarn add @friggframework/api-module-hubspot@1.1.8-canary.102.8b6ec50.0 yarn add @friggframework/api-module-pipedrive@2.0.1-canary.102.8b6ec50.0 yarn add @friggframework/api-module-salesforce@1.0.3-canary.102.8b6ec50.0Version
Published prerelease version:
@friggframework/api-module-hubspot@2.0.0-next.10@friggframework/api-module-pipedrive@2.1.0-next.8@friggframework/api-module-salesforce@2.0.0-next.10Changelog
🚀 Enhancement
@friggframework/api-module-hubspot,@friggframework/api-module-pipedrive,@friggframework/api-module-salesforce@friggframework/api-module-microsoft-teams,@friggframework/api-module-slack,@friggframework/api-module-42matters,@friggframework/api-module-asana,@friggframework/api-module-attio,@friggframework/api-module-clio,@friggframework/api-module-connectwise,@friggframework/api-module-contentful,@friggframework/api-module-contentstack,@friggframework/api-module-crossbeam,@friggframework/api-module-deel,@friggframework/api-module-fathom,@friggframework/api-module-fireflies,@friggframework/api-module-freshbooks,@friggframework/api-module-frigg-scale-test,@friggframework/api-module-frontify,@friggframework/api-module-gong,@friggframework/api-module-google-calendar,@friggframework/api-module-google-drive,@friggframework/api-module-helpscout,@friggframework/api-module-hubspot,@friggframework/api-module-ironclad,@friggframework/api-module-linear,@friggframework/api-module-otter,@friggframework/api-module-pipedrive,@friggframework/api-module-quo,@friggframework/api-module-reevo,@friggframework/api-module-salesforce,@friggframework/api-module-stripe,@friggframework/api-module-unbabel-projects,@friggframework/api-module-unbabel,@friggframework/api-module-zoho-crm,@friggframework/api-module-zoom🐛 Bug Fix
@friggframework/api-module-microsoft-teams,@friggframework/api-module-slack,@friggframework/api-module-42matters,@friggframework/api-module-asana,@friggframework/api-module-attio,@friggframework/api-module-clio,@friggframework/api-module-connectwise,@friggframework/api-module-contentful,@friggframework/api-module-contentstack,@friggframework/api-module-crossbeam,@friggframework/api-module-deel,@friggframework/api-module-fathom,@friggframework/api-module-fireflies,@friggframework/api-module-frigg-scale-test,@friggframework/api-module-frontify,@friggframework/api-module-gong,@friggframework/api-module-google-calendar,@friggframework/api-module-google-drive,@friggframework/api-module-helpscout,@friggframework/api-module-hubspot,@friggframework/api-module-ironclad,@friggframework/api-module-linear,@friggframework/api-module-otter,@friggframework/api-module-pipedrive,@friggframework/api-module-quo,@friggframework/api-module-reevo,@friggframework/api-module-salesforce,@friggframework/api-module-stripe,@friggframework/api-module-unbabel-projects,@friggframework/api-module-unbabel,@friggframework/api-module-zoho-crm,@friggframework/api-module-zoomAuthors: 1