Skip to content

feat: declare the rate-limit policy of the HubSpot, Salesforce and Pipedrive modules - #102

Merged
d-klotz merged 12 commits into
nextfrom
feat/rate-limit-policies
Nov 25, 2026
Merged

d-klotz merged 12 commits into
nextfrom
feat/rate-limit-policies

Conversation

@d-klotz

@d-klotz d-klotz commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

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 gets withLimits, 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

  • HubSpot: 110 requests per 10 s for each account that installs a marketplace OAuth app, and the retryAfter parser. A privately distributed app gets 100, 190 or 250 per 10 s by tier; the module declares the marketplace figure. HubSpot's docs name two policyName values, DAILY and TEN_SECONDLY_ROLLING. classify reads policyName from the 429 body:
    • DAILY is a daily limit with a one hour probe. HubSpot resets it at midnight in the account's time zone, which the module cannot know.
    • SECONDLY is 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.
    • Any other 429 is a burst limit that names only its reason, so a real Retry-After wins and the 10 s window is the fallback.
  • Salesforce: REQUEST_LIMIT_EXCEEDED (a 403 with no statusCode in 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 public withLimits(call), which throws a RateLimitError with the jsforce error as cause. A caller that uses api.conn wraps its own calls.
  • Pipedrive: a rolling 2 s window of 80 requests (the lowest OAuth plan) and the retryAfter and resetHeaders parsers. classify reports a 429 with x-ratelimit-remaining: 0 as a burst limit; the headers supply the wait.

Each README has a "Rate limits" section.

Behaviour change

  • Every HubSpot 429 now has a hint, so the first retry waits 10 s (1 s for SECONDLY), or the Retry-After when there is one, instead of the 1 s of the fixed ladder.
  • A Pipedrive 429 with no requests left in the 2 s window now has reason: 'burst' instead of 'unknown'. Its wait does not change.

Known gaps

  • The Pipedrive daily token budget is not classified. Pipedrive's rate limiting guide documents no header, body or error text for a spent budget, and no 429 body at all. A spent budget retries on the burst hint until midnight server time. x-daily-requests-left covers only api_token POST/PUT requests, counted in UTC; this module uses OAuth.
  • The Pipedrive search limit (10 per 2 s) cannot be told apart. Core passes classify only 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

  • Not run against a live account. No call went to a HubSpot portal, a Salesforce org or a Pipedrive account. withLimits ran against real jsforce 3.10.14 and a local server that answers REQUEST_LIMIT_EXCEEDED.
  • The Salesforce concurrency check reads the error message. Its text is not documented, so the default stays daily.
  • The Salesforce RateLimitError has no scopeKey. The Requester computes one; withLimits does not, so the RATE_LIMITED event of a Salesforce limit carries scopeKey: undefined.
  • Pipedrive's static rateLimit is untyped. Core ships RateLimitPolicy only as an ambient declaration that the module's build does not load. The tests pin the values.
  • The Salesforce RateLimitError message reads GET <instance url> REQUEST_LIMIT_EXCEEDED, because jsforce does not say which verb failed.
  • Pre-existing, not changed here: packages/v1-ready/salesforce/streamHandler.js has a Salesforce consumer key and secret in the source, and a dead nforce import. 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):

  • HubSpot npx jest tests/rateLimit.test.js: 10 pass.
  • Salesforce npm run test:unit: 75 pass.
  • Pipedrive npx vitest run test/rateLimit.test.ts: 7 pass. tsc --noEmit: clean.
  • ESLint (@friggframework/eslint-config) on the changed files: 0 errors.
  • Live calls against a sandbox of each provider.

🤖 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.0

Version

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.10

Changelog

🚀 Enhancement

  • @friggframework/api-module-hubspot, @friggframework/api-module-pipedrive, @friggframework/api-module-salesforce
    • feat: declare the rate-limit policy of the HubSpot, Salesforce and Pipedrive modules #102 (@d-klotz)
  • @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
    • feat(freshbooks): add the FreshBooks API module (v1) #240 (@d-klotz)

🐛 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-zoom
    • fix(salesforce): persist rotated refresh tokens and route jsforce refreshes through core #101 (@d-klotz)

Authors: 1

@d-klotz d-klotz added prerelease This change is available in a prerelease. release labels Sep 29, 2026
d-klotz and others added 3 commits September 29, 2026 19:10
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>
@d-klotz
d-klotz force-pushed the feat/rate-limit-policies branch from 358b809 to 1b8f325 Compare September 29, 2026 22:11
Comment thread packages/v1-ready/salesforce/api.js Resolved
@d-klotz
d-klotz marked this pull request as ready for review October 1, 2026 16:21
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-01T16:25:29.259211Z 1b8f325 Draft marked ready
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 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".

Comment on lines +4 to +5
RateLimitError,
classifyRateLimit,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Comment thread packages/v1-ready/hubspot/api.js Resolved
d-klotz and others added 2 commits November 9, 2026 18:49
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>
d-klotz and others added 3 commits November 25, 2026 16:29
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>
@d-klotz
d-klotz marked this pull request as ready for review November 25, 2026 19:31
d-klotz and others added 4 commits November 25, 2026 17:05
…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>
@d-klotz
d-klotz merged commit 9df1026 into next Nov 25, 2026
3 checks passed
@d-klotz
d-klotz deleted the feat/rate-limit-policies branch November 25, 2026 20:19
@seanspeaks

Copy link
Copy Markdown
Contributor

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants